Android Open Source - non javascript






From Project

Back to project page non.

License

The source code is released under:

MIT License

If you think the Android project non listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package non.languages;
/*from ww  w  .  j a  v a  2  s.c om*/
import org.mozilla.javascript.*;

public class javascript extends Language {
    public String extension() { return "js"; }
    public String version()   { return "1.7R4"; }
    
    private final Context engine;
    private final Scriptable scope;
    
    public javascript() {
        engine = Context.enter();
        engine.setOptimizationLevel(-1);
        scope = engine.initStandardObjects();
    }
    
    public Object invoke(String object, String method, Object... args) {
        Context context = Context.enter();
        try {
            Function func;
            if (method != null) {
                Scriptable obj = (Scriptable)scope.get(object, scope);
                func = (Function)obj.get(method, obj);
            } else {
                func = (Function)scope.get(object, scope);
            }
            
            if (func == null) return null;
            
            if (args != null) {
                Object[] values = new Object[args.length];
                for (int i = 0; i < args.length; i++) values[i] = convert(args[i]);
                return func.call(context, scope, scope, values);
            } else {
                return func.call(context, scope, scope, null);
            }
        } finally {
            Context.exit();
        }
    }

    public Object eval(String script) {
        return engine.evaluateString(scope, script, "JavaScript", 1, null);
    }

    public void put(String key, Object value) {
        ScriptableObject.putProperty(scope, key, convert(value));
    }
    
    public Object get(String key) {
        return scope.get(key, scope);
    }
    
    public Object convert(Object javaValue) {
        return javaValue == null? UniqueTag.NULL_VALUE:
               javaValue instanceof Scriptable? javaValue:
               Context.javaToJS(javaValue, scope);
    }
}




Java Source Code List

%PACKAGE%.android.AndroidLauncher.java
%PACKAGE%.desktop.DesktopLauncher.java
%PACKAGE%.ios.IOSLauncher.java
launcher.Main.java
non.InputHandle.java
non.Line.java
non.NonBuffer.java
non.Non.java
non.Quad.java
non.languages.Language.java
non.languages.javascript.java
non.languages.lua.java
non.plugins.Plugin.java
non.plugins.audio.java
non.plugins.graphics.java
non.plugins.input.java
non.plugins.lights.java
non.plugins.math.java
non.plugins.network.java
non.plugins.non.java
non.plugins.physics.java