Examples of NativeObject


Examples of org.mozilla.javascript.NativeObject

            this.content = content;
            this.scope   = scope;
        }

        public Object[] buildArguments() {
            ScriptableObject so = new NativeObject();
            so.put("success", so,
                   (success) ? Boolean.TRUE : Boolean.FALSE);
            if (mime != null) {
                so.put("contentType", so,
                       Context.toObject(mime, scope));
            }
            if (content != null) {
                so.put("content", so,
                       Context.toObject(content, scope));
            }
            return new Object [] { so };
        }
View Full Code Here

Examples of org.mozilla.javascript.NativeObject

     * @param o a javascript object to be converted into a Map
     * @return the bound script
     * @throws IOException if {@link Pig#bind(Map)} throws an IOException
     */
    public BoundScript bind(Object o) throws IOException {
        NativeObject vars = (NativeObject)o;
        Map<String, Object> params = new HashMap<String, Object>();
        Object[] ids = vars.getIds();
        for (Object id : ids) {
            if (id instanceof String) {
                String name = (String) id;
                Object value = vars.get(name, vars);
                if (!(value instanceof NativeFunction) && value != null) {
                    params.put(name, value.toString());
                }
            }
        }
View Full Code Here

Examples of org.mozilla.javascript.NativeObject

        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

Examples of org.mozilla.javascript.NativeObject

        RhinoExecutor executor = executorPool.get();

        try
        {

            NativeObject result = (NativeObject) executor.invokeFunction("compileCoffeeScriptSource", content, source.toString());

            if (result.containsKey("exception"))
            {
                throw new RuntimeException(getString(result, "exception"));
            }

            return IOUtils.toInputStream(getString(result, "output"), UTF8);
View Full Code Here

Examples of org.mozilla.javascript.NativeObject

    @Test
    public void setPropertyOnSomeObj() {
        RhinoContext context = new RhinoContext();

        NativeObject anObj = (NativeObject) context.evalJS("var obj = { a: 'a'}; obj");
        context.setProperty("obj", "b", "b");

        assertThat(anObj.get("b", anObj)).isEqualTo("b");
    }
View Full Code Here

Examples of org.mozilla.javascript.NativeObject

    public List<Error> run(InputStream source, String options, String globals) {
        final List<Error> results = new ArrayList<JSHint.Error>();

        String sourceAsText = toString(source);

        NativeObject nativeOptions = toJsObject(options);
        NativeObject nativeGlobals = toJsObject(globals);

        Boolean codePassesMuster = rhino.call("JSHINT", sourceAsText, nativeOptions, nativeGlobals);

        if(!codePassesMuster){
            NativeArray errors = rhino.eval("JSHINT.errors");
View Full Code Here

Examples of org.mozilla.javascript.NativeObject

        return results;
    }

    private NativeObject toJsObject(String options) {
        NativeObject nativeOptions = new NativeObject();
        for (final String nextOption : options.split(",")) {
            final String option = nextOption.trim();
            if(!option.isEmpty()){
                final String name;
                final Object value;

                final int valueDelimiter = option.indexOf(':');
                if(valueDelimiter==-1){
                    name = option;
                    value = Boolean.TRUE;
                } else {
                    name = option.substring(0, valueDelimiter);
                    String rest = option.substring(valueDelimiter+1).trim();
                    if (rest.matches("[0-9]+")) {
                        value = Integer.parseInt(rest);
                    } else if (rest.equals("true")) {
                        value = Boolean.TRUE;
                    } else if (rest.equals("false")) {
                        value = Boolean.FALSE;
                    } else {
                        value = rest;           
                    }
                }
                nativeOptions.defineProperty(name, value, NativeObject.READONLY);
            }
        }
        return nativeOptions;
    }
View Full Code Here

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

Examples of org.mozilla.javascript.NativeObject

        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

Examples of org.mozilla.javascript.NativeObject

            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
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.