From f6d21299a0906fbaf216157d789bea7919d38f4f Mon Sep 17 00:00:00 2001 From: hns Date: Tue, 19 Feb 2008 11:52:15 +0000 Subject: [PATCH] * Make sure prototype and parent scope are set correctly for HopObject.getById(). Fixes bug 601 http://helma.org/bugs/show_bug.cgi?id=601 * Do not define HopObject.getById() as READONLY. Fixes bug 602 http://helma.org/bugs/show_bug.cgi?id=602 --- src/helma/scripting/rhino/HopObjectCtor.java | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/helma/scripting/rhino/HopObjectCtor.java b/src/helma/scripting/rhino/HopObjectCtor.java index 3f421d20..e8f71a3f 100644 --- a/src/helma/scripting/rhino/HopObjectCtor.java +++ b/src/helma/scripting/rhino/HopObjectCtor.java @@ -43,7 +43,8 @@ public class HopObjectCtor extends FunctionObject { } } - static final int attr = DONTENUM | PERMANENT | READONLY; + static final int attr = DONTENUM | PERMANENT; + /** * Create and install a HopObject constructor. * Part of this is copied from o.m.j.FunctionObject.addAsConstructor(). @@ -54,10 +55,8 @@ public class HopObjectCtor extends FunctionObject { super(protoName, hopObjCtor, core.global); this.core = core; this.protoProperty = prototype; - // Scriptable ps = prototype.getParentScope(); addAsConstructor(core.global, prototype); - // prototype.setParentScope(ps); - defineProperty("getById", new GetById(), attr); + defineProperty("getById", new GetById(core.global), attr); } /** @@ -139,6 +138,10 @@ public class HopObjectCtor extends FunctionObject { class GetById extends BaseFunction { + public GetById(Scriptable scope) { + ScriptRuntime.setFunctionProtoAndParent(this, scope); + } + /** * Retrieve any persistent HopObject by type name and id. * @@ -165,6 +168,15 @@ public class HopObjectCtor extends FunctionObject { } return node == null ? null : Context.toObject(node, this); } + + public int getArity() { + return 1; + } + + public int getLength() { + return 1; + } + } }