Bug 1396482 part 2. Enumerate JS standard classes on Window Xrays, just like we enumerateWebIDL interfaces. r=bholley
☠☠ backed out by 59496d591584 ☠ ☠
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 28 Sep 2018 10:49:44 -0400
changeset 494475 8c9b27320d6e37b77631980d19607d5c58717896
parent 494474 c23086c123932c3e3ae24a39285ccad83bc03a99
child 494476 89a23642630a660d5d816143f735019a4fc488e7
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1396482
milestone64.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 1396482 part 2. Enumerate JS standard classes on Window Xrays, just like we enumerateWebIDL interfaces. r=bholley
dom/bindings/test/test_dom_xrays.html
js/xpconnect/wrappers/XrayWrapper.cpp
--- a/dom/bindings/test/test_dom_xrays.html
+++ b/dom/bindings/test/test_dom_xrays.html
@@ -27,27 +27,33 @@ function checkXrayProperty(obj, name, va
 {
   var instance = obj;
   do {
     var value = values.shift();
     if (typeof value == "undefined") {
       ok(!obj.hasOwnProperty(name), "hasOwnProperty shouldn't see \"" + name + "\" through Xrays");
       is(Object.getOwnPropertyDescriptor(obj, name), undefined, "getOwnPropertyDescriptor shouldn't see \"" + name + "\" through Xrays");
       ok(!Object.keys(obj).includes(name), "Enumerating the Xray should not return \"" + name + "\"");
+      ok(!Object.getOwnPropertyNames(obj).includes(name),
+         `The Xray's property names should not include ${name}`)
     } else {
       ok(obj.hasOwnProperty(name), "hasOwnProperty should see \"" + name + "\" through Xrays");
       var pd = Object.getOwnPropertyDescriptor(obj, name);
       ok(pd, "getOwnPropertyDescriptor should see \"" + name + "\" through Xrays");
       if (pd && pd.get) {
         is(pd.get.call(instance), value, "Should get the right value for \"" + name + "\" through Xrays");
       } else {
         is(obj[name], value, "Should get the right value for \"" + name + "\" through Xrays");
       }
-      if (pd && pd.enumerable) {
-        ok(Object.keys(obj).indexOf("" + name) > -1, "Enumerating the Xray should return \"" + name + "\"");
+      if (pd) {
+        if (pd.enumerable) {
+          ok(Object.keys(obj).indexOf("" + name) > -1, "Enumerating the Xray should return \"" + name + "\"");
+        }
+        ok(Object.getOwnPropertyNames(obj).indexOf("" + name) > -1,
+           `The Xray's property names should include ${name}`)
       }
     }
   } while ((obj = Object.getPrototypeOf(obj)));
 }
 
 function checkWindowXrayProperty(obj, name, windowValue, windowPrototypeValue, namedPropertiesValue, eventTargetValue)
 {
   checkXrayProperty(obj, name, [ windowValue, windowPrototypeValue, namedPropertiesValue, eventTargetValue ]);
@@ -96,16 +102,23 @@ function test()
   is(obj, win.Object.prototype, "Object.prototype should be at the end of the prototype chain");
 
   // Named properties shouldn't shadow WebIDL- or ECMAScript-defined properties.
   checkWindowXrayProperty(win, "addEventListener", undefined, undefined, undefined, eventTargetProto.addEventListener);
   is(win.addEventListener, eventTargetProto.addEventListener, "Named properties shouldn't shadow WebIDL-defined properties");
 
   is(win.toString, win.Object.prototype.toString, "Named properties shouldn't shadow ECMAScript-defined properties");
 
+  // WebIDL interface names should be exposed.
+  var waivedWin = Cu.waiveXrays(win);
+  checkWindowXrayProperty(win, "Element", Cu.unwaiveXrays(waivedWin.Element))
+
+  // JS standard classes should be exposed.
+  checkWindowXrayProperty(win, "Array", Cu.unwaiveXrays(waivedWin.Array))
+
   // HTMLDocument
   // Unforgeable properties live on the instance.
   checkXrayProperty(doc, "location", [ win.location ]);
   is(String(win.location), document.getElementById("t").src,
      "Should have the right stringification");
 
   // HTMLHtmlElement
   var elem = doc.documentElement;
--- a/js/xpconnect/wrappers/XrayWrapper.cpp
+++ b/js/xpconnect/wrappers/XrayWrapper.cpp
@@ -1737,16 +1737,25 @@ DOMXrayTraits::enumerateNames(JSContext*
             if (!JS_IndexToId(cx, i, &indexId)) {
                 return false;
             }
             props.infallibleAppend(indexId);
         }
     }
 
     JS::Rooted<JSObject*> obj(cx, getTargetObject(wrapper));
+    if (JS_IsGlobalObject(obj)) {
+        // We could do this in a shared enumerateNames with JSXrayTraits, but we
+        // don't really have globals we expose via those.
+        JSAutoRealm ar(cx, obj);
+        if (!JS_NewEnumerateStandardClassesIncludingResolved(
+          cx, obj, props, !(flags & JSITER_HIDDEN))) {
+            return false;
+        }
+    }
     return XrayOwnPropertyKeys(cx, wrapper, obj, flags, props);
 }
 
 bool
 DOMXrayTraits::call(JSContext* cx, HandleObject wrapper,
                     const JS::CallArgs& args, const js::Wrapper& baseInstance)
 {
     RootedObject obj(cx, getTargetObject(wrapper));