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

NativeObjectmapToNativeObject(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));
...
StringnativeArrayToString(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();
ScriptablenewObject()
new Object
Context context = Context.getCurrentContext();
Scriptable scope = ScriptRuntime.getTopCallScope(context);
return context.newObject(scope);
NumbernumberArg(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]);
TobjArg(Object[] args, int pos, Class type, boolean required)
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];
...
StringobjectToXMLString(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) {
...
StringomitLineBreak(AstNode node)
omit Line Break
return omitLineBreak(node.toSource());
StringoneLineStringOf(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;
...
AstNodeparentOfAnyTypes(AstNode node, Set types, boolean isStrict)
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();
...
TparentOfType(AstNode node, Class type)
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;