* Add dontEnum() function to JavaScript Object prototype. Takes a variable list
of String arguments of propertiy names to set to DONTENUM. * Add some missing Javadocs.
This commit is contained in:
parent
58a109b727
commit
c57877dfb8
1 changed files with 36 additions and 8 deletions
|
@ -73,12 +73,17 @@ public class GlobalObject extends ImporterTopLevel implements PropertyRecorder {
|
||||||
defineFunctionProperties(globalFuncs, GlobalObject.class, 0);
|
defineFunctionProperties(globalFuncs, GlobalObject.class, 0);
|
||||||
put("app", this, Context.toObject(new ApplicationBean(app), this));
|
put("app", this, Context.toObject(new ApplicationBean(app), this));
|
||||||
put("Xml", this, Context.toObject(new XmlObject(core), this));
|
put("Xml", this, Context.toObject(new XmlObject(core), this));
|
||||||
|
// Define dontEnum() on Object prototype
|
||||||
|
String[] objFuncs = { "dontEnum" };
|
||||||
|
ScriptableObject objproto = (ScriptableObject) getObjectPrototype(this);
|
||||||
|
objproto.defineFunctionProperties(objFuncs, GlobalObject.class,
|
||||||
|
DONTENUM | READONLY | PERMANENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get the global object's class name
|
||||||
*
|
*
|
||||||
*
|
* @return the class name for the global object
|
||||||
* @return ...
|
|
||||||
*/
|
*/
|
||||||
public String getClassName() {
|
public String getClassName() {
|
||||||
return "GlobalObject";
|
return "GlobalObject";
|
||||||
|
@ -509,11 +514,10 @@ public class GlobalObject extends ImporterTopLevel implements PropertyRecorder {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* (Try to) strip all HTML/XML style tags from the given string argument
|
||||||
*
|
*
|
||||||
*
|
* @param str a string
|
||||||
* @param str ...
|
* @return the string with tags removed
|
||||||
*
|
|
||||||
* @return ...
|
|
||||||
*/
|
*/
|
||||||
public String stripTags(String str) {
|
public String stripTags(String str) {
|
||||||
if (str == null) {
|
if (str == null) {
|
||||||
|
@ -550,6 +554,9 @@ public class GlobalObject extends ImporterTopLevel implements PropertyRecorder {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize a JavaScript object to a file.
|
||||||
|
*/
|
||||||
public static void serialize(Context cx, Scriptable thisObj,
|
public static void serialize(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
throws IOException
|
throws IOException
|
||||||
|
@ -575,6 +582,9 @@ public class GlobalObject extends ImporterTopLevel implements PropertyRecorder {
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read a previously serialized JavaScript object from a file.
|
||||||
|
*/
|
||||||
public static Object deserialize(Context cx, Scriptable thisObj,
|
public static Object deserialize(Context cx, Scriptable thisObj,
|
||||||
Object[] args, Function funObj)
|
Object[] args, Function funObj)
|
||||||
throws IOException, ClassNotFoundException
|
throws IOException, ClassNotFoundException
|
||||||
|
@ -592,7 +602,25 @@ public class GlobalObject extends ImporterTopLevel implements PropertyRecorder {
|
||||||
return Context.toObject(deserialized, scope);
|
return Context.toObject(deserialized, scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set DONTENUM attrubutes on the given properties in this object.
|
||||||
|
* This is set on the JavaScript Object prototype.
|
||||||
|
*/
|
||||||
|
public static Object dontEnum (Context cx, Scriptable thisObj,
|
||||||
|
Object[] args, Function funObj) {
|
||||||
|
if (!(thisObj instanceof ScriptableObject)) {
|
||||||
|
throw new EvaluatorException("dontEnum() called on non-ScriptableObject");
|
||||||
|
}
|
||||||
|
ScriptableObject obj = (ScriptableObject) thisObj;
|
||||||
|
for (int i=0; i<args.length; i++) {
|
||||||
|
if (!(args[i] instanceof String)) {
|
||||||
|
throw new EvaluatorException("dontEnum() called with non-String argument");
|
||||||
|
}
|
||||||
|
String str = (String) args[i];
|
||||||
|
obj.setAttributes(str, obj.getAttributes(str) | DONTENUM);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private static String toString(Object obj) {
|
private static String toString(Object obj) {
|
||||||
if (obj == null || obj == Undefined.instance) {
|
if (obj == null || obj == Undefined.instance) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue