Strict mode eval

Andreas Rossberg rossberg at google.com
Tue May 10 10:16:40 PDT 2011


I'm a bit puzzled regarding the meaning of "use strict" in the context
of higher-order uses of eval.

Consider the following program. What is the expected result of the latter calls?

---------------------
var x = 3

function call_eval() { x = 3; eval("var x = 4"); return x }
function call_eval_strict() { "use strict"; x = 3; eval("var x = 4"); return x }

function get_eval() { return eval }
function get_eval_strict() { "use strict"; return eval }

function call_f(f) { x = 3; f("var x = 4"); return x }
function call_f_strict(f) { "use strict"; x = 3; f("var x = 4"); return x }

call_eval()  // 4
call_eval_strict()  // 3

call_f(eval)  // 4
call_f(get_eval())  // 4
call_f(get_eval_strict())  // ?

call_f_strict(eval)  // ?
call_f_strict(get_eval())  // ?
call_f_strict(get_eval_strict())  // ?

(function() { "use strict"; return call_f_strict(get_eval_strict()) })()  // ?
---------------------

V8 bleeding edge currently returns 4 for all of the latter calls, but
that does not seem quite right to me. Especially for the last two
cases
that would practically amount to a loop hole in strict mode. But where
does the spec say differently?

I'd be happy for any enlightenment.

Thanks,
/Andreas


More information about the es-discuss mailing list