Package org.mozilla.javascript

Examples of org.mozilla.javascript.Function


      try {
          cx.setOptimizationLevel(-1); // must use interpreter mode
          cx.evaluateString(globalScope,
                  "function f(a) { var k = myObject.f(a); var t = []; return k; }",
                  "function test source", 1, null);
          Function f = (Function) globalScope.get("f", globalScope);
          Object[] args = { 7 };
          cx.callFunctionWithContinuations(f, globalScope, args);
          fail("Should throw ContinuationPending");
      } catch (ContinuationPending pending) {
          // serialize
View Full Code Here


      Object _setContextObj = codewriter.get( "_setContext", codewriter );
      if( null == _setContextObj || !(_setContextObj instanceof Function) ) {
        throw new RuntimeException( "no codewriter._setContext in script" );
      }

      Function _setContext = (Function) _setContextObj;
      _setContext.call(cx,scope,codewriter,new Object[]{context});

      Object _generateObj = codewriter.get( "_generate", codewriter );
      if( null == _generateObj || !(_generateObj instanceof Function) ) {
        throw new RuntimeException( "no codewriter._generate in script" );
      }

      Function _generate = (Function) _generateObj;
      result = _generate.call(cx,scope,codewriter,new Object[]{args,new Boolean(throwWriterExceptions)});

      template.setResult( result );
    }

    catch( StandardException se ) {
View Full Code Here

      try {
          cx.setOptimizationLevel(-1); // must use interpreter mode
          cx.evaluateString(globalScope,
                  "function f(a) { return myObject.f(a); }",
                  "function test source", 1, null);
          Function f = (Function) globalScope.get("f", globalScope);
          Object[] args = { 7 };
          cx.callFunctionWithContinuations(f, globalScope, args);
          fail("Should throw ContinuationPending");
      } catch (ContinuationPending pending) {
          Object applicationState = pending.getApplicationState();
View Full Code Here

      try {
          cx.setOptimizationLevel(-1); // must use interpreter mode
          cx.evaluateString(globalScope,
                  "function f(a) { return myObject.f(a); }",
                  "function test source", 1, null);
          Function f = (Function) globalScope.get("f", globalScope);
          Object[] args = { 7 };
          cx.callFunctionWithContinuations(f, globalScope, args);
          fail("Should throw ContinuationPending");
      } catch (ContinuationPending pending) {
          // serialize
View Full Code Here

        return createRhinoFunctionInvoker(functionName, null);
    }

   
    public RhinoFunctionInvoker createRhinoFunctionInvoker(String functionName, Class responseClass) {
        Function function = getFunction(functionName);
        //Class responseClass = responseClasses.get(functionName);
        RhinoFunctionInvoker invoker = new RhinoFunctionInvoker(instanceScope, function, responseClass);
        return invoker;
    }
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

      Object _setContextObj = codewriter.get( "_setContext", codewriter );
      if( null == _setContextObj || !(_setContextObj instanceof Function) ) {
        throw new RuntimeException( "no codewriter._setContext in script" );
      }

      Function _setContext = (Function) _setContextObj;
      _setContext.call(cx,scope,codewriter,new Object[]{context});

      Object _generateObj = codewriter.get( "_generate", codewriter );
      if( null == _generateObj || !(_generateObj instanceof Function) ) {
        throw new RuntimeException( "no codewriter._generate in script" );
      }

      Function _generate = (Function) _generateObj;
      result = _generate.call(cx,scope,codewriter,new Object[]{args,new Boolean(throwWriterExceptions)});

      template.setResult( result );
    }

    catch( StandardException se ) {
View Full Code Here

    Context context = contextFactory.enterContext();
    context.setOptimizationLevel(9);

    final ScriptableObject scope = context.initStandardObjects();

    final Function fnAggregate = context.compileFunction(scope, aggregate, "aggregate", 1, null);
    final Function fnReset = context.compileFunction(scope, reset, "reset", 1, null);
    final Function fnCombine = context.compileFunction(scope, combine, "combine", 1, null);
    Context.exit();

    return new JavaScriptAggregator.ScriptAggregator()
    {
      @Override
      public double aggregate(final double current, final ObjectColumnSelector[] selectorList)
      {
        Context cx = Context.getCurrentContext();
        if (cx == null) {
          cx = contextFactory.enterContext();

          // Disable primitive wrapping- we want Java strings and primitives to behave like JS entities.
          cx.getWrapFactory().setJavaPrimitiveWrap(false);
        }

        final int size = selectorList.length;
        final Object[] args = new Object[size + 1];

        args[0] = current;
        for (int i = 0 ; i < size ; i++) {
          final ObjectColumnSelector selector = selectorList[i];
          if (selector != null) {
            final Object arg = selector.get();
            if (arg != null && arg.getClass().isArray()) {
              // Context.javaToJS on an array sort of works, although it returns false for Array.isArray(...) and
              // may have other issues too. Let's just copy the array and wrap that.
              final Object[] arrayAsObjectArray = new Object[Array.getLength(arg)];
              for (int j = 0; j < Array.getLength(arg); j++) {
                arrayAsObjectArray[j] = Array.get(arg, j);
              }
              args[i + 1] = cx.newArray(scope, arrayAsObjectArray);
            } else {
              args[i + 1] = Context.javaToJS(arg, scope);
            }
          }
        }

        final Object res = fnAggregate.call(cx, scope, scope, args);
        return Context.toNumber(res);
      }

      @Override
      public double combine(final double a, final double b)
      {
        final Object res = contextFactory.call(
            new ContextAction()
            {
              @Override
              public Object run(final Context cx)
              {
                return fnCombine.call(cx, scope, scope, new Object[]{a, b});
              }
            }
        );
        return Context.toNumber(res);
      }
View Full Code Here

  /**
   * ECMA 11.4.3 says that typeof on host object is Implementation-dependent
   */
  public void test0() throws Exception
  {
        final Function f = new BaseFunction()
        {
          @Override
          public Object call(Context _cx, Scriptable _scope, Scriptable _thisObj,
              Object[] _args)
          {
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.