diff options
Diffstat (limited to 'JavaScriptCore/parser/SourceProvider.h')
-rw-r--r-- | JavaScriptCore/parser/SourceProvider.h | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/JavaScriptCore/parser/SourceProvider.h b/JavaScriptCore/parser/SourceProvider.h index 1c59eed..87ea960 100644 --- a/JavaScriptCore/parser/SourceProvider.h +++ b/JavaScriptCore/parser/SourceProvider.h @@ -34,13 +34,10 @@ namespace JSC { - enum SourceBOMPresence { SourceHasNoBOMs, SourceCouldHaveBOMs }; - class SourceProvider : public RefCounted<SourceProvider> { public: - SourceProvider(const UString& url, SourceBOMPresence hasBOMs = SourceCouldHaveBOMs) + SourceProvider(const UString& url) : m_url(url) - , m_hasBOMs(hasBOMs) { } virtual ~SourceProvider() { } @@ -52,29 +49,33 @@ namespace JSC { const UString& url() { return m_url; } intptr_t asID() { return reinterpret_cast<intptr_t>(this); } - SourceBOMPresence hasBOMs() const { return m_hasBOMs; } - private: UString m_url; - SourceBOMPresence m_hasBOMs; }; class UStringSourceProvider : public SourceProvider { public: - static PassRefPtr<UStringSourceProvider> create(const UString& source, const UString& url) + static PassRefPtr<UStringSourceProvider> create(const UString& source, const UString& url, bool hasBOMs = true) { - return adoptRef(new UStringSourceProvider(source, url)); + return adoptRef(new UStringSourceProvider(source, url, hasBOMs)); } - UString getRange(int start, int end) const { return m_source.substr(start, end - start); } + UString getRange(int start, int end) const + { + return m_source.substr(start, end - start); + } const UChar* data() const { return m_source.data(); } int length() const { return m_source.size(); } private: - UStringSourceProvider(const UString& source, const UString& url) + UStringSourceProvider(const UString& source, const UString& url, bool hasBOMs) : SourceProvider(url) , m_source(source) { + if (hasBOMs && m_source.size()) { + bool scratch = false; + m_source = UString(m_source.rep()->copyStringWithoutBOMs(false, scratch)); + } } UString m_source; |