From b80b83ffb3cb69d536b3d4468c94a9ff7daa351e Mon Sep 17 00:00:00 2001 From: hns Date: Wed, 31 Jan 2007 16:59:08 +0000 Subject: [PATCH] * Rename "constructor" property in defineProperty() rathern than in put(), since this is what Rhino uses to set the property at compile time. --- src/helma/scripting/rhino/HopObject.java | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/helma/scripting/rhino/HopObject.java b/src/helma/scripting/rhino/HopObject.java index 6254e74d..ecd2265d 100644 --- a/src/helma/scripting/rhino/HopObject.java +++ b/src/helma/scripting/rhino/HopObject.java @@ -121,6 +121,24 @@ public class HopObject extends ScriptableObject implements Wrapper, PropertyReco return toString(); } + /** + * Define a JavaScript property. We override this in order to redirect the + * "constructor" property with the scripted constructor function as its value + * to "__constructor__" + * + * @param propertyName the name of the property to define. + * @param value the initial value of the property + * @param attributes the attributes of the JavaScript property + */ public void defineProperty(String propertyName, Object value, int attributes) { + // redirect the scripted constructor to __constructor__, + // constructor is set to the native constructor method. + if (node == null && "constructor".equals(propertyName) && + value instanceof NativeFunction) { + propertyName = "__constructor__"; + } + super.defineProperty(propertyName, value, attributes); + } + /** * Return the INode wrapped by this HopObject. * @@ -676,11 +694,6 @@ public class HopObject extends ScriptableObject implements Wrapper, PropertyReco */ public void put(String name, Scriptable start, Object value) { if (node == null) { - // redirect the scripted constructor to __constructor__, - // constructor is set to the native constructor method. - if ("constructor".equals(name) && value instanceof NativeFunction) { - name = "__constructor__"; - } // register property for PropertyRecorder interface if (isRecording) { changedProperties.add(name);