Bug 892903 - Remove Proxy.create from jstests. r=efaust
authorTom Schuster <evilpies@gmail.com>
Fri, 11 Mar 2016 13:32:26 +0100
changeset 288274 346979205b0a21c7de46bc8270c73390b2d1c501
parent 288273 f999b1995dc61c63b60a250a7189fcd452211557
child 288275 0607c9f8df24a0a00cbd1fae8029a42b3325b136
push id30079
push userryanvm@gmail.com
push dateSat, 12 Mar 2016 20:24:19 +0000
treeherdermozilla-central@d1d47ba19ce9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersefaust
bugs892903
milestone48.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 892903 - Remove Proxy.create from jstests. r=efaust
js/src/tests/ecma_5/extensions/proxy-__proto__.js
js/src/tests/ecma_5/extensions/proxy-strict.js
js/src/tests/ecma_5/misc/new-with-non-constructor.js
js/src/tests/ecma_6/extensions/indirect-proxy-preventExtensions-error-realm.js
js/src/tests/ecma_6/extensions/setImmutablePrototype.js
js/src/tests/js1_8_5/extensions/clone-errors.js
js/src/tests/js1_8_5/extensions/correct-this-for-nonnatives-on-array-proto-chain.js
js/src/tests/js1_8_5/extensions/proxy-fix.js
js/src/tests/js1_8_5/extensions/scripted-proxies.js
js/src/tests/js1_8_5/regress/regress-566914.js
js/src/tests/js1_8_5/regress/regress-584578.js
js/src/tests/js1_8_5/regress/regress-595230-1.js
js/src/tests/js1_8_5/regress/regress-618574.js
js/src/tests/js1_8_5/regress/regress-620376-1.js
js/src/tests/js1_8_5/regress/regress-620376-2.js
deleted file mode 100644
--- a/js/src/tests/ecma_5/extensions/proxy-__proto__.js
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/licenses/publicdomain/
- */
-
-var gTestfile = 'proxy-__proto__.js';
-var BUGNUMBER = 770344;
-var summary = "Behavior of __proto__ on proxies";
-
-print(BUGNUMBER + ": " + summary);
-
-/**************
- * BEGIN TEST *
- **************/
-
-var protoDesc = Object.getOwnPropertyDescriptor(Object.prototype, "__proto__");
-var protoGetter = protoDesc.get;
-var protoSetter = protoDesc.set;
-
-function pp(arr)
-{
-  return arr.map(function(v) { return "" + v; }).join(", ");
-}
-
-function testProxy(creator, args, proto)
-{
-  print("Now testing behavior for " +
-        "Proxy." + creator + "(" + pp(args) + ")");
-
-  var pobj = Proxy[creator].apply(Proxy, args);
-
-  // Check [[Prototype]] before attempted mutation
-  assertEq(Object.getPrototypeOf(pobj), proto);
-  assertEq(protoGetter.call(pobj), proto);
-
-  // Attempt [[Prototype]] mutation
-  protoSetter.call(pobj, null);
-
-  // Check [[Prototype]] after attempted mutation
-  assertEq(Object.getPrototypeOf(pobj), null);
-  assertEq(protoGetter.call(pobj), null);
-}
-
-// Proxy object with non-null [[Prototype]]
-var nonNullProto = { toString: function() { return "non-null prototype"; } };
-var nonNullHandler = { toString: function() { return "non-null handler"; } };
-testProxy("create", [nonNullHandler, nonNullProto], nonNullProto);
-
-// Proxy object with null [[Prototype]]
-var nullProto = null;
-var nullHandler = { toString: function() { return "null handler"; } };
-testProxy("create", [nullHandler, nullProto], nullProto);
-
-// Proxy function with [[Call]]
-var callForCallOnly = function () { };
-callForCallOnly.toString = function() { return "callForCallOnly"; };
-var callOnlyHandler = { toString: function() { return "call-only handler"; } };
-testProxy("createFunction",
-          [callOnlyHandler, callForCallOnly], Function.prototype);
-
-// Proxy function with [[Call]] and [[Construct]]
-var callForCallConstruct = function() { };
-callForCallConstruct.toString = function() { return "call/construct call"; };
-var constructForCallConstruct = function() { };
-constructForCallConstruct.toString =
-  function() { return "call/construct construct"; };
-var handlerForCallConstruct =
-  { toString: function() { return "call/construct handler"; } };
-testProxy("createFunction",
-          [handlerForCallConstruct,
-           callForCallConstruct,
-           constructForCallConstruct],
-          Function.prototype);
-
-
-/******************************************************************************/
-
-if (typeof reportCompare === "function")
-  reportCompare(true, true);
-
-print("Tests complete");
--- a/js/src/tests/ecma_5/extensions/proxy-strict.js
+++ b/js/src/tests/ecma_5/extensions/proxy-strict.js
@@ -1,12 +1,12 @@
 /*
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/licenses/publicdomain/
  */
 
 var s = "grape";
 function f() { "use strict"; return this; }
