Package org.mozilla.javascript

Examples of org.mozilla.javascript.ScriptableObject$GetterSlot


        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


        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

        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

  /** 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

        out = System.out;
      else if (sel.equals("System.err"))
        out = System.err;
      Object simStatus = app.find(myUi, "simStatus");
      try {
        ScriptableObject scope = cx.initStandardObjects();
        cx.evaluateString(scope, script, "<cmd>", 1, null);
        if (similarity != null) similarity.destroy();
        similarity = new CustomSimilarity(cx, scope, out);
        app.setCustomSimilarity(similarity);
        app.setString(simStatus, "text", "OK");
View Full Code Here

   * @throws WinkBuildException
   */
  private static void executeJs(final String filename) throws WinkBuildException {
    final Context cx = Context.enter();
    cx.setOptimizationLevel(-1);
    final ScriptableObject scope = cx.initStandardObjects();

    final String fileToInspect = new String(filename);
    boolean goodExecution = false;
    try {
      final Reader buildFile = new FileReader(new File(fileToInspect));
View Full Code Here

      Constants.fileInMemory = Boolean.valueOf(getProperty(Constants.OPTION_FILE_IN_MEMORY));
    }

    final Context cx = Context.enter();
    cx.setOptimizationLevel(-1);
    final ScriptableObject scope = cx.initStandardObjects();

    putFunctions(cx, scope);
    putConf(cx, scope);

    final String mainFile = getProperty(Constants.JS_PATH) + File.separator + getProperty(Constants.JS_MAIN_FILE);
View Full Code Here

        childList.add(childList.size(), text);
    }

    protected void postRenderView() throws Exception {
        ScriptableObject scriptableObject =
                (ScriptableObject) this.page.executeJavaScript("window.LOG").getJavaScriptResult();

        scriptableObject.defineProperty("out", systemOut, ScriptableObject.READONLY);
    }
View Full Code Here

        loadFeatureScript(context, scope, GoogleCode.class);
    }

    public static void GoogleCode_upload(final Context context, final Scriptable thisObj,
                                         final Object[] args, final Function funcObj) throws Exception {
        final ScriptableObject config = (ScriptableObject) args[0];
        final GoogleCodeUploader uploader = new GoogleCodeUploader();
        uploader.setUserName(Context.toString(config.get("userName")));
        uploader.setPassword(Context.toString(config.get("password")));
        uploader.setProjectName(Context.toString(config.get("projectName")));
        uploader.setFileName(Context.toString(config.get("fileName")));
        uploader.setTargetFileName(Context.toString(config.get("targetFileName")));
        uploader.setSummary(Context.toString(config.get("summary")));
        if (ScriptableObject.hasProperty(config, "uploadUrl") && config.get("uploadUrl") != Context.getUndefinedValue()) {
//            uploader.setUploadUrl(Context.toString(config.get("uploadUrl")));
        }
        uploader.setVerbose(Context.toBoolean(config.get("verbose")));
        uploader.setLabels(Context.toString(config.get("labels")));
        uploader.setIgnoreSslCertificateHostname(Context.toBoolean(config.get("ignoreSslCertificateHostname")));
        uploader.execute();
    }
View Full Code Here

    public static Object Module_load(final Context context, final Scriptable thisObj,
                                     final Object[] args, final Function funcObj) throws Exception {
        final String name = toStringArray(args)[0];
        final String baseDir = getString(thisObj, "baseDir");
        final Module module = new Module(name, new File(baseDir, name));
        final ScriptableObject moduleObj = (ScriptableObject) context.newObject(thisObj);
        module.init(context, moduleObj);
        return moduleObj;
    }
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.ScriptableObject$GetterSlot

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.