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

Wed, 31 Dec 2014 07:53:36 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:53:36 +0100
branch
TOR_BUG_3246
changeset 5
4ab42b5ab56c
permissions
-rw-r--r--

Correct small whitespace inconsistency, lost while renaming variables.

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

mercurial