Java Utililty Methods Javascript Mozilla Library

List of utility methods to do Javascript Mozilla Library

Description

The list of methods to do Javascript Mozilla Library are organized into topic(s).

Method

booleanisPrototypePropertyGet(PropertyGet pg)
is Prototype Property Get
return pg != null && pg.getLeft() instanceof Name && isPrototypeNameNode(pg.getRight());
booleanisSimplePropertyGet(PropertyGet pg, String expectedObj, String expectedField)
Returns whether a PropertyGet is a simple one, referencing an object's value 1 level deep.
return pg != null && isName(pg.getLeft(), expectedObj) && isName(pg.getRight(), expectedField);
booleanisStaticProperty(Scriptable property)

Replies true if the mixin property propert is a "static" property.

Object isStatic = ((Scriptable) property).get("static", (Scriptable) property);
return isStatic != Scriptable.NOT_FOUND && isStatic instanceof Boolean && ((Boolean) isStatic);
booleanisValid(Object[] args)
is Valid
return args.length > 0 && args[0] != Context.getUndefinedValue();
booleanisVariable(Name name)
Check if the Name (AstNode) is a variable.
AstNode parent = name.getParent();
if (parent instanceof InfixExpression) {
    InfixExpression ie = (InfixExpression) parent;
    if (ie.getOperator() == Token.GETPROP || ie.getOperator() == Token.GETPROPNOWARN) {
        if (ie.getRight() == name)
            return false;
    } else {
        return true;
...
ObjectjavaToJS(Object o, Scriptable scope)
Convert a Java object to a JavaScript one.
Class<?> cls = o.getClass();
if (cls.isArray()) {
    return new NativeArray((Object[]) o);
} else {
    return Context.javaToJS(o, scope);
ObjectjsToJava(Object jsObject)
js To Java
if (jsObject == null)
    return null;
if (jsObject == org.mozilla.javascript.Context.getUndefinedValue())
    return null;
if (jsObject instanceof String)
    return jsObject;
if (jsObject instanceof Boolean)
    return jsObject;
...
ObjectjsToJava(Object obj)
js To Java
while (obj instanceof Wrapper) {
    obj = ((Wrapper) obj).unwrap();
return obj;
NativeArraylistToNativeArray(List list)
list To Native Array
List<Object> nativeObjects = new ArrayList<Object>();
for (Object object : list) {
    if (object instanceof Map<?, ?>) {
        nativeObjects.add(mapToNativeObject((Map<?, ?>) object));
    } else if (object instanceof List<?>) {
        nativeObjects.add(listToNativeArray((List<?>) object));
    } else {
        nativeObjects.add(object);
...
ObjectmapJSToJava(final Object jsObject)
map JS To Java
if (jsObject instanceof NativeArray) {
    final NativeArray ary = (NativeArray) jsObject;
    final int aryLen = (int) ary.getLength();
    final Object[] aryO = new Object[aryLen];
    final String[] aryS = new String[aryLen];
    final boolean[] aryB = new boolean[aryLen];
    final double[] aryN = new double[aryLen];
    boolean isStringArray = true;
...