List of utility methods to do Javascript Mozilla Library
void | addToScriptable(Scriptable scriptable, String name, Properties props) add To Scriptable try { Context context = Context.enter(); Scriptable obj = context.newObject(scriptable); addToScriptable(scriptable, name, obj); for (Entry<Object, Object> entry : props.entrySet()) { addToScriptable(obj, (String) entry.getKey(), entry.getValue()); } finally { ... |
Scriptable | asObject(final Scriptable scope, final Map, ?> map) Converts a map into a JavaScript object. final Scriptable newObject = Context.getCurrentContext().newObject(scope); for (final Map.Entry<?, ?> mapEntry : map.entrySet()) { newObject.put(mapEntry.getKey().toString(), newObject, mapEntry.getValue()); return newObject; |
boolean | booleanValue(String name, Scriptable scope) Return the boolean value of a JavaScript variable. Object val = scope.get(name, scope); if (val == UniqueTag.NOT_FOUND) { return false; } else { return Context.toBoolean(val); |
Object | callFn(Function function, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) call Fn boolean exitContext = false; if (Context.getCurrentContext() == null) { Context.enter(); exitContext = true; Context context = (cx == null) ? Context.getCurrentContext() : cx; Object result = function.call(context, scope, thisObj, args); if (exitContext) { ... |
Object[] | convertArray(NativeArray jsArray) convert Array Object[] ids = jsArray.getIds(); Object[] result = new Object[ids.length]; for (int i = 0; i < ids.length; i++) { Object id = ids[i]; int index = (Integer) id; Object jsValue = jsArray.get(index, jsArray); result[i] = jsToJava(jsValue); return result; |
Object | convertObject(NativeObject jsObject, Map convert Object Object[] ids = jsObject.getIds(); Map result = new HashMap(ids.length); for (Object id : ids) { if (id instanceof String) { Object jsValue = jsObject.get((String) id, jsObject); result.put(id, jsToJava(jsValue, identities)); } else if (id instanceof Integer) { Object jsValue = jsObject.get((Integer) id, jsObject); ... |
void | copyPropertiesToScriptable(Hashtable properties, Scriptable scriptable) copy Properties To Scriptable if (properties == null || scriptable == null) return; Context cx = Context.enter(); try { for (Enumeration e = properties.keys(); e.hasMoreElements();) { String key = (String) e.nextElement(); Object value = properties.get(key); scriptable.put(key, scriptable, value); ... |
Scriptable | copyScope(Context context, Scriptable scope) copy Scope Scriptable scopeCopy = context.initStandardObjects(); for (Object id : scope.getIds()) { scopeCopy.put(id.toString(), scopeCopy, scope.get(id.toString(), scope)); return scopeCopy; |
void | copyScriptableToProperties(Scriptable scriptable, Map copy Scriptable To Properties if (properties == null || scriptable == null) return; Context.enter(); try { Object ids[] = scriptable.getIds(); for (int i = 0; i < ids.length; i++) { String key = ids[i].toString(); Object value = scriptable.get(ids[i].toString(), scriptable); ... |
Object[] | createJavaAdapterArgs(Scriptable scope, Class[] ifaces, Object jsImpl) create Java Adapter Args Object[] ret = new Object[ifaces.length + 1]; for (int i = 0; i < ifaces.length; i++) { ret[i] = new NativeJavaClass(scope, ifaces[i]); ret[ret.length - 1] = jsImpl; return ret; |