Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (210626 => 210627)
--- trunk/Source/_javascript_Core/ChangeLog 2017-01-12 07:18:28 UTC (rev 210626)
+++ trunk/Source/_javascript_Core/ChangeLog 2017-01-12 09:01:40 UTC (rev 210627)
@@ -1,3 +1,16 @@
+2017-01-12 Yusuke Suzuki <[email protected]>
+
+ Implement InlineClassicScript
+ https://bugs.webkit.org/show_bug.cgi?id=166925
+
+ Reviewed by Ryosuke Niwa.
+
+ Add ScriptFetcher field for SourceOrigin.
+
+ * runtime/SourceOrigin.h:
+ (JSC::SourceOrigin::SourceOrigin):
+ (JSC::SourceOrigin::fetcher):
+
2017-01-11 Andreas Kling <[email protected]>
Crash when WebCore's GC heap grows way too large.
Modified: trunk/Source/_javascript_Core/runtime/SourceOrigin.h (210626 => 210627)
--- trunk/Source/_javascript_Core/runtime/SourceOrigin.h 2017-01-12 07:18:28 UTC (rev 210626)
+++ trunk/Source/_javascript_Core/runtime/SourceOrigin.h 2017-01-12 09:01:40 UTC (rev 210627)
@@ -25,6 +25,7 @@
#pragma once
+#include "ScriptFetcher.h"
#include <wtf/text/WTFString.h>
namespace JSC {
@@ -36,13 +37,22 @@
{
}
+ explicit SourceOrigin(const String& string, Ref<ScriptFetcher>&& fetcher)
+ : m_string(string)
+ , m_fetcher(WTFMove(fetcher))
+ {
+ }
+
SourceOrigin() = default;
const String& string() const { return m_string; }
bool isNull() const { return m_string.isNull(); }
+ ScriptFetcher* fetcher() const { return m_fetcher.get(); }
+
private:
String m_string;
+ RefPtr<ScriptFetcher> m_fetcher;
};
} // namespace JSC
Modified: trunk/Source/WebCore/CMakeLists.txt (210626 => 210627)
--- trunk/Source/WebCore/CMakeLists.txt 2017-01-12 07:18:28 UTC (rev 210626)
+++ trunk/Source/WebCore/CMakeLists.txt 2017-01-12 09:01:40 UTC (rev 210627)
@@ -1067,6 +1067,7 @@
bindings/js/CachedModuleScript.cpp
bindings/js/CachedModuleScriptLoader.cpp
+ bindings/js/CachedScriptFetcher.cpp
bindings/js/CallbackFunction.cpp
bindings/js/CommonVM.cpp
bindings/js/DOMWrapperWorld.cpp
@@ -1442,6 +1443,7 @@
dom/GenericEventQueue.cpp
dom/IdTargetObserver.cpp
dom/IdTargetObserverRegistry.cpp
+ dom/InlineClassicScript.cpp
dom/InlineStyleSheetOwner.cpp
dom/InputEvent.cpp
dom/KeyboardEvent.cpp
Modified: trunk/Source/WebCore/ChangeLog (210626 => 210627)
--- trunk/Source/WebCore/ChangeLog 2017-01-12 07:18:28 UTC (rev 210626)
+++ trunk/Source/WebCore/ChangeLog 2017-01-12 09:01:40 UTC (rev 210627)
@@ -1,3 +1,70 @@
+2017-01-12 Yusuke Suzuki <[email protected]>
+
+ Implement InlineClassicScript
+ https://bugs.webkit.org/show_bug.cgi?id=166925
+
+ Reviewed by Ryosuke Niwa.
+
+ As of r210585, ScriptFetcher functionality is decoupled from ScriptElement.
+ This patch is a further cleanup. We introduce InlineClassicScript, which is
+ similar to LoadableClassicScript / LoadableModuleScript. And we move ScriptFetcher
+ functionality from LoadableScript to CachedScriptFetcher, which is the base
+ class of InlineClassicScript and LoadableScript.
+
+ And we start setting this CachedScriptFetcher to the member of JSC::SourceOrigin.
+ This allows us to examine the ScriptFetcher from the SourceOrigin.
+ When dynamic-import operator is called, we need to get the ScriptFetcher from the
+ caller script SourceOrigin since the subsequent module loading needs to know the
+ metadata about fetching and ScriptFetcher delivers it.
+
+ No behavior change.
+
+ * CMakeLists.txt:
+ * bindings/js/CachedModuleScript.cpp:
+ (WebCore::CachedModuleScript::load):
+ * bindings/js/CachedModuleScript.h:
+ * bindings/js/CachedModuleScriptLoader.cpp:
+ (WebCore::CachedModuleScriptLoader::create):
+ (WebCore::CachedModuleScriptLoader::CachedModuleScriptLoader):
+ (WebCore::CachedModuleScriptLoader::load):
+ * bindings/js/CachedModuleScriptLoader.h:
+ * bindings/js/CachedScriptFetcher.cpp: Copied from Source/WebCore/dom/LoadableScript.cpp.
+ (WebCore::CachedScriptFetcher::requestScriptWithCache):
+ * bindings/js/CachedScriptFetcher.h: Copied from Source/_javascript_Core/runtime/SourceOrigin.h.
+ (WebCore::CachedScriptFetcher::CachedScriptFetcher):
+ * bindings/js/CachedScriptSourceProvider.h:
+ (WebCore::CachedScriptSourceProvider::create):
+ (WebCore::CachedScriptSourceProvider::CachedScriptSourceProvider):
+ (WebCore::makeSource): Deleted.
+ * bindings/js/ScriptController.cpp:
+ (WebCore::ScriptController::loadModuleScriptInWorld):
+ (WebCore::ScriptController::loadModuleScript):
+ * bindings/js/ScriptController.h:
+ * bindings/js/ScriptModuleLoader.cpp:
+ (WebCore::ScriptModuleLoader::fetch):
+ (WebCore::ScriptModuleLoader::notifyFinished):
+ * bindings/js/ScriptSourceCode.h:
+ (WebCore::ScriptSourceCode::ScriptSourceCode):
+ (WebCore::ScriptSourceCode::m_url):
+ * dom/InlineClassicScript.cpp: Added.
+ (WebCore::InlineClassicScript::create):
+ * dom/InlineClassicScript.h: Added.
+ * dom/LoadableClassicScript.cpp:
+ (WebCore::LoadableClassicScript::execute):
+ * dom/LoadableScript.cpp:
+ (WebCore::LoadableScript::requestScriptWithCache): Deleted.
+ * dom/LoadableScript.h:
+ (WebCore::LoadableScript::LoadableScript):
+ (): Deleted.
+ * dom/ScriptElement.cpp:
+ (WebCore::ScriptElement::prepareScript):
+ (WebCore::ScriptElement::requestModuleScript):
+ (WebCore::ScriptElement::executePendingScript):
+ * html/parser/HTMLScriptRunner.cpp:
+ (WebCore::HTMLScriptRunner::runScript):
+ * xml/parser/XMLDocumentParserLibxml2.cpp:
+ (WebCore::XMLDocumentParser::endElementNs):
+
2017-01-11 Eric Carlson <[email protected]>
[MediaStream, Mac] Render media stream audio buffers
Modified: trunk/Source/WebCore/bindings/js/CachedModuleScript.cpp (210626 => 210627)
--- trunk/Source/WebCore/bindings/js/CachedModuleScript.cpp 2017-01-12 07:18:28 UTC (rev 210626)
+++ trunk/Source/WebCore/bindings/js/CachedModuleScript.cpp 2017-01-12 09:01:40 UTC (rev 210627)
@@ -43,16 +43,16 @@
return adoptRef(*new CachedModuleScript());
}
-void CachedModuleScript::load(Document& document, const URL& rootURL, LoadableScript& loadableScript)
+void CachedModuleScript::load(Document& document, const URL& rootURL, CachedScriptFetcher& scriptFetcher)
{
if (auto* frame = document.frame())
- frame->script().loadModuleScript(*this, rootURL.string(), loadableScript);
+ frame->script().loadModuleScript(*this, rootURL.string(), scriptFetcher);
}
-void CachedModuleScript::load(Document& document, const ScriptSourceCode& sourceCode, LoadableScript& loadableScript)
+void CachedModuleScript::load(Document& document, const ScriptSourceCode& sourceCode, CachedScriptFetcher& scriptFetcher)
{
if (auto* frame = document.frame())
- frame->script().loadModuleScript(*this, sourceCode, loadableScript);
+ frame->script().loadModuleScript(*this, sourceCode, scriptFetcher);
}
void CachedModuleScript::notifyLoadCompleted(UniquedStringImpl& moduleKey)
Modified: trunk/Source/WebCore/bindings/js/CachedModuleScript.h (210626 => 210627)
--- trunk/Source/WebCore/bindings/js/CachedModuleScript.h 2017-01-12 07:18:28 UTC (rev 210626)
+++ trunk/Source/WebCore/bindings/js/CachedModuleScript.h 2017-01-12 09:01:40 UTC (rev 210627)
@@ -52,8 +52,8 @@
static Ref<CachedModuleScript> create();
- void load(Document&, const URL& rootURL, LoadableScript&);
- void load(Document&, const ScriptSourceCode&, LoadableScript&);
+ void load(Document&, const URL& rootURL, CachedScriptFetcher&);
+ void load(Document&, const ScriptSourceCode&, CachedScriptFetcher&);
private:
void notifyClientFinished();
Modified: trunk/Source/WebCore/bindings/js/CachedModuleScriptLoader.cpp (210626 => 210627)
--- trunk/Source/WebCore/bindings/js/CachedModuleScriptLoader.cpp 2017-01-12 07:18:28 UTC (rev 210626)
+++ trunk/Source/WebCore/bindings/js/CachedModuleScriptLoader.cpp 2017-01-12 09:01:40 UTC (rev 210627)
@@ -27,10 +27,10 @@
#include "CachedModuleScriptLoader.h"
#include "CachedScript.h"
+#include "CachedScriptFetcher.h"
#include "DOMWrapperWorld.h"
#include "Frame.h"
#include "JSDOMBinding.h"
-#include "LoadableScript.h"
#include "ResourceLoaderOptions.h"
#include "ScriptController.h"
#include "ScriptModuleLoader.h"
@@ -38,14 +38,15 @@
namespace WebCore {
-Ref<CachedModuleScriptLoader> CachedModuleScriptLoader::create(CachedModuleScriptLoaderClient& client, DeferredPromise& promise)
+Ref<CachedModuleScriptLoader> CachedModuleScriptLoader::create(CachedModuleScriptLoaderClient& client, DeferredPromise& promise, CachedScriptFetcher& scriptFetcher)
{
- return adoptRef(*new CachedModuleScriptLoader(client, promise));
+ return adoptRef(*new CachedModuleScriptLoader(client, promise, scriptFetcher));
}
-CachedModuleScriptLoader::CachedModuleScriptLoader(CachedModuleScriptLoaderClient& client, DeferredPromise& promise)
+CachedModuleScriptLoader::CachedModuleScriptLoader(CachedModuleScriptLoaderClient& client, DeferredPromise& promise, CachedScriptFetcher& scriptFetcher)
: m_client(&client)
, m_promise(&promise)
+ , m_scriptFetcher(scriptFetcher)
{
}
@@ -57,10 +58,10 @@
}
}
-bool CachedModuleScriptLoader::load(Document& document, LoadableScript& loadableScript, const URL& sourceURL)
+bool CachedModuleScriptLoader::load(Document& document, const URL& sourceURL)
{
ASSERT(!m_cachedScript);
- m_cachedScript = loadableScript.requestScriptWithCache(document, sourceURL);
+ m_cachedScript = m_scriptFetcher->requestScriptWithCache(document, sourceURL);
if (!m_cachedScript)
return false;
Modified: trunk/Source/WebCore/bindings/js/CachedModuleScriptLoader.h (210626 => 210627)
--- trunk/Source/WebCore/bindings/js/CachedModuleScriptLoader.h 2017-01-12 07:18:28 UTC (rev 210626)
+++ trunk/Source/WebCore/bindings/js/CachedModuleScriptLoader.h 2017-01-12 09:01:40 UTC (rev 210627)
@@ -35,20 +35,21 @@
class CachedModuleScriptLoaderClient;
class CachedScript;
+class CachedScriptFetcher;
class DeferredPromise;
class Document;
class JSDOMGlobalObject;
-class LoadableScript;
class URL;
class CachedModuleScriptLoader final : public RefCounted<CachedModuleScriptLoader>, private CachedResourceClient {
public:
- static Ref<CachedModuleScriptLoader> create(CachedModuleScriptLoaderClient&, DeferredPromise&);
+ static Ref<CachedModuleScriptLoader> create(CachedModuleScriptLoaderClient&, DeferredPromise&, CachedScriptFetcher&);
virtual ~CachedModuleScriptLoader();
- bool load(Document&, LoadableScript&, const URL& sourceURL);
+ bool load(Document&, const URL& sourceURL);
+ CachedScriptFetcher& scriptFetcher() { return m_scriptFetcher.get(); }
CachedScript* cachedScript() { return m_cachedScript.get(); }
void clearClient()
@@ -58,12 +59,13 @@
}
private:
- CachedModuleScriptLoader(CachedModuleScriptLoaderClient&, DeferredPromise&);
+ CachedModuleScriptLoader(CachedModuleScriptLoaderClient&, DeferredPromise&, CachedScriptFetcher&);
void notifyFinished(CachedResource&) final;
CachedModuleScriptLoaderClient* m_client { nullptr };
RefPtr<DeferredPromise> m_promise;
+ Ref<CachedScriptFetcher> m_scriptFetcher;
CachedResourceHandle<CachedScript> m_cachedScript;
};
Copied: trunk/Source/WebCore/bindings/js/CachedScriptFetcher.cpp (from rev 210626, trunk/Source/WebCore/dom/LoadableScript.cpp) (0 => 210627)
--- trunk/Source/WebCore/bindings/js/CachedScriptFetcher.cpp (rev 0)
+++ trunk/Source/WebCore/bindings/js/CachedScriptFetcher.cpp 2017-01-12 09:01:40 UTC (rev 210627)
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2017 Yusuke Suzuki <[email protected]>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "CachedScriptFetcher.h"
+
+#include "CachedResourceLoader.h"
+#include "CachedScript.h"
+#include "ContentSecurityPolicy.h"
+#include "Document.h"
+#include "Settings.h"
+
+namespace WebCore {
+
+CachedResourceHandle<CachedScript> CachedScriptFetcher::requestScriptWithCache(Document& document, const URL& sourceURL) const
+{
+ auto* settings = document.settings();
+ if (settings && !settings->isScriptEnabled())
+ return nullptr;
+
+ ASSERT(document.contentSecurityPolicy());
+ bool hasKnownNonce = document.contentSecurityPolicy()->allowScriptWithNonce(m_nonce, m_isInUserAgentShadowTree);
+ ResourceLoaderOptions options = CachedResourceLoader::defaultCachedResourceOptions();
+ options.contentSecurityPolicyImposition = hasKnownNonce ? ContentSecurityPolicyImposition::SkipPolicyCheck : ContentSecurityPolicyImposition::DoPolicyCheck;
+
+ CachedResourceRequest request(ResourceRequest(sourceURL), options);
+ request.setAsPotentiallyCrossOrigin(m_crossOriginMode, document);
+ request.upgradeInsecureRequestIfNeeded(document);
+
+ request.setCharset(m_charset);
+ request.setInitiator(m_initiatorName);
+
+ return document.cachedResourceLoader().requestScript(WTFMove(request));
+}
+
+}
Copied: trunk/Source/WebCore/bindings/js/CachedScriptFetcher.h (from rev 210626, trunk/Source/_javascript_Core/runtime/SourceOrigin.h) (0 => 210627)
--- trunk/Source/WebCore/bindings/js/CachedScriptFetcher.h (rev 0)
+++ trunk/Source/WebCore/bindings/js/CachedScriptFetcher.h 2017-01-12 09:01:40 UTC (rev 210627)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2017 Yusuke Suzuki <[email protected]>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "CachedResourceHandle.h"
+#include <runtime/ScriptFetcher.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class CachedScript;
+class Document;
+class URL;
+
+class CachedScriptFetcher : public JSC::ScriptFetcher {
+public:
+ CachedResourceHandle<CachedScript> requestScriptWithCache(Document&, const URL& sourceURL) const;
+
+protected:
+ CachedScriptFetcher(const String& nonce, const String& crossOriginMode, const String& charset, const AtomicString& initiatorName, bool isInUserAgentShadowTree)
+ : m_nonce(nonce)
+ , m_crossOriginMode(crossOriginMode)
+ , m_charset(charset)
+ , m_initiatorName(initiatorName)
+ , m_isInUserAgentShadowTree(isInUserAgentShadowTree)
+ {
+ }
+
+private:
+ String m_nonce;
+ String m_crossOriginMode;
+ String m_charset;
+ AtomicString m_initiatorName;
+ bool m_isInUserAgentShadowTree { false };
+};
+
+} // namespace WebCore
Modified: trunk/Source/WebCore/bindings/js/CachedScriptSourceProvider.h (210626 => 210627)
--- trunk/Source/WebCore/bindings/js/CachedScriptSourceProvider.h 2017-01-12 07:18:28 UTC (rev 210626)
+++ trunk/Source/WebCore/bindings/js/CachedScriptSourceProvider.h 2017-01-12 09:01:40 UTC (rev 210627)
@@ -28,6 +28,7 @@
#include "CachedResourceClient.h"
#include "CachedResourceHandle.h"
#include "CachedScript.h"
+#include "CachedScriptFetcher.h"
#include <parser/SourceCode.h>
#include <parser/SourceProvider.h>
@@ -36,7 +37,7 @@
class CachedScriptSourceProvider : public JSC::SourceProvider, public CachedResourceClient {
WTF_MAKE_FAST_ALLOCATED;
public:
- static Ref<CachedScriptSourceProvider> create(CachedScript* cachedScript, JSC::SourceProviderSourceType sourceType) { return adoptRef(*new CachedScriptSourceProvider(cachedScript, sourceType)); }
+ static Ref<CachedScriptSourceProvider> create(CachedScript* cachedScript, JSC::SourceProviderSourceType sourceType, Ref<CachedScriptFetcher>&& scriptFetcher) { return adoptRef(*new CachedScriptSourceProvider(cachedScript, sourceType, WTFMove(scriptFetcher))); }
virtual ~CachedScriptSourceProvider()
{
@@ -47,8 +48,8 @@
StringView source() const override { return m_cachedScript->script(); }
private:
- CachedScriptSourceProvider(CachedScript* cachedScript, JSC::SourceProviderSourceType sourceType)
- : SourceProvider(JSC::SourceOrigin { cachedScript->response().url() }, cachedScript->response().url(), TextPosition(), sourceType)
+ CachedScriptSourceProvider(CachedScript* cachedScript, JSC::SourceProviderSourceType sourceType, Ref<CachedScriptFetcher>&& scriptFetcher)
+ : SourceProvider(JSC::SourceOrigin { cachedScript->response().url(), WTFMove(scriptFetcher) }, cachedScript->response().url(), TextPosition(), sourceType)
, m_cachedScript(cachedScript)
{
m_cachedScript->addClient(*this);
@@ -57,9 +58,4 @@
CachedResourceHandle<CachedScript> m_cachedScript;
};
-inline JSC::SourceCode makeSource(CachedScript* cachedScript)
-{
- return JSC::SourceCode(CachedScriptSourceProvider::create(cachedScript, JSC::SourceProviderSourceType::Program));
-}
-
} // namespace WebCore
Modified: trunk/Source/WebCore/bindings/js/ScriptController.cpp (210626 => 210627)
--- trunk/Source/WebCore/bindings/js/ScriptController.cpp 2017-01-12 07:18:28 UTC (rev 210626)
+++ trunk/Source/WebCore/bindings/js/ScriptController.cpp 2017-01-12 09:01:40 UTC (rev 210627)
@@ -23,6 +23,7 @@
#include "BridgeJSC.h"
#include "CachedModuleScript.h"
+#include "CachedScriptFetcher.h"
#include "CommonVM.h"
#include "ContentSecurityPolicy.h"
#include "DocumentLoader.h"
@@ -186,7 +187,7 @@
return evaluateInWorld(sourceCode, mainThreadNormalWorld(), exceptionDetails);
}
-void ScriptController::loadModuleScriptInWorld(CachedModuleScript& moduleScript, const String& moduleName, LoadableScript& loadableScript, DOMWrapperWorld& world)
+void ScriptController::loadModuleScriptInWorld(CachedModuleScript& moduleScript, const String& moduleName, CachedScriptFetcher& scriptFetcher, DOMWrapperWorld& world)
{
JSLockHolder lock(world.vm());
@@ -193,16 +194,16 @@
auto& shell = *windowShell(world);
auto& state = *shell.window()->globalExec();
- auto& promise = JSMainThreadExecState::loadModule(state, moduleName, JSC::JSScriptFetcher::create(state.vm(), { &loadableScript }));
+ auto& promise = JSMainThreadExecState::loadModule(state, moduleName, JSC::JSScriptFetcher::create(state.vm(), { &scriptFetcher }));
setupModuleScriptHandlers(moduleScript, promise, world);
}
-void ScriptController::loadModuleScript(CachedModuleScript& moduleScript, const String& moduleName, LoadableScript& loadableScript)
+void ScriptController::loadModuleScript(CachedModuleScript& moduleScript, const String& moduleName, CachedScriptFetcher& scriptFetcher)
{
- loadModuleScriptInWorld(moduleScript, moduleName, loadableScript, mainThreadNormalWorld());
+ loadModuleScriptInWorld(moduleScript, moduleName, scriptFetcher, mainThreadNormalWorld());
}
-void ScriptController::loadModuleScriptInWorld(CachedModuleScript& moduleScript, const ScriptSourceCode& sourceCode, LoadableScript& loadableScript, DOMWrapperWorld& world)
+void ScriptController::loadModuleScriptInWorld(CachedModuleScript& moduleScript, const ScriptSourceCode& sourceCode, CachedScriptFetcher& scriptFetcher, DOMWrapperWorld& world)
{
JSLockHolder lock(world.vm());
@@ -209,13 +210,13 @@
auto& shell = *windowShell(world);
auto& state = *shell.window()->globalExec();
- auto& promise = JSMainThreadExecState::loadModule(state, sourceCode.jsSourceCode(), JSC::JSScriptFetcher::create(state.vm(), { &loadableScript }));
+ auto& promise = JSMainThreadExecState::loadModule(state, sourceCode.jsSourceCode(), JSC::JSScriptFetcher::create(state.vm(), { &scriptFetcher }));
setupModuleScriptHandlers(moduleScript, promise, world);
}
-void ScriptController::loadModuleScript(CachedModuleScript& moduleScript, const ScriptSourceCode& sourceCode, LoadableScript& loadableScript)
+void ScriptController::loadModuleScript(CachedModuleScript& moduleScript, const ScriptSourceCode& sourceCode, CachedScriptFetcher& scriptFetcher)
{
- loadModuleScriptInWorld(moduleScript, sourceCode, loadableScript, mainThreadNormalWorld());
+ loadModuleScriptInWorld(moduleScript, sourceCode, scriptFetcher, mainThreadNormalWorld());
}
JSC::JSValue ScriptController::linkAndEvaluateModuleScriptInWorld(CachedModuleScript& moduleScript, DOMWrapperWorld& world)
Modified: trunk/Source/WebCore/bindings/js/ScriptController.h (210626 => 210627)
--- trunk/Source/WebCore/bindings/js/ScriptController.h 2017-01-12 07:18:28 UTC (rev 210626)
+++ trunk/Source/WebCore/bindings/js/ScriptController.h 2017-01-12 09:01:40 UTC (rev 210627)
@@ -52,10 +52,10 @@
namespace WebCore {
class CachedModuleScript;
+class CachedScriptFetcher;
class Frame;
class HTMLDocument;
class HTMLPlugInElement;
-class LoadableScript;
class SecurityOrigin;
class ScriptSourceCode;
class Widget;
@@ -114,10 +114,10 @@
JSC::JSValue evaluate(const ScriptSourceCode&, ExceptionDetails* = nullptr);
JSC::JSValue evaluateInWorld(const ScriptSourceCode&, DOMWrapperWorld&, ExceptionDetails* = nullptr);
- void loadModuleScriptInWorld(CachedModuleScript&, const String& moduleName, LoadableScript&, DOMWrapperWorld&);
- void loadModuleScript(CachedModuleScript&, const String& moduleName, LoadableScript&);
- void loadModuleScriptInWorld(CachedModuleScript&, const ScriptSourceCode&, LoadableScript&, DOMWrapperWorld&);
- void loadModuleScript(CachedModuleScript&, const ScriptSourceCode&, LoadableScript&);
+ void loadModuleScriptInWorld(CachedModuleScript&, const String& moduleName, CachedScriptFetcher&, DOMWrapperWorld&);
+ void loadModuleScript(CachedModuleScript&, const String& moduleName, CachedScriptFetcher&);
+ void loadModuleScriptInWorld(CachedModuleScript&, const ScriptSourceCode&, CachedScriptFetcher&, DOMWrapperWorld&);
+ void loadModuleScript(CachedModuleScript&, const ScriptSourceCode&, CachedScriptFetcher&);
JSC::JSValue linkAndEvaluateModuleScriptInWorld(CachedModuleScript& , DOMWrapperWorld&);
JSC::JSValue linkAndEvaluateModuleScript(CachedModuleScript&);
Modified: trunk/Source/WebCore/bindings/js/ScriptModuleLoader.cpp (210626 => 210627)
--- trunk/Source/WebCore/bindings/js/ScriptModuleLoader.cpp 2017-01-12 07:18:28 UTC (rev 210626)
+++ trunk/Source/WebCore/bindings/js/ScriptModuleLoader.cpp 2017-01-12 09:01:40 UTC (rev 210627)
@@ -159,9 +159,9 @@
}
if (auto* frame = m_document.frame()) {
- auto loader = CachedModuleScriptLoader::create(*this, deferred.get());
+ auto loader = CachedModuleScriptLoader::create(*this, deferred.get(), *static_cast<CachedScriptFetcher*>(JSC::jsCast<JSC::JSScriptFetcher*>(scriptFetcher)->fetcher()));
m_loaders.add(loader.copyRef());
- if (!loader->load(m_document, *static_cast<LoadableScript*>(JSC::jsCast<JSC::JSScriptFetcher*>(scriptFetcher)->fetcher()), completedURL)) {
+ if (!loader->load(m_document, completedURL)) {
loader->clearClient();
m_loaders.remove(WTFMove(loader));
deferred->reject(frame->script().moduleLoaderAlreadyReportedErrorSymbol());
@@ -243,7 +243,7 @@
}
m_requestURLToResponseURLMap.add(cachedScript.url(), cachedScript.response().url());
- ScriptSourceCode scriptSourceCode(&cachedScript, JSC::SourceProviderSourceType::Module);
+ ScriptSourceCode scriptSourceCode(&cachedScript, JSC::SourceProviderSourceType::Module, loader.scriptFetcher());
promise->resolveWithCallback([] (JSC::ExecState& state, JSDOMGlobalObject&, JSC::SourceCode sourceCode) {
return JSC::JSSourceCode::create(state.vm(), WTFMove(sourceCode));
}, scriptSourceCode.jsSourceCode());
Modified: trunk/Source/WebCore/bindings/js/ScriptSourceCode.h (210626 => 210627)
--- trunk/Source/WebCore/bindings/js/ScriptSourceCode.h 2017-01-12 07:18:28 UTC (rev 210626)
+++ trunk/Source/WebCore/bindings/js/ScriptSourceCode.h 2017-01-12 09:01:40 UTC (rev 210627)
@@ -32,6 +32,7 @@
#include "CachedResourceHandle.h"
#include "CachedScript.h"
+#include "CachedScriptFetcher.h"
#include "CachedScriptSourceProvider.h"
#include "URL.h"
#include <parser/SourceProvider.h>
@@ -49,13 +50,20 @@
{
}
- explicit ScriptSourceCode(CachedScript* cachedScript, JSC::SourceProviderSourceType sourceType)
- : m_provider(CachedScriptSourceProvider::create(cachedScript, sourceType))
+ ScriptSourceCode(CachedScript* cachedScript, JSC::SourceProviderSourceType sourceType, Ref<CachedScriptFetcher>&& scriptFetcher)
+ : m_provider(CachedScriptSourceProvider::create(cachedScript, sourceType, WTFMove(scriptFetcher)))
, m_code(m_provider)
, m_cachedScript(cachedScript)
{
}
+ ScriptSourceCode(const String& source, const URL& url, const TextPosition& startPosition, JSC::SourceProviderSourceType sourceType, Ref<CachedScriptFetcher>&& scriptFetcher)
+ : m_provider(JSC::StringSourceProvider::create(source, JSC::SourceOrigin { url.string(), WTFMove(scriptFetcher) }, url.string(), startPosition, sourceType))
+ , m_code(m_provider, startPosition.m_line.oneBasedInt(), startPosition.m_column.oneBasedInt())
+ , m_url(url)
+ {
+ }
+
bool isEmpty() const { return m_code.length() == 0; }
const JSC::SourceCode& jsSourceCode() const { return m_code; }
Added: trunk/Source/WebCore/dom/InlineClassicScript.cpp (0 => 210627)
--- trunk/Source/WebCore/dom/InlineClassicScript.cpp (rev 0)
+++ trunk/Source/WebCore/dom/InlineClassicScript.cpp 2017-01-12 09:01:40 UTC (rev 210627)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2017 Yusuke Suzuki <[email protected]>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "InlineClassicScript.h"
+
+#include "Element.h"
+#include "ScriptElement.h"
+
+namespace WebCore {
+
+Ref<InlineClassicScript> InlineClassicScript::create(ScriptElement& scriptElement)
+{
+ auto& element = scriptElement.element();
+ return adoptRef(*new InlineClassicScript(
+ element.attributeWithoutSynchronization(HTMLNames::nonceAttr),
+ element.attributeWithoutSynchronization(HTMLNames::crossoriginAttr),
+ scriptElement.scriptCharset(),
+ element.localName(),
+ element.isInUserAgentShadowTree()));
+}
+
+}
Added: trunk/Source/WebCore/dom/InlineClassicScript.h (0 => 210627)
--- trunk/Source/WebCore/dom/InlineClassicScript.h (rev 0)
+++ trunk/Source/WebCore/dom/InlineClassicScript.h 2017-01-12 09:01:40 UTC (rev 210627)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2017 Yusuke Suzuki <[email protected]>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "CachedScriptFetcher.h"
+
+namespace WebCore {
+
+class ScriptElement;
+
+class InlineClassicScript final : public CachedScriptFetcher {
+public:
+ static Ref<InlineClassicScript> create(ScriptElement&);
+
+private:
+ InlineClassicScript(const String& nonce, const String& crossOriginMode, const String& charset, const AtomicString& initiatorName, bool isInUserAgentShadowTree)
+ : CachedScriptFetcher(nonce, crossOriginMode, charset, initiatorName, isInUserAgentShadowTree)
+ {
+ }
+};
+
+}
Modified: trunk/Source/WebCore/dom/LoadableClassicScript.cpp (210626 => 210627)
--- trunk/Source/WebCore/dom/LoadableClassicScript.cpp 2017-01-12 07:18:28 UTC (rev 210626)
+++ trunk/Source/WebCore/dom/LoadableClassicScript.cpp 2017-01-12 09:01:40 UTC (rev 210627)
@@ -104,7 +104,7 @@
void LoadableClassicScript::execute(ScriptElement& scriptElement)
{
ASSERT(!error());
- scriptElement.executeClassicScript(ScriptSourceCode(m_cachedScript.get(), JSC::SourceProviderSourceType::Program));
+ scriptElement.executeClassicScript(ScriptSourceCode(m_cachedScript.get(), JSC::SourceProviderSourceType::Program, *this));
}
bool LoadableClassicScript::load(Document& document, const URL& sourceURL)
Modified: trunk/Source/WebCore/dom/LoadableScript.cpp (210626 => 210627)
--- trunk/Source/WebCore/dom/LoadableScript.cpp 2017-01-12 07:18:28 UTC (rev 210626)
+++ trunk/Source/WebCore/dom/LoadableScript.cpp 2017-01-12 09:01:40 UTC (rev 210627)
@@ -60,25 +60,4 @@
client->notifyFinished(*this);
}
-CachedResourceHandle<CachedScript> LoadableScript::requestScriptWithCache(Document& document, const URL& sourceURL) const
-{
- auto* settings = document.settings();
- if (settings && !settings->isScriptEnabled())
- return nullptr;
-
- ASSERT(document.contentSecurityPolicy());
- bool hasKnownNonce = document.contentSecurityPolicy()->allowScriptWithNonce(m_nonce, m_isInUserAgentShadowTree);
- ResourceLoaderOptions options = CachedResourceLoader::defaultCachedResourceOptions();
- options.contentSecurityPolicyImposition = hasKnownNonce ? ContentSecurityPolicyImposition::SkipPolicyCheck : ContentSecurityPolicyImposition::DoPolicyCheck;
-
- CachedResourceRequest request(ResourceRequest(sourceURL), options);
- request.setAsPotentiallyCrossOrigin(m_crossOriginMode, document);
- request.upgradeInsecureRequestIfNeeded(document);
-
- request.setCharset(m_charset);
- request.setInitiator(m_initiatorName);
-
- return document.cachedResourceLoader().requestScript(WTFMove(request));
}
-
-}
Modified: trunk/Source/WebCore/dom/LoadableScript.h (210626 => 210627)
--- trunk/Source/WebCore/dom/LoadableScript.h 2017-01-12 07:18:28 UTC (rev 210626)
+++ trunk/Source/WebCore/dom/LoadableScript.h 2017-01-12 09:01:40 UTC (rev 210627)
@@ -25,9 +25,8 @@
#pragma once
-#include "CachedResourceHandle.h"
+#include "CachedScriptFetcher.h"
#include <runtime/ConsoleTypes.h>
-#include <runtime/JSScriptFetcher.h>
#include <wtf/HashCountedSet.h>
#include <wtf/RefCounted.h>
#include <wtf/text/WTFString.h>
@@ -34,13 +33,10 @@
namespace WebCore {
-class CachedScript;
-class Document;
class LoadableScriptClient;
class ScriptElement;
-class URL;
-class LoadableScript : public JSC::ScriptFetcher {
+class LoadableScript : public CachedScriptFetcher {
public:
enum class ErrorType {
CachedScript,
@@ -73,15 +69,9 @@
virtual bool isClassicScript() const { return false; }
virtual bool isModuleScript() const { return false; }
- CachedResourceHandle<CachedScript> requestScriptWithCache(Document&, const URL& sourceURL) const;
-
protected:
LoadableScript(const String& nonce, const String& crossOriginMode, const String& charset, const AtomicString& initiatorName, bool isInUserAgentShadowTree)
- : m_nonce(nonce)
- , m_crossOriginMode(crossOriginMode)
- , m_charset(charset)
- , m_initiatorName(initiatorName)
- , m_isInUserAgentShadowTree(isInUserAgentShadowTree)
+ : CachedScriptFetcher(nonce, crossOriginMode, charset, initiatorName, isInUserAgentShadowTree)
{
}
@@ -88,12 +78,6 @@
void notifyClientFinished();
private:
- String m_nonce;
- String m_crossOriginMode;
- String m_charset;
- AtomicString m_initiatorName;
- bool m_isInUserAgentShadowTree { false };
-
HashCountedSet<LoadableScriptClient*> m_clients;
};
Modified: trunk/Source/WebCore/dom/ScriptElement.cpp (210626 => 210627)
--- trunk/Source/WebCore/dom/ScriptElement.cpp 2017-01-12 07:18:28 UTC (rev 210626)
+++ trunk/Source/WebCore/dom/ScriptElement.cpp 2017-01-12 09:01:40 UTC (rev 210627)
@@ -38,6 +38,7 @@
#include "HTMLNames.h"
#include "HTMLParserIdioms.h"
#include "IgnoreDestructiveWriteCountIncrementer.h"
+#include "InlineClassicScript.h"
#include "LoadableClassicScript.h"
#include "LoadableModuleScript.h"
#include "MIMETypeRegistry.h"
@@ -275,7 +276,7 @@
} else {
ASSERT(scriptType == ScriptType::Classic);
TextPosition position = document.isInDocumentWrite() ? TextPosition() : scriptStartPosition;
- executeClassicScript(ScriptSourceCode(scriptContent(), document.url(), position, JSC::SourceProviderSourceType::Program));
+ executeClassicScript(ScriptSourceCode(scriptContent(), document.url(), position, JSC::SourceProviderSourceType::Program, InlineClassicScript::create(*this)));
}
return true;
@@ -348,8 +349,10 @@
return true;
}
+ auto script = LoadableModuleScript::create(nonce, crossOriginMode, scriptCharset(), m_element.localName(), m_element.isInUserAgentShadowTree());
+
TextPosition position = m_element.document().isInDocumentWrite() ? TextPosition() : scriptStartPosition;
- ScriptSourceCode sourceCode(scriptContent(), m_element.document().url(), position, JSC::SourceProviderSourceType::Module);
+ ScriptSourceCode sourceCode(scriptContent(), m_element.document().url(), position, JSC::SourceProviderSourceType::Module, script.copyRef());
ASSERT(m_element.document().contentSecurityPolicy());
const auto& contentSecurityPolicy = *m_element.document().contentSecurityPolicy();
@@ -357,7 +360,6 @@
if (!contentSecurityPolicy.allowInlineScript(m_element.document().url(), m_startLineNumber, sourceCode.source().toStringWithoutCopying(), hasKnownNonce))
return false;
- auto script = LoadableModuleScript::create(nonce, crossOriginMode, scriptCharset(), m_element.localName(), m_element.isInUserAgentShadowTree());
script->load(m_element.document(), sourceCode);
m_loadableScript = WTFMove(script);
return true;
@@ -426,7 +428,7 @@
else {
ASSERT(!pendingScript.error());
ASSERT_WITH_MESSAGE(scriptType() == ScriptType::Classic, "Module script always have a loadableScript pointer.");
- executeClassicScript(ScriptSourceCode(scriptContent(), m_element.document().url(), pendingScript.startingPosition(), JSC::SourceProviderSourceType::Program));
+ executeClassicScript(ScriptSourceCode(scriptContent(), m_element.document().url(), pendingScript.startingPosition(), JSC::SourceProviderSourceType::Program, InlineClassicScript::create(*this)));
dispatchLoadEvent();
}
}
Modified: trunk/Source/WebCore/html/parser/HTMLScriptRunner.cpp (210626 => 210627)
--- trunk/Source/WebCore/html/parser/HTMLScriptRunner.cpp 2017-01-12 07:18:28 UTC (rev 210626)
+++ trunk/Source/WebCore/html/parser/HTMLScriptRunner.cpp 2017-01-12 09:01:40 UTC (rev 210627)
@@ -35,6 +35,7 @@
#include "HTMLNames.h"
#include "HTMLScriptRunnerHost.h"
#include "IgnoreDestructiveWriteCountIncrementer.h"
+#include "InlineClassicScript.h"
#include "Microtasks.h"
#include "MutationObserver.h"
#include "NestingLevelIncrementer.h"
@@ -258,7 +259,7 @@
if (m_scriptNestingLevel == 1)
m_parserBlockingScript = PendingScript::create(scriptElement, scriptStartPosition);
else
- scriptElement.executeClassicScript(ScriptSourceCode(scriptElement.element().textContent(), documentURLForScriptExecution(m_document), scriptStartPosition));
+ scriptElement.executeClassicScript(ScriptSourceCode(scriptElement.element().textContent(), documentURLForScriptExecution(m_document), scriptStartPosition, JSC::SourceProviderSourceType::Program, InlineClassicScript::create(scriptElement)));
} else
requestParsingBlockingScript(scriptElement);
}
Modified: trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp (210626 => 210627)
--- trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp 2017-01-12 07:18:28 UTC (rev 210626)
+++ trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp 2017-01-12 09:01:40 UTC (rev 210627)
@@ -38,6 +38,7 @@
#include "HTMLEntityParser.h"
#include "HTMLHtmlElement.h"
#include "HTMLTemplateElement.h"
+#include "InlineClassicScript.h"
#include "Page.h"
#include "PendingScript.h"
#include "ProcessingInstruction.h"
@@ -877,7 +878,7 @@
// the libxml2 and Qt XMLDocumentParser implementations.
if (scriptElement.readyToBeParserExecuted())
- scriptElement.executeClassicScript(ScriptSourceCode(scriptElement.scriptContent(), document()->url(), m_scriptStartPosition));
+ scriptElement.executeClassicScript(ScriptSourceCode(scriptElement.scriptContent(), document()->url(), m_scriptStartPosition, JSC::SourceProviderSourceType::Program, InlineClassicScript::create(scriptElement)));
else if (scriptElement.willBeParserExecuted() && scriptElement.loadableScript()) {
m_pendingScript = PendingScript::create(scriptElement, *scriptElement.loadableScript());
m_pendingScript->setClient(*this);