diff options
author | Moonchild <mcwerewolf@gmail.com> | 2018-04-29 14:44:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-29 14:44:02 +0200 |
commit | dc35e5c26dfa8c7fe6d27f7bc96f7a6e3c02de9b (patch) | |
tree | 56d8df17bdaa6a4558c7b0ed887c9302766f347a /dom | |
parent | 65a580a4efedf51cc542fff8c12b487a2113b987 (diff) | |
parent | bdb4ff581677ad1cd411b55a68c87534f9a64882 (diff) | |
download | uxp-dc35e5c26dfa8c7fe6d27f7bc96f7a6e3c02de9b.tar.gz |
Merge pull request #292 from janekptacijarabaci/js_dom_performance-observer_1
moebius#157: The Performance Observer (improvements)
Diffstat (limited to 'dom')
-rwxr-xr-x | dom/performance/Performance.cpp | 21 | ||||
-rw-r--r-- | dom/performance/PerformanceEntry.h | 21 | ||||
-rw-r--r-- | dom/performance/PerformanceObserver.cpp | 14 | ||||
-rw-r--r-- | dom/performance/PerformanceObserverEntryList.cpp | 15 | ||||
-rw-r--r-- | dom/performance/tests/mochitest.ini | 2 | ||||
-rw-r--r-- | dom/performance/tests/performance_observer.html | 74 | ||||
-rw-r--r-- | dom/performance/tests/test_performance_observer.html | 52 | ||||
-rw-r--r-- | dom/performance/tests/test_worker_observer.html | 13 | ||||
-rw-r--r-- | dom/performance/tests/worker_performance_observer.html | 32 | ||||
-rw-r--r-- | dom/tests/mochitest/general/test_interfaces.html | 4 | ||||
-rw-r--r-- | dom/webidl/PerformanceObserver.webidl | 1 | ||||
-rw-r--r-- | dom/workers/test/serviceworkers/test_serviceworker_interfaces.js | 4 | ||||
-rw-r--r-- | dom/workers/test/test_worker_interfaces.js | 4 |
13 files changed, 107 insertions, 150 deletions
diff --git a/dom/performance/Performance.cpp b/dom/performance/Performance.cpp index 8dc239b05b..497bdea27f 100755 --- a/dom/performance/Performance.cpp +++ b/dom/performance/Performance.cpp @@ -38,27 +38,6 @@ using namespace workers; namespace { -// Helper classes -class MOZ_STACK_CLASS PerformanceEntryComparator final -{ -public: - bool Equals(const PerformanceEntry* aElem1, - const PerformanceEntry* aElem2) const - { - MOZ_ASSERT(aElem1 && aElem2, - "Trying to compare null performance entries"); - return aElem1->StartTime() == aElem2->StartTime(); - } - - bool LessThan(const PerformanceEntry* aElem1, - const PerformanceEntry* aElem2) const - { - MOZ_ASSERT(aElem1 && aElem2, - "Trying to compare null performance entries"); - return aElem1->StartTime() < aElem2->StartTime(); - } -}; - class PrefEnabledRunnable final : public WorkerCheckAPIExposureOnMainThreadRunnable { diff --git a/dom/performance/PerformanceEntry.h b/dom/performance/PerformanceEntry.h index bc4f84f1c2..0af9f669ec 100644 --- a/dom/performance/PerformanceEntry.h +++ b/dom/performance/PerformanceEntry.h @@ -90,6 +90,27 @@ protected: nsString mEntryType; }; +// Helper classes +class MOZ_STACK_CLASS PerformanceEntryComparator final +{ +public: + bool Equals(const PerformanceEntry* aElem1, + const PerformanceEntry* aElem2) const + { + MOZ_ASSERT(aElem1 && aElem2, + "Trying to compare null performance entries"); + return aElem1->StartTime() == aElem2->StartTime(); + } + + bool LessThan(const PerformanceEntry* aElem1, + const PerformanceEntry* aElem2) const + { + MOZ_ASSERT(aElem1 && aElem2, + "Trying to compare null performance entries"); + return aElem1->StartTime() < aElem2->StartTime(); + } +}; + } // namespace dom } // namespace mozilla diff --git a/dom/performance/PerformanceObserver.cpp b/dom/performance/PerformanceObserver.cpp index 11dd30ac23..d02acfb09a 100644 --- a/dom/performance/PerformanceObserver.cpp +++ b/dom/performance/PerformanceObserver.cpp @@ -114,12 +114,13 @@ PerformanceObserver::Notify() RefPtr<PerformanceObserverEntryList> list = new PerformanceObserverEntryList(this, mQueuedEntries); + mQueuedEntries.Clear(); + ErrorResult rv; mCallback->Call(this, *list, *this, rv); if (NS_WARN_IF(rv.Failed())) { rv.SuppressException(); } - mQueuedEntries.Clear(); } void @@ -170,6 +171,17 @@ PerformanceObserver::Observe(const PerformanceObserverInit& aOptions, mEntryTypes.SwapElements(validEntryTypes); mPerformance->AddObserver(this); + + if (aOptions.mBuffered) { + for (auto entryType : mEntryTypes) { + nsTArray<RefPtr<PerformanceEntry>> existingEntries; + mPerformance->GetEntriesByType(entryType, existingEntries); + if (!existingEntries.IsEmpty()) { + mQueuedEntries.AppendElements(existingEntries); + } + } + } + mConnected = true; } diff --git a/dom/performance/PerformanceObserverEntryList.cpp b/dom/performance/PerformanceObserverEntryList.cpp index 349103f08c..20e818f3d7 100644 --- a/dom/performance/PerformanceObserverEntryList.cpp +++ b/dom/performance/PerformanceObserverEntryList.cpp @@ -66,6 +66,7 @@ PerformanceObserverEntryList::GetEntries( aRetval.AppendElement(entry); } + aRetval.Sort(PerformanceEntryComparator()); } void @@ -79,6 +80,7 @@ PerformanceObserverEntryList::GetEntriesByType( aRetval.AppendElement(entry); } } + aRetval.Sort(PerformanceEntryComparator()); } void @@ -88,9 +90,18 @@ PerformanceObserverEntryList::GetEntriesByName( nsTArray<RefPtr<PerformanceEntry>>& aRetval) { aRetval.Clear(); + const bool typePassed = aEntryType.WasPassed(); for (const RefPtr<PerformanceEntry>& entry : mEntries) { - if (entry->GetName().Equals(aName)) { - aRetval.AppendElement(entry); + if (!entry->GetName().Equals(aName)) { + continue; } + + if (typePassed && + !entry->GetEntryType().Equals(aEntryType.Value())) { + continue; + } + + aRetval.AppendElement(entry); } + aRetval.Sort(PerformanceEntryComparator()); } diff --git a/dom/performance/tests/mochitest.ini b/dom/performance/tests/mochitest.ini index 18f7f0e455..7005637e1b 100644 --- a/dom/performance/tests/mochitest.ini +++ b/dom/performance/tests/mochitest.ini @@ -1,13 +1,11 @@ [DEFAULT] support-files = - performance_observer.html test_performance_observer.js test_performance_user_timing.js test_worker_performance_now.js worker_performance_user_timing.js worker_performance_observer.js sharedworker_performance_user_timing.js - worker_performance_observer.html [test_performance_observer.html] [test_performance_user_timing.html] diff --git a/dom/performance/tests/performance_observer.html b/dom/performance/tests/performance_observer.html deleted file mode 100644 index b8ced9296c..0000000000 --- a/dom/performance/tests/performance_observer.html +++ /dev/null @@ -1,74 +0,0 @@ -<!-- - Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ ---> -<!DOCTYPE html> -<meta charset=utf-8> -<html> -<head> -<title>Test for performance observer</title> -<script> -'use strict'; -[ - "promise_test", "test", "setup", - "assert_true", "assert_equals", "assert_array_equals", - "assert_throws", "assert_unreached" -].forEach(func => { - window[func] = opener[func].bind(opener); -}); -function done() { - opener.add_completion_callback(() => { - self.close(); - }); - opener.done(); -} - -</script> -<script src="test_performance_observer.js"></script> -</head> -<body> -<div id="log"></div> -<script> -function makeXHR(aUrl) { - var xmlhttp = new XMLHttpRequest(); - xmlhttp.open("get", aUrl, true); - xmlhttp.send(); -} - -promise_test(t => { - var promise = new Promise(resolve => { - performance.clearResourceTimings(); - - var observer = new PerformanceObserver(list => resolve(list)); - observer.observe({entryTypes: ['resource']}); - t.add_cleanup(() => observer.disconnect()); - }); - - makeXHR("test-data.json"); - - return promise.then(list => { - assert_equals(list.getEntries().length, 1); - assert_array_equals(list.getEntries(), - performance.getEntriesByType("resource"), - "Observed 'resource' entries should equal to entries obtained by getEntriesByType."); - - // getEntries filtering tests - assert_array_equals(list.getEntries({name: "http://mochi.test:8888/tests/dom/base/test/test-data.json"}), - performance.getEntriesByName("http://mochi.test:8888/tests/dom/base/test/test-data.json"), - "getEntries with name filter should return correct results."); - assert_array_equals(list.getEntries({entryType: "resource"}), - performance.getEntriesByType("resource"), - "getEntries with entryType filter should return correct results."); - assert_array_equals(list.getEntries({initiatorType: "xmlhttprequest"}), - performance.getEntriesByType("resource"), - "getEntries with initiatorType filter should return correct results."); - assert_array_equals(list.getEntries({initiatorType: "link"}), - [], - "getEntries with non-existent initiatorType filter should return an empty array."); - }); -}, "resource-timing test"); - -done(); - -</script> -</body> diff --git a/dom/performance/tests/test_performance_observer.html b/dom/performance/tests/test_performance_observer.html index d368783155..7df881bd48 100644 --- a/dom/performance/tests/test_performance_observer.html +++ b/dom/performance/tests/test_performance_observer.html @@ -3,15 +3,55 @@ http://creativecommons.org/publicdomain/zero/1.0/ --> <!DOCTYPE html> +<html> +<head> <meta charset=utf-8> <title>Test for performance observer</title> <script src="/resources/testharness.js"></script> <script src="/resources/testharnessreport.js"></script> -<div id=log></div> +</head> +<body> +<div id="log"></div> +<script src="test_performance_observer.js"></script> <script> -'use strict'; -SpecialPowers.pushPrefEnv({"set": [["dom.enable_performance_observer", true]]}, - function() { - window.open("performance_observer.html"); - }); +function makeXHR(aUrl) { + var xmlhttp = new XMLHttpRequest(); + xmlhttp.open("get", aUrl, true); + xmlhttp.send(); +} + +promise_test(t => { + var promise = new Promise(resolve => { + performance.clearResourceTimings(); + + var observer = new PerformanceObserver(list => resolve(list)); + observer.observe({entryTypes: ['resource']}); + t.add_cleanup(() => observer.disconnect()); + }); + + makeXHR("test-data.json"); + + return promise.then(list => { + assert_equals(list.getEntries().length, 1); + assert_array_equals(list.getEntries(), + performance.getEntriesByType("resource"), + "Observed 'resource' entries should equal to entries obtained by getEntriesByType."); + + // getEntries filtering tests + assert_array_equals(list.getEntries({name: "http://mochi.test:8888/tests/dom/base/test/test-data.json"}), + performance.getEntriesByName("http://mochi.test:8888/tests/dom/base/test/test-data.json"), + "getEntries with name filter should return correct results."); + assert_array_equals(list.getEntries({entryType: "resource"}), + performance.getEntriesByType("resource"), + "getEntries with entryType filter should return correct results."); + assert_array_equals(list.getEntries({initiatorType: "xmlhttprequest"}), + performance.getEntriesByType("resource"), + "getEntries with initiatorType filter should return correct results."); + assert_array_equals(list.getEntries({initiatorType: "link"}), + [], + "getEntries with non-existent initiatorType filter should return an empty array."); + }); +}, "resource-timing test"); + </script> +</body> diff --git a/dom/performance/tests/test_worker_observer.html b/dom/performance/tests/test_worker_observer.html index b9ed0c9646..9a55ef1d5a 100644 --- a/dom/performance/tests/test_worker_observer.html +++ b/dom/performance/tests/test_worker_observer.html @@ -3,15 +3,16 @@ http://creativecommons.org/publicdomain/zero/1.0/ --> <!DOCTYPE html> +<html> +<head> <meta charset=utf-8> <title>Test for performance observer in worker</title> <script src="/resources/testharness.js"></script> <script src="/resources/testharnessreport.js"></script> -<div id=log></div> +</head> +<body> +<div id="log"></div> <script> -'use strict'; -SpecialPowers.pushPrefEnv({"set": [["dom.enable_performance_observer", true]]}, - function() { - window.open("worker_performance_observer.html"); - }); +fetch_tests_from_worker(new Worker("worker_performance_observer.js")); </script> +</body> diff --git a/dom/performance/tests/worker_performance_observer.html b/dom/performance/tests/worker_performance_observer.html deleted file mode 100644 index 613762f521..0000000000 --- a/dom/performance/tests/worker_performance_observer.html +++ /dev/null @@ -1,32 +0,0 @@ -<!-- - Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ ---> -<!DOCTYPE html> -<meta charset=utf-8> -<html> -<head> -<title>Test for performance observer in worker</title> -</head> -<body> -<div id="log"></div> -<script> -[ - "async_test", "test", "setup", - "assert_true", "assert_equals", "assert_array_equals", - "assert_throws", "fetch_tests_from_worker" -].forEach(func => { - window[func] = opener[func].bind(opener); -}); - -function done() { - opener.add_completion_callback(() => { - self.close(); - }); - opener.done(); -} - -fetch_tests_from_worker(new Worker("worker_performance_observer.js")); -done(); -</script> -</body> diff --git a/dom/tests/mochitest/general/test_interfaces.html b/dom/tests/mochitest/general/test_interfaces.html index acbc12e072..cbd08d8d45 100644 --- a/dom/tests/mochitest/general/test_interfaces.html +++ b/dom/tests/mochitest/general/test_interfaces.html @@ -751,9 +751,9 @@ var interfaceNamesInGlobalScope = // IMPORTANT: Do not change this list without review from a DOM peer! "PerformanceNavigation", // IMPORTANT: Do not change this list without review from a DOM peer! - {name: "PerformanceObserver", nightly: true}, + "PerformanceObserver", // IMPORTANT: Do not change this list without review from a DOM peer! - {name: "PerformanceObserverEntryList", nightly: true}, + "PerformanceObserverEntryList", // IMPORTANT: Do not change this list without review from a DOM peer! "PerformanceResourceTiming", // IMPORTANT: Do not change this list without review from a DOM peer! diff --git a/dom/webidl/PerformanceObserver.webidl b/dom/webidl/PerformanceObserver.webidl index a3a14cb1e5..4cebecbeba 100644 --- a/dom/webidl/PerformanceObserver.webidl +++ b/dom/webidl/PerformanceObserver.webidl @@ -9,6 +9,7 @@ dictionary PerformanceObserverInit { required sequence<DOMString> entryTypes; + boolean buffered = false; }; callback PerformanceObserverCallback = void (PerformanceObserverEntryList entries, PerformanceObserver observer); diff --git a/dom/workers/test/serviceworkers/test_serviceworker_interfaces.js b/dom/workers/test/serviceworkers/test_serviceworker_interfaces.js index 9dbfcc0990..a4d498fb86 100644 --- a/dom/workers/test/serviceworkers/test_serviceworker_interfaces.js +++ b/dom/workers/test/serviceworkers/test_serviceworker_interfaces.js @@ -172,9 +172,9 @@ var interfaceNamesInGlobalScope = // IMPORTANT: Do not change this list without review from a DOM peer! "PerformanceMeasure", // IMPORTANT: Do not change this list without review from a DOM peer! - { name: "PerformanceObserver", nightly: true }, + "PerformanceObserver", // IMPORTANT: Do not change this list without review from a DOM peer! - { name: "PerformanceObserverEntryList", nightly: true }, + "PerformanceObserverEntryList", // IMPORTANT: Do not change this list without review from a DOM peer! "Request", // IMPORTANT: Do not change this list without review from a DOM peer! diff --git a/dom/workers/test/test_worker_interfaces.js b/dom/workers/test/test_worker_interfaces.js index e0647682c7..6fe5fcaff0 100644 --- a/dom/workers/test/test_worker_interfaces.js +++ b/dom/workers/test/test_worker_interfaces.js @@ -163,9 +163,9 @@ var interfaceNamesInGlobalScope = // IMPORTANT: Do not change this list without review from a DOM peer! "PerformanceMeasure", // IMPORTANT: Do not change this list without review from a DOM peer! - { name: "PerformanceObserver", nightly: true }, + "PerformanceObserver", // IMPORTANT: Do not change this list without review from a DOM peer! - { name: "PerformanceObserverEntryList", nightly: true }, + "PerformanceObserverEntryList", // IMPORTANT: Do not change this list without review from a DOM peer! "Request", // IMPORTANT: Do not change this list without review from a DOM peer! |