Skip to content
Permalink
Browse files

Fix bug if using an undefined member of an object for for..in (fix #1437

)
  • Loading branch information
gfwilliams committed May 23, 2018
1 parent 7a48144 commit bf4416ab9129ee3afd56739ea4e3cd0da5484b6b
Showing with 13 additions and 17 deletions.
  1. +1 −0 ChangeLog
  2. +12 −17 src/jsparse.c
@@ -3,6 +3,7 @@
Fix parsing of try..catch when not executing (fix #1439)
Add extra ReferenceError checks, even if variable is not used
Allow Ctrl-C out of while...continue loop (fix #1441)
Fix bug if using an undefined member of an object for for..in (fix #1437)

1v99 : Increase jslMatch error buffer size to handle "UNFINISHED TEMPLATE LITERAL" string (#1426)
nRF5x: Make FlashWrite cope with flash writes > 4k
@@ -122,6 +122,16 @@ void jspReplaceWith(JsVar *dst, JsVar *src) {
}
}

void jspReplaceWithOrAddToRoot(JsVar *dst, JsVar *src) {
/* If we're assigning to this and we don't have a parent,
* add it to the symbol table root */
if (!jsvGetRefs(dst) && jsvIsName(dst)) {
if (!jsvIsArrayBufferName(dst) && !jsvIsNewChild(dst))
jsvAddName(execInfo.root, dst);
}
jspReplaceWith(dst, src);
}

bool jspeiAddScope(JsVar *scope) {
if (execInfo.scopeCount >= JSPARSE_MAX_SCOPES) {
jsExceptionHere(JSET_ERROR, "Maximum number of scopes exceeded");
@@ -1971,13 +1981,7 @@ NO_INLINE JsVar *__jspeAssignmentExpression(JsVar *lhs) {

if (JSP_SHOULD_EXECUTE && lhs) {
if (op=='=') {
/* If we're assigning to this and we don't have a parent,
* add it to the symbol table root */
if (!jsvGetRefs(lhs) && jsvIsName(lhs)) {
if (!jsvIsArrayBufferName(lhs) && !jsvIsNewChild(lhs))
jsvAddName(execInfo.root, lhs);
}
jspReplaceWith(lhs, rhs);
jspReplaceWithOrAddToRoot(lhs, rhs);
} else {
if (op==LEX_PLUSEQUAL) op='+';
else if (op==LEX_MINUSEQUAL) op='-';
@@ -2330,12 +2334,6 @@ NO_INLINE JsVar *jspeStatementFor() {
jsExceptionHere(JSET_ERROR, "FOR a IN b - 'a' must be a variable name, not %t", forStatement);
return 0;
}
bool addedIteratorToScope = false;
if (JSP_SHOULD_EXECUTE && !jsvGetRefs(forStatement)) {
// if the variable did not exist, add it to the scope
addedIteratorToScope = true;
jsvAddName(execInfo.root, forStatement);
}
JSP_MATCH_WITH_CLEANUP_AND_RETURN(LEX_R_IN, jsvUnLock(forStatement), 0);
JsVar *array = jsvSkipNameAndUnLock(jspeExpression());
JSP_MATCH_WITH_CLEANUP_AND_RETURN(')', jsvUnLock2(forStatement, array), 0);
@@ -2371,7 +2369,7 @@ NO_INLINE JsVar *jspeStatementFor() {
loopIndexVar;
if (indexValue) { // could be out of memory
assert(!jsvIsName(indexValue) && jsvGetRefs(indexValue)==0);
jsvSetValueOfName(forStatement, indexValue);
jspReplaceWithOrAddToRoot(forStatement, indexValue);
if (indexValue!=loopIndexVar) jsvUnLock(indexValue);

jsvIteratorNext(&it);
@@ -2410,9 +2408,6 @@ NO_INLINE JsVar *jspeStatementFor() {
jslCharPosFree(&forBodyStart);
jslCharPosFree(&forBodyEnd);

if (addedIteratorToScope) {
jsvRemoveChild(execInfo.root, forStatement);
}
jsvUnLock2(forStatement, array);
} else { // ----------------------------------------------- NORMAL FOR LOOP
#ifdef JSPARSE_MAX_LOOP_ITERATIONS

0 comments on commit bf4416a

Please sign in to comment.