* Be more careful about setting parent scope on functions (which may be nested).
Fixes bug 531 reported by juerg lehni on helma-dev. http://helma.org/bugs/show_bug.cgi?id=531
This commit is contained in:
parent
fb3029ed25
commit
de0c08ce5a
2 changed files with 20 additions and 4 deletions
|
@ -696,9 +696,15 @@ public class HopObject extends ScriptableObject implements Wrapper, PropertyReco
|
|||
if (value instanceof Function) {
|
||||
// reset function's parent scope, needed because of the way we compile
|
||||
// prototype code, using the prototype objects as scope
|
||||
Function f = (Function) value;
|
||||
if (f.getParentScope() == this)
|
||||
f.setParentScope(core.global);
|
||||
Scriptable scriptable = (Scriptable) value;
|
||||
while (scriptable != null) {
|
||||
Scriptable scope = scriptable.getParentScope();
|
||||
if (scope == this) {
|
||||
scriptable.setParentScope(core.global);
|
||||
break;
|
||||
}
|
||||
scriptable = scope;
|
||||
}
|
||||
}
|
||||
}
|
||||
super.put(name, start, value);
|
||||
|
|
|
@ -30,6 +30,7 @@ public class HopObjectCtor extends FunctionObject {
|
|||
// static constructor property access
|
||||
boolean initialized;
|
||||
RhinoCore core;
|
||||
Scriptable protoProperty;
|
||||
|
||||
static Method hopObjCtor;
|
||||
|
||||
|
@ -52,6 +53,7 @@ public class HopObjectCtor extends FunctionObject {
|
|||
public HopObjectCtor(String protoName, RhinoCore core, Scriptable prototype) {
|
||||
super(protoName, hopObjCtor, core.global);
|
||||
this.core = core;
|
||||
this.protoProperty = prototype;
|
||||
// Scriptable ps = prototype.getParentScope();
|
||||
addAsConstructor(core.global, prototype);
|
||||
// prototype.setParentScope(ps);
|
||||
|
@ -122,7 +124,15 @@ public class HopObjectCtor extends FunctionObject {
|
|||
if (value instanceof Function) {
|
||||
// reset static function's parent scope, needed because of the way we compile
|
||||
// prototype code, using the prototype objects as scope
|
||||
((Function) value).setParentScope(core.global);
|
||||
Scriptable scriptable = (Scriptable) value;
|
||||
while (scriptable != null) {
|
||||
Scriptable scope = scriptable.getParentScope();
|
||||
if (scope == protoProperty) {
|
||||
scriptable.setParentScope(core.global);
|
||||
break;
|
||||
}
|
||||
scriptable = scope;
|
||||
}
|
||||
}
|
||||
super.put(name, start, value);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue