- Revision
- 194153
- Author
- [email protected]
- Date
- 2015-12-16 09:49:14 -0800 (Wed, 16 Dec 2015)
Log Message
[JSC] fix error message for eval/arguments CoverInitializedName in strict code
https://bugs.webkit.org/show_bug.cgi?id=152304
Patch by Caitlin Potter <[email protected]> on 2015-12-16
Reviewed by Darin Adler.
Because the error was originally classified as indicating a Pattern, the
error in AssignmentPattern parsing causes the reported message to revert to
the original _expression_ error message, which in this case is incorrect.
This change modifies the implementation of the strict code
error slightly, and reclassifies the error to prevent the message revert,
which improves the clarity of the message overall.
* parser/Parser.cpp:
(JSC::Parser<LexerType>::parseAssignmentElement):
(JSC::Parser<LexerType>::parseDestructuringPattern):
* parser/Parser.h:
(JSC::Parser::ExpressionErrorClassifier::reclassifyExpressionError):
(JSC::Parser::reclassifyExpressionError):
* tests/stress/destructuring-assignment-syntax.js:
Modified Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (194152 => 194153)
--- trunk/Source/_javascript_Core/ChangeLog 2015-12-16 17:46:02 UTC (rev 194152)
+++ trunk/Source/_javascript_Core/ChangeLog 2015-12-16 17:49:14 UTC (rev 194153)
@@ -1,3 +1,26 @@
+2015-12-16 Caitlin Potter <[email protected]>
+
+ [JSC] fix error message for eval/arguments CoverInitializedName in strict code
+ https://bugs.webkit.org/show_bug.cgi?id=152304
+
+ Reviewed by Darin Adler.
+
+ Because the error was originally classified as indicating a Pattern, the
+ error in AssignmentPattern parsing causes the reported message to revert to
+ the original _expression_ error message, which in this case is incorrect.
+
+ This change modifies the implementation of the strict code
+ error slightly, and reclassifies the error to prevent the message revert,
+ which improves the clarity of the message overall.
+
+ * parser/Parser.cpp:
+ (JSC::Parser<LexerType>::parseAssignmentElement):
+ (JSC::Parser<LexerType>::parseDestructuringPattern):
+ * parser/Parser.h:
+ (JSC::Parser::ExpressionErrorClassifier::reclassifyExpressionError):
+ (JSC::Parser::reclassifyExpressionError):
+ * tests/stress/destructuring-assignment-syntax.js:
+
2015-12-16 Joseph Pecoraro <[email protected]>
Builtin source should be minified more
Modified: trunk/Source/_javascript_Core/parser/Parser.cpp (194152 => 194153)
--- trunk/Source/_javascript_Core/parser/Parser.cpp 2015-12-16 17:46:02 UTC (rev 194152)
+++ trunk/Source/_javascript_Core/parser/Parser.cpp 2015-12-16 17:49:14 UTC (rev 194153)
@@ -843,8 +843,8 @@
semanticFailIfFalse(element && context.isAssignmentLocation(element), "Invalid destructuring assignment target");
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");
+ bool isEvalOrArguments = m_vm->propertyNames->eval == *m_lastIdentifier || m_vm->propertyNames->arguments == *m_lastIdentifier;
+ failIfTrueIfStrict(isEvalOrArguments, "Cannot modify '", m_lastIdentifier->impl(), "' in strict mode");
}
return createAssignmentElement(context, element, startPosition, lastTokenEndPosition());
@@ -931,9 +931,11 @@
if (consume(COLON))
innerPattern = parseBindingOrAssignmentElement(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1);
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");
+ if (kind == DestructureToExpressions) {
+ bool isEvalOrArguments = m_vm->propertyNames->eval == *propertyName || m_vm->propertyNames->arguments == *propertyName;
+ if (isEvalOrArguments && strictMode())
+ reclassifyExpressionError(ErrorIndicatesPattern, ErrorIndicatesNothing);
+ failIfTrueIfStrict(isEvalOrArguments, "Cannot modify '", propertyName->impl(), "' in strict mode");
}
innerPattern = createBindingPattern(context, kind, exportType, *propertyName, identifierToken, bindingContext, duplicateIdentifier);
}
Modified: trunk/Source/_javascript_Core/parser/Parser.h (194152 => 194153)
--- trunk/Source/_javascript_Core/parser/Parser.h 2015-12-16 17:46:02 UTC (rev 194152)
+++ trunk/Source/_javascript_Core/parser/Parser.h 2015-12-16 17:49:14 UTC (rev 194153)
@@ -764,6 +764,13 @@
m_class = classification;
}
+ void reclassifyExpressionError(ExpressionErrorClass oldClassification, ExpressionErrorClass classification)
+ {
+ if (m_class != oldClassification)
+ return;
+ m_class = classification;
+ }
+
void propagateExpressionErrorClass()
{
if (m_previous && m_class != ErrorIndicatesNothing)
@@ -784,6 +791,12 @@
m_expressionErrorClassifier->classifyExpressionError(classification);
}
+ ALWAYS_INLINE void reclassifyExpressionError(ExpressionErrorClass oldClassification, ExpressionErrorClass classification)
+ {
+ if (m_expressionErrorClassifier)
+ m_expressionErrorClassifier->reclassifyExpressionError(oldClassification, classification);
+ }
+
ALWAYS_INLINE DestructuringKind destructuringKindFromDeclarationType(DeclarationType type)
{
switch (type) {
Modified: trunk/Source/_javascript_Core/tests/stress/destructuring-assignment-syntax.js (194152 => 194153)
--- trunk/Source/_javascript_Core/tests/stress/destructuring-assignment-syntax.js 2015-12-16 17:46:02 UTC (rev 194152)
+++ trunk/Source/_javascript_Core/tests/stress/destructuring-assignment-syntax.js 2015-12-16 17:49:14 UTC (rev 194153)
@@ -59,13 +59,11 @@
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'; ({ 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'; ({ 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.");