Package org.mozilla.javascript

Examples of org.mozilla.javascript.ContextFactory$GlobalSetter


  /**
   * Runs the provided action at the given optimization level
   */
  public static void runWithOptimizationLevel(final ContextAction action, final int optimizationLevel)
  {
    runWithOptimizationLevel(new ContextFactory(), action, optimizationLevel);
  }
View Full Code Here


            return super.doTopCall(callable, cx, scope, thisObj, args);
        }
    }

    private void baseCase(int optimizationLevel, String source) {
        ContextFactory factory = new MyFactory();
        Context cx = factory.enterContext();
        cx.setOptimizationLevel(optimizationLevel);
        assertTrue(cx instanceof MyContext);
        try {
            Scriptable globalScope = cx.initStandardObjects();
            cx.evaluateString(globalScope,
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

        return result;
    }

    @Test
    public void runDoctest() throws Exception {
        ContextFactory factory = ContextFactory.getGlobal();
        Context cx = factory.enterContext();
        try {
            cx.setOptimizationLevel(optimizationLevel);
            Global global = new Global(cx);
            // global.runDoctest throws an exception on any failure
            int testsPassed = global.runDoctest(cx, global, source, name, 1);
View Full Code Here

public class Bug637811Test {
    private Context cx;

    @Before
    public void setUp() throws Exception {
        cx = new ContextFactory() {
            @Override
            protected boolean hasFeature(Context cx, int featureIndex) {
                switch (featureIndex) {
                case Context.FEATURE_STRICT_MODE:
                case Context.FEATURE_WARNING_AS_ERROR:
View Full Code Here

    public void testClassGen() {
        final List<Class<?>> classes = new ArrayList<Class<?>>();
        classes.add(java.lang.Runnable.class);
        classes.add(java.lang.Appendable.class);
        ContextFactory cf = ContextFactory.getGlobal();
        cf.call(new ContextAction() {
            public Object run(Context cx) {
                Class<?> c1 = EventAdapter.getAdapterClass(classes.toArray(), null);
                Class<?> c2 = EventAdapter.getAdapterClass(classes.toArray(), null);
                assertTrue(c1.getSuperclass() == Object.class);
                assertTrue(Runnable.class.isAssignableFrom(c1));
                assertTrue(Appendable.class.isAssignableFrom(c1));
                assertEquals(c1, c2);
                return null;
            }
        });
        cf.call(new ContextAction() {
            public Object run(Context cx) {
                Map<String,String> bindings = new HashMap<String,String>();
                bindings.put("append", "add");
                bindings.put("run", "run");
                Class<?> c1 = EventAdapter.getAdapterClass(classes.toArray(),
View Full Code Here

    public void setDebuggerScript(String path) {
        debuggerScript = path;
    }

    public void install() {
        ContextFactory factory = Context.getCurrentContext().getFactory();
        factory.addListener(new ContextFactory.Listener() {
            public void contextCreated(Context cx) {
                DebuggerBase debugger = createDebugger();
                if (debugger != null) {
                    debugger.attach(createContextData());
                }
View Full Code Here

        }
        if (args.length < || !(args[0] instanceof Function)) {
            throw Context.reportRuntimeError("spawn() requires a function argument");
        }
        final Scriptable scope = funObj.getParentScope();
        final ContextFactory cxfactory = cx.getFactory();
        final Function function = (Function) args[0];
        final Object[] fnArgs;
        if (args.length > 1 && args[1] instanceof Scriptable) {
            fnArgs = cx.getElements((Scriptable) args[1]);
        } else {
            fnArgs = ScriptRuntime.emptyArgs;
        }
        return getThreadPool().submit(new Callable<Object>() {
            public Object call() {
                return cxfactory.call(new ContextAction() {
                    public Object run(Context cx) {
                        return function.call(cx, scope, scope, fnArgs);
                    }
                });
            }
View Full Code Here

                                       final Function callback, final boolean keyed) throws ScriptException {

        String regex = "^[\\s\\t\\r\\n]*[Ss][Ee][Ll][Ee][Cc][Tt].*";//select
        final boolean isSelect = query.matches(regex);
        if (callback != null) {
            final ContextFactory factory = cx.getFactory();
            final ExecutorService es = Executors.newSingleThreadExecutor();
            es.submit(new Callable() {
                public Object call() throws Exception {
                    Context cx = RhinoEngine.enterContext(factory);
                    try {
View Full Code Here

TOP

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

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.