Ignore:
Timestamp:
Nov 7, 2011, 6:25:20 PM (14 years ago)
Author:
[email protected]
Message:

"use strict" can not contain escape sequences or line continuation
https://bugs.webkit.org/show_bug.cgi?id=71532

Reviewed by Darin Adler.

Source/JavaScriptCore:

Store the actual literal length (before the escapes and line
continuation are encoded) while parsing the directive and use it
for the directive comparison.

  • parser/Parser.cpp:

(JSC::Parser::parseSourceElements):
(JSC::Parser::parseStatement):

  • parser/Parser.h:

LayoutTests:

  • fast/js/basic-strict-mode-expected.txt:
  • fast/js/script-tests/basic-strict-mode.js:

(testLineContinuation): Added.
(testEscapeSequence): Added.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/Parser.cpp

    r99436 r99513  
    130130template <Parser::SourceElementsMode mode, class TreeBuilder> TreeSourceElements Parser::parseSourceElements(TreeBuilder& context)
    131131{
     132    const unsigned lengthOfUseStrictLiteral = 12; // "use strict".length
    132133    TreeSourceElements sourceElements = context.createSourceElements();
    133134    bool seenNonDirective = false;
    134135    const Identifier* directive = 0;
     136    unsigned directiveLiteralLength = 0;
    135137    unsigned startOffset = m_token.m_info.startOffset;
    136138    unsigned oldLastLineNumber = m_lexer->lastLineNumber();
    137139    unsigned oldLineNumber = m_lexer->lineNumber();
    138140    bool hasSetStrict = false;
    139     while (TreeStatement statement = parseStatement(context, directive)) {
     141    while (TreeStatement statement = parseStatement(context, directive, &directiveLiteralLength)) {
    140142        if (mode == CheckForStrictMode && !seenNonDirective) {
    141143            if (directive) {
    142                 if (!hasSetStrict && m_globalData->propertyNames->useStrictIdentifier == *directive) {
     144                // "use strict" must be the exact literal without escape sequences or line continuation.
     145                if (!hasSetStrict && directiveLiteralLength == lengthOfUseStrictLiteral && m_globalData->propertyNames->useStrictIdentifier == *directive) {
    143146                    setStrictMode();
    144147                    hasSetStrict = true;
     
    649652}
    650653
    651 template <class TreeBuilder> TreeStatement Parser::parseStatement(TreeBuilder& context, const Identifier*& directive)
     654template <class TreeBuilder> TreeStatement Parser::parseStatement(TreeBuilder& context, const Identifier*& directive, unsigned* directiveLiteralLength)
    652655{
    653656    DepthManager statementDepth(&m_statementDepth);
     
    703706    case STRING:
    704707        directive = m_token.m_data.ident;
     708        if (directiveLiteralLength)
     709            *directiveLiteralLength = m_token.m_info.endOffset - m_token.m_info.startOffset;
    705710        nonTrivialExpressionCount = m_nonTrivialExpressionCount;
    706711    default:
Note: See TracChangeset for help on using the changeset viewer.