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


Java Context.resumeContinuation方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: testScriptWithMultipleContinuations

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


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