-var p = Proxy.createFunction(f, f);
+var p = new Proxy(f, {});
 String.prototype.p = p;
 assertEq(s.p(), "grape");
 
 reportCompare(true,true);
--- a/js/src/tests/ecma_5/misc/new-with-non-constructor.js
+++ b/js/src/tests/ecma_5/misc/new-with-non-constructor.js
@@ -3,42 +3,30 @@
  * http://creativecommons.org/licenses/publicdomain/
  */
 
 function checkConstruct(thing) {
     try {
         new thing();
         assertEq(0, 1, "not reached " + thing);
     } catch (e) {
-        assertEq(String(e.message).indexOf(" is not a constructor") === -1, false);
+        assertEq(e.message.includes(" is not a constructor") ||
+                 e.message === "Function.prototype.toString called on incompatible object", true);
     }
 }
 
 var re = /aaa/
 checkConstruct(re);
 
 var boundFunctionPrototype = Function.prototype.bind();
 checkConstruct(boundFunctionPrototype);
 
 var boundBuiltin = Math.sin.bind();
 checkConstruct(boundBuiltin);
 
-/* We set the proxies construct trap to undefined,
- * so the call trap is used as constructor.
- */
-
-var handler = {
-    getPropertyDescriptor(name) {
-        /* toSource may be called to generate error message. */
-        assertEq(name, "toSource");
-        return { value: () => "foo" };
-    }
-};
-
-var proxiedFunctionPrototype = Proxy.create(handler, Function.prototype, undefined);
+var proxiedFunctionPrototype = new Proxy(Function.prototype, {});
 checkConstruct(proxiedFunctionPrototype);
 
-var proxiedBuiltin = Proxy.create(handler, parseInt, undefined);
+var proxiedBuiltin = new Proxy(parseInt, {});
 checkConstruct(proxiedBuiltin);
 
-
 if (typeof reportCompare == 'function')
     reportCompare(0, 0, "ok");
