Bug 1552632 - Resolve globalThis when querying all properties of the global object. r=jandem, a=jcristau
authorJason Orendorff <jorendorff@mozilla.com>
Thu, 30 May 2019 17:55:14 +0000
changeset 536643 5588ca581cbeee519064e8e2acd80126ff770017
parent 536642 aef4e0bd81ca7a00f0b199497f0e1f0389cc39c3
child 536644 2e7f918e6874a712a7f9ff07d30f24521a32193a
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem, jcristau
bugs1552632
milestone68.0
Bug 1552632 - Resolve globalThis when querying all properties of the global object. r=jandem, a=jcristau globalThis was already handled specially in JS_ResolveStandardClass, JS_MayResolveStandardClass, and various other places, but not in JS_NewEnumerateStandardClasses. Differential Revision: https://phabricator.services.mozilla.com/D32045
js/src/jsapi.cpp
js/src/tests/non262/global/globalThis-enumeration.js
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -967,16 +967,26 @@ static bool EnumerateStandardClasses(JSC
   Handle<GlobalObject*> global = obj.as<GlobalObject>();
 
   // It's fine to always append |undefined| here, it's non-configurable and
   // the enumeration code filters duplicates.
   if (!properties.append(NameToId(cx->names().undefined))) {
     return false;
   }
 
+  bool resolved = false;
+  if (!GlobalObject::maybeResolveGlobalThis(cx, global, &resolved)) {
+    return false;
+  }
+  if (resolved || includeResolved) {
+    if (!properties.append(NameToId(cx->names().globalThis))) {
+      return false;
+    }
+  }
+
   if (!EnumerateStandardClassesInTable(cx, global, properties,
                                        standard_class_names, includeResolved)) {
     return false;
   }
   if (!EnumerateStandardClassesInTable(
           cx, global, properties, builtin_property_names, includeResolved)) {
     return false;
   }
new file mode 100644
--- /dev/null
+++ b/js/src/tests/non262/global/globalThis-enumeration.js
@@ -0,0 +1,5 @@
+assertEq(Object.getOwnPropertyNames(this).includes('globalThis'), true);
+
+if (typeof reportCompare === "function") {
+  reportCompare(0, 0);
+}