From 85a6afe8575d4ca5f0cc72a33e718f151e7bde72 Mon Sep 17 00:00:00 2001 From: hns Date: Tue, 17 Jun 2003 14:44:39 +0000 Subject: [PATCH] * 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(). --- src/helma/scripting/rhino/RhinoCore.java | 27 +++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/helma/scripting/rhino/RhinoCore.java b/src/helma/scripting/rhino/RhinoCore.java index 3f224019..ebcbc463 100644 --- a/src/helma/scripting/rhino/RhinoCore.java +++ b/src/helma/scripting/rhino/RhinoCore.java @@ -178,7 +178,7 @@ public final class RhinoCore { try { FunctionObject fp = new FunctionObject(name, HopObject.hopObjCtor, global); - fp.addAsConstructor(global, op); + installConstructor(fp, op); } catch (Exception ignore) { System.err.println("Error adding ctor for " + name + ": " + ignore); ignore.printStackTrace(); @@ -246,16 +246,16 @@ public final class RhinoCore { // Register a constructor for all types except global. // This will first create a new prototyped hopobject and then calls // the actual (scripted) constructor on it. - if (!"global".equalsIgnoreCase(name) && !"root".equalsIgnoreCase(name)) { + /* if (!"global".equalsIgnoreCase(name) && !"root".equalsIgnoreCase(name)) { try { FunctionObject fp = new FunctionObject(name, HopObject.hopObjCtor, global); - fp.addAsConstructor(global, op); + installConstructor(fp, op); } catch (Exception ignore) { System.err.println("Error adding ctor for " + name + ": " + ignore); ignore.printStackTrace(); } - } + } */ for (Iterator it = prototype.getZippedCode().values().iterator(); it.hasNext();) { 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 * functions. @@ -518,7 +535,7 @@ public final class RhinoCore { Scriptable w = (Scriptable) wrappercache.get(e); - if (e == null) { + if (w == null) { // Gotta find out the prototype name to use for this object... String prototypeName = app.getPrototypeName(e);