Skip to content

Commit

Permalink
JIT: Ensure ternary block skips 'named' variables (and references the…
Browse files Browse the repository at this point in the history
…m correctly)
  • Loading branch information
gfwilliams committed Oct 20, 2023
1 parent 442c0c7 commit bb046d2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
Remove createChild argument from jsvFindChildFromString, add jsvFindOrAddChildFromString instead
Add ES9 optional catch binding (`try {} catch {}`)
Bangle.js: Fix terminal's repeated call to '.flip' that broke double buffering on Bangle.js 1
JIT: Ensure ternary block skips 'named' variables (and references them correctly)

2v19 : Fix Object.values/entries for numeric keys after 2v18 regression (fix #2375)
nRF52: for SD>5 use static buffers for advertising and scan response data (#2367)
Expand Down
14 changes: 9 additions & 5 deletions src/jsjit.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,21 +745,25 @@ void jsjConditionalExpression() {
jsjBinaryExpression();
if (lex->tk=='?') {
JSP_ASSERT_MATCH('?');
if (jit.phase == JSJP_EMIT) {
/* we handle the condition here because it means the stack level is
then the same when we capture the true/false blocks as when we emit them */
DEBUG_JIT("; ternary condition\n");
jsjPopAsBool(0);
jsjcCompareImm(0, 0);
}
DEBUG_JIT_EMIT("; capture ternary true block\n");
JsVar *oldBlock = jsjcStartBlock();
jsjAssignmentExpression();
if (jit.phase == JSJP_EMIT) jsjPopAsVar(0); // we pop to r0 here so we can push after and avoid confusing the stack size checker
if (jit.phase == JSJP_EMIT) jsjPopNoName(0); // we pop to r0 here so we can push after and avoid confusing the stack size checker
JsVar *trueBlock = jsjcStopBlock(oldBlock);
JSP_MATCH(':');
DEBUG_JIT_EMIT("; capture ternary false block\n");
oldBlock = jsjcStartBlock();
jsjAssignmentExpression();
if (jit.phase == JSJP_EMIT) jsjPopAsVar(0); // we pop to r0 here so we can push after and avoid confusing the stack size checker
if (jit.phase == JSJP_EMIT) jsjPopNoName(0); // we pop to r0 here so we can push after and avoid confusing the stack size checker
JsVar *falseBlock = jsjcStopBlock(oldBlock);
if (jit.phase == JSJP_EMIT) {
DEBUG_JIT("; ternary condition\n");
jsjPopAsBool(0);
jsjcCompareImm(0, 0);
DEBUG_JIT("; ternary jump after condition\n");
// if false, jump after true block (if an 'else' we need to jump over the jsjcBranchRelative
jsjcBranchConditionalRelative(JSJAC_EQ, jsvGetStringLength(trueBlock) + 2);
Expand Down

0 comments on commit bb046d2

Please sign in to comment.