List of utility methods to do Javascript Mozilla Library
boolean | isPrototypePropertyGet(PropertyGet pg) is Prototype Property Get return pg != null && pg.getLeft() instanceof Name && isPrototypeNameNode(pg.getRight()); |
boolean | isSimplePropertyGet(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);
|
boolean | isStaticProperty(Scriptable property) Replies true if the mixin property Object isStatic = ((Scriptable) property).get("static", (Scriptable) property); return isStatic != Scriptable.NOT_FOUND && isStatic instanceof Boolean && ((Boolean) isStatic); |
boolean | isValid(Object[] args) is Valid return args.length > 0 && args[0] != Context.getUndefinedValue();
|
boolean | isVariable(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; ... |
Object | javaToJS(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); |
Object | jsToJava(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; ... |
Object | jsToJava(Object obj) js To Java while (obj instanceof Wrapper) { obj = ((Wrapper) obj).unwrap(); return obj; |
NativeArray | listToNativeArray(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); ... |
Object | mapJSToJava(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; ... |