From dd4beb2490dd60cfa6488a564bf965623f5e8dc0 Mon Sep 17 00:00:00 2001 From: hns Date: Wed, 20 Jun 2007 09:13:52 +0000 Subject: [PATCH] * Reintroduce defineLibraryScope() because it is still used in various places, but deprecate and drop second argument (boolean initStandardObjects). --- src/helma/scripting/rhino/GlobalObject.java | 25 ++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/helma/scripting/rhino/GlobalObject.java b/src/helma/scripting/rhino/GlobalObject.java index 1cf8c3b4..85f10b92 100644 --- a/src/helma/scripting/rhino/GlobalObject.java +++ b/src/helma/scripting/rhino/GlobalObject.java @@ -73,7 +73,7 @@ public class GlobalObject extends ImporterTopLevel implements PropertyRecorder { "encodeXml", "encodeForm", "stripTags", "formatParagraphs", "getXmlDocument", "getHtmlDocument", "seal", "getDBConnection", "getURL", "write", "writeln", - "serialize", "deserialize", + "serialize", "deserialize", "defineLibraryScope", "wrapJavaMap", "unwrapJavaMap", "toJava" }; @@ -367,6 +367,29 @@ public class GlobalObject extends ImporterTopLevel implements PropertyRecorder { return null; } + /** + * Creates a libary namespace in the global scope. + * + * @param name the name of the libary namespace + * @deprecated should be implemented in JavaScript instead + */ + public void defineLibraryScope(final String name) { + Object obj = get(name, this); + if (obj != NOT_FOUND) { + // put the property again to fool PropertyRecorder + // into believing it has been renewed + put(name, this, obj); + return; + } + ScriptableObject scope = new NativeObject() { + public String getClassName() { + return name; + } + }; + scope.setPrototype(ScriptableObject.getObjectPrototype(this)); + put(name, this, scope); + } + /** * Wrap a java.util.Map so that it looks and behaves like a native JS object * @param obj a map