From 6882a04fb36642862b11efe514251d32070c3d65 Mon Sep 17 00:00:00 2001 From: Konstantin Tokarev Date: Thu, 25 Aug 2016 19:20:41 +0300 Subject: Imported QtWebKit TP3 (git b57bc6801f1876c3220d5a4bfea33d620d477443) Change-Id: I3b1d8a2808782c9f34d50240000e20cb38d3680f Reviewed-by: Konstantin Tokarev --- Source/JavaScriptCore/parser/SourceProvider.h | 80 +++++++++++++++++++++------ 1 file changed, 64 insertions(+), 16 deletions(-) (limited to 'Source/JavaScriptCore/parser/SourceProvider.h') diff --git a/Source/JavaScriptCore/parser/SourceProvider.h b/Source/JavaScriptCore/parser/SourceProvider.h index 4ced9d9c7..1a9a6bd9e 100644 --- a/Source/JavaScriptCore/parser/SourceProvider.h +++ b/Source/JavaScriptCore/parser/SourceProvider.h @@ -10,7 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * 3. Neither the name of Apple Inc. ("Apple") nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * @@ -29,7 +29,6 @@ #ifndef SourceProvider_h #define SourceProvider_h -#include #include #include #include @@ -44,19 +43,20 @@ namespace JSC { JS_EXPORT_PRIVATE virtual ~SourceProvider(); - virtual const String& source() const = 0; - String getRange(int start, int end) const + virtual unsigned hash() const = 0; + virtual StringView source() const = 0; + StringView getRange(int start, int end) const { - return source().substringSharingImpl(start, end - start); + return source().substring(start, end - start); } - const String& url() { return m_url; } + const String& url() const { return m_url; } + const String& sourceURL() const { return m_sourceURLDirective; } + const String& sourceMappingURL() const { return m_sourceMappingURLDirective; } + TextPosition startPosition() const { return m_startPosition; } intptr_t asID() { - ASSERT(this); - if (!this) // Be defensive in release mode. - return nullID; if (!m_id) getID(); return m_id; @@ -66,11 +66,16 @@ namespace JSC { void setValid() { m_validated = true; } private: + template friend class Parser; + + void setSourceURLDirective(const String& sourceURL) { m_sourceURLDirective = sourceURL; } + void setSourceMappingURLDirective(const String& sourceMappingURL) { m_sourceMappingURLDirective = sourceMappingURL; } JS_EXPORT_PRIVATE void getID(); - Vector& lineStarts(); String m_url; + String m_sourceURLDirective; + String m_sourceMappingURLDirective; TextPosition m_startPosition; bool m_validated : 1; uintptr_t m_id : sizeof(uintptr_t) * 8 - 1; @@ -78,26 +83,69 @@ namespace JSC { class StringSourceProvider : public SourceProvider { public: - static PassRefPtr create(const String& source, const String& url, const TextPosition& startPosition = TextPosition::minimumPosition()) + static Ref create(const String& source, const String& url, const TextPosition& startPosition = TextPosition::minimumPosition()) { - return adoptRef(new StringSourceProvider(source, url, startPosition)); + return adoptRef(*new StringSourceProvider(source, url, startPosition)); } - virtual const String& source() const OVERRIDE + JS_EXPORT_PRIVATE ~StringSourceProvider() override; + + unsigned hash() const override { - return m_source; + return m_source.get().hash(); + } + + virtual StringView source() const override + { + return m_source.get(); } private: StringSourceProvider(const String& source, const String& url, const TextPosition& startPosition) : SourceProvider(url, startPosition) - , m_source(source) + , m_source(source.isNull() ? *StringImpl::empty() : *source.impl()) { } - String m_source; + Ref m_source; }; +#if ENABLE(WEBASSEMBLY) + class WebAssemblySourceProvider : public SourceProvider { + public: + static Ref create(const Vector& data, const String& url) + { + return adoptRef(*new WebAssemblySourceProvider(data, url)); + } + + unsigned hash() const override + { + return m_source.impl()->hash(); + } + + virtual StringView source() const override + { + return m_source; + } + + const Vector& data() const + { + return m_data; + } + + private: + WebAssemblySourceProvider(const Vector& data, const String& url) + : SourceProvider(url, TextPosition::minimumPosition()) + , m_source("[WebAssembly source]") + , m_data(data) + { + } + + String m_source; + Vector m_data; + }; +#endif + } // namespace JSC #endif // SourceProvider_h -- cgit v1.2.1