Changeset 62416 in webkit for trunk/JavaScriptCore/parser
- Timestamp:
- Jul 2, 2010, 4:49:07 PM (15 years ago)
- Location:
- trunk/JavaScriptCore/parser
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/parser/Lexer.cpp
r62410 r62416 46 46 namespace JSC { 47 47 48 static const UChar byteOrderMark = 0xFEFF; 48 49 49 50 enum CharacterTypes { … … 256 257 m_buffer16.reserveInitialCapacity((m_codeEnd - m_code) / 2); 257 258 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 258 270 if (LIKELY(m_code < m_codeEnd)) 259 271 m_current = *m_code; … … 261 273 m_current = -1; 262 274 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 caller 281 // should strip the BOMs when creating the SourceProvider object and do its own 282 // 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(); 263 294 } 264 295 … … 1150 1181 SourceCode Lexer::sourceCode(int openBrace, int closeBrace, int firstLine) 1151 1182 { 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 1152 1203 return SourceCode(m_source->provider(), openBrace, closeBrace + 1, firstLine); 1153 1204 } -
trunk/JavaScriptCore/parser/SourceProvider.h
r62410 r62416 35 35 namespace JSC { 36 36 37 enum SourceBOMPresence { SourceHasNoBOMs, SourceCouldHaveBOMs }; 38 37 39 class SourceProvider : public RefCounted<SourceProvider> { 38 40 public: 39 SourceProvider(const UString& url )41 SourceProvider(const UString& url, SourceBOMPresence hasBOMs = SourceCouldHaveBOMs) 40 42 : m_url(url) 43 , m_hasBOMs(hasBOMs) 41 44 { 42 45 } … … 50 53 intptr_t asID() { return reinterpret_cast<intptr_t>(this); } 51 54 55 SourceBOMPresence hasBOMs() const { return m_hasBOMs; } 56 52 57 private: 53 58 UString m_url; 59 SourceBOMPresence m_hasBOMs; 54 60 }; 55 61 56 62 class UStringSourceProvider : public SourceProvider { 57 63 public: 58 static PassRefPtr<UStringSourceProvider> create(const UString& source, const UString& url , bool hasBOMs = true)64 static PassRefPtr<UStringSourceProvider> create(const UString& source, const UString& url) 59 65 { 60 return adoptRef(new UStringSourceProvider(source, url , hasBOMs));66 return adoptRef(new UStringSourceProvider(source, url)); 61 67 } 62 68 63 UString getRange(int start, int end) const 64 { 65 return m_source.substr(start, end - start); 66 } 69 UString getRange(int start, int end) const { return m_source.substr(start, end - start); } 67 70 const UChar* data() const { return m_source.data(); } 68 71 int length() const { return m_source.size(); } 69 72 70 73 private: 71 UStringSourceProvider(const UString& source, const UString& url , bool hasBOMs)74 UStringSourceProvider(const UString& source, const UString& url) 72 75 : SourceProvider(url) 73 76 , m_source(source) 74 77 { 75 if (hasBOMs && m_source.size()) {76 bool scratch = false;77 m_source = UString(m_source.rep()->copyStringWithoutBOMs(false, scratch));78 }79 78 } 80 79
Note:
See TracChangeset
for help on using the changeset viewer.