Ignore:
Timestamp:
Oct 29, 2012, 3:50:02 PM (13 years ago)
Author:
[email protected]
Message:

Non-special escape character sequences cause JSC::Lexer::parseString to create 16 bit strings
https://bugs.webkit.org/show_bug.cgi?id=100576

Reviewed by Darin Adler.

Source/JavaScriptCore:

Changed singleEscape() processing to be based on a lookup of a static table. The table
covers ASCII characters SPACE through DEL. If a character can be a single character escape,
then the table provides the non-zero result of that escape. Updated the result of
singleEscape to be an LChar to make the table as small as possible.
Added a new test fast/js/normal-character-escapes-in-string-literals.html to validated
the behavior.

  • parser/Lexer.cpp:

(JSC::singleEscape):
(JSC::Lexer::parseString):
(JSC::Lexer::parseStringSlowCase):

LayoutTests:

Added a new test to validated the behavior of the corresponding changes to string processing
in the Lexer.

  • fast/js/normal-character-escapes-in-string-literals-expected.txt: Added.
  • fast/js/normal-character-escapes-in-string-literals.html: Added.
  • fast/js/script-tests/normal-character-escapes-in-string-literals.js: Added.
File:
1 edited

Legend:

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

    r131956 r132853  
    356356};
    357357
     358// This table provides the character that results from \X where X is the index in the table beginning
     359// with SPACE. A table value of 0 means that more processing needs to be done.
     360static const LChar singleCharacterEscapeValuesForASCII[128] = {
     361/*   0 - Null               */ 0,
     362/*   1 - Start of Heading   */ 0,
     363/*   2 - Start of Text      */ 0,
     364/*   3 - End of Text        */ 0,
     365/*   4 - End of Transm.     */ 0,
     366/*   5 - Enquiry            */ 0,
     367/*   6 - Acknowledgment     */ 0,
     368/*   7 - Bell               */ 0,
     369/*   8 - Back Space         */ 0,
     370/*   9 - Horizontal Tab     */ 0,
     371/*  10 - Line Feed          */ 0,
     372/*  11 - Vertical Tab       */ 0,
     373/*  12 - Form Feed          */ 0,
     374/*  13 - Carriage Return    */ 0,
     375/*  14 - Shift Out          */ 0,
     376/*  15 - Shift In           */ 0,
     377/*  16 - Data Line Escape   */ 0,
     378/*  17 - Device Control 1   */ 0,
     379/*  18 - Device Control 2   */ 0,
     380/*  19 - Device Control 3   */ 0,
     381/*  20 - Device Control 4   */ 0,
     382/*  21 - Negative Ack.      */ 0,
     383/*  22 - Synchronous Idle   */ 0,
     384/*  23 - End of Transmit    */ 0,
     385/*  24 - Cancel             */ 0,
     386/*  25 - End of Medium      */ 0,
     387/*  26 - Substitute         */ 0,
     388/*  27 - Escape             */ 0,
     389/*  28 - File Separator     */ 0,
     390/*  29 - Group Separator    */ 0,
     391/*  30 - Record Separator   */ 0,
     392/*  31 - Unit Separator     */ 0,
     393/*  32 - Space              */ ' ',
     394/*  33 - !                  */ '!',
     395/*  34 - "                  */ '"',
     396/*  35 - #                  */ '#',
     397/*  36 - $                  */ '$',
     398/*  37 - %                  */ '%',
     399/*  38 - &                  */ '&',
     400/*  39 - '                  */ '\'',
     401/*  40 - (                  */ '(',
     402/*  41 - )                  */ ')',
     403/*  42 - *                  */ '*',
     404/*  43 - +                  */ '+',
     405/*  44 - ,                  */ ',',
     406/*  45 - -                  */ '-',
     407/*  46 - .                  */ '.',
     408/*  47 - /                  */ '/',
     409/*  48 - 0                  */ 0,
     410/*  49 - 1                  */ 0,
     411/*  50 - 2                  */ 0,
     412/*  51 - 3                  */ 0,
     413/*  52 - 4                  */ 0,
     414/*  53 - 5                  */ 0,
     415/*  54 - 6                  */ 0,
     416/*  55 - 7                  */ 0,
     417/*  56 - 8                  */ 0,
     418/*  57 - 9                  */ 0,
     419/*  58 - :                  */ ':',
     420/*  59 - ;                  */ ';',
     421/*  60 - <                  */ '<',
     422/*  61 - =                  */ '=',
     423/*  62 - >                  */ '>',
     424/*  63 - ?                  */ '?',
     425/*  64 - @                  */ '@',
     426/*  65 - A                  */ 'A',
     427/*  66 - B                  */ 'B',
     428/*  67 - C                  */ 'C',
     429/*  68 - D                  */ 'D',
     430/*  69 - E                  */ 'E',
     431/*  70 - F                  */ 'F',
     432/*  71 - G                  */ 'G',
     433/*  72 - H                  */ 'H',
     434/*  73 - I                  */ 'I',
     435/*  74 - J                  */ 'J',
     436/*  75 - K                  */ 'K',
     437/*  76 - L                  */ 'L',
     438/*  77 - M                  */ 'M',
     439/*  78 - N                  */ 'N',
     440/*  79 - O                  */ 'O',
     441/*  80 - P                  */ 'P',
     442/*  81 - Q                  */ 'Q',
     443/*  82 - R                  */ 'R',
     444/*  83 - S                  */ 'S',
     445/*  84 - T                  */ 'T',
     446/*  85 - U                  */ 'U',
     447/*  86 - V                  */ 'V',
     448/*  87 - W                  */ 'W',
     449/*  88 - X                  */ 'X',
     450/*  89 - Y                  */ 'Y',
     451/*  90 - Z                  */ 'Z',
     452/*  91 - [                  */ '[',
     453/*  92 - \                  */ '\\',
     454/*  93 - ]                  */ ']',
     455/*  94 - ^                  */ '^',
     456/*  95 - _                  */ '_',
     457/*  96 - `                  */ '`',
     458/*  97 - a                  */ 'a',
     459/*  98 - b                  */ 0x08,
     460/*  99 - c                  */ 'c',
     461/* 100 - d                  */ 'd',
     462/* 101 - e                  */ 'e',
     463/* 102 - f                  */ 0x0C,
     464/* 103 - g                  */ 'g',
     465/* 104 - h                  */ 'h',
     466/* 105 - i                  */ 'i',
     467/* 106 - j                  */ 'j',
     468/* 107 - k                  */ 'k',
     469/* 108 - l                  */ 'l',
     470/* 109 - m                  */ 'm',
     471/* 110 - n                  */ 0x0A,
     472/* 111 - o                  */ 'o',
     473/* 112 - p                  */ 'p',
     474/* 113 - q                  */ 'q',
     475/* 114 - r                  */ 0x0D,
     476/* 115 - s                  */ 's',
     477/* 116 - t                  */ 0x09,
     478/* 117 - u                  */ 0,
     479/* 118 - v                  */ 0x0B,
     480/* 119 - w                  */ 'w',
     481/* 120 - x                  */ 0,
     482/* 121 - y                  */ 'y',
     483/* 122 - z                  */ 'z',
     484/* 123 - {                  */ '{',
     485/* 124 - |                  */ '|',
     486/* 125 - }                  */ '}',
     487/* 126 - ~                  */ '~',
     488/* 127 - Delete             */ 0
     489};
     490
    358491template <typename T>
    359492Lexer<T>::Lexer(JSGlobalData* globalData)
     
    548681}
    549682
    550 static inline int singleEscape(int c)
    551 {
    552     switch (c) {
    553     case 'b':
    554         return 0x08;
    555     case 't':
    556         return 0x09;
    557     case 'n':
    558         return 0x0A;
    559     case 'v':
    560         return 0x0B;
    561     case 'f':
    562         return 0x0C;
    563     case 'r':
    564         return 0x0D;
    565     case '\\':
    566         return '\\';
    567     case '\'':
    568         return '\'';
    569     case '"':
    570         return '"';
    571     default:
    572         return 0;
    573     }
     683static inline LChar singleEscape(int c)
     684{
     685    if (c < 128) {
     686        ASSERT(static_cast<size_t>(c) < ARRAY_SIZE(singleCharacterEscapeValuesForASCII));
     687        return singleCharacterEscapeValuesForASCII[c];
     688    }
     689    return 0;
    574690}
    575691
     
    843959            shift();
    844960
    845             int escape = singleEscape(m_current);
     961            LChar escape = singleEscape(m_current);
    846962
    847963            // Most common escape sequences first
     
    9081024            shift();
    9091025
    910             int escape = singleEscape(m_current);
     1026            LChar escape = singleEscape(m_current);
    9111027
    9121028            // Most common escape sequences first
Note: See TracChangeset for help on using the changeset viewer.