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

StringgetFunctionArgsString(FunctionNode fn)
Iterates through a function's parameters and returns a string representation of them, suitable for presentation as part of the method's signature.
StringBuilder sb = new StringBuilder("(");
int paramCount = fn.getParamCount();
if (paramCount > 0) {
    List<AstNode> fnParams = fn.getParams();
    for (int i = 0; i < paramCount; i++) {
        String paramName = null;
        AstNode paramNode = fnParams.get(i);
        switch (paramNode.getType()) {
...
ContextgetGlobalContextForValidation()
get Global Context For Validation
Context context = Context.enter();
context.setOptimizationLevel(-1);
return context;
ObjectgetJavaObject(Scriptable scope, String name)
get Java Object
NativeJavaObject objWrapper = (NativeJavaObject) scope.get(name, null);
return objWrapper.unwrap();
ScriptablegetJsArray(Scriptable scope, Vector v)
get Js Array
List<Object> list = new ArrayList<Object>();
for (int i = 0; i < v.size(); i++) {
    if (v.get(i) != null)
        list.add(Context.toObject(v.get(i), scope));
Context cx = Context.getCurrentContext();
return cx.newArray(scope, list.toArray());
MapgetMapArgument(Object[] args, int pos)
Get an argument as Map
if (pos >= args.length || args[pos] == null || args[pos] == Undefined.instance)
    return null;
if (args[pos] instanceof Map<?, ?>)
    return (Map<?, ?>) args[pos];
throw new IllegalArgumentException("Can't convert to java.util.Map: " + args[pos]);
ObjectgetObjectArgument(Object[] args, int pos, Object defaultValue)
Get an argument as object
if (pos >= args.length || args[pos] == null || args[pos] == Undefined.instance)
    return defaultValue;
return Context.jsToJava(args[pos], Object.class);
ObjectgetProperty(Scriptable obj, final String prop)
get Property
while (obj != null) {
    final Object val = obj.get(prop, obj);
    if (val != Scriptable.NOT_FOUND) {
        return val;
    obj = obj.getPrototype();
throw new NoSuchFieldException(prop);
...
StringgetPropertyName(AstNode propKeyNode)
Property keys in object literals can be identifiers or string literals.
return (propKeyNode instanceof Name) ? ((Name) propKeyNode).getIdentifier()
        : ((StringLiteral) propKeyNode).getValue();
StringgetPrototypeClazz(List nodes)
get Prototype Clazz
return getPrototypeClazz(nodes, -1);
ScriptableObjectgetScriptableArgument(Object[] args, int pos, boolean allowNull)
Get an argument as ScriptableObject
if (pos >= args.length || args[pos] == null || args[pos] == Undefined.instance) {
    if (allowNull)
        return null;
    throw new IllegalArgumentException("Argument " + (pos + 1) + " must not be null");
if (args[pos] instanceof ScriptableObject) {
    return (ScriptableObject) args[pos];
throw new IllegalArgumentException("Can't convert to ScriptableObject: " + args[pos]);