當前位置: 首頁>>代碼示例>>Java>>正文


Java Context.setOptimizationLevel方法代碼示例

本文整理匯總了Java中org.mozilla.javascript.Context.setOptimizationLevel方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.setOptimizationLevel方法的具體用法?Java Context.setOptimizationLevel怎麽用?Java Context.setOptimizationLevel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.mozilla.javascript.Context的用法示例。


在下文中一共展示了Context.setOptimizationLevel方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: decryptSignature

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
private String decryptSignature(String encryptedSig, String decryptionCode) throws DecryptException {
    Context context = Context.enter();
    context.setOptimizationLevel(-1);
    Object result;
    try {
        ScriptableObject scope = context.initStandardObjects();
        context.evaluateString(scope, decryptionCode, "decryptionCode", 1, null);
        Function decryptionFunc = (Function) scope.get("decrypt", scope);
        result = decryptionFunc.call(context, scope, scope, new Object[]{encryptedSig});
    } catch (Exception e) {
        throw new DecryptException("could not get decrypt signature", e);
    } finally {
        Context.exit();
    }
    return result == null ? "" : result.toString();
}
 
開發者ID:TeamNewPipe,項目名稱:NewPipeExtractor,代碼行數:17,代碼來源:YoutubeStreamExtractor.java

示例2: runJsTests

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
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
                                           // files
            char[] buf = new char[length];
            new FileReader(f).read(buf, 0, length);
            String session = new String(buf);
            runJsTest(cx, shared, f.getName(), session);
        }
    } finally {
        Context.exit();
    }
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:19,代碼來源:JsTestsBase.java

