Changeset 62449 in webkit for trunk/JavaScriptCore/parser/Lexer.cpp
- Timestamp:
- Jul 3, 2010, 1:30:24 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/parser/Lexer.cpp
r62416 r62449 46 46 namespace JSC { 47 47 48 static const UChar byteOrderMark = 0xFEFF;49 48 50 49 enum CharacterTypes { … … 257 256 m_buffer16.reserveInitialCapacity((m_codeEnd - m_code) / 2); 258 257 259 // ECMA-262 calls for stripping all Cf characters, but we only strip BOM characters.260 // See <https://bugs.webkit.org/show_bug.cgi?id=4931> for details.261 if (source.provider()->hasBOMs()) {262 for (const UChar* p = m_codeStart; p < m_codeEnd; ++p) {263 if (UNLIKELY(*p == byteOrderMark)) {264 copyCodeWithoutBOMs();265 break;266 }267 }268 }269 270 258 if (LIKELY(m_code < m_codeEnd)) 271 259 m_current = *m_code; … … 273 261 m_current = -1; 274 262 ASSERT(currentOffset() == source.startOffset()); 275 }276 277 void Lexer::copyCodeWithoutBOMs()278 {279 // Note: In this case, the character offset data for debugging will be incorrect.280 // If it's important to correctly debug code with extraneous BOMs, then the caller281 // should strip the BOMs when creating the SourceProvider object and do its own282 // mapping of offsets within the stripped text to original text offset.283 284 m_codeWithoutBOMs.reserveCapacity(m_codeEnd - m_code);285 for (const UChar* p = m_code; p < m_codeEnd; ++p) {286 UChar c = *p;287 if (c != byteOrderMark)288 m_codeWithoutBOMs.append(c);289 }290 ptrdiff_t startDelta = m_codeStart - m_code;291 m_code = m_codeWithoutBOMs.data();292 m_codeStart = m_code + startDelta;293 m_codeEnd = m_codeWithoutBOMs.data() + m_codeWithoutBOMs.size();294 263 } 295 264 … … 1181 1150 SourceCode Lexer::sourceCode(int openBrace, int closeBrace, int firstLine) 1182 1151 { 1183 if (m_codeWithoutBOMs.isEmpty())1184 return SourceCode(m_source->provider(), openBrace, closeBrace + 1, firstLine);1185 1186 const UChar* data = m_source->provider()->data();1187 1188 ASSERT(openBrace < closeBrace);1189 int i;1190 for (i = m_source->startOffset(); i < openBrace; ++i) {1191 if (data[i] == byteOrderMark) {1192 openBrace++;1193 closeBrace++;1194 }1195 }1196 for (; i < closeBrace; ++i) {1197 if (data[i] == byteOrderMark)1198 closeBrace++;1199 }1200 1201 ASSERT(openBrace < closeBrace);1202 1203 1152 return SourceCode(m_source->provider(), openBrace, closeBrace + 1, firstLine); 1204 1153 }
Note:
See TracChangeset
for help on using the changeset viewer.