Skip to content

Commit 7df65ff

Browse files
committed
fix
1 parent 01e1fd9 commit 7df65ff

2 files changed

Lines changed: 6 additions & 13 deletions

File tree

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/translation/imtranslation/StackTraceInjector2.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -380,21 +380,14 @@ private void rewriteFuncRefs(final List<ImFuncRefOrCall> funcRefs, Set<ImFunctio
380380
ImExprs args = JassIm.ImExprs(str);
381381
ImStmts body = bridgeFunc.getBody();
382382
de.peeeq.wurstscript.ast.Element trace = frTrace;
383-
ImVar savedStackDepth = JassIm.ImVar(trace, TypesHelper.imInt(), "bridge_oldStackDepth", false);
384-
bridgeFunc.getLocals().add(savedStackDepth);
385-
body.add(JassIm.ImSet(trace, JassIm.ImVarAccess(savedStackDepth), JassIm.ImVarAccess(stackSize)));
386-
// reset stack and add information for callback:
387-
body.add(JassIm.ImSet(trace, JassIm.ImVarAccess(stackSize), JassIm.ImIntVal(0)));
388383

389384
ImFunctionCall call = JassIm.ImFunctionCall(frTrace, f, JassIm.ImTypeArguments(), args, true, CallType.NORMAL);
390385
if (bridgeFunc.getReturnType() instanceof ImVoid) {
391-
body.add(call);
392-
stmt = JassIm.ImSet(trace, JassIm.ImVarAccess(stackSize), JassIm.ImVarAccess(savedStackDepth));
386+
stmt = call;
393387
} else {
394388
ImVar bridgeReturn = JassIm.ImVar(trace, bridgeFunc.getReturnType().copy(), "bridge_return", false);
395389
bridgeFunc.getLocals().add(bridgeReturn);
396390
body.add(JassIm.ImSet(trace, JassIm.ImVarAccess(bridgeReturn), call));
397-
body.add(JassIm.ImSet(trace, JassIm.ImVarAccess(stackSize), JassIm.ImVarAccess(savedStackDepth)));
398391
stmt = JassIm.ImReturn(frTrace, JassIm.ImVarAccess(bridgeReturn));
399392
}
400393
body.add(stmt);

de.peeeq.wurstscript/src/test/java/tests/wurstscript/tests/BugTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,7 +1465,7 @@ public void executeFuncWithStackTrace() {
14651465
}
14661466

14671467
@Test
1468-
public void executeFuncBridgeRestoresStackDepth() {
1468+
public void executeFuncBridgeKeepsCallerStackFrames() {
14691469
test().executeProg(false).executeTests(false).lines(
14701470
"package Test",
14711471
"@extern native ExecuteFunc(string f)",
@@ -1483,13 +1483,13 @@ public void executeFuncBridgeRestoresStackDepth() {
14831483

14841484
try {
14851485
String jass = Files.toString(
1486-
new File(TEST_OUTPUT_PATH + "BugTests_executeFuncBridgeRestoresStackDepth_stacktraceinlopt.j"),
1486+
new File(TEST_OUTPUT_PATH + "BugTests_executeFuncBridgeKeepsCallerStackFrames_stacktraceinlopt.j"),
14871487
Charsets.UTF_8
14881488
);
14891489
Assert.assertTrue(jass.contains("function bridge_foo"));
1490-
Assert.assertTrue(jass.contains("bridge_oldStackDepth"));
1491-
Assert.assertTrue(jass.contains("set wurst_stack_depth = 0"));
1492-
Assert.assertTrue(jass.contains("set wurst_stack_depth = bridge_oldStackDepth"));
1490+
Assert.assertFalse(jass.contains("bridge_oldStackDepth"));
1491+
Assert.assertFalse(jass.contains("set wurst_stack_depth = 0"));
1492+
Assert.assertTrue(jass.contains("via ExecuteFunc"));
14931493
} catch (IOException e) {
14941494
throw new RuntimeException(e);
14951495
}

0 commit comments

Comments
 (0)