From 35791bf5fbdd716288fa133bc2938dc125d96484 Mon Sep 17 00:00:00 2001 From: hns Date: Mon, 20 Dec 2004 12:15:35 +0000 Subject: [PATCH] Fixes for bug 390 * Use the same class for temporary compile time prototypes as for live protos * Switch over parent scope when moving properties to live prototype. This does not fix any problems because the functions causing the problems in AntvilleLib are nested properties, but it seems like the right thing to do. --- src/helma/scripting/rhino/RhinoCore.java | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/helma/scripting/rhino/RhinoCore.java b/src/helma/scripting/rhino/RhinoCore.java index 56252ea3..24e2b7c7 100644 --- a/src/helma/scripting/rhino/RhinoCore.java +++ b/src/helma/scripting/rhino/RhinoCore.java @@ -884,14 +884,15 @@ public final class RhinoCore { * code against. */ public void prepareCompilation() { - tmpObjProto = new ScriptableObject() { - public String getClassName() { - return frameworkProto.getName(); - } - }; - tmpObjProto.setPrototype(objProto); - if (!"global".equals(frameworkProto.getLowerCaseName())) + if ("global".equals(frameworkProto.getLowerCaseName())) { + tmpObjProto = new GlobalObject(RhinoCore.this, app); + tmpObjProto.setPrototype(global); + tmpObjProto.setParentScope(null); + } else { + tmpObjProto = new HopObject(frameworkProto.getName()); + tmpObjProto.setPrototype(objProto); tmpObjProto.setParentScope(global); + } } /** @@ -923,6 +924,13 @@ public final class RhinoCore { // copy them over to the actual prototype object int attributes = tmpObjProto.getAttributes(key); Object value = tmpObjProto.get(key, tmpObjProto); + if (value instanceof ScriptableObject) { + // switch parent scope to actual prototype + ScriptableObject obj = (ScriptableObject) value; + if (obj.getParentScope() == tmpObjProto) { + obj.setParentScope(objProto); + } + } objProto.defineProperty(key, value, attributes); }