Skip to content

Commit

Permalink
Merge remote-tracking branch 'anba/bug-685403'
Browse files Browse the repository at this point in the history
  • Loading branch information
hns committed Aug 7, 2012
2 parents fc3bcad + b443810 commit a215da6
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/org/mozilla/javascript/Interpreter.java
Expand Up @@ -1957,6 +1957,8 @@ private static Object interpretLoop(Context cx, CallFrame frame,
exState = EX_CATCH_STATE;
} else if (throwable instanceof EvaluatorException) {
exState = EX_CATCH_STATE;
} else if (throwable instanceof ContinuationPending) {
exState = EX_NO_JS_STATE;
} else if (throwable instanceof RuntimeException) {
exState = cx.hasFeature(Context.FEATURE_ENHANCED_JAVA_ACCESS)
? EX_CATCH_STATE
Expand Down
70 changes: 70 additions & 0 deletions testsrc/org/mozilla/javascript/tests/Bug685403Test.java
@@ -0,0 +1,70 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.javascript.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContinuationPending;
import org.mozilla.javascript.Function;
import org.mozilla.javascript.Script;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;

/**
* @author André Bargull
*
*/
public class Bug685403Test {
private Context cx;
private ScriptableObject scope;

@Before
public void setUp() {
cx = Context.enter();
cx.setOptimizationLevel(-1);
scope = cx.initStandardObjects();
}

@After
public void tearDown() {
Context.exit();
}

public static Object continuation(Context cx, Scriptable thisObj,
Object[] args, Function funObj) {
ContinuationPending pending = cx.captureContinuation();
throw pending;
}

@Test
public void test() {
String source = "var state = '';";
source += "function A(){state += 'A'}";
source += "function B(){state += 'B'}";
source += "function C(){state += 'C'}";
source += "try { A(); continuation(); B() } finally { C() }";
source += "state";

String[] functions = new String[] { "continuation" };
scope.defineFunctionProperties(functions, Bug685403Test.class,
ScriptableObject.DONTENUM);

Object state = null;
Script script = cx.compileString(source, "", 1, null);
try {
cx.executeScriptWithContinuations(script, scope);
fail("expected ContinuationPending exception");
} catch (ContinuationPending pending) {
state = cx.resumeContinuation(pending.getContinuation(), scope, "");
}
assertEquals("ABC", state);
}

}

0 comments on commit a215da6

Please sign in to comment.