Package org.mozilla.javascript

Examples of org.mozilla.javascript.ContextFactory$Listener


     *
     * TODO: make the custom class loader work (at not loading all the Java classes).
     */
    @BeforeClass
    public static void messWithClassLoader() {
      ContextFactory.initGlobal(new ContextFactory() {
        @Override
        protected Context makeContext() {
          Context cx = super.makeContext();
          cx.setWrapFactory(new WrapFactory() {
            @Override
            public Object wrap(Context cx, Scriptable scope, Object obj, Class staticType) {
              return super.wrap(cx, scope, obj, staticType);
            }
            @Override
            public Scriptable wrapNewObject(Context cx, Scriptable scope, Object obj) {
              return super.wrapNewObject(cx, scope, obj);
            }
            @Override
            public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, Object javaObject, Class staticType) {
              return new SandboxNativeJavaObject(scope, javaObject, staticType);
            }           
          });
          return cx;
        }       
      });
      ContextFactory factory = ContextFactory.getGlobal();
      factory.initApplicationClassLoader(new SandboxClassLoader(TurtleSpecSection2_1Test.class.getClassLoader()));   
    }
View Full Code Here


   *
   * TODO: make the custom class loader work (at not loading all the Java classes).
   */
  @BeforeClass
  public static void messWithClassLoader() {
    ContextFactory.initGlobal(new ContextFactory() {
      @Override
      protected Context makeContext() {
        Context cx = super.makeContext();
        cx.setWrapFactory(new WrapFactory() {
          @Override
          public Object wrap(Context cx, Scriptable scope, Object obj, Class staticType) {
            return super.wrap(cx, scope, obj, staticType);
          }
          @Override
          public Scriptable wrapNewObject(Context cx, Scriptable scope, Object obj) {
            return super.wrapNewObject(cx, scope, obj);
          }
          @Override
          public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, Object javaObject, Class staticType) {
            return new SandboxNativeJavaObject(scope, javaObject, staticType);
          }           
        });
        return cx;
      }       
    });
    ContextFactory factory = ContextFactory.getGlobal();
    factory.initApplicationClassLoader(new SandboxClassLoader(TurtleSpecSection2_1Test.class.getClassLoader()));   
  }
View Full Code Here

   *
   * TODO: make the custom classloader work (at not loading all the Java classes).
   */
  @BeforeClass
  public static void messWithClassLoader() {
    ContextFactory.initGlobal(new ContextFactory() {
      @Override
      protected Context makeContext() {
        Context cx = super.makeContext();
        cx.setWrapFactory(new WrapFactory() {
          @Override
          public Object wrap(Context cx, Scriptable scope, Object obj, Class staticType) {
            return super.wrap(cx, scope, obj, staticType);
          }
          @Override
          public Scriptable wrapNewObject(Context cx, Scriptable scope, Object obj) {
            return super.wrapNewObject(cx, scope, obj);
          }
          @Override
          public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, Object javaObject, Class staticType) {
            return new SandboxNativeJavaObject(scope, javaObject, staticType);
          }           
        });
        return cx;
      }       
    });
    ContextFactory factory = ContextFactory.getGlobal();
    factory.initApplicationClassLoader(new SandboxClassLoader(TurtleSpecSection2_2Test.class.getClassLoader()));   
  }
View Full Code Here

   *
   * TODO: make the custom classloader work (at not loading all the Java classes).
   */
  @BeforeClass
  public static void messWithClassLoader() {
    ContextFactory.initGlobal(new ContextFactory() {
      @Override
      protected Context makeContext() {
        Context cx = super.makeContext();
        cx.setWrapFactory(new WrapFactory() {
          @Override
          public Object wrap(Context cx, Scriptable scope, Object obj, Class staticType) {
            return super.wrap(cx, scope, obj, staticType);
          }
          @Override
          public Scriptable wrapNewObject(Context cx, Scriptable scope, Object obj) {
            return super.wrapNewObject(cx, scope, obj);
          }
          @Override
          public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, Object javaObject, Class staticType) {
            return new SandboxNativeJavaObject(scope, javaObject, staticType);
          }           
        });
        return cx;
      }       
    });
    ContextFactory factory = ContextFactory.getGlobal();
    factory.initApplicationClassLoader(new SandboxClassLoader(TurtleSpecSection2_2Test.class.getClassLoader()));   
  }
