List of utility methods to do Javascript Mozilla Library
NativeObject | mapToNativeObject(Map, ?> map) map To Native Object NativeObject nativeObject = new NativeObject(); for (Object key : map.keySet()) { if (map.get(key) instanceof Map<?, ?>) { nativeObject.put(key.toString(), nativeObject, mapToNativeObject((Map<?, ?>) map.get(key))); } else if (map.get(key) instanceof List<?>) { nativeObject.put(key.toString(), nativeObject, listToNativeArray((List<?>) map.get(key))); } else { nativeObject.put(key.toString(), nativeObject, map.get(key)); ... |
String | nativeArrayToString(Object scriptObject) native Array To String List<Object> list = new ArrayList<Object>(); NativeArray array = ((NativeArray) scriptObject); for (int i = 0; i < array.getLength(); i++) { Object object = array.get(i); list.add(scriptableObjectToString(object)); return list.toString(); |
Scriptable | newObject() new Object Context context = Context.getCurrentContext();
Scriptable scope = ScriptRuntime.getTopCallScope(context);
return context.newObject(scope);
|
Number | numberArg(Object[] args, int pos) Return the argument at "pos" as a Number, or throw an exception if the argument list is not long enough. ensureArg(args, pos);
return Context.toNumber(args[pos]);
|
T | objArg(Object[] args, int pos, Class Return the argument at "pos" as a member of the specified Java class, and throw an exception if "required" and the list is too short. if (required) { ensureArg(args, pos); if (pos < args.length) { if (type.isInstance(args[pos])) { return type.cast(args[pos]); } else { Object arg = args[pos]; ... |
String | objectToXMLString(Object xml) object To XML String String xmlStr; if (xml instanceof String) { xmlStr = (String) xml; } else if (xml instanceof Scriptable) { Scriptable xmls = (Scriptable) xml; Context cx = Context.getCurrentContext(); boolean exitContext = false; if (cx == null) { ... |
String | omitLineBreak(AstNode node) omit Line Break return omitLineBreak(node.toSource());
|
String | oneLineStringOf(AstNode node) one Line String Of if (node == null) return ""; String[] str = node.toSource().split("\n"); if (str.length == 1) return str[0]; else { int numOfShownLine = 2; boolean use1 = str.length > 2 && str[0].length() < 10; ... |
AstNode | parentOfAnyTypes(AstNode node, Set return nearest parent node whose type is one of specified ones. AstNode originalCopy = node; while (node != null) { for (Class type : types) { if (type.isInstance(node)) { return node; node = node.getParent(); ... |
T | parentOfType(AstNode node, Class return nearest parent whose type is type. while (node != null) { if (type.isInstance(node)) { @SuppressWarnings("unchecked") T ret = (T) node; return ret; node = node.getParent(); return null; |