Closed
Bug 277462
Opened 20 years ago
Closed 20 years ago
new Function("...") shoud set the parent scope of the created object
Categories
(Rhino Graveyard :: Core, defect)
Tracking
(Not tracked)
RESOLVED
INVALID
People
(Reporter: mguillemot, Assigned: igor)
Details
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20040913
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20040913
var foo = 123;
var f = new Function("alert(foo)");
f();
the parent scope of f has to be the one of the Function() call else it gets
executed in a scope where "alert" and "foo" don't exist.
Reproducible: Always| Assignee | ||
Comment 1•20 years ago
|
||
Which version of Rhino do you use? If I run
var f = new Function("return 1");
print(f.__parent__ === this)
print(f.__proto__ === Function.prototype)
in Rhino shell it prints
true
trueI use 1.6R1 (as JS engine for http://htmlunit.sourceforge.net). I think that my example was not so good because it executes in top scope (and yours as well). May that be the cause of the problem? (I don't see what I could provide as simple example to illustrate it).
| Assignee | ||
Comment 3•20 years ago
|
||
Rhino always sets up the parent scope for function created via Function constructor to the top scope of the currently executed code to fulfill ECMAScript requirements. If you pass to Context.evaluateString or Script.exec a scope object which is not a top scope, then due to the above the constructed functions would not see it. In general using anything but top scopes in Rhino may not work as expected since in too many places Rhino assumes that scriptableInstance.getParentScope() != null => scriptableInstance is an internal temporary scope that should not be stored in functions etc. Marking the bug as invalid.
Status: NEW → RESOLVED
Closed: 20 years ago
Resolution: --- → INVALID
You need to log in
before you can comment on or make changes to this bug.
Description
•