deleted file mode 100644
--- a/js/src/tests/ecma_6/extensions/indirect-proxy-preventExtensions-error-realm.js
+++ /dev/null
@@ -1,75 +0,0 @@
-// |reftest| skip-if(!xulRuntime.shell) -- needs newGlobal()
-/*
- * Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/licenses/publicdomain/
- */
-
-var gTestfile = "indirect-proxy-preventExtensions-error-realm.js";
-var BUGNUMBER = 1085566;
-var summary =
-  "The preventExtensions trap should return success/failure (with the " +
-  "outermost preventExtension caller deciding what to do in response), " +
-  "rather than throwing a TypeError itself";
-
-print(BUGNUMBER + ": " + summary);
-
-/**************
- * BEGIN TEST *
- **************/
-
-var g = newGlobal();
-
-// Someday indirect proxies will be thrown into the lake of fire and sulfur
-// alongside the beast and the false prophet, to be tormented day and night for
-// ever and ever.  When that happens, this test will need to be updated.
-//
-// The requirements for |p| are that 1) it be a cross-compartment wrapper, 2) to
-// a proxy, 3) whose C++ preventExtensions handler method returns true while
-// setting |*succeeded = false|.  The other options when this test was written)
-// were a global scope polluter (WindowNamedPropertiesHandler), a window object
-// (nsOuterWindowProxy), a DOM proxy (DOMProxyHandler), a SecurityWrapper, a
-// DebugScopeProxy (seemingly never directly exposed to script), and an
-// XrayWrapper.  Sadly none of these are simply available in both shell and
-// browser, so indirect proxies are it.
-//
-// (The other option would be to do this with a jsapi-test that defines a custom
-// proxy, but this was easier to write.  Maybe in the future, if no other such
-// proxies arise before indirect proxies die.)
-var p = g.Proxy.create({}, {});
-
-try
-{
-  // What we expect to happen is this:
-  //
-  //   * Object.preventExtensions delegates to
-  //   * cross-compartment wrapper preventExtensions trap, which delegates to
-  //   * indirect proxy preventExtensions trap, which sets |*succeeded = false|
-  //     *and does not throw or return false (in the JSAPI sense)*
-  //
-  // Returning false does not immediately create an error.  Instead that bubbles
-  // backward through the layers to the initial [[PreventExtensions]] call, made
-  // by Object.preventExtensions.  That function then creates and throws a
-  // TypeError in response to that false result -- from its realm, not from the
-  // indirect proxy's realm.
-  Object.preventExtensions(p);
-
-  throw new Error("didn't throw at all");
-}
-catch (e)
-{
-  assertEq(e instanceof TypeError, true,
-           "expected a TypeError from this global, instead got " + e +
-           ", from " +
-           (e.constructor === TypeError
-            ? "this global"
-            : e.constructor === g.TypeError
-            ? "the proxy's global"
-            : "somewhere else (!!!)"));
-}
-
-/******************************************************************************/
-
-if (typeof reportCompare === "function")
-  reportCompare(true, true);
-
-print("Tests complete");
--- a/js/src/tests/ecma_6/extensions/setImmutablePrototype.js
+++ b/js/src/tests/ecma_6/extensions/setImmutablePrototype.js
@@ -175,28 +175,16 @@ function runNormalTests(global)
     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,
              "expected TypeError, instead threw " + e);
   }
