Java Utililty Methods Javascript AST Check

List of utility methods to do Javascript AST Check

Description

The list of methods to do Javascript AST Check are organized into topic(s).

Method

intgetJSArrayLength(JSObject jsObject)
get JS Array Length
Object length = jsObject.getMember("length");
return (length == null) ? 0 : (int) length;
JSObjectgetObject(JSObject parent, Object object)
Creates a new JSObject from string representation of a valid JavaScript object.
return (JSObject) parent.eval(String.format("(function() { return %s; })()", object));
booleanhasMember(JSObject object, String name)
has Member
if (object == null)
    return false;
if (name == null)
    return false;
try {
    return (boolean) object.eval("typeof this." + name + " !== 'undefined'");
} catch (JSException e) {
    return false;
...
int[]toPrimitiveIntArray(JSObject jsObject)
to Primitive Int Array
int length = getJSArrayLength(jsObject);
int[] array = new int[length];
for (int i = 0; i < length; i++)
    array[i] = (int) jsObject.getSlot(i);
return array;