Package org.mozilla.javascript

Examples of org.mozilla.javascript.ContextFactory$GlobalSetter


import java.nio.ByteBuffer;

public class JavascriptDimExtractionFn implements DimExtractionFn
{
  private static Function<String, String> 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<String, String>()
    {
      public String apply(String input)
      {
        // 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();
        }

        final Object res = fn.call(cx, scope, scope, new String[]{input});
        return res != null ? Context.toString(res) : null;
      }
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

        assertTrue("success".equals(result));
        System.out.println("passed");
    }
   
    public void runJsTests(File[] tests) throws IOException {
        ContextFactory factory = ContextFactory.getGlobal();
        Context cx = factory.enterContext();
        try {
            cx.setOptimizationLevel(this.optimizationLevel);
            Scriptable shared = cx.initStandardObjects();
            for (File f : tests) {
                int length = (int) f.length(); // don't worry about very long
View Full Code Here

   
    private synchronized void initRhinoGlobal()
    {
       
        if (!ContextFactory.hasExplicitGlobal()){
            ContextFactory.initGlobal(new ContextFactory() {
                public boolean hasFeature(Context cx, int featureIndex)
                {
                    switch (featureIndex) {
                        case Context.FEATURE_STRICT_MODE:
                            return false;
View Full Code Here

        super(classpathReference);
    }

    public void initializeRhino() {

        rhinoContextFactory = new ContextFactory();
        if (System.getProperty("cxf.jsdebug") != null && !rhinoDebuggerUp) {
            Main.mainEmbedded(rhinoContextFactory, rhinoScope, "Debug embedded JavaScript.");
            rhinoDebuggerUp = true;
        }
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

        cx.evaluateString(top, script, "script", 0, null);
        return null;
      }
    };
   
    final ContextFactory contextFactory = new ContextFactory() {
      @Override
      protected boolean hasFeature(final Context cx, final int featureIndex) {
        if (Context.FEATURE_STRICT_MODE == featureIndex) {
          return !acceptWriteReadOnly;
        }
        return super.hasFeature(cx, featureIndex);
      }
    };
    contextFactory.call(action);
  }
View Full Code Here

        System.out.println("string[]");
    }

    @Test
    public void callOverloadedFunction() {
        new ContextFactory().call(new ContextAction() {
            public Object run(Context cx) {
                cx.evaluateString(
                    cx.initStandardObjects(),
                    "new org.mozilla.javascript.tests.Bug496585().method('one', 'two', 'three')",
                    "<test>", 1, null);
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

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.