-
-  // hated indirect proxies
-  var oldProto = {};
-  var indirectProxy = global.Proxy.create({}, oldProto);
-  assertEq(setImmutablePrototype(indirectProxy), true);
-  assertEq(Object.getPrototypeOf(indirectProxy), oldProto);
-  checkPrototypeMutationFailure(indirectProxy, "indirectProxy");
-
-  var indirectFunctionProxy = global.Proxy.createFunction({}, function call() {});
-  assertEq(setImmutablePrototype(indirectFunctionProxy), true);
-  assertEq(Object.getPrototypeOf(indirectFunctionProxy), global.Function.prototype);
-  checkPrototypeMutationFailure(indirectFunctionProxy, "indirectFunctionProxy");
 }
 
 var global = this;
 runNormalTests(global); // same-global
 
 if (typeof newGlobal === "function")
 {
   var otherGlobal = newGlobal();
--- a/js/src/tests/js1_8_5/extensions/clone-errors.js
+++ b/js/src/tests/js1_8_5/extensions/clone-errors.js
@@ -12,14 +12,14 @@ function check(v) {
     throw new Error("serializing " + uneval(v) + " should have failed with an exception");
 }
 
 // Unsupported object types.
 check(new Error("oops"));
 check(this);
 check(Math);
 check(function () {});
-check(Proxy.create({enumerate: function () { return []; }}));
+check(new Proxy({}, {}));
 
 // A failing getter.
 check({get x() { throw new Error("fail"); }});
 
 reportCompare(0, 0, "ok");
deleted file mode 100644
--- a/js/src/tests/js1_8_5/extensions/correct-this-for-nonnatives-on-array-proto-chain.js
+++ /dev/null
@@ -1,42 +0,0 @@
-// Any copyright is dedicated to the Public Domain.
-// http://creativecommons.org/licenses/publicdomain/
-
-//-----------------------------------------------------------------------------
-var BUGNUMBER = 699705;
-var summary =
-  "When getting a property from a dense array that lives on the proto chain "+
-  "and in particular lives on a non-native object, we should still invoke "+
-  "property getter";
-
-print(BUGNUMBER + ": " + summary);
-
-/**************
- * BEGIN TEST *
- **************/
-
-var protoArr = Proxy.create({
-    getOwnPropertyDescriptor: function(name) {
-        if (name == "foo") return { get: function() { return this[0]; } };
-        return (void 0);
-    },
-    getPropertyDescriptor: function(name) {
-        return this.getOwnPropertyDescriptor(name);
-    },
-}, null);
-void (Array.prototype.__proto__ = protoArr);
-var testArr = [ "PASS" ];
-// Make sure we don't optimize the get to a .foo get, so do the dance
-// with passing in a string.
-function f(name) {
-    return testArr[name];
-}
-var propValue = f("foo");
-assertEq(propValue, "PASS",
-	 "expected to get 'PASS' out of the getter, got: " + propValue);
-
-/******************************************************************************/
-
-if (typeof reportCompare === "function")
-  reportCompare(true, true);
-
-print("All tests passed!");
deleted file mode 100644
--- a/js/src/tests/js1_8_5/extensions/proxy-fix.js
+++ /dev/null
@@ -1,10 +0,0 @@
-// |reftest| skip
-// Any copyright is dedicated to the Public Domain.
-// http://creativecommons.org/licenses/publicdomain/
-// Contributor: Josh Matthews
-
-var p = Proxy.create({ fix: function() { return {foo: {value: 2} }; } });
-Object.preventExtensions(p);
-reportCompare(p.foo, 2, "property exists");
-p.foo = 3;
-reportCompare(p.foo, 2, "proxy is frozen");
\ No newline at end of file
deleted file mode 100644
--- a/js/src/tests/js1_8_5/extensions/scripted-proxies.js
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/licenses/publicdomain/
- * Contributor: Andreas Gal
- */
-
-//-----------------------------------------------------------------------------
-var BUGNUMBER = 546590;
-var summary = 'basic scripted proxies tests';
-var actual = '';
-var expect = '';
-
-//-----------------------------------------------------------------------------
-test();
-//-----------------------------------------------------------------------------
-
-function test() {
-    enterFunc ('test');
-    printBugNumber(BUGNUMBER);
-    printStatus(summary);
-
-    testObj({ foo: 1, bar: 2 });
-    testObj({ 1: 2, 3: 4 });
-    testObj([ 1, 2, 3 ]);
-    testObj(new Date());
-    testObj(new Array());
-    testObj(new RegExp());
-    testObj(Date);
-    testObj(Array);
-    testObj(RegExp);
-
-    /* Test function proxies. */
-    var proxy = Proxy.createFunction({
-        get: function(obj, name) {
-            return Function.prototype[name];
-        },
-        getOwnPropertyDescriptor: function(obj, name) {
-            return Object.getOwnPropertyDescriptor(Function.prototype, name);
-        },
-        fix: function() {
-            return ({});
-        }
-    }, function() { return "call"; });
-
-    assertEq(proxy(), "call");
-    assertEq(Function.prototype.bind.call(proxy)(), "call");
-    assertEq(typeof proxy, "function");
-    if ("isTrapping" in Proxy) {
-	assertEq(Proxy.isTrapping(proxy), true);
-	assertEq(Proxy.fix(proxy), true);
-	assertEq(Proxy.isTrapping(proxy), false);
-	assertEq(typeof proxy, "function");
-	assertEq(proxy(), "call");
-    }
-
-    /* Test function proxies as constructors. */
-    var proxy = Proxy.createFunction({
-        get: function(obj, name) {
-            return Function.prototype[name];
-        },
-        getOwnPropertyDescriptor: function(obj, name) {
-            return Object.getOwnPropertyDescriptor(Function.prototype, name);
-        },
-        fix: function() {
-            return ({});
-        }
-    },
-    function() { var x = {}; x.origin = "call"; return x; },
-    function() { var x = {}; x.origin = "new"; return x; })
-
-    assertEq(proxy().origin, "call");
-    assertEq(Function.prototype.bind.call(proxy)().origin, "call");
-    assertEq((new proxy()).origin, "new");
-    assertEq(new (Function.prototype.bind.call(proxy))().origin, "new");
-    if ("fix" in Proxy) {
-	assertEq(Proxy.fix(proxy), true);
-	assertEq(proxy().origin, "call");
-	assertEq((new proxy()).origin, "new");
-    }
-
-    /* Test fallback on call if no construct trap was given. */
-    var proxy = Proxy.createFunction({
-        get: function(obj, name) { return Function.prototype[name]; },
-        fix: function() { return ({}); }
-    },
-    function() { this.origin = "new"; return "new-ret"; });
-
-    assertEq((new proxy()).origin, "new");
-    if ("fix" in Proxy) {
-        assertEq(Proxy.fix(proxy), true);
-        assertEq((new proxy()).origin, "new");
-    }
-
-    /* Test invoke. */
-    var proxy = Proxy.create({ get: function(obj,name) { return function(a,b,c) { return name + uneval([a,b,c]); } }});
-    assertEq(proxy.foo(1,2,3), "foo[1, 2, 3]");
-
-    reportCompare(0, 0, "done.");
-
-    exitFunc ('test');
-}
-
-/* Test object proxies. */
-function noopHandlerMaker(obj) {
-    return {
-	getOwnPropertyDescriptor: function(name) {
-	    var desc = Object.getOwnPropertyDescriptor(obj);
-	    // a trapping proxy's properties must always be configurable
-	    desc.configurable = true;
-	    return desc;
-	},
-	getPropertyDescriptor: function(name) {
-	    var desc = Object.getPropertyDescriptor(obj); // assumed
-	    // a trapping proxy's properties must always be configurable
-	    desc.configurable = true;
-	    return desc;
-	},
-	getOwnPropertyNames: function() {
-	    return Object.getOwnPropertyNames(obj);
-	},
-	defineProperty: function(name, desc) {
-	    return Object.defineProperty(obj, name, desc);
-	},
-	delete: function(name) { return delete obj[name]; },
-	fix: function() {
-	    // As long as obj is not frozen, the proxy won't allow itself to be fixed
-	    // if (!Object.isFrozen(obj)) [not implemented in SpiderMonkey]
-	    //     return undefined;
-	    // return Object.getOwnProperties(obj); // assumed [not implemented in SpiderMonkey]
-	    var props = {};
-	    for (x in obj)
-		props[x] = Object.getOwnPropertyDescriptor(obj, x);
-	    return props;
-	},
- 	has: function(name) { return name in obj; },
-	hasOwn: function(name) { return ({}).hasOwnProperty.call(obj, name); },
-	get: function(receiver, name) { return obj[name]; },
-	set: function(receiver, name, val) { obj[name] = val; return true; }, // bad behavior when set fails in non-strict mode
-	enumerate: function() {
-	    var result = [];
-	    for (name in obj) { result.push(name); };
-	    return result;
-	},
-	keys: function() { return Object.keys(obj); }
-    };
-};
-
-function testNoopHandler(obj, proxy) {
-    /* Check that both objects see the same properties. */
-    for (x in obj)
-	assertEq(obj[x], proxy[x]);
-    for (x in proxy)
-	assertEq(obj[x], proxy[x]);
-    /* Check that the iteration order is the same. */
-    var a = [], b = [];
-    for (x in obj)
-	a.push(x);
-    for (x in proxy)
-	b.push(x);
-    assertEq(uneval(a), uneval(b));
-}
-
-function testObj(obj) {
-    var proxy = Proxy.create(noopHandlerMaker(obj));
-    testNoopHandler(obj, proxy);
-    assertEq(typeof proxy, "object");
-    if ("isTrapping" in Proxy) {
-	assertEq(Proxy.isTrapping(proxy), true);
-	assertEq(Proxy.fix(proxy), true);
-	assertEq(Proxy.isTrapping(proxy), false);
-	assertEq(typeof proxy, "object");
-	testNoopHandler(obj, proxy);
-    }
-}
deleted file mode 100644
--- a/js/src/tests/js1_8_5/regress/regress-566914.js
+++ /dev/null
@@ -1,21 +0,0 @@
-function f(code) {
-	    code.replace(/s/, "")
-	    eval(code)
-	}
-	this.__defineGetter__("x", function() { return /x/.exec('x'); })
-	f("function a() {\
-	    x = Proxy.createFunction((function () {\
-	        return {\
-defineProperty:	 function (name, desc) {\
-	                Object.defineProperty(x, name, desc)\
-	            },\
-has:	 function () {},\
-get:	 function (r, name) {\
-	                return x[name]\
-	            }\
-	        }\
-	    })(), Object.defineProperties).__defineGetter__(\"\",(Function(\"\")))} ;\
-	a()\
-	")
-
-reportCompare("ok", "ok", "bug 566914");
deleted file mode 100644
--- a/js/src/tests/js1_8_5/regress/regress-584578.js
+++ /dev/null
@@ -1,12 +0,0 @@
-// |reftest| skip
-// Any copyright is dedicated to the Public Domain.
-// http://creativecommons.org/licenses/publicdomain/
-// Contributor: Jesse Ruderman <jruderman@gmail.com>
-
-try {
-  var x = Proxy.create( {get:function(r,name){return {}[name]}} );
-  x.watch('e', function(){});
-} catch (exc) {
-}
-
-reportCompare(0, 0, 'ok');
deleted file mode 100644
--- a/js/src/tests/js1_8_5/regress/regress-595230-1.js
+++ /dev/null
@@ -1,19 +0,0 @@
-// |reftest| fails-if(!xulRuntime.shell)
-// Any copyright is dedicated to the Public Domain.
-// http://creativecommons.org/licenses/publicdomain/
-// Contributors: Gary Kwong <gary@rumblingedge.com>, Brendan Eich <brendan@mozilla.com>
-
-var box = evalcx('lazy');
-
-var src =
-    'try {\n' +
-    '    __proto__ = Proxy.createFunction((function() {}), function() {})\n' +
-    '    var x\n' +
-    '    {}\n' +
-    '} catch(e) {}\n' +
-    'for (let b in [0, 0]) {}\n' +
-    '0\n';
-
-evalcx(src, box);
-
-this.reportCompare(0, 0, "ok");
deleted file mode 100644
--- a/js/src/tests/js1_8_5/regress/regress-618574.js
+++ /dev/null
@@ -1,21 +0,0 @@
-// |reftest| skip
-/*
- * Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/licenses/publicdomain/
- * Contributors: Gary Kwong and Jason Orendorff
- */
-
-var x = Proxy.create({
-    iterate: function () {
-            function f(){}
-            f.next = function () { throw StopIteration; }
-            return f;
-        }
-    });
-
-for each (var e in [{}, {}, {}, {}, {}, {}, {}, {}, x]) {
-    for (var v in e)  // do not assert
-        ;
-}
-
-reportCompare(0, 0, 'ok');
--- a/js/src/tests/js1_8_5/regress/regress-620376-1.js
+++ b/js/src/tests/js1_8_5/regress/regress-620376-1.js
@@ -5,17 +5,17 @@
  * Contributors: Igor Bukanov
  */
 
 // Test that we can terminate looping array enumeration
 function test() {
     if (typeof timeout != "function")
 	return;
 
-    var p = Proxy.create({ keys: function() { return Array(1e9); }});
+    var p = new Proxy({}, { onwKeys: function() { return Array(1e9); }});
 
     expectExitCode(6);
     timeout(0.001);
 
     var n = 0;
     for (i in p) { ++n;}
     return n;
 }
deleted file mode 100644
--- a/js/src/tests/js1_8_5/regress/regress-620376-2.js
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/licenses/publicdomain/
- * Contributors: Igor Bukanov
- */
-
-function test() {
-    var p = Proxy.create({ keys: function() { return { get length() { throw 1; }}; }});
-
-    try {
-	for (i in p);
-	throw new Error("an exception should be thrown");
-    } catch (e) {
-	assertEq(e, 1);
-    }
-}
-
-test();
-reportCompare(0, 0, "ok");