Ignore:
Timestamp:
Aug 17, 2019, 7:20:07 PM (6 years ago)
Author:
Ross Kirsling
Message:

[ESNext] Support hashbang.
https://bugs.webkit.org/show_bug.cgi?id=200865

Reviewed by Mark Lam.

JSTests:

  • stress/hashbang.js: Added.
  • test262/expectations.yaml: Mark 6 cases as passing.

Source/JavaScriptCore:

Hashbang (a.k.a. shebang) support is at Stage 3 in TC39:
https://github.com/tc39/proposal-hashbang

This allows #! to be treated like //, but only at the very start of the source text.

  • parser/Lexer.cpp:

(JSC::Lexer<T>::Lexer):
(JSC::Lexer<T>::lexWithoutClearingLineTerminator):

File:
1 edited

Legend:

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

    r247845 r248826  
    9696    // Other types (only one so far)
    9797    CharacterWhiteSpace,
     98    CharacterHash,
    9899    CharacterPrivateIdentifierStart
    99100};
     
    136137/*  33 - !                  */ CharacterExclamationMark,
    137138/*  34 - "                  */ CharacterQuote,
    138 /*  35 - #                  */ CharacterInvalid,
     139/*  35 - #                  */ CharacterHash,
    139140/*  36 - $                  */ CharacterIdentifierStart,
    140141/*  37 - %                  */ CharacterModulo,
     
    24232424        m_lineStart = m_code;
    24242425        goto start;
     2426    case CharacterHash:
     2427        // Hashbang is only permitted at the start of the source text.
     2428        if (peek(1) == '!' && !currentOffset()) {
     2429            shift();
     2430            shift();
     2431            goto inSingleLineComment;
     2432        }
     2433        goto invalidCharacter;
    24252434    case CharacterPrivateIdentifierStart:
    24262435        if (m_parsingBuiltinFunction)
    24272436            goto parseIdent;
    2428 
    2429         FALLTHROUGH;
     2437        goto invalidCharacter;
    24302438    case CharacterOtherIdentifierPart:
    24312439    case CharacterInvalid:
    2432         m_lexErrorMessage = invalidCharacterMessage();
    2433         token = ERRORTOK;
    2434         goto returnError;
     2440        goto invalidCharacter;
    24352441    default:
    24362442        RELEASE_ASSERT_NOT_REACHED();
     
    24822488    fillTokenInfo(tokenRecord, token, m_lineNumber, currentOffset(), currentLineStartOffset(), currentPosition());
    24832489    return token;
     2490
     2491invalidCharacter:
     2492    m_lexErrorMessage = invalidCharacterMessage();
     2493    token = ERRORTOK;
     2494    // Falls through to return error.
    24842495
    24852496returnError:
Note: See TracChangeset for help on using the changeset viewer.