Skip to content

Commit

Permalink
Ensure AssignmentExpr returns the value of LHS, not the LHS. `(a=2)=3…
Browse files Browse the repository at this point in the history
…` now fails (as per spec)

            Ensure default args for arrow functions fail with error `(a,b=3)=>a+b` now fails (until default args get added)
  • Loading branch information
gfwilliams committed Sep 18, 2023
1 parent eccac25 commit f87a53c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
Bangle.js2: Allow 2 central links at once
Fix `if (0);"test"||fail()` 2v19 regression - strings after if(0) didn't get interpreted
Ensure eval("1;;;")==1 - eval("1;")==1 before, but not eval("1;;")
Ensure AssignmentExpr returns the value of LHS, not the LHS. `(a=2)=3` now fails (as per spec)
Ensure default args for arrow functions fail with error `(a,b=3)=>a+b` now fails (until default args get added)

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: 4 additions & 10 deletions src/jsparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -2205,6 +2205,7 @@ NO_INLINE JsVar *__jspeAssignmentExpression(JsVar *lhs) {
}
}
jsvUnLock(rhs);
lhs = jsvSkipNameAndUnLock(lhs);
}
return lhs;
}
Expand Down Expand Up @@ -2318,6 +2319,7 @@ NO_INLINE JsVar *jspeBlockOrStatement() {
return 0;
} else {
JsVar *v = jspeStatement();
if (lex->tk==';') JSP_ASSERT_MATCH(';');
return v;
}
}
Expand All @@ -2329,7 +2331,6 @@ 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 @@ -2410,9 +2411,7 @@ NO_INLINE JsVar *jspeStatementIf() {
JSP_SAVE_EXECUTE();
if (!cond) jspSetNoExecute();
JsExecFlags hasError = 0;
JsVar *a = 0;
if (lex->tk!=';')
a = jspeBlockOrStatement();
JsVar *a = jspeBlockOrStatement();
hasError |= execInfo.execute&EXEC_ERROR_MASK;
if (!cond) {
jsvUnLock(a);
Expand All @@ -2421,16 +2420,11 @@ 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 = 0;
if (lex->tk!=';')
a = jspeBlockOrStatement();
JsVar *a = jspeBlockOrStatement();
hasError |= execInfo.execute&EXEC_ERROR_MASK;
if (cond) {
jsvUnLock(a);
Expand Down

0 comments on commit f87a53c

Please sign in to comment.