js/src/tests/ecma_5/Global/eval-02.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 // Any copyright is dedicated to the Public Domain.
     2 // http://creativecommons.org/licenses/publicdomain/
     4 var a = 9;
     6 function directArg(eval, s) {
     7     var a = 1;
     8     return eval(s);
     9 }
    11 function directVar(f, s) {
    12     var eval = f;
    13     var a = 1;
    14     return eval(s);
    15 }
    17 function directWith(obj, s) {
    18     var f;
    19     with (obj) {
    20 	f = function () {
    21 	    var a = 1;
    22 	    return eval(s);
    23 	};
    24     }
    25     return f();
    26 }
    28 // direct eval, even though 'eval' is an argument
    29 assertEq(directArg(eval, 'a+1'), 2);
    31 // direct eval, even though 'eval' is a var
    32 assertEq(directVar(eval, 'a+1'), 2);
    34 // direct eval, even though 'eval' is found via a with block
    35 assertEq(directWith(this, 'a+1'), 2);
    36 assertEq(directWith({eval: eval, a: -1000}, 'a+1'), 2);
    38 reportCompare(0, 0);

mercurial