View Full Code Here

   *
   * TODO: make the custom class loader work (at not loading all the Java classes).
   */
  @BeforeClass
  public static void messWithClassLoader() {
    ContextFactory.initGlobal(new ContextFactory() {
      @Override
      protected Context makeContext() {
        Context cx = super.makeContext();
        cx.setWrapFactory(new WrapFactory() {
          @Override
          public Object wrap(Context cx, Scriptable scope, Object obj, Class staticType) {
            return super.wrap(cx, scope, obj, staticType);
          }
          @Override
          public Scriptable wrapNewObject(Context cx, Scriptable scope, Object obj) {
            return super.wrapNewObject(cx, scope, obj);
          }
          @Override
          public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, Object javaObject, Class staticType) {
            return new SandboxNativeJavaObject(scope, javaObject, staticType);
          }           
        });
        return cx;
      }       
    });
    ContextFactory factory = ContextFactory.getGlobal();
    factory.initApplicationClassLoader(new SandboxClassLoader(StringsTest.class.getClassLoader()));   
  }
View Full Code Here

   *
   * TODO: make the custom classloader work (at not loading all the Java classes).
   */
  @BeforeClass
  public static void messWithClassLoader() {
    ContextFactory.initGlobal(new ContextFactory() {
      @Override
      protected Context makeContext() {
        Context cx = super.makeContext();
        cx.setWrapFactory(new WrapFactory() {
          @Override
          public Object wrap(Context cx, Scriptable scope, Object obj, Class staticType) {
            return super.wrap(cx, scope, obj, staticType);
          }
          @Override
          public Scriptable wrapNewObject(Context cx, Scriptable scope, Object obj) {
            return super.wrapNewObject(cx, scope, obj);
          }
          @Override
          public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, Object javaObject, Class staticType) {
            return new SandboxNativeJavaObject(scope, javaObject, staticType);
          }           
        });
        return cx;
      }       
    });
    ContextFactory factory = ContextFactory.getGlobal();
    factory.initApplicationClassLoader(new SandboxClassLoader(TurtleSpecSection2_2Test.class.getClassLoader()));   
  }
View Full Code Here

  {
    public double apply(final Object[] args);
  }

  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();


    return new Function()
    {
      public double apply(Object[] args)
      {
        // ideally we need a close() function to discard the context once it is not used anymore
        Context cx = Context.getCurrentContext();
        if (cx == null) {
          cx = contextFactory.enterContext();
        }

        return Context.toNumber(fn.call(cx, scope, scope, args));
      }
    };
View Full Code Here

  public void testSetNullForScriptableSetter() throws Exception {

    final String scriptCode = "foo.myProp = new Foo2();\n"
      + "foo.myProp = null;";

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

    try {
          final ScriptableObject topScope = cx.initStandardObjects();
          final Foo foo = new Foo();
View Full Code Here

            return super.hasFeature(cx, featureIndex);
        }
    }

    public void testCustomContextFactory() {
        ContextFactory factory = new MyFactory();
        Context cx = factory.enterContext();
        try {
            Scriptable globalScope = cx.initStandardObjects();
            // Test that FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME is enabled
            /* TODO(stevey): fix this functionality in parser
            Object result = cx.evaluateString(globalScope,
View Full Code Here

    doTest(1, expected, action);
  }

  private void doTest(final int optimizationLevel, final String expected, final ContextAction action)
  {
    Object o = new ContextFactory().call(new ContextAction()
      {
        public Object run(final Context context)
        {
          context.setOptimizationLevel(optimizationLevel);
          return Context.toString(action.run(context));
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.ContextFactory$Listener

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.