* We now have our own version of FunctionObject.addAsConstructor() to install
HopObject constructors, because we do not want the prototype.constructor property to be set. Otherwise, scripted constructor functions are shadowed. * Fix typo in getElementWrapper().
This commit is contained in:
parent
9581df2ac4
commit
85a6afe857
1 changed files with 22 additions and 5 deletions
|
@ -178,7 +178,7 @@ public final class RhinoCore {
|
||||||
try {
|
try {
|
||||||
FunctionObject fp = new FunctionObject(name, HopObject.hopObjCtor, global);
|
FunctionObject fp = new FunctionObject(name, HopObject.hopObjCtor, global);
|
||||||
|
|
||||||
fp.addAsConstructor(global, op);
|
installConstructor(fp, op);
|
||||||
} catch (Exception ignore) {
|
} catch (Exception ignore) {
|
||||||
System.err.println("Error adding ctor for " + name + ": " + ignore);
|
System.err.println("Error adding ctor for " + name + ": " + ignore);
|
||||||
ignore.printStackTrace();
|
ignore.printStackTrace();
|
||||||
|
@ -246,16 +246,16 @@ public final class RhinoCore {
|
||||||
// Register a constructor for all types except global.
|
// Register a constructor for all types except global.
|
||||||
// This will first create a new prototyped hopobject and then calls
|
// This will first create a new prototyped hopobject and then calls
|
||||||
// the actual (scripted) constructor on it.
|
// the actual (scripted) constructor on it.
|
||||||
if (!"global".equalsIgnoreCase(name) && !"root".equalsIgnoreCase(name)) {
|
/* if (!"global".equalsIgnoreCase(name) && !"root".equalsIgnoreCase(name)) {
|
||||||
try {
|
try {
|
||||||
FunctionObject fp = new FunctionObject(name, HopObject.hopObjCtor, global);
|
FunctionObject fp = new FunctionObject(name, HopObject.hopObjCtor, global);
|
||||||
|
|
||||||
fp.addAsConstructor(global, op);
|
installConstructor(fp, op);
|
||||||
} catch (Exception ignore) {
|
} catch (Exception ignore) {
|
||||||
System.err.println("Error adding ctor for " + name + ": " + ignore);
|
System.err.println("Error adding ctor for " + name + ": " + ignore);
|
||||||
ignore.printStackTrace();
|
ignore.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
} */
|
||||||
|
|
||||||
for (Iterator it = prototype.getZippedCode().values().iterator(); it.hasNext();) {
|
for (Iterator it = prototype.getZippedCode().values().iterator(); it.hasNext();) {
|
||||||
Object code = it.next();
|
Object code = it.next();
|
||||||
|
@ -270,6 +270,23 @@ public final class RhinoCore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a version of org.mozilla.javascript.FunctionObject.addAsConstructor()
|
||||||
|
* that does not set the constructor property in the prototype. This is because
|
||||||
|
* we want our own scripted constructor function to prevail, if it is defined.
|
||||||
|
*/
|
||||||
|
private void installConstructor(FunctionObject fo, Scriptable prototype) {
|
||||||
|
ScriptRuntime.setFunctionProtoAndParent(global, fo);
|
||||||
|
fo.setImmunePrototypeProperty(prototype);
|
||||||
|
|
||||||
|
prototype.setParentScope(fo);
|
||||||
|
|
||||||
|
String name = prototype.getClassName();
|
||||||
|
ScriptableObject.defineProperty(global, name, fo, ScriptableObject.DONTENUM);
|
||||||
|
|
||||||
|
fo.setParentScope(global);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an object prototype to its initial state, removing all application specific
|
* Return an object prototype to its initial state, removing all application specific
|
||||||
* functions.
|
* functions.
|
||||||
|
@ -518,7 +535,7 @@ public final class RhinoCore {
|
||||||
|
|
||||||
Scriptable w = (Scriptable) wrappercache.get(e);
|
Scriptable w = (Scriptable) wrappercache.get(e);
|
||||||
|
|
||||||
if (e == null) {
|
if (w == null) {
|
||||||
// Gotta find out the prototype name to use for this object...
|
// Gotta find out the prototype name to use for this object...
|
||||||
String prototypeName = app.getPrototypeName(e);
|
String prototypeName = app.getPrototypeName(e);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue