Bug 1518753 part 6 - Various fixes for jstests to work with same-compartment realms. r=anba
authorJan de Mooij <jdemooij@mozilla.com>
Sat, 12 Jan 2019 10:50:12 +0000
changeset 453632 02251eb9e2c1
parent 453631 cfa1c48c7170
child 453633 83c9c1d0af97
push id35362
push userncsoregi@mozilla.com
push dateSat, 12 Jan 2019 21:35:38 +0000
treeherdermozilla-central@877169d8ef49 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersanba
bugs1518753
milestone66.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 1518753 part 6 - Various fixes for jstests to work with same-compartment realms. r=anba Differential Revision: https://phabricator.services.mozilla.com/D16171
js/src/tests/non262/Function/Object-toSource.js
js/src/tests/non262/Promise/dependent-promises.js
js/src/tests/non262/TypedArray/slice-validation.js
js/src/tests/non262/TypedArray/subarray-validation.js
js/src/tests/non262/extensions/collect-gray.js
js/src/tests/non262/extensions/setImmutablePrototype.js
js/src/tests/non262/extensions/typedarray.js
js/src/tests/non262/regress/regress-698028-2.js
js/src/tests/non262/regress/regress-698028-3.js
--- a/js/src/tests/non262/Function/Object-toSource.js
+++ b/js/src/tests/non262/Function/Object-toSource.js
@@ -245,26 +245,27 @@ assertEq(obj.toSource(),
          "({get foo() {}})");
 
 obj = {};
 Object.defineProperty(obj, "foo", {set: proxy, enumerable: true});
 assertEq(obj.toSource(),
          "({set foo() {}})");
 
 // Methods from other global.
-// Treated as normal property.
+// Treated as normal property in the cross-compartment case.
 
 let g = newGlobal();
 
 method = g.eval("({ foo() {} }).foo");
 
 obj = {};
 Object.defineProperty(obj, "foo", {value: method, enumerable: true});
-assertEq(obj.toSource(),
-         "({foo:foo() {}})");
+assertEq((obj.toSource() === "({foo:foo() {}})" ||
+          obj.toSource() === "({foo() {}})"),
+         true);
 
 // Accessors from other global.
 // Accessor syntax is composed.
 
 accessor = g.eval("Object.getOwnPropertyDescriptor({ get foo() {} }, 'foo').get");
 
 obj = {};
 Object.defineProperty(obj, "foo", {get: accessor, enumerable: true});
--- a/js/src/tests/non262/Promise/dependent-promises.js
+++ b/js/src/tests/non262/Promise/dependent-promises.js
@@ -1,11 +1,11 @@
 // |reftest| skip-if(!xulRuntime.shell) -- needs Debugger
 
