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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_5/extensions/cross-global-eval-is-indirect.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,60 @@
     1.4 +// |reftest| skip-if(!xulRuntime.shell) -- needs newGlobal()
     1.5 +/*
     1.6 + * Any copyright is dedicated to the Public Domain.
     1.7 + * http://creativecommons.org/licenses/publicdomain/
     1.8 + */
     1.9 +
    1.10 +//-----------------------------------------------------------------------------
    1.11 +var BUGNUMBER = 608473;
    1.12 +var summary =
    1.13 +  '|var eval = otherWindow.eval; eval(...)| should behave like indirectly ' +
    1.14 +  'calling that eval from a script in that other window';
    1.15 +
    1.16 +print(BUGNUMBER + ": " + summary);
    1.17 +
    1.18 +/**************
    1.19 + * BEGIN TEST *
    1.20 + **************/
    1.21 +
    1.22 +var originalEval = eval;
    1.23 +var res;
    1.24 +
    1.25 +function f()
    1.26 +{
    1.27 +  return [this, eval("this")];
    1.28 +}
    1.29 +
    1.30 +var otherGlobalSameCompartment = newGlobal("same-compartment");
    1.31 +
    1.32 +eval = otherGlobalSameCompartment.eval;
    1.33 +res = new f();
    1.34 +assertEq(res[0] !== res[1], true);
    1.35 +assertEq(res[0] !== this, true);
    1.36 +assertEq(res[0] instanceof f, true);
    1.37 +assertEq(res[1], otherGlobalSameCompartment);
    1.38 +
    1.39 +res = f();
    1.40 +assertEq(res[0] !== res[1], true);
    1.41 +assertEq(res[0], this);
    1.42 +assertEq(res[1], otherGlobalSameCompartment);
    1.43 +
    1.44 +var otherGlobalDifferentCompartment = newGlobal();
    1.45 +
    1.46 +eval = otherGlobalDifferentCompartment.eval;
    1.47 +res = new f();
    1.48 +assertEq(res[0] !== res[1], true);
    1.49 +assertEq(res[0] !== this, true);
    1.50 +assertEq(res[0] instanceof f, true);
    1.51 +assertEq(res[1], otherGlobalDifferentCompartment);
    1.52 +
    1.53 +res = f();
    1.54 +assertEq(res[0] !== res[1], true);
    1.55 +assertEq(res[0], this);
    1.56 +assertEq(res[1], otherGlobalDifferentCompartment);
    1.57 +
    1.58 +/******************************************************************************/
    1.59 +
    1.60 +if (typeof reportCompare === "function")
    1.61 +  reportCompare(true, true);
    1.62 +
    1.63 +print("All tests passed!");

mercurial