If "load" builtin is called on global object or as a direct call, it uses global object as "this" for the script evaluated as well as global object as "scope" for evaluation. But, if load is indirectly invoked with a different "this" then that object is used as "this" for evaluated code as well as "scope" for the evaluated code. Example: var obj = { foo: 44 }; load.call(obj, "foo = 40; var bar = 'hello'"); // obj.foo assigned! Also, the evaluated code can not access global variables. Trying to access "Object" or "print" from evaluated script results in ReferenceError/TypeError (calling "undefined") etc. Also, all definitions in the evaluated code go as properties. In the above example, new "bar" property is created in obj. This is very different anything else in the language/API. For eg. indirect "eval" call always uses global object as "this" as well as "scope" object for evaluated code. Direct "eval" uses surrounding scope and surrounding "this" -- but only in non-strict mode. Even in that case, function local scope objects are not accessible to user script. In strict mode, direct eval uses an intermediate "scope" object which is not accessible to user code directly. Even in the case of "with" statement, global is always accessible within the with block. The "load-on-arbitrary-object" exposes a new kind of scope object to user code (apart from global object alone) - where global's properties are not available to user script but definitions from evaluated code go into a user accessible object. We need to revisit this behaviour and also add tests.
|