-var g = newGlobal();
+var g = newGlobal({newCompartment: true});
 var dbg = new Debugger(g);
 var gw = dbg.addDebuggee(g);
 
 g.eval(`
 var p = new Promise(() => {});
 p.name = "p";
 var q = p.then();
 q.name = "q";
--- a/js/src/tests/non262/TypedArray/slice-validation.js
+++ b/js/src/tests/non262/TypedArray/slice-validation.js
@@ -1,15 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // Summary: Ensure typed array validation is called for TypedArray.prototype.slice.
 
-const otherGlobal = typeof newGlobal === "function" ? newGlobal() : undefined;
+const otherGlobal = typeof newGlobal === "function" ? newGlobal({newCompartment: true}) : undefined;
 const typedArrayLengths = [0, 1, 1024];
 
 function createTestCases(TAConstructor, constructor, constructorCrossRealm) {
     let testCases = [];
     testCases.push({
         species: constructor,
         method: TAConstructor.prototype.slice,
         error: TypeError,
@@ -19,17 +19,18 @@ function createTestCases(TAConstructor, 
             species: constructorCrossRealm,
             method: TAConstructor.prototype.slice,
             error: TypeError,
         });
         testCases.push({
             species: constructor,
             method: otherGlobal[TAConstructor.name].prototype.slice,
             // Note: slice uses CallTypedArrayMethodIfWrapped, which results
-            //       in throwing a TypeError from the wrong Realm.
+            //       in throwing a TypeError from the wrong Realm if
+            //       cross-compartment.
             error: TypeError,
         });
     }
     return testCases;
 }
 
 // Throws TypeError when the returned value is not a typed array.
 for (const TAConstructor of anyTypedArrayConstructors) {
--- a/js/src/tests/non262/TypedArray/subarray-validation.js
+++ b/js/src/tests/non262/TypedArray/subarray-validation.js
@@ -1,15 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // Summary: Ensure typed array validation is called for TypedArray.prototype.subarray.
 
-const otherGlobal = typeof newGlobal === "function" ? newGlobal() : undefined;
+const otherGlobal = typeof newGlobal === "function" ? newGlobal({newCompartment: true}) : undefined;
 const typedArrayLengths = [0, 1, 1024];
 
 function createTestCases(TAConstructor, constructor, constructorCrossRealm) {
     let testCases = [];
     testCases.push({
         species: constructor,
         method: TAConstructor.prototype.subarray,
         error: TypeError,
@@ -19,17 +19,18 @@ function createTestCases(TAConstructor, 
             species: constructorCrossRealm,
             method: TAConstructor.prototype.subarray,
             error: TypeError,
         });
         testCases.push({
             species: constructor,
             method: otherGlobal[TAConstructor.name].prototype.subarray,
             // Note: subarray uses CallTypedArrayMethodIfWrapped, which results
-            //       in throwing a TypeError from the wrong Realm.
+            //       in throwing a TypeError from the wrong Realm if
+            //       cross-compartment.
             error: TypeError,
         });
     }
     return testCases;
 }
 
 // Throws TypeError when the returned value is not a typed array.
 for (const TAConstructor of anyTypedArrayConstructors) {
--- a/js/src/tests/non262/extensions/collect-gray.js
+++ b/js/src/tests/non262/extensions/collect-gray.js
@@ -25,17 +25,17 @@ grayRoot().x = 7; // Overwrite the objec
 gc();
 marks = getMarks();
 assertEq(marks[0], 'gray', 'gray root');
 assertEq(marks[1], 'dead', 'object no longer reachable from gray root');
 assertEq(marks[2], 'black', 'global');
 assertEq(marks[3], 'dead', 'dead object should have been collected');
 
 var wm = new WeakMap();
-var global = newGlobal();
+var global = newGlobal({newCompartment: true});
 
 var wrapper1 = global.eval("Object.create(null)");
 wrapper1.name = "wrapper1";
 var value1 = Object.create(null);
 wm.set(wrapper1, value1);
 
 var wrapper2 = global.eval("Object.create(null)");
 wrapper2.name = "wrapper2";
--- a/js/src/tests/non262/extensions/setImmutablePrototype.js
+++ b/js/src/tests/non262/extensions/setImmutablePrototype.js
@@ -139,21 +139,22 @@ function runNormalTests(global)
   assertEq(revocable.revoke(), undefined);
   try
   {
     setImmutablePrototype(revocable.proxy);
     throw new Error("expected to throw on revoked proxy");
   }
   catch (e)
   {
-    // Note: This is a TypeError from |global|, because the proxy's
-    //       |setImmutablePrototype| method is what actually throws here.
+    // Note: In the cross-compartment case, this is a TypeError from |global|,
+    //       because the proxy's |setImmutablePrototype| method is what actually
+    //       throws here. That's why we check for TypeError from either global.
     //       (Usually the method simply sets |*succeeded| to false and the
     //       caller handles or throws as needed after that.  But not here.)
-    assertEq(e instanceof global.TypeError, true,
+    assertEq(e instanceof global.TypeError || e instanceof TypeError, true,
              "expected TypeError, instead threw " + e);
   }
 
   var anotherRevocableTarget = global.evaluate("({})");
   assertEq(setImmutablePrototype(anotherRevocableTarget), true);
   checkPrototypeMutationFailure(anotherRevocableTarget, "another revocable target");
 
   var anotherRevocable = global.Proxy.revocable(anotherRevocableTarget, {});
@@ -162,18 +163,18 @@ function runNormalTests(global)
   assertEq(anotherRevocable.revoke(), undefined);
   try
   {
     var rv = setImmutablePrototype(anotherRevocable.proxy);
     throw new Error("expected to throw on another revoked proxy, returned " + rv);
   }
   catch (e)
   {
-    // NOTE: Again from |global|, as above.
-    assertEq(e instanceof global.TypeError, true,
+    // NOTE: Again from |global| or |this|, as above.
+    assertEq(e instanceof global.TypeError || e instanceof TypeError, true,
              "expected TypeError, instead threw " + e);
   }
 }
 
 var global = this;
 runNormalTests(global); // same-global
 
 if (typeof newGlobal === "function")
--- a/js/src/tests/non262/extensions/typedarray.js
+++ b/js/src/tests/non262/extensions/typedarray.js
@@ -555,22 +555,25 @@ function test()
     // this compartment. (There should never be a compartment boundary between
     // an ArrayBufferView and its ArrayBuffer.)
     var view = new Int8Array(alien_buffer);
 
     // First make sure they're looking at the same data
     alien_view[3] = 77;
     check(() => view[3] == 77);
 
-    // Now check that the proxy setup is as expected
-    check(() => isProxy(alien_view));
-    check(() => isProxy(alien_buffer));
-    check(() => isProxy(view)); // the real test
+    // Now check that the proxy setup is as expected in the cross-compartment
+    // case.
+    if (isProxy(alien)) {
+        check(() => isProxy(alien_view));
+        check(() => isProxy(alien_buffer));
+        check(() => isProxy(view)); // the real test
+    }
 
-    // cross-compartment property access
+    // cross-realm property access
     check(() => alien_buffer.byteLength == 7);
     check(() => alien_view.byteLength == 7);
     check(() => view.byteLength == 7);
 
     // typed array protos should be equal
     simple = new Int8Array(12);
     check(() => Object.getPrototypeOf(view) == Object.getPrototypeOf(simple));
     check(() => Object.getPrototypeOf(view) == Int8Array.prototype);
--- a/js/src/tests/non262/regress/regress-698028-2.js
+++ b/js/src/tests/non262/regress/regress-698028-2.js
@@ -1,14 +1,14 @@
 // |reftest| skip-if(!xulRuntime.shell) -- uses evalInFrame
 //
 // Any copyright is dedicated to the Public Domain.
 // http://creativecommons.org/licenses/publicdomain/
 
-var g = newGlobal();
+var g = newGlobal({newCompartment: true});
 var dbg = new g.Debugger(this);
 
 if (typeof evalInFrame === 'function') {
     let x00, x01, x02, x03, x04, x05, x06, x07, x08, x09, x0a, x0b, x0c, x0d, x0e, x0f, 
         x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x1a, x1b, x1c, x1d, x1e, x1f, 
         x20, x21, x22, x23, x24, x25, x26, x27, x28, x29, x2a, x2b, x2c, x2d, x2e, x2f, 
         x30, x31, x32, x33, x34, x35, x36, x37, x38, x39, x3a, x3b, x3c, x3d, x3e, x3f, 
         x40, x41, x42, x43, x44, x45, x46, x47, x48, x49, x4a, x4b, x4c, x4d, x4e, x4f, 
--- a/js/src/tests/non262/regress/regress-698028-3.js
+++ b/js/src/tests/non262/regress/regress-698028-3.js
@@ -1,13 +1,13 @@
 // Any copyright is dedicated to the Public Domain.
 // http://creativecommons.org/licenses/publicdomain/
 
 if (typeof Debugger === 'function') {
-    var g = newGlobal();
+    var g = newGlobal({newCompartment: true});
     var dbg = new Debugger(g);
     dbg.onDebuggerStatement = function (frame) { frame.eval(''); };
     var s = '{ let ';
     for (var i = 0; i < 128; i++)
         s += 'x' + i + ', ';
     s += 'X = 0; debugger; }';
     g.eval(s);
 }