本文整理匯總了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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}