Changeset 194153 in webkit


Ignore:
Timestamp:
Dec 16, 2015 9:49:14 AM (8 years ago)
Author:
commit-queue@webkit.org
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 <caitp@igalia.com> 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:
Location:
trunk/Source/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r194144 r194153  
     12015-12-16  Caitlin Potter  <caitp@igalia.com>
     2
     3        [JSC] fix error message for eval/arguments CoverInitializedName in strict code
     4        https://bugs.webkit.org/show_bug.cgi?id=152304
     5
     6        Reviewed by Darin Adler.
     7
     8        Because the error was originally classified as indicating a Pattern, the
     9        error in AssignmentPattern parsing causes the reported message to revert to
     10        the original Expression error message, which in this case is incorrect.
     11
     12        This change modifies the implementation of the strict code
     13        error slightly, and reclassifies the error to prevent the message revert,
     14        which improves the clarity of the message overall.
     15
     16        * parser/Parser.cpp:
     17        (JSC::Parser<LexerType>::parseAssignmentElement):
     18        (JSC::Parser<LexerType>::parseDestructuringPattern):
     19        * parser/Parser.h:
     20        (JSC::Parser::ExpressionErrorClassifier::reclassifyExpressionError):
     21        (JSC::Parser::reclassifyExpressionError):
     22        * tests/stress/destructuring-assignment-syntax.js:
     23
    1242015-12-16  Joseph Pecoraro  <pecoraro@apple.com>
    225
  • trunk/Source/JavaScriptCore/parser/Parser.cpp

    r194107 r194153  
    844844
    845845    if (strictMode() && m_lastIdentifier && context.isResolve(element)) {
    846         failIfTrueIfStrict(m_vm->propertyNames->eval == *m_lastIdentifier, "Cannot modify 'eval' in strict mode");
    847         failIfTrueIfStrict(m_vm->propertyNames->arguments == *m_lastIdentifier, "Cannot modify 'arguments' in strict mode");
     846        bool isEvalOrArguments = m_vm->propertyNames->eval == *m_lastIdentifier || m_vm->propertyNames->arguments == *m_lastIdentifier;
     847        failIfTrueIfStrict(isEvalOrArguments, "Cannot modify '", m_lastIdentifier->impl(), "' in strict mode");
    848848    }
    849849
     
    932932                    innerPattern = parseBindingOrAssignmentElement(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1);
    933933                else {
    934                     if (kind == DestructureToExpressions && strictMode()) {
    935                         failIfTrueIfStrict(m_vm->propertyNames->eval == *propertyName, "Cannot modify 'eval' in strict mode");
    936                         failIfTrueIfStrict(m_vm->propertyNames->arguments == *propertyName, "Cannot modify 'arguments' in strict mode");
     934                    if (kind == DestructureToExpressions) {
     935                        bool isEvalOrArguments = m_vm->propertyNames->eval == *propertyName || m_vm->propertyNames->arguments == *propertyName;
     936                        if (isEvalOrArguments && strictMode())
     937                            reclassifyExpressionError(ErrorIndicatesPattern, ErrorIndicatesNothing);
     938                        failIfTrueIfStrict(isEvalOrArguments, "Cannot modify '", propertyName->impl(), "' in strict mode");
    937939                    }
    938940                    innerPattern = createBindingPattern(context, kind, exportType, *propertyName, identifierToken, bindingContext, duplicateIdentifier);
  • trunk/Source/JavaScriptCore/parser/Parser.h

    r194017 r194153  
    765765        }
    766766
     767        void reclassifyExpressionError(ExpressionErrorClass oldClassification, ExpressionErrorClass classification)
     768        {
     769            if (m_class != oldClassification)
     770                return;
     771            m_class = classification;
     772        }
     773
    767774        void propagateExpressionErrorClass()
    768775        {
     
    783790        if (m_expressionErrorClassifier)
    784791            m_expressionErrorClassifier->classifyExpressionError(classification);
     792    }
     793
     794    ALWAYS_INLINE void reclassifyExpressionError(ExpressionErrorClass oldClassification, ExpressionErrorClass classification)
     795    {
     796        if (m_expressionErrorClassifier)
     797            m_expressionErrorClassifier->reclassifyExpressionError(oldClassification, classification);
    785798    }
    786799
  • trunk/Source/JavaScriptCore/tests/stress/destructuring-assignment-syntax.js

    r194107 r194153  
    6060
    6161testSyntaxError("'use strict'; ({ eval } = {})", "SyntaxError: Cannot modify 'eval' in strict mode.");
    62 // FIXME: support CoverInitializedName properly.
    63 //testSyntaxError("'use strict'; ({ eval = 0 } = {})", "SyntaxError: Cannot modify 'eval' in strict mode.");
     62testSyntaxError("'use strict'; ({ eval = 0 } = {})", "SyntaxError: Cannot modify 'eval' in strict mode.");
    6463testSyntaxError("'use strict'; ({ a: eval } = {})", "SyntaxError: Cannot modify 'eval' in strict mode.");
    6564testSyntaxError("'use strict'; ({ a: eval = 0 } = {})", "SyntaxError: Cannot modify 'eval' in strict mode.");
    6665testSyntaxError("'use strict'; ({ arguments } = {})", "SyntaxError: Cannot modify 'arguments' in strict mode.");
    67 // FIXME: support CoverInitializedName properly.
    68 //testSyntaxError("'use strict'; ({ arguments = 0 } = {})", "SyntaxError: Cannot modify 'arguments' in strict mode.");
     66testSyntaxError("'use strict'; ({ arguments = 0 } = {})", "SyntaxError: Cannot modify 'arguments' in strict mode.");
    6967testSyntaxError("'use strict'; ({ a: arguments } = {})", "SyntaxError: Cannot modify 'arguments' in strict mode.");
    7068testSyntaxError("'use strict'; ({ a: arguments = 0 } = {})", "SyntaxError: Cannot modify 'arguments' in strict mode.");
Note: See TracChangeset for help on using the changeset viewer.