global.eval kann keine Variablen im lexikalischen Bereich aufrufen. Entspricht das Verhalten dem ECMAScript-Standard?
Ich habe eine JavaScript-Datei,e.js
var global = Function('return this')();
var i = 1;
console.log(eval("100-1"));
console.log(eval("i"));
console.log(global.eval("100-1"));
console.log(global.eval("i"));
Wenn ich es von V8 ausführe:
$ node e.js
99
1
99
undefined:1
i
^
ReferenceError: i is not defined
at eval (eval at <anonymous> (/private/tmp/xxxx/e.js:8:20), <anonymous>:1:1)
at eval (native)
at Object.<anonymous> (/private/tmp/xxxx/e.js:8:20)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
Als Ergebnis,global.eval
funktioniert für den mathematischen Operator, kann aber die Variable @ nicht besuchi
, währendeval
funktioniert in beiden Fällen.
Ist dieses Verhalten eine Einschränkung von V8? Oder ist es das erwartete Verhalten nach ECMAScript-Standard?