Package org.mozilla.javascript

Examples of org.mozilla.javascript.ScriptableObject$KeySet


  private static Function compile(String function) {
    final ContextFactory contextFactory = ContextFactory.getGlobal();
    final Context context = contextFactory.enterContext();
    context.setOptimizationLevel(9);

    final ScriptableObject scope = context.initStandardObjects();

    final org.mozilla.javascript.Function fn = context.compileFunction(scope, function, "fn", 1, null);
    Context.exit();

View Full Code Here


    private ModelAndView handleRequestInContext(
            final HttpServletRequest request,
            final HttpServletResponse response,
            final NativeContinuation continuation, final Context cx) throws Exception
    {
        final ScriptableObject scope;
        if(continuation == null)
        {
            scope = scriptStorage.createNewTopLevelScope(cx);
        }
        else
View Full Code Here

        }
    }
   
    ScriptableObject createNewTopLevelScope(Context cx)
    {
        ScriptableObject scope = (ScriptableObject)cx.newObject(library);
        scope.setPrototype(library);
        scope.setParentScope(null);
        return scope;
    }
View Full Code Here

    final ContextFactory factory = new ContextFactory();
    final Context cx = factory.enterContext();

    try {
          final ScriptableObject topScope = cx.initStandardObjects();
          final Foo foo = new Foo();

          // define custom setter method
          final Method setMyPropMethod = Foo.class.getMethod("setMyProp", Foo2.class);
          foo.defineProperty("myProp", null, null, setMyPropMethod, ScriptableObject.EMPTY);

          topScope.put("foo", topScope, foo);

          ScriptableObject.defineClass(topScope, Foo2.class);

          cx.evaluateString(topScope, scriptCode, "myScript", 1, null);
    }
View Full Code Here

    final ContextAction action = new ContextAction()
    {
      public Object run(final Context _cx)
      {
        final ScriptableObject scope = _cx.initStandardObjects();
        final Object result = _cx.evaluateString(scope, script, "test script", 0, null);
        assertEquals("b1,b2,a0,a1,,a3", Context.toString(result));
        return null;
      }
    };
View Full Code Here

   
    final ContextAction action = new ContextAction()
    {
      public Object run(final Context _cx)
      {
        final ScriptableObject scope = _cx.initStandardObjects();
        final Object result = _cx.evaluateString(scope, script, "test script", 0, null);
        return null;
      }
    };
View Full Code Here

    final ContextAction action = new ContextAction()
    {
      public Object run(final Context _cx)
      {
        final ScriptableObject scope = _cx.initStandardObjects();
        final Object result = _cx.evaluateString(scope, script, "test script", 0, null);
        assertEquals("object", ScriptRuntime.typeof(result));
        assertEquals("1", Context.toString(result));
        return null;
      }
View Full Code Here

        reference.put("b", Boolean.TRUE);
        reference.put("c", new HashMap());
        reference.put(new Integer(1), new Integer(42));
        // get a js object as map
        Context context = Context.enter();
        ScriptableObject scope = context.initStandardObjects();
        map = (Map<Object, Object>) context.evaluateString(scope,
                "({ a: 'a', b: true, c: new java.util.HashMap(), 1: 42});",
                "testsrc", 1, null);
        Context.exit();
    }
View Full Code Here

    final ContextFactory factory = new ContextFactory();
    final Context cx = factory.enterContext();

    try {
          final ScriptableObject topScope = cx.initStandardObjects();
          final Foo foo = new Foo();
 
          // define custom setter method
          final Method setMyPropMethod = Foo.class.getMethod("setMyProp", Foo2.class);
          foo.defineProperty("myProp", null, null, setMyPropMethod, ScriptableObject.EMPTY);
 
          topScope.put("foo", topScope, foo);
         
          ScriptableObject.defineClass(topScope, Foo2.class);
     
          cx.evaluateString(topScope, scriptCode, "myScript", 1, null);
    }
View Full Code Here

        Context cx = Context.enter();
        cx.setOptimizationLevel(-1);

        try {

            ScriptableObject scope = new ImporterTopLevel(cx);

            // evaluate stencil set and beautifier
            cx.evaluateString(scope, stencilsetScript, "<cmd>", 1, null);
            cx.evaluateString(scope, beautifierScript, "<cmd>", 1, null);

            // run beautifier on stencil set
            String result = (String) ScriptableObject.callMethod(scope, "beautify", new Object[] { scope.get("set", scope) });

            System.out.println(result.toString());

        } finally {
            Context.exit();
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.ScriptableObject$KeySet

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.