* Add new global function defineLibraryScope(string, boolean). This creates a new global
property object with the name in argument 1 only if it doesn't exist yet, and optionally populates it with the standard JavaScript object (String, Date, isNaN, ...)
This commit is contained in:
parent
05bce5953e
commit
5c804670cb
1 changed files with 29 additions and 1 deletions
|
@ -67,7 +67,7 @@ public class GlobalObject extends ImporterTopLevel implements PropertyRecorder {
|
||||||
"encodeXml", "encodeForm", "stripTags", "formatParagraphs",
|
"encodeXml", "encodeForm", "stripTags", "formatParagraphs",
|
||||||
"getXmlDocument", "getHtmlDocument", "seal",
|
"getXmlDocument", "getHtmlDocument", "seal",
|
||||||
"getDBConnection", "getURL", "write", "writeln",
|
"getDBConnection", "getURL", "write", "writeln",
|
||||||
"serialize", "deserialize"
|
"serialize", "deserialize", "defineLibraryScope"
|
||||||
};
|
};
|
||||||
|
|
||||||
defineFunctionProperties(globalFuncs, GlobalObject.class, 0);
|
defineFunctionProperties(globalFuncs, GlobalObject.class, 0);
|
||||||
|
@ -365,6 +365,34 @@ public class GlobalObject extends ImporterTopLevel implements PropertyRecorder {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a global object, optionally initializing it with standard
|
||||||
|
* JavaScript objects. This can be used for script libraries that want
|
||||||
|
* to extend standard JavaScript functionality, but leave the original
|
||||||
|
* prototypes alone.
|
||||||
|
*
|
||||||
|
* @param name the name of the new scope
|
||||||
|
*/
|
||||||
|
public void defineLibraryScope(final String name, boolean initStandardObjects) {
|
||||||
|
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 ScriptableObject() {
|
||||||
|
public String getClassName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (initStandardObjects) {
|
||||||
|
Context cx = Context.getCurrentContext();
|
||||||
|
cx.initStandardObjects(scope, false);
|
||||||
|
}
|
||||||
|
put(name, this, scope);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue