Package org.mozilla.javascript

Examples of org.mozilla.javascript.Function


            oldQuery = watchEntry.getKey();
            if (oldQuery.equals(key)) {
              break;
            }
          }
          final Function newFunction = ((Query) key).conditionFunction;
          final Function oldFunction = ((Query) oldQuery).conditionFunction;
          if (oldFunction != null) {
            // create a new function that combines the other two
            ((Query) oldQuery).conditionFunction = new BaseFunction() {
              public Object call(org.mozilla.javascript.Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
                return ScriptRuntime.toBoolean(newFunction.call(cx,  scope, thisObj, args)) ||
                  ScriptRuntime.toBoolean(oldFunction.call(cx, scope, thisObj, args));
              }
            };
          }
        }
        watchSet.put(key, value);
View Full Code Here


        }
        Object body = ((Scriptable) result).get("body", (Scriptable) result);
        if(body instanceof String)
          response.getOutputStream().write(((String)body).getBytes("UTF-8"));
        else if (body instanceof Scriptable){
          Function forEach = (Function) ScriptableObject.getProperty((Scriptable) body, "forEach");
          Scriptable global = GlobalData.getGlobalScope();
          final ServletOutputStream outputStream = response.getOutputStream();
          forEach.call(PersevereContextFactory.getContext(), global, (Scriptable) body, new Object[]{
            new PersevereNativeFunction(){
              @Override
              public Object profilableCall(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
                try {
                  outputStream.write(args[0].toString().getBytes("UTF-8"));
View Full Code Here

    for (NewObject newObject : new ArrayList<NewObject>(newObjects)) {
      if(!newObject.processed){
        DataSource source = DataSourceManager.getSourceByPrototype(newObject.object.getPrototype());
        if (!("Array".equals(source.getId()) || "Object".equals(source.getId()))){
          Persistable rootQuery = ObjectId.idForObject(source,"").getTarget();
          Function postMethod = (Function) ScriptableObject.getProperty((Persistable) rootQuery, "post");
          if(postMethod instanceof Method)
            ((Method)postMethod).call(PersevereContextFactory.getContext(), GlobalData.getGlobalScope(), rootQuery, new Object[]{newObject.object}, true);
          else
            postMethod.call(PersevereContextFactory.getContext(), GlobalData.getGlobalScope(), rootQuery, new Object[]{newObject.object});
          Method onSave = (Method) ScriptableObject.getProperty(newObject.object, "onSave");
          onSave.call(PersevereContextFactory.getContext(), GlobalData.getGlobalScope(), newObject.object, new Object[0], true);
        }
        newObject.processed = true;
      }
View Full Code Here

     
      globalScope.put("Thread", globalScope, new ThreadConstructor());
      globalScope.put("global", globalScope, globalScope);
      globalScope.put("setTimeout", globalScope, new TimerFunction(false));
      globalScope.put("setInterval", globalScope, new TimerFunction(true));
      Function clearTimer = new PersevereNativeFunction() {
        @Override
        public Object call(Context cx, final Scriptable scope,
            Scriptable thisObj, Object[] args) {
          if(args.length > 0 && args[0] instanceof Number)
            currentQueuedTasks.remove(((Number)args[0]).intValue()).cancel();
View Full Code Here

    Scriptable scope = cx.initStandardObjects(global);
    cx.evaluateString(scope, "var exports = {};", "exports", 1, null);
    cx.evaluateReader(scope, new InputStreamReader(cssmin.openConnection().getInputStream()), cssmin.getFile(), 1, null);
    Scriptable exports = (Scriptable) scope.get("exports", scope);
    Scriptable compressor = (Scriptable) exports.get("compressor", exports);
    Function fn = (Function) compressor.get("cssmin", compressor);
    content = ((String) Context.call(null, fn, compressor, compressor, new Object[] {
        new String(content, charset).replaceFirst("^/\\*", "/*!")})).getBytes(charset);
    Context.exit();
  }
 
View Full Code Here

    private void notifyReadyStateChangeListener() {
        if (readyStateChangeListener instanceof Function) {
            LOG.fine("notify " + readyState);
            // for now, call with no args.
            Function listenerFunction = (Function)readyStateChangeListener;
            listenerFunction.call(Context.getCurrentContext(), getParentScope(), null, new Object[] {});
        }
    }
View Full Code Here

                                              final Object... args) {
        Object fObj = rhinoScope.get(functionName, rhinoScope);
        if (!(fObj instanceof Function)) {
            throw new RuntimeException("Missing test function " + functionName);
        }
        Function function = (Function)fObj;
        try {
            return function.call(rhinoContext, rhinoScope, rhinoScope, args);
        } catch (RhinoException angryRhino) {
            if (expectingException != null && angryRhino instanceof JavaScriptException) {
                JavaScriptException jse = (JavaScriptException)angryRhino;
                Assert.assertEquals(jse.getValue(), expectingException);
                return null;
View Full Code Here

     * @param functionName the name of the function
     * @param passedParams the parameters to pass
     * @return the result of the function
     */
    public Object jsCall(String functionName, Object[] passedParams) {
        Function f = (Function)scope.get(functionName, scope);
        Object result = f.call(getContext(), scope, scope, passedParams);
        return result;
    }
View Full Code Here

                    path = otherBinding.getPath();
                }
            }

            // Build load script
            Function loadScript = null;
            if (commonAtts.loadEnabled) {
                if (otherBinding != null) {
                    loadScript = otherBinding.getLoadScript();
                }

                Element loadElem = DomHelper.getChildElement(element, BindingManager.NAMESPACE, "load-form");
                if (loadElem != null) {
                  loadScript = JavaScriptHelper.buildFunction(loadElem, "loadForm", JavaScriptJXPathBinding.LOAD_PARAMS);
                }
            }

            // Build save script
            Function saveScript = null;
            if (commonAtts.saveEnabled) {
              if (otherBinding != null) {
                    saveScript = otherBinding.getSaveScript();
                }
View Full Code Here

        while (stok.hasMoreTokens()) {
            String fname = stok.nextToken();
            ret.addTriggerWidget(fname);
        }

        Function func = JavaScriptHelper.buildFunction(algorithmElement, "calculate", new String[]{"form", "parent"});
        ret.setJsfunction(func);

        return ret;
    }
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.