Skip to content
Permalink
Browse files
[JSC] SyntaxError if AssignmentElement is eval or arguments in st…
…rict code

https://bugs.webkit.org/show_bug.cgi?id=152302

Patch by Caitlin Potter <caitp@igalia.com> on 2015-12-15
Reviewed by Mark Lam.

`eval` and `arguments` must not be assigned to in strict code. This
change fixes `language/expressions/assignment/destructuring/obj-id-simple-strict.js`
in Test262, as well as a variety of other similar tests.

* parser/Parser.cpp:
(JSC::Parser<LexerType>::parseAssignmentElement):
(JSC::Parser<LexerType>::parseDestructuringPattern):
* tests/stress/destructuring-assignment-syntax.js:

Canonical link: https://commits.webkit.org/170414@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@194107 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
caitp authored and webkit-commit-queue committed Dec 15, 2015
1 parent ef40924 commit beca2df64289cfb5e25ef0172351fcb7ada0fa4d
Showing with 51 additions and 9 deletions.
  1. +16 −0 Source/JavaScriptCore/ChangeLog
  2. +20 −9 Source/JavaScriptCore/parser/Parser.cpp
  3. +15 −0 Source/JavaScriptCore/tests/stress/destructuring-assignment-syntax.js
@@ -1,3 +1,19 @@
2015-12-15 Caitlin Potter <caitp@igalia.com>

[JSC] SyntaxError if AssignmentElement is `eval` or `arguments` in strict code
https://bugs.webkit.org/show_bug.cgi?id=152302

Reviewed by Mark Lam.

`eval` and `arguments` must not be assigned to in strict code. This
change fixes `language/expressions/assignment/destructuring/obj-id-simple-strict.js`
in Test262, as well as a variety of other similar tests.

* parser/Parser.cpp:
(JSC::Parser<LexerType>::parseAssignmentElement):
(JSC::Parser<LexerType>::parseDestructuringPattern):
* tests/stress/destructuring-assignment-syntax.js:

2015-12-15 Csaba Osztrogonác <ossy@webkit.org>

URTBF after 194062.
@@ -827,21 +827,27 @@ template <class TreeBuilder> TreeDestructuringPattern Parser<LexerType>::parseBi
template <typename LexerType>
template <class TreeBuilder> TreeDestructuringPattern Parser<LexerType>::parseAssignmentElement(TreeBuilder& context, DestructuringKind kind, ExportType exportType, const Identifier** duplicateIdentifier, bool* hasDestructuringPattern, AssignmentContext bindingContext, int depth)
{
SavePoint savePoint = createSavePoint();
TreeDestructuringPattern assignmentTarget = 0;

if (match(OPENBRACE) || match(OPENBRACKET))
if (match(OPENBRACE) || match(OPENBRACKET)) {
SavePoint savePoint = createSavePoint();
assignmentTarget = parseDestructuringPattern(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth);
if (!assignmentTarget || match(DOT) || match(OPENBRACKET) || match(OPENPAREN) || match(TEMPLATE)) {
if (assignmentTarget && !match(DOT) && !match(OPENBRACKET) && !match(OPENPAREN) && !match(TEMPLATE))
return assignmentTarget;
restoreSavePoint(savePoint);
JSTextPosition startPosition = tokenStartPosition();
auto element = parseMemberExpression(context);
}

JSTextPosition startPosition = tokenStartPosition();
auto element = parseMemberExpression(context);

semanticFailIfFalse(element && context.isAssignmentLocation(element), "Invalid destructuring assignment target");
semanticFailIfFalse(element && context.isAssignmentLocation(element), "Invalid destructuring assignment target");

return createAssignmentElement(context, element, startPosition, lastTokenEndPosition());
if (strictMode() && m_lastIdentifier && context.isResolve(element)) {
failIfTrueIfStrict(m_vm->propertyNames->eval == *m_lastIdentifier, "Cannot modify 'eval' in strict mode");
failIfTrueIfStrict(m_vm->propertyNames->arguments == *m_lastIdentifier, "Cannot modify 'arguments' in strict mode");
}
return assignmentTarget;

return createAssignmentElement(context, element, startPosition, lastTokenEndPosition());
}

template <typename LexerType>
@@ -924,8 +930,13 @@ template <class TreeBuilder> TreeDestructuringPattern Parser<LexerType>::parseDe
next();
if (consume(COLON))
innerPattern = parseBindingOrAssignmentElement(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1);
else
else {
if (kind == DestructureToExpressions && strictMode()) {
failIfTrueIfStrict(m_vm->propertyNames->eval == *propertyName, "Cannot modify 'eval' in strict mode");
failIfTrueIfStrict(m_vm->propertyNames->arguments == *propertyName, "Cannot modify 'arguments' in strict mode");
}
innerPattern = createBindingPattern(context, kind, exportType, *propertyName, identifierToken, bindingContext, duplicateIdentifier);
}
} else {
JSTokenType tokenType = m_token.m_type;
switch (m_token.m_type) {
@@ -57,3 +57,18 @@ testSyntaxError("[false] = []", "SyntaxError: Invalid destructuring assignment t
testSyntaxError("[f\\u0061lse] = []", "SyntaxError: Invalid destructuring assignment target.");
testSyntaxError("[null] = []", "SyntaxError: Invalid destructuring assignment target.");
testSyntaxError("[n\\u{75}ll] = []", "SyntaxError: Invalid destructuring assignment target.");

testSyntaxError("'use strict'; ({ eval } = {})", "SyntaxError: Cannot modify 'eval' in strict mode.");
// FIXME: support CoverInitializedName properly.
//testSyntaxError("'use strict'; ({ eval = 0 } = {})", "SyntaxError: Cannot modify 'eval' in strict mode.");
testSyntaxError("'use strict'; ({ a: eval } = {})", "SyntaxError: Cannot modify 'eval' in strict mode.");
testSyntaxError("'use strict'; ({ a: eval = 0 } = {})", "SyntaxError: Cannot modify 'eval' in strict mode.");
testSyntaxError("'use strict'; ({ arguments } = {})", "SyntaxError: Cannot modify 'arguments' in strict mode.");
// FIXME: support CoverInitializedName properly.
//testSyntaxError("'use strict'; ({ arguments = 0 } = {})", "SyntaxError: Cannot modify 'arguments' in strict mode.");
testSyntaxError("'use strict'; ({ a: arguments } = {})", "SyntaxError: Cannot modify 'arguments' in strict mode.");
testSyntaxError("'use strict'; ({ a: arguments = 0 } = {})", "SyntaxError: Cannot modify 'arguments' in strict mode.");
testSyntaxError("'use strict'; ([ eval ] = [])", "SyntaxError: Cannot modify 'eval' in strict mode.");
testSyntaxError("'use strict'; ([ eval = 0 ] = [])", "SyntaxError: Cannot modify 'eval' in strict mode.");
testSyntaxError("'use strict'; ([ arguments ] = [])", "SyntaxError: Cannot modify 'arguments' in strict mode.");
testSyntaxError("'use strict'; ([ arguments = 0 ] = [])", "SyntaxError: Cannot modify 'arguments' in strict mode.");

0 comments on commit beca2df

Please sign in to comment.