List of utility methods to do Javascript Mozilla Library
T | prototypeCast(Scriptable s, Class prototype Cast Scriptable obj = s; while (obj != null && !type.isInstance(obj)) { obj = obj.getPrototype(); return type.cast(obj); |
void | removeLinkFromXhtml(Object xhtml, String link) remove Link From Xhtml if (xhtml instanceof Scriptable) { Scriptable sxhtml = (Scriptable) xhtml; String classname = sxhtml.getClassName().toLowerCase(); if ("xml".equals(classname) || "xmllist".equals(classname)) { final String XHTML_DEL_LINK = "var link_re = new RegExp('" + link + "/?');" + "for each (var x in xhtml..*.(link_re.test(@href.toString() || @src.toString()))) { " + "x.parent().replace(x.childIndex(), x.*); " + "}"; Context cx = Context.getCurrentContext(); ... |
void | runWithAllOptimizationLevels(final ContextAction action) Runs the action successively with all available optimization levels runWithOptimizationLevel(action, -1); runWithOptimizationLevel(action, 0); runWithOptimizationLevel(action, 1); |
void | runWithOptimizationLevel(final ContextAction action, final int optimizationLevel) Runs the provided action at the given optimization level runWithOptimizationLevel(new ContextFactory(), action, optimizationLevel);
|
String | scriptableObjectToString(Object scriptObject) scriptable Object To String String objectName = scriptObject.getClass().getSimpleName(); if (objectName.equals("Double") || scriptObject.getClass().getSimpleName().equals("Integer")) { return scriptObject.toString(); if (objectName.equals("NativeArray")) { return nativeArrayToString(scriptObject); if (objectName.equals("NativeObject")) { ... |
double | stringToNumber(CharSequence string) Decodes a JSON-compatible number from string. int len = string.length(); int start = 0; char startChar; for (;;) { if (start == len) { return +0.0; startChar = string.charAt(start); ... |
String | stringValue(String name, Scriptable scope) Returns the value of a JavaScript variable, or null. if (scope == null) { return null; Object o = scope.get(name, scope); return o instanceof String ? (String) o : null; |
int | toInt(Object obj, int defaultValue) Try to convert an object to an int value, returning the default value if conversion fails. double d = ScriptRuntime.toNumber(obj); if (d == ScriptRuntime.NaN || (int) d != d) { return defaultValue; return (int) d; |
boolean | toJavaBoolean(final Scriptable options, final String key) to Java Boolean try { return (boolean) Context.jsToJava(ScriptableObject.getProperty(options, key), Boolean.TYPE); } catch (Exception e) { return false; |
Integer | toJavaInt(final Object fromScript) to Java Int try { return (Integer) Context.jsToJava(fromScript, Integer.class); } catch (Exception e) { return null; |