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>
13 lines
430 B
JavaScript
13 lines
430 B
JavaScript
// eval() edge cases — non-string passthrough, empty string, throw propagation,
|
|
// indirect-eval var isolation, doubly-parenthesized direct eval
|
|
console.log(eval(null));
|
|
console.log(eval(''));
|
|
var caught;
|
|
try { eval('throw 42'); } catch(e) { caught = e; }
|
|
console.log(caught);
|
|
var e = eval;
|
|
e('var leaked = 1');
|
|
try { leaked; console.log('bad'); } catch(_) { console.log('isolated'); }
|
|
((eval))('var dp = 55');
|
|
console.log(dp);
|