Package org.mozilla.javascript

Examples of org.mozilla.javascript.NativeObject


    executeTimer();
    ScriptResult scriptResult = page.executeJavaScript("window.simulationContext.results");
    NativeArray array = (NativeArray) scriptResult.getJavaScriptResult();
   
    for (int i = 0; i < array.getLength(); i++) {
      NativeObject object = (NativeObject) array.get(i, array);

      String data = null;
     
      Object dataObject = object.get("data", object);
      if (!(dataObject instanceof Undefined)) {
        data = (String) dataObject;
      }
     
      Double startTime = (Double) object.get("startTime", object);
      Double endTime = (Double) object.get("endTime", object);
     
      Object aborted = object.get("aborted", object);
      boolean abortedBoolean = aborted instanceof Boolean && (Boolean) aborted;
     
      result.addData(new RequestData(data, startTime, endTime, abortedBoolean));
    }
   
View Full Code Here


        this.console = console;
    }

    @Override
    public Scriptable getConsoleAsScriptable(Scriptable scope) {
        NativeObject consoleNativeObject = new NativeObject();
        Map<String, LogFunctionWrapper> functionWrapperMap = new HashMap<String, LogFunctionWrapper>();

        for (Method method : Console.class.getDeclaredMethods()) {
            functionWrapperMap.put(method.getName(), LogFunctionWrapper.fromMethodWithDebugging(console, method, scope));
        }

        for (Map.Entry<String, LogFunctionWrapper> stringFunctionWrapperEntry : functionWrapperMap.entrySet()) {
            consoleNativeObject.put(stringFunctionWrapperEntry.getKey(), consoleNativeObject, stringFunctionWrapperEntry.getValue());
        }

        return consoleNativeObject;
    }
View Full Code Here

            ctx.setLanguageVersion(170);

            final Global global = new Global();
            global.initStandardObjects(ctx,false);

            NativeObject exports = new NativeObject();
            global.put("exports", global, exports);

            InputStream resourceAsStream = Rhinodo.class.getClassLoader().getResourceAsStream("META-INF/env/path.js");
            ctx.evaluateReader(global,new InputStreamReader(resourceAsStream), "path",-1, null);

            Function function = (Function) exports.get("basename");
            Object result = (Object) function.call(ctx, global, exports, new Object[]{"hello/bye/now"});

            assertEquals("now", Context.toString(result));

        } finally {
View Full Code Here

            ctx.setLanguageVersion(170);

            final Global global = new Global();
            global.initStandardObjects(ctx,false);

            NativeObject exports = new NativeObject();
            global.put("exports", global, exports);
            global.put("__dirname", global, "/a/b/c/");

            System.setProperty("user.dir", "/a/b/c/");

            InputStream resourceAsStream = Rhinodo.class.getClassLoader().getResourceAsStream("META-INF/env/path.js");
            ctx.evaluateReader(global,new InputStreamReader(resourceAsStream), "path",-1, null);

            Function function = (Function) exports.get("resolve");
            Object result = (Object) function.call(ctx, global, exports, new Object[]{"../hello"});
            assertEquals("/a/b/hello", Context.toString(result));

            result = (Object) function.call(ctx, global, exports, new Object[]{"./bye"});
            assertEquals("/a/b/c/bye", Context.toString(result));
View Full Code Here

        String json = "{" +
                "\"bool\" : false, " +
                "\"str\"  : \"xyz\", " +
                "\"obj\"  : {\"a\":1} " +
                "}";
    NativeObject actual = (NativeObject) parser.parseValue(json);
    assertEquals(false, actual.get("bool", actual));
    assertEquals("xyz", actual.get("str", actual));

    NativeObject innerObj = (NativeObject) actual.get("obj", actual);
    assertEquals(1, innerObj.get("a", innerObj));
    }
View Full Code Here

    }

    public SortedMap<String, FileData> jsonToMap(String data) {
        TreeMap<String, FileData> map = new TreeMap<String, FileData>();
        try {
            NativeObject json = (NativeObject) parser.parseValue(data);
            for (Object scriptURI : json.keySet()) {
                NativeObject scriptData = (NativeObject) json.get(scriptURI);
                NativeArray lineCoverageArray = (NativeArray) scriptData.get("lineData");
                NativeObject branchJSONArray = (NativeObject) scriptData.get("branchData");
                List<Integer> countData = new ArrayList<Integer>(lineCoverageArray.size());
                for (int i = 0; i < lineCoverageArray.size(); i++)
                    countData.add((Integer) lineCoverageArray.get(i));
   
                // Function Coverage (HA-CA)
View Full Code Here

        }
    }

    private void readBranchCondition(List<BranchData> branchConditionArray, NativeArray conditionsJSON) {
        for (int j = 0; j < conditionsJSON.size(); j++) {
            NativeObject conditionJSON = (NativeObject) conditionsJSON.get(j);
            if (conditionJSON == null) {
                branchConditionArray.add(null);
            } else {
                int position = (Integer) conditionJSON.get("position");
                int nodeLength = (Integer) conditionJSON.get("nodeLength");
                String src = (String) conditionJSON.get("src");
                int evalFalse = (Integer) conditionJSON.get("evalFalse");
                int evalTrue = (Integer) conditionJSON.get("evalTrue");
                branchConditionArray.add(new BranchData(position, nodeLength, src, evalFalse, evalTrue));
            }
        }
    }
View Full Code Here

            throw ScriptRuntime.constructError("Error", "Bounds constructor takes a single argument");
        }
        Bounds bounds = null;
        Object arg = args[0];
        if (arg instanceof NativeObject) {
            NativeObject config = (NativeObject) arg;
            if (inNewExpr) {
                bounds = new Bounds(config);
            } else {
                bounds = new Bounds(config.getParentScope(), config);
            }
        } else if (arg instanceof NativeArray) {
            NativeArray array = (NativeArray) arg;
            if (inNewExpr) {
                bounds = new Bounds(array);
View Full Code Here

     * @param configObj
     * @return
     */
    protected static NativeObject prepConfig(Context context, Scriptable configObj) {
        Scriptable scope = configObj.getParentScope();
        NativeObject config = null;
        if (configObj instanceof NativeObject) {
            getRequiredMember(configObj, "coordinates", NativeArray.class, "Array");
            config = (NativeObject) configObj;
        } else if (configObj instanceof NativeArray) {
            NativeArray array = (NativeArray) configObj;
            config = (NativeObject) context.newObject(scope);
            config.put("coordinates", config, array);
        } else {
            throw ScriptRuntime.constructError("Error",
                    "Geometry config must be an array or an object with a coordinates member");
        }
        return config;
View Full Code Here

    @JSConstructor
    public static Object constructor(Context cx, Object[] args, Function ctorObj, boolean inNewExpr) {
        if (args.length != 1) {
            throw ScriptRuntime.constructError("Error", "Point constructor takes a single argument");
        }
        NativeObject config = prepConfig(cx, (Scriptable) args[0]);
        Point point = null;
        if (inNewExpr) {
            point = new Point(config);
        } else {
            point = new Point(config.getParentScope(), config);
        }
        return point;
    }
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.NativeObject

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.