Examples of ScriptableObject


Examples of net.sourceforge.htmlunit.corejs.javascript.ScriptableObject

    /*
     * 1. lookup functions by name. 2. Find context and scope. 3. Convert
     * thisObject to ScriptableObject 4. Convert args 5. Get return value
     */
    Context jsContext = Context.getCurrentContext();
    ScriptableObject jsThis;
    if (thisObj.getType() == ValueType.NULL) {
      jsThis = window;
    } else {
      jsThis = (ScriptableObject) makeJsvalFromValue(jsContext, thisObj);
    }
View Full Code Here

Examples of net.sourceforge.htmlunit.corejs.javascript.ScriptableObject

      if (value instanceof ScriptableObject) {
        /*
         * HACK: check for native types like NativeString. NativeString is
         * package-protected. What other types do we need to check?
         */
        ScriptableObject scriptableValue = (ScriptableObject) value;
        String className = scriptableValue.getClassName();
        if (className.equals("String")) {
          return new Value(scriptableValue.toString());
        }
      }
      Integer refId = jsObjectToRef.get(value);
      if (refId == null) {
        refId = nextRefId++;
View Full Code Here

Examples of net.sourceforge.htmlunit.corejs.javascript.ScriptableObject

    /*
     * 1. lookup functions by name. 2. Find context and scope. 3. Convert
     * thisObject to ScriptableObject 4. Convert args 5. Get return value
     */
    Context jsContext = Context.getCurrentContext();
    ScriptableObject jsThis;
    if (thisObj.getType() == ValueType.NULL) {
      jsThis = window;
    } else {
      jsThis = (ScriptableObject) makeJsvalFromValue(jsContext, thisObj);
    }
View Full Code Here

Examples of net.sourceforge.htmlunit.corejs.javascript.ScriptableObject

      if (value instanceof ScriptableObject) {
        /*
         * HACK: check for native types like NativeString. NativeString is
         * package-protected. What other types do we need to check?
         */
        ScriptableObject scriptableValue = (ScriptableObject) value;
        String className = scriptableValue.getClassName();
        if (className.equals("String")) {
          return new Value(scriptableValue.toString());
        }
      }
      Integer refId = jsObjectToRef.get(value);
      if (refId == null) {
        refId = nextRefId++;
View Full Code Here

Examples of net.sourceforge.htmlunit.corejs.javascript.ScriptableObject

    /*
     * 1. lookup functions by name. 2. Find context and scope. 3. Convert
     * thisObject to ScriptableObject 4. Convert args 5. Get return value
     */
    Context jsContext = Context.getCurrentContext();
    ScriptableObject jsThis = null;
    if (thisObj.getType() == ValueType.NULL) {
      jsThis = window;
    } else {
      Object obj = makeJsvalFromValue(jsContext, thisObj);
      if (obj instanceof ScriptableObject) {
View Full Code Here

Examples of net.sourceforge.htmlunit.corejs.javascript.ScriptableObject

      if (value instanceof ScriptableObject) {
        /*
         * HACK: check for native types like NativeString. NativeString is
         * package-protected. What other types do we need to check?
         */
        ScriptableObject scriptableValue = (ScriptableObject) value;
        String className = scriptableValue.getClassName();
        if (className.equals("String")) {
          return new Value(scriptableValue.toString());
        }
      }
      Integer refId = jsObjectToRef.get(value);
      if (refId == null) {
        refId = nextRefId++;
View Full Code Here

Examples of org.mozilla.javascript.ScriptableObject

        String lowerCaseName = prototype.getLowerCaseName();

        TypeInfo type = (TypeInfo) prototypes.get(lowerCaseName);

        // check if the prototype info exists already
        ScriptableObject op = (type == null) ? null : type.objProto;

        // if prototype info doesn't exist (i.e. is a standard prototype
        // built by HopExtension), create it.
        if (op == null) {
            if ("global".equals(lowerCaseName)) {
                op = global;
            } else if ("hopobject".equals(lowerCaseName)) {
                op = hopObjectProto;
            } else {
                op = new HopObject(name, this);
            }
            type = registerPrototype(prototype, op);
        }

        // Register a constructor for all types except global.
        // This will first create a new prototyped HopObject and then calls
        // the actual (scripted) constructor on it.
        if (!"global".equals(lowerCaseName)) {
            try {
                new HopObjectCtor(name, this, op);
                op.setParentScope(global);
            } catch (Exception x) {
                app.logError("Error adding ctor for " + name,  x);
            }
        }
View Full Code Here

Examples of org.mozilla.javascript.ScriptableObject

        return new FileObject(args[0].toString(), args[1].toString());
    }

    public static void init(Scriptable scope) {
        Method[] methods = FileObject.class.getDeclaredMethods();
        ScriptableObject proto = new FileObject();
        proto.setPrototype(getObjectPrototype(scope));
        Member ctorMember = null;
        for (int i=0; i<methods.length; i++) {
            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",
                                "write",
                                "remove",
                                "list",
                                "flush",
                                "writeln",
                                "close",
                                "getPath",
                                "open",
                                "error",
                                "canRead",
                                "canWrite",
                                "exists",
                                "getAbsolutePath",
                                "getLength",
                                "isDirectory",
                                "isFile",
                                "lastModified",
                                "mkdir",
                                "renameTo",
                                "eof",
                                "isOpened",
                                "readln",
                                "clearError",
                                "readAll"
                               };
        try {
            proto.defineFunctionProperties(fileFuncs, FileObject.class, 0);
        } catch (Exception ignore) {
            System.err.println ("Error defining function properties: "+ignore);
        }
    }
View Full Code Here

Examples of org.mozilla.javascript.ScriptableObject

        return new FtpObject(args[0].toString());
    }

    public static void init(Scriptable scope) {
        Method[] methods = FtpObject.class.getDeclaredMethods();
        ScriptableObject proto = new FtpObject();
        proto.setPrototype(getObjectPrototype(scope));
        Member ctorMember = null;
        for (int i=0; i<methods.length; i++) {
            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"
                            };
        try {
            proto.defineFunctionProperties(ftpFuncs, FtpObject.class, 0);
        } catch (Exception ignore) {
            System.err.println ("Error defining function properties: "+ignore);
        }
    }
View Full Code Here

Examples of org.mozilla.javascript.ScriptableObject

  /** Execute supplied code against supplied data,
   *   see JavascriptEngineTest for examples */
  public String execute(String code, String jsonData) throws IOException {
        final String jsCode = "data=" + jsonData + ";\n" + code;
        final Context rhinoContext = Context.enter();
        final ScriptableObject scope = rhinoContext.initStandardObjects();

        // execute the script, out script variable maps to sw
        final StringWriter sw = new StringWriter();
        final PrintWriter pw = new PrintWriter(sw, true);
        ScriptableObject.putProperty(scope, "out", Context.javaToJS(pw, scope));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.