js/src/tests/ecma_5/extensions/cross-global-eval-is-indirect.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 // |reftest| skip-if(!xulRuntime.shell) -- needs newGlobal()
michael@0 2 /*
michael@0 3 * Any copyright is dedicated to the Public Domain.
michael@0 4 * http://creativecommons.org/licenses/publicdomain/
michael@0 5 */
michael@0 6
michael@0 7 //-----------------------------------------------------------------------------
michael@0 8 var BUGNUMBER = 608473;
michael@0 9 var summary =
michael@0 10 '|var eval = otherWindow.eval; eval(...)| should behave like indirectly ' +
michael@0 11 'calling that eval from a script in that other window';
michael@0 12
michael@0 13 print(BUGNUMBER + ": " + summary);
michael@0 14
michael@0 15 /**************
michael@0 16 * BEGIN TEST *
michael@0 17 **************/
michael@0 18
michael@0 19 var originalEval = eval;
michael@0 20 var res;
michael@0 21
michael@0 22 function f()
michael@0 23 {
michael@0 24 return [this, eval("this")];
michael@0 25 }
michael@0 26
michael@0 27 var otherGlobalSameCompartment = newGlobal("same-compartment");
michael@0 28
michael@0 29 eval = otherGlobalSameCompartment.eval;
michael@0 30 res = new f();
michael@0 31 assertEq(res[0] !== res[1], true);
michael@0 32 assertEq(res[0] !== this, true);
michael@0 33 assertEq(res[0] instanceof f, true);
michael@0 34 assertEq(res[1], otherGlobalSameCompartment);
michael@0 35
michael@0 36 res = f();
michael@0 37 assertEq(res[0] !== res[1], true);
michael@0 38 assertEq(res[0], this);
michael@0 39 assertEq(res[1], otherGlobalSameCompartment);
michael@0 40
michael@0 41 var otherGlobalDifferentCompartment = newGlobal();
michael@0 42
michael@0 43 eval = otherGlobalDifferentCompartment.eval;
michael@0 44 res = new f();
michael@0 45 assertEq(res[0] !== res[1], true);
michael@0 46 assertEq(res[0] !== this, true);
michael@0 47 assertEq(res[0] instanceof f, true);
michael@0 48 assertEq(res[1], otherGlobalDifferentCompartment);
michael@0 49
michael@0 50 res = f();
michael@0 51 assertEq(res[0] !== res[1], true);
michael@0 52 assertEq(res[0], this);
michael@0 53 assertEq(res[1], otherGlobalDifferentCompartment);
michael@0 54
michael@0 55 /******************************************************************************/
michael@0 56
michael@0 57 if (typeof reportCompare === "function")
michael@0 58 reportCompare(true, true);
michael@0 59
michael@0 60 print("All tests passed!");

mercurial