Bug 1709232 - Make PerformanceObserver.supportedEntryTypes respects dom.enable_event_timing r=emilio
authorSean Feng <sefeng@mozilla.com>
Wed, 05 May 2021 17:20:12 +0000
changeset 578622 809f11778c3990c3eab0d284b298620d0121ea77
parent 578621 ba92ff62f0965c433f2926fc6af7e11f7ed10dff
child 578623 9ab607973f20efb77d47d1eec36fd817dc749cdb
push id142605
push usersefeng@mozilla.com
push dateWed, 05 May 2021 17:22:39 +0000
treeherderautoland@809f11778c39 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1709232
milestone90.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1709232 - Make PerformanceObserver.supportedEntryTypes respects dom.enable_event_timing r=emilio PerformanceObserver.supportedEntryTypes doesn't check whether PerformanceEventTiming is enabled or not, so it'll falsely claims PerformanceEventTiming is supported even if the pref is disabled. This patch fixes that by adding a guard to it. Differential Revision: https://phabricator.services.mozilla.com/D114250
dom/performance/PerformanceObserver.cpp
testing/web-platform/meta/html/semantics/interactive-elements/the-dialog-element/supported-types-consistent-with-self.ini
testing/web-platform/tests/event-timing/supported-types-consistent-with-self.html
--- a/dom/performance/PerformanceObserver.cpp
+++ b/dom/performance/PerformanceObserver.cpp
@@ -121,23 +121,25 @@ void PerformanceObserver::Notify() {
 
 void PerformanceObserver::QueueEntry(PerformanceEntry* aEntry) {
   MOZ_ASSERT(aEntry);
   MOZ_ASSERT(ObservesTypeOfEntry(aEntry));
 
   mQueuedEntries.AppendElement(aEntry);
 }
 
+static constexpr nsLiteralString kValidEventTimingNames[2] = {
+    u"event"_ns, u"first-input"_ns};
+
 /*
  * Keep this list in alphabetical order.
  * https://w3c.github.io/performance-timeline/#supportedentrytypes-attribute
  */
-static const char16_t* const sValidTypeNames[7] = {
-    u"event",      u"first-input", u"mark",     u"measure",
-    u"navigation", u"paint",       u"resource",
+static constexpr nsLiteralString kValidTypeNames[5] = {
+    u"mark"_ns, u"measure"_ns, u"navigation"_ns, u"paint"_ns, u"resource"_ns,
 };
 
 void PerformanceObserver::ReportUnsupportedTypesErrorToConsole(
     bool aIsMainThread, const char* msgId, const nsString& aInvalidTypes) {
   if (!aIsMainThread) {
     nsTArray<nsString> params;
     params.AppendElement(aInvalidTypes);
     WorkerPrivate::ReportErrorToConsole(msgId, params);
@@ -201,21 +203,27 @@ void PerformanceObserver::Observe(const 
     const Sequence<nsString>& entryTypes = maybeEntryTypes.Value();
 
     if (entryTypes.IsEmpty()) {
       return;
     }
 
     /* 3.3.1.5.2 */
     nsTArray<nsString> validEntryTypes;
-    for (const char16_t* name : sValidTypeNames) {
-      nsDependentString validTypeName(name);
-      if (entryTypes.Contains<nsString>(validTypeName) &&
-          !validEntryTypes.Contains<nsString>(validTypeName)) {
-        validEntryTypes.AppendElement(validTypeName);
+
+    if (StaticPrefs::dom_enable_event_timing()) {
+      for (const nsLiteralString& name : kValidEventTimingNames) {
+        if (entryTypes.Contains(name) && !validEntryTypes.Contains(name)) {
+          validEntryTypes.AppendElement(name);
+        }
+      }
+    }
+    for (const nsLiteralString& name : kValidTypeNames) {
+      if (entryTypes.Contains(name) && !validEntryTypes.Contains(name)) {
+        validEntryTypes.AppendElement(name);
       }
     }
 
     nsAutoString invalidTypesJoined;
     bool addComma = false;
     for (const auto& type : entryTypes) {
       if (!validEntryTypes.Contains<nsString>(type)) {
         if (addComma) {
@@ -248,19 +256,26 @@ void PerformanceObserver::Observe(const 
     mOptions.AppendElement(aOptions);
 
   } else {
     MOZ_ASSERT(mObserverType == ObserverTypeSingle);
     bool typeValid = false;
     nsString type = maybeType.Value();
 
     /* 3.3.1.6.2 */
-    for (const char16_t* name : sValidTypeNames) {
-      nsDependentString validTypeName(name);
-      if (type == validTypeName) {
+    if (StaticPrefs::dom_enable_event_timing()) {
+      for (const nsLiteralString& name : kValidEventTimingNames) {
+        if (type == name) {
+          typeValid = true;
+          break;
+        }
+      }
+    }
+    for (const nsLiteralString& name : kValidTypeNames) {
+      if (type == name) {
         typeValid = true;
         break;
       }
     }
 
     if (!typeValid) {
       ReportUnsupportedTypesErrorToConsole(
           NS_IsMainThread(), UnsupportedEntryTypesIgnoredMsgId, type);
@@ -304,19 +319,23 @@ void PerformanceObserver::Observe(const 
   mConnected = true;
 }
 
 void PerformanceObserver::GetSupportedEntryTypes(
     const GlobalObject& aGlobal, JS::MutableHandle<JSObject*> aObject) {
   nsTArray<nsString> validTypes;
   JS::Rooted<JS::Value> val(aGlobal.Context());
 
-  for (const char16_t* name : sValidTypeNames) {
-    nsString validTypeName(name);
-    validTypes.AppendElement(validTypeName);
+  if (StaticPrefs::dom_enable_event_timing()) {
+    for (const nsLiteralString& name : kValidEventTimingNames) {
+      validTypes.AppendElement(name);
+    }
+  }
+  for (const nsLiteralString& name : kValidTypeNames) {
+    validTypes.AppendElement(name);
   }
 
   if (!ToJSValue(aGlobal.Context(), validTypes, &val)) {
     /*
      * If this conversion fails, we don't set a result.
      * The spec does not allow us to throw an exception.
      */
     return;
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/meta/html/semantics/interactive-elements/the-dialog-element/supported-types-consistent-with-self.ini
@@ -0,0 +1,1 @@
+prefs: [dom.enable_event_timing:false]
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/event-timing/supported-types-consistent-with-self.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<meta charset=utf-8 />
+<title>Event Timing: supportedEntryTypes should be consistent with `'PerformanceEventTiming' in Self`
+</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script>
+test(() => {
+  const isFirstInputSupportedInEntryTypes = PerformanceObserver.supportedEntryTypes.includes('first-input');
+  const isEventSupportedInEntryTypes = PerformanceObserver.supportedEntryTypes.includes('event');
+
+  const isEventTimingSupportedInSelf = 'PerformanceEventTiming' in self;
+
+  assert_equals(isFirstInputSupportedInEntryTypes, isEventTimingSupportedInSelf)
+  assert_equals(isEventSupportedInEntryTypes, isEventTimingSupportedInSelf)
+}, "supportedEntryTypes should be consistent with `'PerformanceEventTiming' in Self`");
+</script>
+</html>