Package org.mozilla.javascript

Examples of org.mozilla.javascript.FunctionObject


            if ("fileObjCtor".equals(methods[i].getName())) {
                ctorMember = methods[i];
                break;
            }
        }
        FunctionObject ctor = new FunctionObject("File", ctorMember, scope);
        ctor.addAsConstructor(scope, proto);
        String[] fileFuncs = {
                                "toString",
                                "getName",
                                "getParent",
                                "isAbsolute",
View Full Code Here


            if ("imageCtor".equals(methods[i].getName())) {
                ctorMember = methods[i];
                break;
            }
        }
        FunctionObject ctor = new FunctionObject("Image", ctorMember, scope);
        ScriptableObject.defineProperty(scope, "Image", ctor, ScriptableObject.DONTENUM);
        ctor.put("getInfo", ctor, new GetInfo());
    }
View Full Code Here

            if ("ftpObjCtor".equals(methods[i].getName())) {
                ctorMember = methods[i];
                break;
            }
        }
        FunctionObject ctor = new FunctionObject("FtpClient", ctorMember, scope);
        ctor.addAsConstructor(scope, proto);
        String[] ftpFuncs = {
                "login", "cd", "mkdir", "lcd", "putFile",
                "putString", "getFile", "getString", "logout",
                "binary", "ascii"
                            };
View Full Code Here

            return null;
        }

        private void runCompiledModule(Script compiled, Context cx, ModuleImpl mod)
        {
            Function requireFunc = new FunctionObject("require",
                                                      Utils.findMethod(NativeImpl.class, "require"),
                                                      this);

            // The script code found in src/main/javascript is wrapped with a function by the Rhino compiler
            // (see the pom.xml for the wrapper code). What we actually
View Full Code Here

        Scriptable exports = cx.newObject(scope);
        exports.setParentScope(null);
        exports.setPrototype(scope);

        ScriptableObject.defineClass(exports, ParserImpl.class);
        FunctionObject fn = new FunctionObject("HTTPParser", Utils.findMethod(ParserImpl.class, "newParser"),
                                               exports);
        fn.put("REQUEST", fn, ParserImpl.REQUEST);
        fn.put("RESPONSE", fn, ParserImpl.RESPONSE);
        exports.put("HTTPParser", exports, fn);
        return exports;
    }
View Full Code Here

        // of CryptoImpl out of a hat and uses it for the `this` scope in the Java code. This new instance is
        // *not* `exports`, and hasn't been initialized here, so it doesn't have a reference to the runtime.
        // With the varargs form, `thisObj` is the "wrong" scope (not a CryptoImpl), and func.getParentScope()
        // is the new, uninitialized CryptoImpl instance.
        ScriptableObject proto = (ScriptableObject) export.getPrototype();
        FunctionObject randomBytes = (FunctionObject) proto.get("randomBytes", proto);
        randomBytes.setParentScope(export);
        FunctionObject pseudoRandomBytes = (FunctionObject) proto.get("pseudoRandomBytes", proto);
        pseudoRandomBytes.setParentScope(export);

        ScriptableObject.defineClass(export, HashImpl.class, false, true);
        ScriptableObject.defineClass(export, MacImpl.class, false, true);
        ScriptableObject.defineClass(export, CipherImpl.class);
        ScriptableObject.defineClass(export, DecipherImpl.class);
View Full Code Here

    // http://stackoverflow.com/questions/3441947/how-do-i-call-a-method-of-a-java-instance-from-javascript/16479685#16479685
    try {
      Class[] parameters = new Class[] { String.class };
      Method inMethod = ECMAScriptDataModel.class.getMethod("jsIn",
          parameters);
      FunctionObject inFunc = new FunctionObject("In", inMethod,
          newDM.scope);
      newDM.scope.put("In", newDM.scope, inFunc);
    } catch (SecurityException e) {
      System.err.println(e);
    } catch (NoSuchMethodException e) {
View Full Code Here

     
      Scriptable globalScope = cx.initStandardObjects(s);

      cx.setOptimizationLevel(-1); // must use interpreter mode
     
      FunctionObject f = new FunctionObject("foo", JsClass.class.getMethod("foo", String.class, Object.class), globalScope);
     
      cx.putThreadLocal("tl", "bla");
     
      globalScope.put("foo", globalScope, f);//necessary or scriptus.foo won't work either...
      globalScope.put("scriptus", globalScope, s);
View Full Code Here

        if(m.hasSeparateImpl()) {
            continue;
        }
       
          globalScope.put(m.getMethodName(), globalScope,
                  new FunctionObject(
                          m.getMethodName(),
                          this.getClass().getMethod(m.getMethodName(), m.getMethodArgs()),
                        globalScope)
          );
    }
   
//    globalScope.put("log", globalScope, new FunctionObject("log", this.getClass().getMethod("log", Object.class), globalScope));
//    globalScope.put("fork", globalScope, new FunctionObject("fork", this.getClass().getMethod("fork"), globalScope));
//    globalScope.put("kill", globalScope, new FunctionObject("kill", this.getClass().getMethod("kill", String.class), globalScope));
//    globalScope.put("exec", globalScope, new FunctionObject("exec", this.getClass().getMethod("exec", String.class, String.class), globalScope));
//    globalScope.put("listen", globalScope, new FunctionObject("listen", this.getClass().getMethod("listen", NativeObject.class), globalScope));
//    globalScope.put("say", globalScope, new FunctionObject("say", this.getClass().getMethod("say", String.class, NativeObject.class), globalScope));
//    globalScope.put("ask", globalScope, new FunctionObject("ask", this.getClass().getMethod("ask", String.class, NativeObject.class), globalScope));
//    globalScope.put("get", globalScope, new FunctionObject("get", this.getClass().getMethod("get", String.class), globalScope));
//    globalScope.put("sleep", globalScope, new FunctionObject("sleep", this.getClass().getMethod("sleep", Object.class), globalScope));
//    globalScope.put("exit", globalScope, new FunctionObject("exit", this.getClass().getMethod("exit", Object.class), globalScope));

    String source;
    try {
      source = IOUtils.toString(globalScope.getClass().getClassLoader().getResourceAsStream("wait.js"));
    } catch (IOException e) {
      throw new ScriptusRuntimeException(e);
    }

    Function getLastPid = new FunctionObject("_intern_getLastPid", this.getClass().getMethod("_intern_getLastPid"),
        globalScope);
    Function wait_intern = new FunctionObject("_intern_wait", this.getClass().getMethod("_intern_wait", String.class), globalScope);

    Function wait_ctor = cx.compileFunction(globalScope, source, "wait_internal.js", 0, null);

    Function wait = (Function) wait_ctor.call(cx, globalScope, null, new Object[] { wait_intern, getLastPid });
   
View Full Code Here

        response.setEntity(new OutputRepresentation(mediaType) {
           
            @Override
            public void write(OutputStream outputStream) throws IOException {
                Context cx = CommonJSEngine.enterContext();
                FunctionObject writeFunc = new FunctionObject("bodyWriter", writeMethod, scope);
                BoundFunction boundWrite = new BoundFunction(cx, scope, writeFunc, body, new Object[] {outputStream});
                Object[] args = {boundWrite};
                try {
                    forEach.call(cx, scope, body, args);
                } finally {
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.FunctionObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.