No, this is not a bug. Unlike "eval", "load" does not use local scopes (function scope, 'with' scope) etc. "load" always evaluates script using global object as the scope. Because there is no "foo" in global scope, the load throws ReferenceError for "foo". "eval" can see "foo" as eval can use local scopes in non-strict mode. With "strict" mode, "eval" too uses global scope always (does not use function scopes).

-Sundar

On Tuesday 02 September 2014 03:35 PM, David P. Caldwell wrote:
Is this a bug?

scopes.js

with({ foo: "bar" }) {
var evaluated = eval("foo");
  print(evaluated);
var loaded = load({ name: "foo.js", script: "foo" });
  print(loaded);
}

$ jrunscript scopes.js
bar
script error in file scopes.js : ReferenceError: "foo" is not defined in
foo.js at line number 1

This is with jdk1.8.0_20.

-- David P. Caldwell
http://www.davidpcaldwell.com/

Reply via email to