Package org.mozilla.javascript

Examples of org.mozilla.javascript.Function


        }
      }
      if(!stream.started){
        // call the onConnect function
        Scriptable global = GlobalData.getGlobalScope();
        Function onConnect = (Function) global.get("onConnect", global);
        onConnect.call(PersevereContextFactory.getContext(), global, global, new Object[]{ stream });
      }
      stream.started = true;
    }
    return stream;
  }
View Full Code Here


  }
  public static void grabSecurityHandlers() {
    Scriptable global = GlobalData.getGlobalScope();
    createUserHandler = (Function) global.get("createUser", global);
    grantAccessHandler = (Function) global.get("grantAccess", global);
    final Function doAuthentication = (Function) global.get("authenticate", global);
    // create a wrapper to record the authenticated user in the current thread
    authenticateHandler = new PersevereNativeFunction(){
      @Override
      public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
        Object user = doAuthentication.call(cx, scope, thisObj, args);
        UserSecurity.registerThisThread(user);
        return user;
      }
     
    };
View Full Code Here

      if(schema == null){
        schema = ObjectId.idForString("Class/Object").getTarget();
      }
      Scriptable global = GlobalData.getGlobalScope();
     
      Function queryFunction = (Function) ScriptableObject.getProperty(schema, "query");
      Function QueryString = (Function) global.get("QueryString", global);
      Scriptable queryString = QueryString.construct(PersevereContextFactory.getContext(), global, new Object[]{jsonPath, paramScope});
      if(queryFunction instanceof Method){
        queryFunction = ((Method)queryFunction).innerFunction;
      }
      result = queryFunction.call(PersevereContextFactory.getContext(), global, target, new Object[]{queryString, target});
    }finally{
View Full Code Here

    Transaction.startTransaction();
    PersistableObject.enableSecurity(true);
    for(Object testObject : ((List)args[0])){
      Scriptable test = (Scriptable) testObject;
      String name = "anonymous";
      Function testFunction;
      Object nameObject;
      if(test instanceof Function){
        testFunction = (Function) test;
      }
      else{
        testFunction = (Function) test.get("runTest", test);
        nameObject = test.get("name", test);
        if (nameObject instanceof String)
          name =  (String) nameObject;
      }
      nameObject = testFunction.get("name", test);
      if (nameObject instanceof String)
        name =  (String) nameObject;
     
      try{
        totalTests++;
        testFunction.call(cx, scope, thisObj, args);
        try{
          Transaction.currentTransaction().commit();
        }
        finally{
          Transaction.startTransaction();
View Full Code Here

    @Override
    public String handle(ClientImpl client, Transport transport, Message message) throws IOException {
      if (!message.getChannel().startsWith("/meta")){
        // These are published messages
        Persistable target = (Persistable) Identification.idForString((String) message.getChannel()).getTarget();
        Function messageFunc = (Function) target.get("message");
        messageFunc.call(PersevereContextFactory.getContext(), GlobalData.getGlobalScope(), target, new Object[]{message.getData()});
        // don't actually publish it, let Persevere handle it
        return null;
      }
      if (message.getChannel().startsWith("/meta/subscribe")){
        // A subscription request, we just need to make sure the global listener
View Full Code Here

            // Wrapped Java objects won't have "toSource" and will report
            // errors for get()s of nonexistent name, so use has() first
            if (ScriptableObject.hasProperty(obj, "toSource")) {
        Object v = ScriptableObject.getProperty(obj, "toSource");
        if (v instanceof Function) {
            Function f = (Function)v;
            return ScriptRuntime.toString(f.call(cx, scope, obj, ScriptRuntime.emptyArgs));
        }
            }
            return ScriptRuntime.toString(value);
        }
        return value.toString();
View Full Code Here

    finished = true;
    synchronized(streams){
      streams.remove(connectionId);// remove the stream, this should make it gc-able.
    }
    Scriptable global = GlobalData.getGlobalScope();
    Function onDisconnect = (Function) global.get("onDisconnect", global);

    if(started){
     
      onDisconnect.call(PersevereContextFactory.getContext(), global, global, new Object[]{ this });
    }
  }
View Full Code Here

            Object callbackArg = args.length > 0 ? args[0] : Undefined.instance;
            if (callbackArg == null || !(callbackArg instanceof Function)) {
                throw ScriptRuntime.notFunctionError(
                         ScriptRuntime.toString(callbackArg));
            }
            final Function f = (Function) callbackArg;

        return new QueryArray(null){
          long sizeEstimate = ((QueryArray)thisObj).estimatedSize(0);
          int lastSizeEstimateIndex = -1;
          @Override
          public Iterator iterator() {
            final Iterator sourceIterator = ((List)thisObj).iterator();
           
            return new Iterator(){
              int i = -1;
              Object next;
              private void getNext(){
                do{
                  next = Scriptable.NOT_FOUND;
                  if(!sourceIterator.hasNext())
                    return;
                  i++;
                  if(i % 100 == 0){
                    if(i > maxIterations && PersistableObject.isSecurityEnabled() && !UserSecurity.hasPermission(SystemPermission.runLongQueries)){
                      throw ScriptRuntime.constructError("AccessError", "Query has taken too much computation, and the user is not allowed to execute resource-intense queries. Increase maxIterations in your config file to allow longer running non-indexed queries to be processed.");
                    }
                  }
                  next = sourceIterator.next();
                  if(ScriptRuntime.toBoolean(f.call(cx, scope, thisObj, new Object[]{next, i, thisObj})))
                    return;
                  if(i > lastSizeEstimateIndex){
                    lastSizeEstimateIndex = i;
                    sizeEstimate--;
                  }
View Full Code Here

                throw ScriptRuntime.constructError("AccessError", "Query has taken too much computation, and the user is not allowed to execute resource-intense queries");
              }
            }
            if (o1 instanceof Scriptable && o2 instanceof Scriptable){
              while(sortIndex < args.length){
                Function func = ((Function)args[sortIndex]);
                boolean ascending = (Boolean)args[sortIndex + 1];
                Object v1;
                try{
                  v1 = func.call(cx, scope, (Scriptable) o1, new Object[]{o1});
                }catch(EcmaError e){
                  v1 = Undefined.instance;
                }
                Object v2;
                try{
                  v2 = func.call(cx, scope, (Scriptable) o2, new Object[]{o2});
                }catch(EcmaError e){
                  v2 = Undefined.instance;
                }
                int comparison = CompareValues.instance.compare(v1, v2);
                if (comparison != 0)
View Full Code Here

        }
      }
    }
    HttpServletResponse response = Client.getCurrentObjectResponse().getHttpResponse();
    if(bestRep != null){
      Function getContentType = (Function) ScriptableObject.getProperty(bestRep, "output");
      PersistableObject.enableSecurity(true);
      if(response != null && setType) {
        response.setContentType(bestType + "; charset=UTF-8");
      }
      getContentType.call(PersevereContextFactory.getContext(), GlobalData.getGlobalScope(), bestRep, new Object[]{value});
      return;
    }
   
    response.setStatus(406);
    try {
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.Function

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.