Bug 976148 - Tests. r=gabor
authorBobby Holley <bobbyholley@gmail.com>
Thu, 19 Jun 2014 09:57:06 -0700
changeset 203417 871d570bc7c9194bef14848cd84dbd7323043402
parent 203416 206d7f502e142587002b10f96f49e76f0cacf594
child 203418 fefe4c4ffe939468dad5203c470046c8a9839073
push id6561
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 21:23:20 +0000
treeherdermozilla-aurora@428d4d3c8588 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgabor
bugs976148
milestone33.0a1
Bug 976148 - Tests. r=gabor
js/xpconnect/tests/chrome/test_xrayToJS.xul
--- a/js/xpconnect/tests/chrome/test_xrayToJS.xul
+++ b/js/xpconnect/tests/chrome/test_xrayToJS.xul
@@ -79,16 +79,35 @@ https://bugzilla.mozilla.org/show_bug.cg
       ok(false, "should have thrown while setting property on object");
     } catch (e) {
       ok(!!/denied/.test(e), "Threw correctly: " + e);
     }
     var factoryFun = new iwin.Function('return {foo: 32}');
     is(global(factoryFun), iwin, "proper global for factoryFun");
     is(factoryFun().foo, 32, "factoryFun invokable");
     is(global(factoryFun()), iwin, "minted objects live in the content scope");
+    testXray('Function', factoryFun, new iwin.Function(), ['caller', 'arguments', 'length', 'name']);
+    var echoThis = new iwin.Function('return this;');
+    echoThis.wrappedJSObject.bind = 42;
+    var boundEchoThis = echoThis.bind(document);
+    is(boundEchoThis(), document, "bind() works correctly over Xrays");
+    is(global(boundEchoThis), window, "bound functions live in the caller's scope");
+    ok(/return this/.test(echoThis.toSource()), 'toSource works: ' + echoThis.toSource());
+    ok(/return this/.test(echoThis.toString()), 'toString works: ' + echoThis.toString());
+    is(iwin.Function.prototype, Object.getPrototypeOf(echoThis), "Function.prototype works for standard classes");
+    is(echoThis.prototype, undefined, "Function.prototype not visible for non standard constructors");
+    iwin.eval('var foopyFunction = function namedFoopyFunction(a, b, c) {}');
+    var foopyFunction = Cu.unwaiveXrays(Cu.waiveXrays(iwin).foopyFunction);
+    ok(Cu.isXrayWrapper(foopyFunction), "Should be Xrays");
+    is(foopyFunction.name, "namedFoopyFunction", ".name works over Xrays");
+    is(foopyFunction.length, 3, ".length works over Xrays");
+    ok(Object.getOwnPropertyNames(foopyFunction).indexOf('length') >= 0, "Should list length");
+    ok(Object.getOwnPropertyNames(foopyFunction).indexOf('name') >= 0, "Should list name");
+    ok(Object.getOwnPropertyNames(foopyFunction).indexOf('prototype') == -1, "Should not list prototype");
+    ok(Object.getOwnPropertyNames(iwin.Array).indexOf('prototype') >= 0, "Should list prototype for standard constructor");
 
     // Test interface objects that don't actually construct things.
     is(iwin.Math.tan(4.5), Math.tan(4.5), "Math.tan works");
     is(iwin.Math.E, Math.E, "Math.E works");
     var json = JSON.stringify({a: 2, b: 'hi', c: {d: 'there'}});
     is(global(iwin.JSON.parse(json)), iwin, "JSON rehydrated into the right context");
     is(iwin.JSON.stringify(iwin.JSON.parse(json)), json, "JSON composition identity holds");
 
@@ -158,16 +177,19 @@ https://bugzilla.mozilla.org/show_bug.cg
       "reducePar", "scanPar", "scatterPar", "filterPar", "find", "findIndex", "copyWithin",
       "fill", "@@iterator", "entries", "keys", "constructor"];
   for (var c of typedArrayClasses) {
     gPrototypeProperties[c] = ["constructor", "BYTES_PER_ELEMENT", "length", "buffer",
                                "byteLength", "byteOffset", "@@iterator", "subarray", "set"];
     if (!isReleaseBuild)
       gPrototypeProperties[c].push("move");
   }
+  gPrototypeProperties['Function'] =
+    ["constructor", "toSource", "toString", "apply", "call", "bind",
+     "isGenerator", "length", "name", "arguments", "caller"];
 
   function filterOut(array, props) {
     return array.filter(p => props.indexOf(p) == -1);
   }
 
   function testXray(classname, xray, xray2, propsToSkip) {
     propsToSkip = propsToSkip || [];
     let xrayProto = Object.getPrototypeOf(xray);