Package org.mozilla.javascript

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


        }
        if (!(args[0] instanceof NativeObject)) {
            HostObjectUtil.invalidArgsError(hostObjectName, functionName, "1", "string", args[0], false);
        }

        NativeObject jcookie = (NativeObject) args[0];
        Gson gson = new Gson();
        Cookie cookie = gson.fromJson(HostObjectUtil.serializeJSON(jcookie), Cookie.class);


        ResponseHostObject rho = (ResponseHostObject) thisObj;
View Full Code Here

        if (!(args[2] instanceof String) && !(args[2] instanceof Integer)) {
            HostObjectUtil.invalidArgsError(hostObjectName, hostObjectName, "3", "string", args[2], true);
        }

        NativeObject configs = null;
        if (argsCount == 4) {
            if (!(args[3] instanceof NativeObject)) {
                HostObjectUtil.invalidArgsError(hostObjectName, hostObjectName, "4", "object", args[3], true);
            }
            configs = (NativeObject) args[3];
View Full Code Here

    stopWatch.stop();

    stopWatch.start("compile");
    try {
      final String execute = getCompilationCommand(typeScript);
      final NativeObject compilationResult = (NativeObject) builder.evaluate(execute, "compile");
      final NativeArray errors = (NativeArray) compilationResult.get(PARAM_ERRORS);
      if (errors.size() > 0) {
        throwCompilationError(errors);
      }
      return compilationResult.get(PARAM_SOURCE).toString();
    } finally {
      stopWatch.stop();
      LOG.debug(stopWatch.prettyPrint());
    }
  }
View Full Code Here

    // fields to be added to the object. If it is a Callable,
    // call it on the object and again use its return value
    // as a hashtable if it is a NativeObject.
    Class classObject = getClassObject();
    int modifiers = classObject.getModifiers();
    NativeObject properties = null;
    Callable initialize = null;
    if (args.length > 0
        && !Modifier.isInterface(modifiers)
        && !Modifier.isAbstract(modifiers)) {
      // Look at the last argument to find out if we need to do something
View Full Code Here

      properties.remove(name);
  }

  public Scriptable getInstancePrototype() {
    if (instanceProto == null) {
      instanceProto = new NativeObject();
      // Set the prototype chain correctly for this prototype object,
      // so properties in the prototype of parent classes are found too:
      Class sup = getClassObject().getSuperclass();
      Scriptable parent;
      if (sup != null) {
View Full Code Here

  public Object unwrap(Object obj) {
    if (obj instanceof Wrapper) {
      return ((Wrapper) obj).unwrap();
    } else if (obj instanceof NativeObject) {
      // Allow JS objects to define a unwrap method:
      NativeObject object = (NativeObject) obj;
      Object unwrap = ScriptableObject.getProperty(object, "unwrap");
      if (unwrap != Scriptable.NOT_FOUND
          && unwrap instanceof org.mozilla.javascript.Callable) {
        obj = ((org.mozilla.javascript.Callable) unwrap).call(
            Context.getCurrentContext(),
View Full Code Here

      throw new RhinoScriptException(this, e);
    }
  }
 
  public Scope createScope() {
    Scriptable scope = new NativeObject();
    // Sharing the top level scope:
    // https://developer.mozilla.org/En/Rhino_documentation/Scopes_and_Contexts
    scope.setPrototype(topLevel);
    scope.setParentScope(null);
    return new RhinoScope(this, scope);
  }
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);
        value = option.substring(valueDelimiter+1);
    }
    nativeOptions.defineProperty(name, value, NativeObject.READONLY);
      }
  }
  return nativeOptions;
    }
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.