Changeset 184337 in webkit for trunk/Source/JavaScriptCore/parser/Lexer.cpp
- Timestamp:
- May 14, 2015, 9:07:54 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/parser/Lexer.cpp
r183552 r184337 570 570 m_buffer8.reserveInitialCapacity(initialReadBufferCapacity); 571 571 m_buffer16.reserveInitialCapacity((m_codeEnd - m_code) / 2); 572 m_bufferForRawTemplateString16.reserveInitialCapacity(initialReadBufferCapacity); 572 573 573 574 if (LIKELY(m_code < m_codeEnd)) … … 1375 1376 1376 1377 template <typename T> 1377 template <bool shouldBuildStrings> typename Lexer<T>::StringParseResult Lexer<T>::parseTemplateLiteral(JSTokenData* tokenData )1378 template <bool shouldBuildStrings> typename Lexer<T>::StringParseResult Lexer<T>::parseTemplateLiteral(JSTokenData* tokenData, RawStringsBuildMode rawStringsBuildMode) 1378 1379 { 1379 1380 const T* stringStart = currentSourcePtr(); … … 1436 1437 if (m_current == '\r') { 1437 1438 // Normalize <CR>, <CR><LF> to <LF>. 1438 if (stringStart != currentSourcePtr() && shouldBuildStrings) 1439 append16(stringStart, currentSourcePtr() - stringStart); 1440 if (shouldBuildStrings) 1439 if (shouldBuildStrings) { 1440 if (stringStart != currentSourcePtr()) 1441 append16(stringStart, currentSourcePtr() - stringStart); 1442 if (rawStringStart != currentSourcePtr() && rawStringsBuildMode == RawStringsBuildMode::BuildRawStrings) 1443 m_bufferForRawTemplateString16.append(rawStringStart, currentSourcePtr() - rawStringStart); 1444 1441 1445 record16('\n'); 1446 if (rawStringsBuildMode == RawStringsBuildMode::BuildRawStrings) 1447 m_bufferForRawTemplateString16.append('\n'); 1448 } 1442 1449 lineNumberAdder.add(m_current); 1443 1450 shift(); … … 1447 1454 } 1448 1455 stringStart = currentSourcePtr(); 1456 rawStringStart = currentSourcePtr(); 1449 1457 } else { 1450 1458 lineNumberAdder.add(m_current); … … 1462 1470 bool isTail = m_current == '`'; 1463 1471 1464 if (currentSourcePtr() != stringStart && shouldBuildStrings) 1465 append16(stringStart, currentSourcePtr() - stringStart); 1472 if (shouldBuildStrings) { 1473 if (currentSourcePtr() != stringStart) 1474 append16(stringStart, currentSourcePtr() - stringStart); 1475 if (rawStringStart != currentSourcePtr() && rawStringsBuildMode == RawStringsBuildMode::BuildRawStrings) 1476 m_bufferForRawTemplateString16.append(rawStringStart, currentSourcePtr() - rawStringStart); 1477 } 1466 1478 1467 1479 if (shouldBuildStrings) { 1468 1480 tokenData->cooked = makeIdentifier(m_buffer16.data(), m_buffer16.size()); 1469 // TODO: While line terminator normalization (e.g. <CR> => <LF>) should be applied to both the raw and cooked representations, 1470 // this raw implementation just slices the source string. As a result, line terminators appear in the raw representation without normalization. 1471 // For example, when parsing `<CR>`, <CR> appears in the raw representation. 1472 // While non-tagged template literals don't use the raw representation, tagged templates use the raw representation. 1473 // So line terminator normalization should be applied to the raw representation when implementing tagged templates. 1474 tokenData->raw = makeIdentifier(rawStringStart, currentSourcePtr() - rawStringStart); 1481 // Line terminator normalization (e.g. <CR> => <LF>) should be applied to both the raw and cooked representations. 1482 if (rawStringsBuildMode == RawStringsBuildMode::BuildRawStrings) 1483 tokenData->raw = makeIdentifier(m_bufferForRawTemplateString16.data(), m_bufferForRawTemplateString16.size()); 1484 else 1485 tokenData->raw = makeEmptyIdentifier(); 1475 1486 } else { 1476 tokenData->cooked = nullptr;1477 tokenData->raw = nullptr;1487 tokenData->cooked = makeEmptyIdentifier(); 1488 tokenData->raw = makeEmptyIdentifier(); 1478 1489 } 1479 1490 tokenData->isTail = isTail; 1480 1491 1481 1492 m_buffer16.shrink(0); 1493 m_bufferForRawTemplateString16.shrink(0); 1482 1494 1483 1495 if (isTail) { … … 2126 2138 StringParseResult result = StringCannotBeParsed; 2127 2139 if (lexerFlags & LexerFlagsDontBuildStrings) 2128 result = parseTemplateLiteral<false>(tokenData );2140 result = parseTemplateLiteral<false>(tokenData, RawStringsBuildMode::BuildRawStrings); 2129 2141 else 2130 result = parseTemplateLiteral<true>(tokenData );2142 result = parseTemplateLiteral<true>(tokenData, RawStringsBuildMode::BuildRawStrings); 2131 2143 2132 2144 if (UNLIKELY(result != StringParsedSuccessfully)) { … … 2332 2344 #if ENABLE(ES6_TEMPLATE_LITERAL_SYNTAX) 2333 2345 template <typename T> 2334 JSTokenType Lexer<T>::scanTrailingTemplateString(JSToken* tokenRecord )2346 JSTokenType Lexer<T>::scanTrailingTemplateString(JSToken* tokenRecord, RawStringsBuildMode rawStringsBuildMode) 2335 2347 { 2336 2348 JSTokenData* tokenData = &tokenRecord->m_data; … … 2341 2353 // Leading closing brace } is already shifted in the previous token scan. 2342 2354 // So in this re-scan phase, shift() is not needed here. 2343 StringParseResult result = parseTemplateLiteral<true>(tokenData );2355 StringParseResult result = parseTemplateLiteral<true>(tokenData, rawStringsBuildMode); 2344 2356 JSTokenType token = ERRORTOK; 2345 2357 if (UNLIKELY(result != StringParsedSuccessfully)) { … … 2375 2387 m_buffer16.swap(newBuffer16); 2376 2388 2389 Vector<UChar> newBufferForRawTemplateString16; 2390 m_bufferForRawTemplateString16.swap(newBufferForRawTemplateString16); 2391 2377 2392 m_isReparsing = false; 2378 2393 }
Note:
See TracChangeset
for help on using the changeset viewer.