Java Javascript Mozilla Library javaToJS(Object o, Scriptable scope)

Here you can find the source of javaToJS(Object o, Scriptable scope)

Description

Convert a Java object to a JavaScript one.

License

Open Source License

Parameter

Parameter Description
o Any Java object.
scope The scope within which the conversion is made.

Return

An equivalent JavaScript object.

Declaration

static Object javaToJS(Object o, Scriptable scope) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import org.mozilla.javascript.Context;
import org.mozilla.javascript.NativeArray;

import org.mozilla.javascript.Scriptable;

public class Main {
    /**//  ww  w .  j  a  v a  2  s. c  o m
     * Convert a Java object to a JavaScript one. This is basically like {@link Context#javaToJS} except that we convert arrays to real JavaScript arrays instead of {@link NativeJavaArray} instances.
     * This is done in order to satisfy lint implementation of {@code Array.isArray()}.
     * @param o Any Java object.
     * @param scope The scope within which the conversion is made.
     * @return An equivalent JavaScript object.
     */
    static Object javaToJS(Object o, Scriptable scope) {
        Class<?> cls = o.getClass();
        if (cls.isArray()) {
            return new NativeArray((Object[]) o);
        } else {
            return Context.javaToJS(o, scope);
        }
    }
}

Related

  1. isPrototypePropertyGet(PropertyGet pg)
  2. isSimplePropertyGet(PropertyGet pg, String expectedObj, String expectedField)
  3. isStaticProperty(Scriptable property)
  4. isValid(Object[] args)
  5. isVariable(Name name)
  6. jsToJava(Object jsObject)
  7. jsToJava(Object obj)
  8. listToNativeArray(List list)
  9. mapJSToJava(final Object jsObject)