Implement eval() as a sentinel-intercepted builtin that parses and executes code strings at runtime with proper scope and strict mode handling. Direct eval inherits caller scope (vars leak in non-strict), while indirect and strict eval contain declarations via function scope. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
11 lines
252 B
JavaScript
11 lines
252 B
JavaScript
// eval() scope — var leaking, caller variable access, modification
|
|
var x = 10;
|
|
console.log(eval("x"));
|
|
eval("var y = 42");
|
|
console.log(y);
|
|
var z = 1;
|
|
eval("z = 2");
|
|
console.log(z);
|
|
eval("function greet() { return 'hello'; }");
|
|
console.log(greet());
|