Package org.mozilla.javascript

Examples of org.mozilla.javascript.NativeObject$ValueCollection


        return thisObj instanceof Persistable ? ((Persistable)thisObj).getParent() : null;
      }
    },false);
    objectProto.setAttributes("parent",ScriptableObject.DONTENUM);
   
    Scriptable applicationJavascript = new NativeObject();
    objectProto.put("representation:application/javascript", objectProto, applicationJavascript);
    objectProtoMirror.put("representation:application/javascript", objectProtoMirror, applicationJavascript);
    objectProto.setAttributes("representation:application/javascript",ScriptableObject.DONTENUM);
    applicationJavascript.put("quality", applicationJavascript, 0.9);
    applicationJavascript.put("output", applicationJavascript, new PersevereNativeFunction(){
      @Override
      public Object call(Context cx, Scriptable scope,
          Scriptable thisObj, Object[] args) {
        try {
          HttpServletResponse response = Client.getCurrentObjectResponse().getHttpResponse();
          DirtyOutputStreamWriter writer = new DirtyOutputStreamWriter(response.getOutputStream(),"UTF8");
          try{
            new JavaScriptSerializer().serialize(args[0], Client.getCurrentObjectResponse(), writer);
          }
          catch(RuntimeException e){
            if(writer.isDirty)
              writer.write("&&");
            throw e;
          }
          finally{
            writer.flushIfDirty();
          }
          return null;
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

    });
   
    Scriptable applicationJson = new NativeObject();
    objectProto.put("representation:application/json", objectProto, applicationJson);
    objectProtoMirror.put("representation:application/json", objectProtoMirror, applicationJson);
    objectProto.setAttributes("representation:application/json",ScriptableObject.DONTENUM);
    applicationJson.put("quality", applicationJson, 0.8);
    applicationJson.put("output", applicationJson, new PersevereNativeFunction(){
      @Override
      public Object call(Context cx, Scriptable scope,
          Scriptable thisObj, Object[] args) {
        try {
          HttpServletResponse response = Client.getCurrentObjectResponse().getHttpResponse();
View Full Code Here


  context.exit();
  // Get JSLint errors
  NativeArray errors = (NativeArray) lint.get("errors", null);
  List<JSLintIssue> result = new ArrayList<JSLintIssue>();
  for (int i = 0; i < errors.getLength(); i++) {
      NativeObject error = (NativeObject) errors.get(i, null);
      if (null == error) {
    continue;
      }
      // Add error
      result.add(new JSLintIssue(error));
View Full Code Here

            this.content = content;
            this.windowWrapper = ww;
        }

        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, windowWrapper));
            }
            if (content != null) {
                so.put("content", so,
                       Context.toObject(content, windowWrapper));
            }
            return new Object [] { so };
        }
View Full Code Here

            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

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

        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

        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

    @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

    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

        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

TOP

Related Classes of org.mozilla.javascript.NativeObject$ValueCollection

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.