Skip to content

Commit

Permalink
Reinstate if (0);"test" fix after f87a53c accidentally reverted it
Browse files Browse the repository at this point in the history
  • Loading branch information
gfwilliams committed Nov 8, 2023
1 parent 463e94a commit 4c13af9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Allow `throw undefined` to still show an exception in the REPL (fix #2423)
When parsing function declarations, don't interpret the strings inside them
Bangle.js2: Fix spurious tap events when HRM enabled by changing threshold
Reinstate `if (0);"test"` fix after f87a53c accidentally reverted it

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
13 changes: 10 additions & 3 deletions src/jsparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -2324,7 +2324,6 @@ NO_INLINE JsVar *jspeBlockOrStatement() {
return 0;
} else {
JsVar *v = jspeStatement();
if (lex->tk==';') JSP_ASSERT_MATCH(';');
return v;
}
}
Expand All @@ -2336,6 +2335,7 @@ NO_INLINE JsVar *jspParse() {
while (!JSP_SHOULDNT_PARSE && lex->tk != LEX_EOF) {
jsvUnLock(v);
v = jspeBlockOrStatement();
while (lex->tk==';') JSP_ASSERT_MATCH(';');
jsvCheckReferenceError(v);
}
return v;
Expand Down Expand Up @@ -2416,7 +2416,9 @@ NO_INLINE JsVar *jspeStatementIf() {
JSP_SAVE_EXECUTE();
if (!cond) jspSetNoExecute();
JsExecFlags hasError = 0;
JsVar *a = jspeBlockOrStatement();
JsVar *a = 0;
if (lex->tk!=';')
a = jspeBlockOrStatement();
hasError |= execInfo.execute&EXEC_ERROR_MASK;
if (!cond) {
jsvUnLock(a);
Expand All @@ -2425,11 +2427,16 @@ NO_INLINE JsVar *jspeStatementIf() {
} else {
result = a;
}
/* We must manually parse ';' here, because if we did it when execInfo.execute==false (eg `if(0);`)
then if a String comes straight after it wouldn't have been interpreted */
if (lex->tk==';') JSP_ASSERT_MATCH(';');
if (lex->tk==LEX_R_ELSE) {
JSP_ASSERT_MATCH(LEX_R_ELSE);
JSP_SAVE_EXECUTE();
if (cond) jspSetNoExecute();
JsVar *a = jspeBlockOrStatement();
JsVar *a = 0;
if (lex->tk!=';')
a = jspeBlockOrStatement();
hasError |= execInfo.execute&EXEC_ERROR_MASK;
if (cond) {
jsvUnLock(a);
Expand Down
1 change: 1 addition & 0 deletions tests/test_string_noparse.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ if (1) 1;"test"||fail("if(1)1;") // ok
if (0) 1;"test"||fail("if(0)1;") // failed
if (0);"test"||fail("if(0);") // failed
if (1);else;"test"||fail("if(1);else;") // failed
(function(){ if(0)return 42;'OK'!='OK'&&fail('if(0)return')})()
// if we got here we're ok
result=1

0 comments on commit 4c13af9

Please sign in to comment.