Please consider the two snippets of code (the first prints "Local eval", the second prints "Global eval"):
(function f() {
var x;
try {
eval("x");
console.log('Local eval');
}
catch (e) {
console.log('Global eval');
}
}())
and
var globalEval = eval;
(function f() {
var x;
try {
globalEval("x");
console.log('Local eval');
}
catch (e) {
console.log('Global eval');
}
}())
It turns out that even though globalEval === eval
evaluates to true
, globalEval
and eval
behave differently because they have different names. (An eval can only be local if it is precisely written eval
.)
How can I distinguish to two evals? Is there are a way to extract variable labels to infer behaviour?