示例3: testJsApi

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public void testJsApi() throws Exception {
    Context cx = Context.enter();
    cx.setOptimizationLevel(-1);
    Script script = cx.compileReader(new InputStreamReader(
            Bug482203.class.getResourceAsStream("conttest.js")), 
            "", 1, null);
    Scriptable scope = cx.initStandardObjects();
    script.exec(cx, scope);
    for(;;)
    {
        Object cont = ScriptableObject.getProperty(scope, "c");
        if(cont == null)
        {
            break;
        }
        ((Callable)cont).call(cx, scope, scope, new Object[] { null });
    }
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:19,代碼來源:Bug482203.java

示例4: testJavaApi

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public void testJavaApi() throws Exception {
    Context cx = Context.enter();
    try {
     cx.setOptimizationLevel(-1);
     Script script = cx.compileReader(new InputStreamReader(
             Bug482203.class.getResourceAsStream("conttest.js")), 
             "", 1, null);
     Scriptable scope = cx.initStandardObjects();
     cx.executeScriptWithContinuations(script, scope);
     for(;;)
     {
         Object cont = ScriptableObject.getProperty(scope, "c");
         if(cont == null)
         {
             break;
         }
         cx.resumeContinuation(cont, scope, null);
     }
    } finally {
    	Context.exit();
    }
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:23,代碼來源:Bug482203.java

示例5: testScriptWithContinuations

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public void testScriptWithContinuations() {
    Context cx = Context.enter();
    try {
        cx.setOptimizationLevel(-1); // must use interpreter mode
        Script script = cx.compileString("myObject.f(3) + 1;",
                "test source", 1, null);
        cx.executeScriptWithContinuations(script, globalScope);
        fail("Should throw ContinuationPending");
    } catch (ContinuationPending pending) {

        Object applicationState = pending.getApplicationState();
        assertEquals(new Integer(3), applicationState);
        int saved = (Integer) applicationState;
        Object result = cx.resumeContinuation(pending.getContinuation(), globalScope, saved + 1);
        assertEquals(5, ((Number)result).intValue());

    } finally {
        Context.exit();
    }
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:21,代碼來源:ContinuationsApiTest.java

示例6: testScriptWithNestedContinuations

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public void testScriptWithNestedContinuations() {
    Context cx = Context.enter();
    try {
        cx.setOptimizationLevel(-1); // must use interpreter mode
        Script script = cx.compileString("myObject.g( myObject.f(1) ) + 2;",
                "test source", 1, null);
        cx.executeScriptWithContinuations(script, globalScope);
        fail("Should throw ContinuationPending");
    } catch (ContinuationPending pending) {
        try {
            Object applicationState = pending.getApplicationState();
            assertEquals(new Integer(1), applicationState);
            int saved = (Integer) applicationState;
            cx.resumeContinuation(pending.getContinuation(), globalScope, saved + 1);
            fail("Should throw another ContinuationPending");
        } catch (ContinuationPending pending2) {
            Object applicationState2 = pending2.getApplicationState();
            assertEquals(new Integer(4), applicationState2);
            int saved2 = (Integer) applicationState2;
            Object result2 = cx.resumeContinuation(pending2.getContinuation(), globalScope, saved2 + 2);
            assertEquals(8, ((Number)result2).intValue());
        }
    } finally {
        Context.exit();
    }
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:27,代碼來源:ContinuationsApiTest.java

示例7: testFunctionWithContinuations

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public void testFunctionWithContinuations() {
    Context cx = Context.enter();
    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();
        assertEquals(7, ((Number)applicationState).intValue());
        int saved = (Integer) applicationState;
        Object result = cx.resumeContinuation(pending.getContinuation(), globalScope, saved + 1);
        assertEquals(8, ((Number)result).intValue());
    } finally {
        Context.exit();
    }
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:22,代碼來源:ContinuationsApiTest.java

示例8: testErrorOnEvalCall

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
/**
 * Since a continuation can only capture JavaScript frames and not Java
 * frames, ensure that Rhino throws an exception when the JavaScript frames
 * don't reach all the way to the code called by
 * executeScriptWithContinuations or callFunctionWithContinuations.
 */
public void testErrorOnEvalCall() {
    Context cx = Context.enter();
    try {
        cx.setOptimizationLevel(-1); // must use interpreter mode
        Script script = cx.compileString("eval('myObject.f(3);');",
                "test source", 1, null);
        cx.executeScriptWithContinuations(script, globalScope);
        fail("Should throw IllegalStateException");
    } catch (WrappedException we) {
        Throwable t = we.getWrappedException();
        assertTrue(t instanceof IllegalStateException);
        assertTrue(t.getMessage().startsWith("Cannot capture continuation"));
    } finally {
        Context.exit();
    }
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:23,代碼來源:ContinuationsApiTest.java

示例9: createTest

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
private static Test createTest(final File testDir, final String name) {
    return new TestCase(name) {
        @Override
        public int countTestCases() {
            return 1;
        }
        @Override
        public void runBare() throws Throwable {
            final Context cx = Context.enter();
            try {
                cx.setOptimizationLevel(-1);
                final Scriptable scope = cx.initStandardObjects();
                ScriptableObject.putProperty(scope, "print", new Print(scope));
                createRequire(testDir, cx, scope).requireMain(cx, "program");
            }
            finally {
                Context.exit();
            }
        }
    };
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:22,代碼來源:ComplianceTest.java

示例10: runDoctest

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
@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);
        System.out.println(name + "(" + optimizationLevel + "): " +
                testsPassed + " passed.");
        assertTrue(testsPassed > 0);
    } catch (Exception ex) {
      System.out.println(name + "(" + optimizationLevel + "): FAILED due to "+ex);
      throw ex;
    } finally {
        Context.exit();
    }  
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:20,代碼來源:DoctestsTest.java

示例11: decipherKey

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
/**
 * After finding the decrypted code in the js html5 player code
 * run the code passing the encryptedSig parameter
 *
 * @param encryptedSig
 * @param html5player
 * @return
 * @throws Exception
 */
private static String decipherKey(String encryptedSig, String html5player)
        throws Exception {
    String decipherFunc = loadFunction(html5player);
    Context context = Context.enter();
    // Rhino interpreted mode
    context.setOptimizationLevel(-1);
    Object result = null;
    try {
        ScriptableObject scope = context.initStandardObjects();
        context.evaluateString(scope, decipherFunc, "decipherFunc", 1, null);
        Function decryptionFunc = (Function) scope.get("decrypt", scope);
        result = decryptionFunc.call(context, scope, scope, new Object[]{encryptedSig});
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        Context.exit();
    }
    if (result == null) {
        return "";
    } else {
        return result.toString();
    }
}
 
開發者ID:89luca89,項目名稱:ThunderMusic,代碼行數:33,代碼來源:YoutubeLinkRetriever.java

示例12: testAttributeName

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
@Test
public void testAttributeName() {
    Context context = Context.enter();
    Scriptable scriptable = context.initStandardObjects();
    context.setOptimizationLevel(-1);
    Object o = context.evaluateString(scriptable, "XML.ignoreProcessingInstructions = true; (<xml id=\"foo\"></xml>).attributes()[0].name()", "<e4x>", 1, null);
    System.out.println(o);
}
 
開發者ID:feifadaima,項目名稱:https-github.com-hyb1996-NoRootScriptDroid,代碼行數:9,代碼來源:RhinoE4XTest.java

示例13: createContext

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
protected Context createContext() {
    if (!ContextFactory.hasExplicitGlobal()) {
        ContextFactory.initGlobal(new InterruptibleAndroidContextFactory(new File(mAndroidContext.getCacheDir(), "classes")));
    }
    Context context = new RhinoAndroidHelper(mAndroidContext).enterContext();
    contextCount++;
    context.setOptimizationLevel(-1);
    context.setLanguageVersion(Context.VERSION_ES6);
    return context;
}
 
開發者ID:feifadaima,項目名稱:https-github.com-hyb1996-NoRootScriptDroid,代碼行數:11,代碼來源:RhinoJavaScriptEngine.java

示例14: preHandle

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
@Override
public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler)
        throws Exception {
    final Context cx = getContextFactory().enterContext();
    if (cx.getOptimizationLevel() != -1) {
        cx.setOptimizationLevel(-1);
    }
    return true;
}
 
開發者ID:szegedi,項目名稱:spring-web-jsflow,代碼行數:10,代碼來源:OpenContextInViewInterceptor.java

示例15: setUp

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
@Override
public void setUp() {
    Context cx = Context.enter();
    try {
        globalScope = cx.initStandardObjects();
        cx.setOptimizationLevel(-1); // must use interpreter mode
        globalScope.put("myObject", globalScope,
                Context.javaToJS(new MyClass(), globalScope));
    } finally {
        Context.exit();
    }
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:13,代碼來源:ContinuationsApiTest.java


注:本文中的org.mozilla.javascript.Context.setOptimizationLevel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。