Commit 68ebd178 authored by Camillo Bruni's avatar Camillo Bruni Committed by Chromium LUCI CQ

[blink] Prepare module script compilation for streaming

- Use ModuleScriptCreationParams as main parameter for module
  compilation
- Add streaming members to ModuleScriptCreationParams, currently
  unused and cleared on crossing thread boundaries

This CL prepares ModuleScriptCreationParams for passing on the
ScriptStreamer from the ScriptResource to compilation in
V8ScriptRunner::CompileModule.

Bug: 1061857, 1154943
Change-Id: Ie0bc25fac1f5841766392ff435a690eed9bc8813
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2547682
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: default avatarHiroshige Hayashizaki <hiroshige@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833404}
parent 2db922f5
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "third_party/blink/renderer/bindings/core/v8/referrer_script_info.h" #include "third_party/blink/renderer/bindings/core/v8/referrer_script_info.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_script_runner.h" #include "third_party/blink/renderer/bindings/core/v8/v8_script_runner.h"
#include "third_party/blink/renderer/core/loader/modulescript/module_script_creation_params.h"
#include "third_party/blink/renderer/core/probe/core_probes.h" #include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/core/script/modulator.h" #include "third_party/blink/renderer/core/script/modulator.h"
#include "third_party/blink/renderer/core/script/module_record_resolver.h" #include "third_party/blink/renderer/core/script/module_record_resolver.h"
...@@ -46,14 +47,12 @@ void ModuleRecordProduceCacheData::Trace(Visitor* visitor) const { ...@@ -46,14 +47,12 @@ void ModuleRecordProduceCacheData::Trace(Visitor* visitor) const {
v8::Local<v8::Module> ModuleRecord::Compile( v8::Local<v8::Module> ModuleRecord::Compile(
v8::Isolate* isolate, v8::Isolate* isolate,
const String& source, const ModuleScriptCreationParams& params,
const KURL& source_url,
const KURL& base_url, const KURL& base_url,
const ScriptFetchOptions& options, const ScriptFetchOptions& options,
const TextPosition& text_position, const TextPosition& text_position,
ExceptionState& exception_state, ExceptionState& exception_state,
mojom::blink::V8CacheOptions v8_cache_options, mojom::blink::V8CacheOptions v8_cache_options,
SingleCachedMetadataHandler* cache_handler,
ScriptSourceLocationType source_location_type, ScriptSourceLocationType source_location_type,
ModuleRecordProduceCacheData** out_produce_cache_data) { ModuleRecordProduceCacheData** out_produce_cache_data) {
v8::TryCatch try_catch(isolate); v8::TryCatch try_catch(isolate);
...@@ -71,12 +70,12 @@ v8::Local<v8::Module> ModuleRecord::Compile( ...@@ -71,12 +70,12 @@ v8::Local<v8::Module> ModuleRecord::Compile(
V8CodeCache::ProduceCacheOptions produce_cache_options; V8CodeCache::ProduceCacheOptions produce_cache_options;
v8::ScriptCompiler::NoCacheReason no_cache_reason; v8::ScriptCompiler::NoCacheReason no_cache_reason;
std::tie(compile_options, produce_cache_options, no_cache_reason) = std::tie(compile_options, produce_cache_options, no_cache_reason) =
V8CodeCache::GetCompileOptions(v8_cache_options, cache_handler, V8CodeCache::GetCompileOptions(v8_cache_options, params.CacheHandler(),
source.length(), source_location_type); params.GetSourceText().length(),
source_location_type);
if (!V8ScriptRunner::CompileModule( if (!V8ScriptRunner::CompileModule(
isolate, source, cache_handler, source_url, text_position, isolate, params, text_position, compile_options, no_cache_reason,
compile_options, no_cache_reason,
ReferrerScriptInfo(base_url, options, ReferrerScriptInfo(base_url, options,
ReferrerScriptInfo::BaseUrlSource::kOther)) ReferrerScriptInfo::BaseUrlSource::kOther))
.ToLocal(&module)) { .ToLocal(&module)) {
...@@ -89,7 +88,7 @@ v8::Local<v8::Module> ModuleRecord::Compile( ...@@ -89,7 +88,7 @@ v8::Local<v8::Module> ModuleRecord::Compile(
if (out_produce_cache_data) { if (out_produce_cache_data) {
*out_produce_cache_data = *out_produce_cache_data =
MakeGarbageCollected<ModuleRecordProduceCacheData>( MakeGarbageCollected<ModuleRecordProduceCacheData>(
isolate, cache_handler, produce_cache_options, module); isolate, params.CacheHandler(), produce_cache_options, module);
} }
return module; return module;
......
...@@ -22,6 +22,7 @@ namespace blink { ...@@ -22,6 +22,7 @@ namespace blink {
class ExceptionState; class ExceptionState;
class KURL; class KURL;
class ModuleScriptCreationParams;
class ScriptFetchOptions; class ScriptFetchOptions;
class ScriptState; class ScriptState;
class ScriptValue; class ScriptValue;
...@@ -63,14 +64,12 @@ class CORE_EXPORT ModuleRecord final { ...@@ -63,14 +64,12 @@ class CORE_EXPORT ModuleRecord final {
public: public:
static v8::Local<v8::Module> Compile( static v8::Local<v8::Module> Compile(
v8::Isolate*, v8::Isolate*,
const String& source, const ModuleScriptCreationParams& params,
const KURL& source_url,
const KURL& base_url, const KURL& base_url,
const ScriptFetchOptions&, const ScriptFetchOptions&,
const TextPosition&, const TextPosition&,
ExceptionState&, ExceptionState&,
mojom::blink::V8CacheOptions = mojom::blink::V8CacheOptions::kDefault, mojom::blink::V8CacheOptions = mojom::blink::V8CacheOptions::kDefault,
SingleCachedMetadataHandler* = nullptr,
ScriptSourceLocationType source_location_type = ScriptSourceLocationType source_location_type =
ScriptSourceLocationType::kInternal, ScriptSourceLocationType::kInternal,
ModuleRecordProduceCacheData** out_produce_cache_data = nullptr); ModuleRecordProduceCacheData** out_produce_cache_data = nullptr);
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include "third_party/blink/renderer/core/frame/local_dom_window.h" #include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/inspector/inspector_trace_events.h" #include "third_party/blink/renderer/core/inspector/inspector_trace_events.h"
#include "third_party/blink/renderer/core/loader/modulescript/module_script_creation_params.h"
#include "third_party/blink/renderer/core/probe/core_probes.h" #include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/core/script/modulator.h" #include "third_party/blink/renderer/core/script/modulator.h"
#include "third_party/blink/renderer/core/script/module_script.h" #include "third_party/blink/renderer/core/script/module_script.h"
...@@ -247,13 +248,12 @@ v8::MaybeLocal<v8::Script> V8ScriptRunner::CompileScript( ...@@ -247,13 +248,12 @@ v8::MaybeLocal<v8::Script> V8ScriptRunner::CompileScript(
v8::MaybeLocal<v8::Module> V8ScriptRunner::CompileModule( v8::MaybeLocal<v8::Module> V8ScriptRunner::CompileModule(
v8::Isolate* isolate, v8::Isolate* isolate,
const String& source_text, const ModuleScriptCreationParams& params,
SingleCachedMetadataHandler* cache_handler,
const String& file_name,
const TextPosition& start_position, const TextPosition& start_position,
v8::ScriptCompiler::CompileOptions compile_options, v8::ScriptCompiler::CompileOptions compile_options,
v8::ScriptCompiler::NoCacheReason no_cache_reason, v8::ScriptCompiler::NoCacheReason no_cache_reason,
const ReferrerScriptInfo& referrer_info) { const ReferrerScriptInfo& referrer_info) {
const String file_name = params.SourceURL();
constexpr const char* kTraceEventCategoryGroup = "v8,devtools.timeline"; constexpr const char* kTraceEventCategoryGroup = "v8,devtools.timeline";
TRACE_EVENT_BEGIN1(kTraceEventCategoryGroup, "v8.compileModule", "fileName", TRACE_EVENT_BEGIN1(kTraceEventCategoryGroup, "v8.compileModule", "fileName",
file_name.Utf8()); file_name.Utf8());
...@@ -271,7 +271,8 @@ v8::MaybeLocal<v8::Module> V8ScriptRunner::CompileModule( ...@@ -271,7 +271,8 @@ v8::MaybeLocal<v8::Module> V8ScriptRunner::CompileModule(
true, // is_module true, // is_module
referrer_info.ToV8HostDefinedOptions(isolate)); referrer_info.ToV8HostDefinedOptions(isolate));
v8::Local<v8::String> code = V8String(isolate, source_text); // TODO(crbug.com/1061857): Finalize module streaming here.
v8::Local<v8::String> code = V8String(isolate, params.GetSourceText());
v8::MaybeLocal<v8::Module> script; v8::MaybeLocal<v8::Module> script;
inspector_compile_script_event::V8CacheResult cache_result; inspector_compile_script_event::V8CacheResult cache_result;
...@@ -287,6 +288,7 @@ v8::MaybeLocal<v8::Module> V8ScriptRunner::CompileModule( ...@@ -287,6 +288,7 @@ v8::MaybeLocal<v8::Module> V8ScriptRunner::CompileModule(
case v8::ScriptCompiler::kConsumeCodeCache: { case v8::ScriptCompiler::kConsumeCodeCache: {
// Compile a script, and consume a V8 cache that was generated previously. // Compile a script, and consume a V8 cache that was generated previously.
SingleCachedMetadataHandler* cache_handler = params.CacheHandler();
DCHECK(cache_handler); DCHECK(cache_handler);
v8::ScriptCompiler::CachedData* cached_data = v8::ScriptCompiler::CachedData* cached_data =
V8CodeCache::CreateCachedData(cache_handler); V8CodeCache::CreateCachedData(cache_handler);
......
...@@ -40,15 +40,15 @@ class TextPosition; ...@@ -40,15 +40,15 @@ class TextPosition;
namespace blink { namespace blink {
class ScriptEvaluationResult;
class ExecutionContext; class ExecutionContext;
class KURL; class KURL;
class ModuleScript; class ModuleScript;
class ModuleScriptCreationParams;
class ReferrerScriptInfo; class ReferrerScriptInfo;
class ScriptEvaluationResult;
class ScriptFetchOptions; class ScriptFetchOptions;
class ScriptSourceCode; class ScriptSourceCode;
class ScriptState; class ScriptState;
class SingleCachedMetadataHandler;
class CORE_EXPORT V8ScriptRunner final { class CORE_EXPORT V8ScriptRunner final {
STATIC_ONLY(V8ScriptRunner); STATIC_ONLY(V8ScriptRunner);
...@@ -114,9 +114,7 @@ class CORE_EXPORT V8ScriptRunner final { ...@@ -114,9 +114,7 @@ class CORE_EXPORT V8ScriptRunner final {
const ReferrerScriptInfo&); const ReferrerScriptInfo&);
static v8::MaybeLocal<v8::Module> CompileModule( static v8::MaybeLocal<v8::Module> CompileModule(
v8::Isolate*, v8::Isolate*,
const String& source, const ModuleScriptCreationParams&,
SingleCachedMetadataHandler*,
const String& file_name,
const WTF::TextPosition&, const WTF::TextPosition&,
v8::ScriptCompiler::CompileOptions, v8::ScriptCompiler::CompileOptions,
v8::ScriptCompiler::NoCacheReason, v8::ScriptCompiler::NoCacheReason,
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "third_party/blink/renderer/core/loader/modulescript/document_module_script_fetcher.h" #include "third_party/blink/renderer/core/loader/modulescript/document_module_script_fetcher.h"
#include "third_party/blink/public/mojom/script/script_type.mojom-blink-forward.h" #include "third_party/blink/public/mojom/script/script_type.mojom-blink-forward.h"
#include "third_party/blink/renderer/bindings/core/v8/script_streamer.h"
#include "third_party/blink/renderer/core/inspector/console_message.h" #include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/loader/resource/script_resource.h" #include "third_party/blink/renderer/core/loader/resource/script_resource.h"
#include "third_party/blink/renderer/platform/bindings/parkable_string.h" #include "third_party/blink/renderer/platform/bindings/parkable_string.h"
...@@ -26,7 +27,7 @@ void DocumentModuleScriptFetcher::Fetch( ...@@ -26,7 +27,7 @@ void DocumentModuleScriptFetcher::Fetch(
DCHECK(fetch_client_settings_object_fetcher); DCHECK(fetch_client_settings_object_fetcher);
DCHECK(!client_); DCHECK(!client_);
client_ = client; client_ = client;
// TODO(crbug.com/1061857): Enable streaming.
ScriptResource::Fetch(fetch_params, fetch_client_settings_object_fetcher, ScriptResource::Fetch(fetch_params, fetch_client_settings_object_fetcher,
this, ScriptResource::kNoStreaming); this, ScriptResource::kNoStreaming);
} }
...@@ -43,11 +44,12 @@ void DocumentModuleScriptFetcher::NotifyFinished(Resource* resource) { ...@@ -43,11 +44,12 @@ void DocumentModuleScriptFetcher::NotifyFinished(Resource* resource) {
client_->NotifyFetchFinished(base::nullopt, error_messages); client_->NotifyFetchFinished(base::nullopt, error_messages);
return; return;
} }
// TODO(crbug.com/1061857): Pass ScriptStreamer to the client here.
ModuleScriptCreationParams params( ModuleScriptCreationParams params(
script_resource->GetResponse().CurrentRequestUrl(), module_type, script_resource->GetResponse().CurrentRequestUrl(), module_type,
script_resource->SourceText(), script_resource->CacheHandler(), script_resource->SourceText(), script_resource->CacheHandler(),
script_resource->GetResourceRequest().GetCredentialsMode()); script_resource->GetResourceRequest().GetCredentialsMode(), nullptr,
ScriptStreamer::NotStreamingReason::kStreamingDisabled);
client_->NotifyFetchFinished(params, error_messages); client_->NotifyFetchFinished(params, error_messages);
} }
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "base/optional.h" #include "base/optional.h"
#include "third_party/blink/public/platform/web_url_request.h" #include "third_party/blink/public/platform/web_url_request.h"
#include "third_party/blink/renderer/bindings/core/v8/script_streamer.h"
#include "third_party/blink/renderer/core/script/modulator.h"
#include "third_party/blink/renderer/platform/bindings/parkable_string.h" #include "third_party/blink/renderer/platform/bindings/parkable_string.h"
#include "third_party/blink/renderer/platform/heap/persistent.h" #include "third_party/blink/renderer/platform/heap/persistent.h"
#include "third_party/blink/renderer/platform/loader/fetch/cached_metadata_handler.h" #include "third_party/blink/renderer/platform/loader/fetch/cached_metadata_handler.h"
...@@ -24,18 +26,27 @@ class ModuleScriptCreationParams { ...@@ -24,18 +26,27 @@ class ModuleScriptCreationParams {
public: public:
ModuleScriptCreationParams( ModuleScriptCreationParams(
const KURL& response_url, const KURL& source_url,
const ModuleScriptCreationParams::ModuleType module_type, const ModuleScriptCreationParams::ModuleType module_type,
const ParkableString& source_text, const ParkableString& source_text,
SingleCachedMetadataHandler* cache_handler, SingleCachedMetadataHandler* cache_handler,
network::mojom::CredentialsMode credentials_mode) network::mojom::CredentialsMode credentials_mode,
: response_url_(response_url), ScriptStreamer* script_streamer = nullptr,
ScriptStreamer::NotStreamingReason not_streaming_reason =
ScriptStreamer::NotStreamingReason::kStreamingDisabled)
: source_url_(source_url),
module_type_(module_type), module_type_(module_type),
is_isolated_(false), is_isolated_(false),
source_text_(source_text), source_text_(source_text),
isolated_source_text_(), isolated_source_text_(),
cache_handler_(cache_handler), cache_handler_(cache_handler),
credentials_mode_(credentials_mode) {} credentials_mode_(credentials_mode),
script_streamer_(script_streamer),
not_streaming_reason_(not_streaming_reason) {
DCHECK_EQ(
!script_streamer,
not_streaming_reason != ScriptStreamer::NotStreamingReason::kInvalid);
}
~ModuleScriptCreationParams() = default; ~ModuleScriptCreationParams() = default;
...@@ -43,8 +54,7 @@ class ModuleScriptCreationParams { ...@@ -43,8 +54,7 @@ class ModuleScriptCreationParams {
String isolated_source_text = String isolated_source_text =
isolated_source_text_ ? isolated_source_text_.IsolatedCopy() isolated_source_text_ ? isolated_source_text_.IsolatedCopy()
: GetSourceText().ToString().IsolatedCopy(); : GetSourceText().ToString().IsolatedCopy();
return ModuleScriptCreationParams(SourceURL().Copy(), module_type_,
return ModuleScriptCreationParams(GetResponseUrl().Copy(), module_type_,
isolated_source_text, isolated_source_text,
GetFetchCredentialsMode()); GetFetchCredentialsMode());
} }
...@@ -53,7 +63,8 @@ class ModuleScriptCreationParams { ...@@ -53,7 +63,8 @@ class ModuleScriptCreationParams {
return module_type_; return module_type_;
} }
const KURL& GetResponseUrl() const { return response_url_; } const KURL& SourceURL() const { return source_url_; }
const ParkableString& GetSourceText() const { const ParkableString& GetSourceText() const {
if (is_isolated_) { if (is_isolated_) {
source_text_ = ParkableString(isolated_source_text_.ReleaseImpl()); source_text_ = ParkableString(isolated_source_text_.ReleaseImpl());
...@@ -62,30 +73,46 @@ class ModuleScriptCreationParams { ...@@ -62,30 +73,46 @@ class ModuleScriptCreationParams {
} }
return source_text_; return source_text_;
} }
// TODO(crbug.com/1154943): Make this non-const.
void ClearSourceText() const {
source_text_ = ParkableString();
isolated_source_text_ = String();
is_isolated_ = false;
}
SingleCachedMetadataHandler* CacheHandler() const { return cache_handler_; } SingleCachedMetadataHandler* CacheHandler() const { return cache_handler_; }
network::mojom::CredentialsMode GetFetchCredentialsMode() const { network::mojom::CredentialsMode GetFetchCredentialsMode() const {
return credentials_mode_; return credentials_mode_;
} }
bool IsSafeToSendToAnotherThread() const { bool IsSafeToSendToAnotherThread() const {
return response_url_.IsSafeToSendToAnotherThread() && is_isolated_; return source_url_.IsSafeToSendToAnotherThread() && is_isolated_;
} }
private: private:
// Creates an isolated copy. // Creates an isolated copy.
ModuleScriptCreationParams( ModuleScriptCreationParams(
const KURL& response_url, const KURL& source_url,
const ModuleScriptCreationParams::ModuleType& module_type, const ModuleScriptCreationParams::ModuleType& module_type,
const String& isolated_source_text, const String& isolated_source_text,
network::mojom::CredentialsMode credentials_mode) network::mojom::CredentialsMode credentials_mode)
: response_url_(response_url), : source_url_(source_url),
module_type_(module_type), module_type_(module_type),
is_isolated_(true), is_isolated_(true),
source_text_(), source_text_(),
isolated_source_text_(isolated_source_text), isolated_source_text_(isolated_source_text),
credentials_mode_(credentials_mode) {} credentials_mode_(credentials_mode),
// The ScriptStreamer is intentionally cleared since it cannot be passed
const KURL response_url_; // across threads. This only disables script streaming on worklet
// top-level scripts where the ModuleScriptCreationParams is
// passed across threads.
script_streamer_(nullptr),
not_streaming_reason_(
ScriptStreamer::NotStreamingReason::kStreamingDisabled) {}
const KURL source_url_;
const ModuleType module_type_; const ModuleType module_type_;
// Mutable because an isolated copy can become bound to a thread when // Mutable because an isolated copy can become bound to a thread when
...@@ -98,14 +125,18 @@ class ModuleScriptCreationParams { ...@@ -98,14 +125,18 @@ class ModuleScriptCreationParams {
Persistent<SingleCachedMetadataHandler> cache_handler_; Persistent<SingleCachedMetadataHandler> cache_handler_;
const network::mojom::CredentialsMode credentials_mode_; const network::mojom::CredentialsMode credentials_mode_;
// |script_streamer_| is cleared when crossing thread boundaries.
Persistent<ScriptStreamer> script_streamer_;
const ScriptStreamer::NotStreamingReason not_streaming_reason_;
}; };
} // namespace blink } // namespace blink
namespace WTF { namespace WTF {
// Creates a deep copy because |response_url_| and |source_text_| are not // Creates a deep copy because |source_url_|, |source_text_| and
// cross-thread-transfer-safe. // |script_streamer_| are not cross-thread-transfer-safe.
template <> template <>
struct CrossThreadCopier<blink::ModuleScriptCreationParams> { struct CrossThreadCopier<blink::ModuleScriptCreationParams> {
static blink::ModuleScriptCreationParams Copy( static blink::ModuleScriptCreationParams Copy(
......
...@@ -271,9 +271,8 @@ void ModuleScriptLoader::NotifyFetchFinished( ...@@ -271,9 +271,8 @@ void ModuleScriptLoader::NotifyFetchFinished(
// a module script given source text, module map settings object, // a module script given source text, module map settings object,
// response's url, and options." [spec text] // response's url, and options." [spec text]
module_script_ = JSModuleScript::Create( module_script_ = JSModuleScript::Create(
params->GetSourceText(), params->CacheHandler(), params.value(), params->SourceURL() /* base URL */,
ScriptSourceLocationType::kExternalFile, modulator_, ScriptSourceLocationType::kExternalFile, modulator_, options_);
params->GetResponseUrl(), params->GetResponseUrl(), options_);
break; break;
} }
......
...@@ -5,8 +5,12 @@ ...@@ -5,8 +5,12 @@
#include "third_party/blink/renderer/core/script/js_module_script.h" #include "third_party/blink/renderer/core/script/js_module_script.h"
#include "third_party/blink/renderer/bindings/core/v8/script_value.h" #include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/core/loader/modulescript/module_script_creation_params.h"
#include "third_party/blink/renderer/core/script/modulator.h"
#include "third_party/blink/renderer/core/script/module_record_resolver.h" #include "third_party/blink/renderer/core/script/module_record_resolver.h"
#include "third_party/blink/renderer/platform/bindings/parkable_string.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h" #include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "v8/include/v8.h" #include "v8/include/v8.h"
namespace blink { namespace blink {
...@@ -14,19 +18,16 @@ namespace blink { ...@@ -14,19 +18,16 @@ namespace blink {
// <specdef // <specdef
// href="https://html.spec.whatwg.org/C/#creating-a-javascript-module-script"> // href="https://html.spec.whatwg.org/C/#creating-a-javascript-module-script">
JSModuleScript* JSModuleScript::Create( JSModuleScript* JSModuleScript::Create(
const ParkableString& original_source_text, const ModuleScriptCreationParams& params,
SingleCachedMetadataHandler* cache_handler, const KURL& base_url,
ScriptSourceLocationType source_location_type, ScriptSourceLocationType source_location_type,
Modulator* modulator, Modulator* modulator,
const KURL& source_url,
const KURL& base_url,
const ScriptFetchOptions& options, const ScriptFetchOptions& options,
const TextPosition& start_position) { const TextPosition& start_position) {
// <spec step="1">If scripting is disabled for settings's responsible browsing // <spec step="1">If scripting is disabled for settings's responsible browsing
// context, then set source to the empty string.</spec> // context, then set source to the empty string.</spec>
ParkableString source_text; if (modulator->IsScriptingDisabled())
if (!modulator->IsScriptingDisabled()) params.ClearSourceText();
source_text = original_source_text;
// <spec step="2">Let script be a new module script that this algorithm will // <spec step="2">Let script be a new module script that this algorithm will
// subsequently initialize.</spec> // subsequently initialize.</spec>
...@@ -45,10 +46,10 @@ JSModuleScript* JSModuleScript::Create( ...@@ -45,10 +46,10 @@ JSModuleScript* JSModuleScript::Create(
ModuleRecordProduceCacheData* produce_cache_data = nullptr; ModuleRecordProduceCacheData* produce_cache_data = nullptr;
v8::Local<v8::Module> result = ModuleRecord::Compile( v8::Local<v8::Module> result =
isolate, source_text.ToString(), source_url, base_url, options, ModuleRecord::Compile(isolate, params, base_url, options, start_position,
start_position, exception_state, modulator->GetV8CacheOptions(), exception_state, modulator->GetV8CacheOptions(),
cache_handler, source_location_type, &produce_cache_data); source_location_type, &produce_cache_data);
// CreateInternal processes Steps 4 and 8-10. // CreateInternal processes Steps 4 and 8-10.
// //
...@@ -56,9 +57,9 @@ JSModuleScript* JSModuleScript::Create( ...@@ -56,9 +57,9 @@ JSModuleScript* JSModuleScript::Create(
// Steps 8-13 before Step 6. In a case that compile failed, we will // Steps 8-13 before Step 6. In a case that compile failed, we will
// immediately turn the script into errored state. Thus the members will not // immediately turn the script into errored state. Thus the members will not
// be used for the speced algorithms, but may be used from inspector. // be used for the speced algorithms, but may be used from inspector.
JSModuleScript* script = JSModuleScript* script = CreateInternal(
CreateInternal(source_text.length(), modulator, result, source_url, params.GetSourceText().length(), modulator, result, params.SourceURL(),
base_url, options, start_position, produce_cache_data); base_url, options, start_position, produce_cache_data);
// <spec step="8">If result is a list of errors, then:</spec> // <spec step="8">If result is a list of errors, then:</spec>
if (exception_state.HadException()) { if (exception_state.HadException()) {
......
...@@ -5,20 +5,19 @@ ...@@ -5,20 +5,19 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_SCRIPT_JS_MODULE_SCRIPT_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_SCRIPT_JS_MODULE_SCRIPT_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_SCRIPT_JS_MODULE_SCRIPT_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_SCRIPT_JS_MODULE_SCRIPT_H_
#include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/script/modulator.h"
#include "third_party/blink/renderer/core/script/module_script.h" #include "third_party/blink/renderer/core/script/module_script.h"
#include "third_party/blink/renderer/platform/bindings/name_client.h" #include "third_party/blink/renderer/platform/bindings/name_client.h"
#include "third_party/blink/renderer/platform/bindings/parkable_string.h" #include "third_party/blink/renderer/platform/bindings/parkable_string.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/weborigin/kurl_hash.h"
#include "third_party/blink/renderer/platform/wtf/hash_map.h"
#include "third_party/blink/renderer/platform/wtf/text/text_position.h" #include "third_party/blink/renderer/platform/wtf/text/text_position.h"
namespace blink { namespace blink {
class KURL;
class Modulator;
class ModuleScriptCreationParams;
// JSModuleScript is a model object for the "JavaScript module script" spec // JSModuleScript is a model object for the "JavaScript module script" spec
// concept. https://html.spec.whatwg.org/C/#javascript-module-script // concept. https://html.spec.whatwg.org/C/#javascript-module-script
class CORE_EXPORT JSModuleScript final : public ModuleScript, class CORE_EXPORT JSModuleScript final : public ModuleScript,
...@@ -26,12 +25,10 @@ class CORE_EXPORT JSModuleScript final : public ModuleScript, ...@@ -26,12 +25,10 @@ class CORE_EXPORT JSModuleScript final : public ModuleScript,
public: public:
// https://html.spec.whatwg.org/C/#creating-a-javascript-module-script // https://html.spec.whatwg.org/C/#creating-a-javascript-module-script
static JSModuleScript* Create( static JSModuleScript* Create(
const ParkableString& source_text, const ModuleScriptCreationParams& params,
SingleCachedMetadataHandler*, const KURL& base_url,
ScriptSourceLocationType, ScriptSourceLocationType,
Modulator*, Modulator*,
const KURL& source_url,
const KURL& base_url,
const ScriptFetchOptions&, const ScriptFetchOptions&,
const TextPosition& start_position = TextPosition::MinimumPosition()); const TextPosition& start_position = TextPosition::MinimumPosition());
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "third_party/blink/public/common/features.h" #include "third_party/blink/public/common/features.h"
#include "third_party/blink/renderer/bindings/core/v8/module_record.h" #include "third_party/blink/renderer/bindings/core/v8/module_record.h"
#include "third_party/blink/renderer/bindings/core/v8/script_evaluation_result.h"
#include "third_party/blink/renderer/bindings/core/v8/script_value.h" #include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h" #include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h" #include "third_party/blink/renderer/core/frame/local_dom_window.h"
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "third_party/blink/renderer/bindings/core/v8/script_source_code.h" #include "third_party/blink/renderer/bindings/core/v8/script_source_code.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h"
#include "third_party/blink/renderer/core/loader/modulescript/module_script_creation_params.h"
#include "third_party/blink/renderer/core/script/classic_script.h" #include "third_party/blink/renderer/core/script/classic_script.h"
#include "third_party/blink/renderer/core/script/js_module_script.h" #include "third_party/blink/renderer/core/script/js_module_script.h"
#include "third_party/blink/renderer/core/script/value_wrapper_synthetic_module_script.h" #include "third_party/blink/renderer/core/script/value_wrapper_synthetic_module_script.h"
...@@ -80,11 +81,14 @@ class ModuleScriptTest : public ::testing::Test, public ParametrizedModuleTest { ...@@ -80,11 +81,14 @@ class ModuleScriptTest : public ::testing::Test, public ParametrizedModuleTest {
Modulator* modulator, Modulator* modulator,
const String& source_text, const String& source_text,
SingleCachedMetadataHandler* cache_handler) { SingleCachedMetadataHandler* cache_handler) {
return JSModuleScript::Create( ModuleScriptCreationParams params(
KURL("https://fox.url/script.js"),
ModuleScriptCreationParams::ModuleType::kJavaScriptModule,
ParkableString(source_text.IsolatedCopy().ReleaseImpl()), cache_handler, ParkableString(source_text.IsolatedCopy().ReleaseImpl()), cache_handler,
ScriptSourceLocationType::kExternalFile, modulator, network::mojom::CredentialsMode::kOmit);
KURL("https://fox.url/script.js"), KURL("https://fox.url/"), return JSModuleScript::Create(params, KURL("https://fox.url/"),
ScriptFetchOptions()); ScriptSourceLocationType::kExternalFile,
modulator, ScriptFetchOptions());
} }
static ValueWrapperSyntheticModuleScript* static ValueWrapperSyntheticModuleScript*
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "third_party/blink/renderer/core/script/script_loader.h" #include "third_party/blink/renderer/core/script/script_loader.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "services/network/public/mojom/fetch_api.mojom-shared.h"
#include "third_party/blink/public/common/feature_policy/feature_policy.h" #include "third_party/blink/public/common/feature_policy/feature_policy.h"
#include "third_party/blink/public/common/features.h" #include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/feature_policy/feature_policy_feature.mojom-blink.h" #include "third_party/blink/public/mojom/feature_policy/feature_policy_feature.mojom-blink.h"
...@@ -44,6 +45,7 @@ ...@@ -44,6 +45,7 @@
#include "third_party/blink/renderer/core/html_names.h" #include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/inspector/console_message.h" #include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/loader/importance_attribute.h" #include "third_party/blink/renderer/core/loader/importance_attribute.h"
#include "third_party/blink/renderer/core/loader/modulescript/module_script_creation_params.h"
#include "third_party/blink/renderer/core/loader/modulescript/module_script_fetch_request.h" #include "third_party/blink/renderer/core/loader/modulescript/module_script_fetch_request.h"
#include "third_party/blink/renderer/core/loader/subresource_integrity_helper.h" #include "third_party/blink/renderer/core/loader/subresource_integrity_helper.h"
#include "third_party/blink/renderer/core/script/classic_pending_script.h" #include "third_party/blink/renderer/core/script/classic_pending_script.h"
...@@ -706,10 +708,15 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position, ...@@ -706,10 +708,15 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position,
// <spec label="fetch-an-inline-module-script-graph" step="1">Let script // <spec label="fetch-an-inline-module-script-graph" step="1">Let script
// be the result of creating a JavaScript module script using source // be the result of creating a JavaScript module script using source
// text, settings object, base URL, and options.</spec> // text, settings object, base URL, and options.</spec>
ModuleScript* module_script =
JSModuleScript::Create(ParkableString(source_text.Impl()), nullptr, ModuleScriptCreationParams params(
ScriptSourceLocationType::kInline, modulator, source_url,
source_url, base_url, options, position); ModuleScriptCreationParams::ModuleType::kJavaScriptModule,
ParkableString(source_text.Impl()), nullptr,
options.CredentialsMode());
ModuleScript* module_script = JSModuleScript::Create(
params, base_url, ScriptSourceLocationType::kInline, modulator,
options, position);
// <spec label="fetch-an-inline-module-script-graph" step="2">If script // <spec label="fetch-an-inline-module-script-graph" step="2">If script
// is null, asynchronously complete this algorithm with null, and abort // is null, asynchronously complete this algorithm with null, and abort
......
...@@ -39,8 +39,8 @@ ValueWrapperSyntheticModuleScript::CreateCSSWrapperSyntheticModuleScript( ...@@ -39,8 +39,8 @@ ValueWrapperSyntheticModuleScript::CreateCSSWrapperSyntheticModuleScript(
v8::Local<v8::Value> error = V8ThrowException::CreateTypeError( v8::Local<v8::Value> error = V8ThrowException::CreateTypeError(
isolate, "Cannot create CSS Module in non-document context"); isolate, "Cannot create CSS Module in non-document context");
return ValueWrapperSyntheticModuleScript::CreateWithError( return ValueWrapperSyntheticModuleScript::CreateWithError(
v8::Local<v8::Value>(), settings_object, params->GetResponseUrl(), v8::Local<v8::Value>(), settings_object, params->SourceURL(), KURL(),
KURL(), ScriptFetchOptions(), error); ScriptFetchOptions(), error);
} }
CSSStyleSheetInit* init = CSSStyleSheetInit::Create(); CSSStyleSheetInit* init = CSSStyleSheetInit::Create();
CSSStyleSheet* style_sheet = CSSStyleSheet* style_sheet =
...@@ -49,20 +49,20 @@ ValueWrapperSyntheticModuleScript::CreateCSSWrapperSyntheticModuleScript( ...@@ -49,20 +49,20 @@ ValueWrapperSyntheticModuleScript::CreateCSSWrapperSyntheticModuleScript(
v8::Local<v8::Value> error = exception_state.GetException(); v8::Local<v8::Value> error = exception_state.GetException();
exception_state.ClearException(); exception_state.ClearException();
return ValueWrapperSyntheticModuleScript::CreateWithError( return ValueWrapperSyntheticModuleScript::CreateWithError(
v8::Local<v8::Value>(), settings_object, params->GetResponseUrl(), v8::Local<v8::Value>(), settings_object, params->SourceURL(), KURL(),
KURL(), ScriptFetchOptions(), error); ScriptFetchOptions(), error);
} }
style_sheet->replaceSync(params->GetSourceText().ToString(), exception_state); style_sheet->replaceSync(params->GetSourceText().ToString(), exception_state);
if (exception_state.HadException()) { if (exception_state.HadException()) {
v8::Local<v8::Value> error = exception_state.GetException(); v8::Local<v8::Value> error = exception_state.GetException();
exception_state.ClearException(); exception_state.ClearException();
return ValueWrapperSyntheticModuleScript::CreateWithError( return ValueWrapperSyntheticModuleScript::CreateWithError(
v8::Local<v8::Value>(), settings_object, params->GetResponseUrl(), v8::Local<v8::Value>(), settings_object, params->SourceURL(), KURL(),
KURL(), ScriptFetchOptions(), error); ScriptFetchOptions(), error);
} }
v8::Local<v8::Value> v8_value_stylesheet = ToV8(style_sheet, script_state); v8::Local<v8::Value> v8_value_stylesheet = ToV8(style_sheet, script_state);
return ValueWrapperSyntheticModuleScript::CreateWithDefaultExport( return ValueWrapperSyntheticModuleScript::CreateWithDefaultExport(
v8_value_stylesheet, settings_object, params->GetResponseUrl(), KURL(), v8_value_stylesheet, settings_object, params->SourceURL(), KURL(),
ScriptFetchOptions()); ScriptFetchOptions());
} }
...@@ -77,7 +77,7 @@ ValueWrapperSyntheticModuleScript::CreateJSONWrapperSyntheticModuleScript( ...@@ -77,7 +77,7 @@ ValueWrapperSyntheticModuleScript::CreateJSONWrapperSyntheticModuleScript(
v8::Isolate* isolate = context->GetIsolate(); v8::Isolate* isolate = context->GetIsolate();
v8::TryCatch try_catch(isolate); v8::TryCatch try_catch(isolate);
v8::Local<v8::String> original_json = v8::Local<v8::String> original_json =
V8String(isolate, params->GetSourceText().ToString()); V8String(isolate, params->GetSourceText());
v8::Local<v8::Value> parsed_json; v8::Local<v8::Value> parsed_json;
ExceptionState exception_state(isolate, ExceptionState::kExecutionContext, ExceptionState exception_state(isolate, ExceptionState::kExecutionContext,
"ModuleScriptLoader", "ModuleScriptLoader",
...@@ -101,11 +101,11 @@ ValueWrapperSyntheticModuleScript::CreateJSONWrapperSyntheticModuleScript( ...@@ -101,11 +101,11 @@ ValueWrapperSyntheticModuleScript::CreateJSONWrapperSyntheticModuleScript(
v8::Local<v8::Value> error = exception_state.GetException(); v8::Local<v8::Value> error = exception_state.GetException();
exception_state.ClearException(); exception_state.ClearException();
return ValueWrapperSyntheticModuleScript::CreateWithError( return ValueWrapperSyntheticModuleScript::CreateWithError(
parsed_json, settings_object, params->GetResponseUrl(), KURL(), parsed_json, settings_object, params->SourceURL(), KURL(),
ScriptFetchOptions(), error); ScriptFetchOptions(), error);
} else { } else {
return ValueWrapperSyntheticModuleScript::CreateWithDefaultExport( return ValueWrapperSyntheticModuleScript::CreateWithDefaultExport(
parsed_json, settings_object, params->GetResponseUrl(), KURL(), parsed_json, settings_object, params->SourceURL(), KURL(),
ScriptFetchOptions()); ScriptFetchOptions());
} }
} }
......
...@@ -26,7 +26,11 @@ v8::Local<v8::Module> ModuleTestBase::CompileModule( ...@@ -26,7 +26,11 @@ v8::Local<v8::Module> ModuleTestBase::CompileModule(
String source, String source,
const KURL& url, const KURL& url,
ExceptionState& exception_state) { ExceptionState& exception_state) {
return ModuleRecord::Compile(isolate, source, url, url, ScriptFetchOptions(), ModuleScriptCreationParams params(
url, ModuleScriptCreationParams::ModuleType::kJavaScriptModule,
ParkableString(source.Impl()), nullptr,
network::mojom::CredentialsMode::kOmit);
return ModuleRecord::Compile(isolate, params, url, ScriptFetchOptions(),
TextPosition::MinimumPosition(), TextPosition::MinimumPosition(),
exception_state); exception_state);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment