Changeset 62410 in webkit
- Timestamp:
- Jul 2, 2010, 3:31:40 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r62405 r62410 1 2010-07-02 Oliver Hunt <[email protected]> 2 3 Reviewed by Geoffrey Garen. 4 5 Move BOM handling out of the lexer and parser 6 https://bugs.webkit.org/show_bug.cgi?id=41539 7 8 Doing the BOM stripping in the lexer meant that we could 9 end up having to strip the BOMs from a source multiple times. 10 To deal with this we now require all strings provided by 11 a SourceProvider to already have had the BOMs stripped. 12 This also simplifies some of the lexer logic. 13 14 * parser/Lexer.cpp: 15 (JSC::Lexer::setCode): 16 (JSC::Lexer::sourceCode): 17 * parser/SourceProvider.h: 18 (JSC::SourceProvider::SourceProvider): 19 (JSC::UStringSourceProvider::create): 20 (JSC::UStringSourceProvider::getRange): 21 (JSC::UStringSourceProvider::UStringSourceProvider): 22 * wtf/text/StringImpl.h: 23 (WebCore::StringImpl::copyStringWithoutBOMs): 24 1 25 2010-07-02 Renata Hodovan <[email protected]> 2 26 -
trunk/JavaScriptCore/parser/Lexer.cpp
r62366 r62410 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 } -
trunk/JavaScriptCore/parser/SourceProvider.h
r44224 r62410 35 35 namespace JSC { 36 36 37 enum SourceBOMPresence { SourceHasNoBOMs, SourceCouldHaveBOMs };38 39 37 class SourceProvider : public RefCounted<SourceProvider> { 40 38 public: 41 SourceProvider(const UString& url , SourceBOMPresence hasBOMs = SourceCouldHaveBOMs)39 SourceProvider(const UString& url) 42 40 : m_url(url) 43 , m_hasBOMs(hasBOMs)44 41 { 45 42 } … … 53 50 intptr_t asID() { return reinterpret_cast<intptr_t>(this); } 54 51 55 SourceBOMPresence hasBOMs() const { return m_hasBOMs; }56 57 52 private: 58 53 UString m_url; 59 SourceBOMPresence m_hasBOMs;60 54 }; 61 55 62 56 class UStringSourceProvider : public SourceProvider { 63 57 public: 64 static PassRefPtr<UStringSourceProvider> create(const UString& source, const UString& url )58 static PassRefPtr<UStringSourceProvider> create(const UString& source, const UString& url, bool hasBOMs = true) 65 59 { 66 return adoptRef(new UStringSourceProvider(source, url ));60 return adoptRef(new UStringSourceProvider(source, url, hasBOMs)); 67 61 } 68 62 69 UString getRange(int start, int end) const { return m_source.substr(start, end - start); } 63 UString getRange(int start, int end) const 64 { 65 return m_source.substr(start, end - start); 66 } 70 67 const UChar* data() const { return m_source.data(); } 71 68 int length() const { return m_source.size(); } 72 69 73 70 private: 74 UStringSourceProvider(const UString& source, const UString& url )71 UStringSourceProvider(const UString& source, const UString& url, bool hasBOMs) 75 72 : SourceProvider(url) 76 73 , m_source(source) 77 74 { 75 if (hasBOMs && m_source.size()) { 76 bool scratch = false; 77 m_source = UString(m_source.rep()->copyStringWithoutBOMs(false, scratch)); 78 } 78 79 } 79 80 -
trunk/JavaScriptCore/wtf/text/StringImpl.h
r60332 r62410 258 258 } 259 259 260 PassRefPtr<StringImpl> copyStringWithoutBOMs(bool definitelyHasBOMs, bool& hasBOMs) 261 { 262 static const UChar byteOrderMark = 0xFEFF; 263 size_t i = 0; 264 if (!definitelyHasBOMs) { 265 hasBOMs = false; 266 // ECMA-262 calls for stripping all Cf characters, but we only strip BOM characters. 267 // See <https://bugs.webkit.org/show_bug.cgi?id=4931> for details. 268 for (; i < m_length; i++) { 269 if (UNLIKELY(m_data[i] == byteOrderMark)) { 270 hasBOMs = true; 271 break; 272 } 273 } 274 if (!hasBOMs) 275 return this; 276 } 277 Vector<UChar> result; 278 result.reserveInitialCapacity(m_length); 279 for (; i < m_length; i++) 280 result.append(m_data[i]); 281 for (; i < m_length; i++) { 282 UChar c = m_data[i]; 283 if (c != byteOrderMark) 284 result.append(c); 285 } 286 return StringImpl::adopt(result); 287 } 288 260 289 // Returns a StringImpl suitable for use on another thread. 261 290 PassRefPtr<StringImpl> crossThreadString(); -
trunk/WebCore/ChangeLog
r62407 r62410 1 2010-07-02 Oliver Hunt <[email protected]> 2 3 Reviewed by Geoffrey Garen. 4 5 Move BOM handling out of the lexer and parser 6 https://bugs.webkit.org/show_bug.cgi?id=41539 7 8 Update WebCore to ensure that SourceProviders don't 9 produce strings with BOMs in them. 10 11 * bindings/js/ScriptSourceProvider.h: 12 (WebCore::ScriptSourceProvider::ScriptSourceProvider): 13 * bindings/js/StringSourceProvider.h: 14 (WebCore::StringSourceProvider::StringSourceProvider): 15 * loader/CachedScript.cpp: 16 (WebCore::CachedScript::CachedScript): 17 (WebCore::CachedScript::script): 18 * loader/CachedScript.h: 19 (WebCore::CachedScript::): 20 CachedScript now stores decoded data with the BOMs stripped, 21 and caches the presence of BOMs across memory purges. 22 1 23 2010-07-02 Sam Weinig <[email protected]> 2 24 -
trunk/WebCore/bindings/js/ScriptSourceProvider.h
r46253 r62410 36 36 class ScriptSourceProvider : public JSC::SourceProvider { 37 37 public: 38 ScriptSourceProvider(const JSC::UString& url , JSC::SourceBOMPresence hasBOMs = JSC::SourceCouldHaveBOMs)39 : SourceProvider(url , hasBOMs)38 ScriptSourceProvider(const JSC::UString& url) 39 : SourceProvider(url) 40 40 { 41 41 } -
trunk/WebCore/bindings/js/StringSourceProvider.h
r57738 r62410 50 50 , m_source(source) 51 51 { 52 if (m_source.length()) { 53 bool scratch = false; 54 m_source = String(source.impl()->copyStringWithoutBOMs(false, scratch)); 55 } 52 56 } 53 57 -
trunk/WebCore/loader/CachedScript.cpp
r59576 r62410 38 38 CachedScript::CachedScript(const String& url, const String& charset) 39 39 : CachedResource(url, Script) 40 , m_scriptHasBOMs(SourceCouldHaveBOMs) 40 41 , m_decoder(TextResourceDecoder::create("application/javascript", charset)) 41 42 , m_decodedDataDeletionTimer(this, &CachedScript::decodedDataDeletionTimerFired) … … 79 80 m_script = m_decoder->decode(m_data->data(), encodedSize()); 80 81 m_script += m_decoder->flush(); 82 if (m_scriptHasBOMs != SourceHasNoBOMs && m_script.length()) { 83 bool hasBOMs = false; 84 m_script = String(m_script.impl()->copyStringWithoutBOMs(m_scriptHasBOMs == SourceHasBOMs, hasBOMs)); 85 m_scriptHasBOMs = hasBOMs ? SourceHasBOMs : SourceHasNoBOMs; 86 } 81 87 setDecodedSize(m_script.length() * sizeof(UChar)); 82 88 } -
trunk/WebCore/loader/CachedScript.h
r44749 r62410 60 60 61 61 String m_script; 62 enum { SourceHasNoBOMs, SourceCouldHaveBOMs, SourceHasBOMs } m_scriptHasBOMs; 62 63 RefPtr<TextResourceDecoder> m_decoder; 63 64 Timer<CachedScript> m_decodedDataDeletionTimer;
Note:
See TracChangeset
for help on using the changeset viewer.