Commit ac76aa5a authored by Hiroshige Hayashizaki's avatar Hiroshige Hayashizaki Committed by Commit Bot

Format/update more spec comments in core/script

Bug: 827415
Change-Id: Ia2b38a57a7232dffaaa5f815b486baccbca92d4b
Reviewed-on: https://chromium-review.googlesource.com/c/1274904
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#599999}
parent 4f567e69
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
namespace blink { namespace blink {
// <specdef href="https://html.spec.whatwg.org/#fetch-a-classic-script">
ClassicPendingScript* ClassicPendingScript::Fetch( ClassicPendingScript* ClassicPendingScript::Fetch(
const KURL& url, const KURL& url,
Document& element_document, Document& element_document,
...@@ -51,9 +52,7 @@ ClassicPendingScript* ClassicPendingScript::Fetch( ...@@ -51,9 +52,7 @@ ClassicPendingScript* ClassicPendingScript::Fetch(
pending_script->intervened_ = pending_script->intervened_ =
MaybeDisallowFetchForDocWrittenScript(params, element_document); MaybeDisallowFetchForDocWrittenScript(params, element_document);
// <spec // <spec step="2">Set request's client to settings object.</spec>
// href="https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-classic-script"
// step="2">Set request's client to settings object.</spec>
// //
// Note: |element_document| corresponds to the settings object. // Note: |element_document| corresponds to the settings object.
ScriptResource::Fetch(params, element_document.Fetcher(), pending_script); ScriptResource::Fetch(params, element_document.Fetcher(), pending_script);
...@@ -392,8 +391,9 @@ ClassicScript* ClassicPendingScript::GetSource(const KURL& document_url) const { ...@@ -392,8 +391,9 @@ ClassicScript* ClassicPendingScript::GetSource(const KURL& document_url) const {
ScriptSourceCode source_code(streamer_ready ? streamer_ : nullptr, resource, ScriptSourceCode source_code(streamer_ready ? streamer_ : nullptr, resource,
not_streamed_reason); not_streamed_reason);
// The base URL for external classic script is // The base URL for external classic script is
// "the URL from which the script was obtained" [spec text] //
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-base-url // <spec href="https://html.spec.whatwg.org/#concept-script-base-url">
// ... the URL from which the script was obtained, ...</spec>
const KURL& base_url = source_code.Url(); const KURL& base_url = source_code.Url();
return ClassicScript::Create(source_code, base_url, options_, return ClassicScript::Create(source_code, base_url, options_,
resource->CalculateAccessControlStatus()); resource->CalculateAccessControlStatus());
......
...@@ -44,10 +44,10 @@ bool ModulatorImplBase::IsScriptingDisabled() const { ...@@ -44,10 +44,10 @@ bool ModulatorImplBase::IsScriptingDisabled() const {
return !GetExecutionContext()->CanExecuteScripts(kAboutToExecuteScript); return !GetExecutionContext()->CanExecuteScripts(kAboutToExecuteScript);
} }
// [fetch-a-module-script-tree] // <specdef label="fetch-a-module-script-tree"
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-script-tree // href="https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-script-tree">
// [fetch-a-module-worker-script-tree] // <specdef label="fetch-a-module-worker-script-tree"
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-worker-script-tree // href="https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-worker-script-tree">
void ModulatorImplBase::FetchTree( void ModulatorImplBase::FetchTree(
const KURL& url, const KURL& url,
FetchClientSettingsObjectSnapshot* fetch_client_settings_object, FetchClientSettingsObjectSnapshot* fetch_client_settings_object,
...@@ -107,7 +107,7 @@ ModuleScript* ModulatorImplBase::GetFetchedModuleScript(const KURL& url) { ...@@ -107,7 +107,7 @@ ModuleScript* ModulatorImplBase::GetFetchedModuleScript(const KURL& url) {
return map_->GetFetchedModuleScript(url); return map_->GetFetchedModuleScript(url);
} }
// https://html.spec.whatwg.org/multipage/webappapis.html#resolve-a-module-specifier // <specdef href="https://html.spec.whatwg.org/#resolve-a-module-specifier">
KURL ModulatorImplBase::ResolveModuleSpecifier(const String& module_request, KURL ModulatorImplBase::ResolveModuleSpecifier(const String& module_request,
const KURL& base_url, const KURL& base_url,
String* failure_reason) { String* failure_reason) {
...@@ -130,8 +130,6 @@ KURL ModulatorImplBase::ResolveModuleSpecifier(const String& module_request, ...@@ -130,8 +130,6 @@ KURL ModulatorImplBase::ResolveModuleSpecifier(const String& module_request,
// SOLIDUS (/), the two-character sequence U+002E FULL STOP, U+002F SOLIDUS // SOLIDUS (/), the two-character sequence U+002E FULL STOP, U+002F SOLIDUS
// (./), or the three-character sequence U+002E FULL STOP, U+002E FULL STOP, // (./), or the three-character sequence U+002E FULL STOP, U+002E FULL STOP,
// U+002F SOLIDUS (../), return failure.</spec> // U+002F SOLIDUS (../), return failure.</spec>
//
// (../), return failure and abort these steps." [spec text]
if (!module_request.StartsWith("/") && !module_request.StartsWith("./") && if (!module_request.StartsWith("/") && !module_request.StartsWith("./") &&
!module_request.StartsWith("../")) { !module_request.StartsWith("../")) {
if (failure_reason) { if (failure_reason) {
...@@ -143,7 +141,7 @@ KURL ModulatorImplBase::ResolveModuleSpecifier(const String& module_request, ...@@ -143,7 +141,7 @@ KURL ModulatorImplBase::ResolveModuleSpecifier(const String& module_request,
} }
// <spec step="3">Return the result of applying the URL parser to specifier // <spec step="3">Return the result of applying the URL parser to specifier
// with script's base URL as the base URL.</spec> // with base URL as the base URL.</spec>
DCHECK(base_url.IsValid()); DCHECK(base_url.IsValid());
KURL absolute_url(base_url, module_request); KURL absolute_url(base_url, module_request);
if (absolute_url.IsValid()) if (absolute_url.IsValid())
...@@ -174,17 +172,19 @@ void ModulatorImplBase::ResolveDynamically( ...@@ -174,17 +172,19 @@ void ModulatorImplBase::ResolveDynamically(
referrer_info, resolver); referrer_info, resolver);
} }
// https://html.spec.whatwg.org/multipage/webappapis.html#hostgetimportmetaproperties // <specdef href="https://html.spec.whatwg.org/#hostgetimportmetaproperties">
ModuleImportMeta ModulatorImplBase::HostGetImportMetaProperties( ModuleImportMeta ModulatorImplBase::HostGetImportMetaProperties(
ScriptModule record) const { ScriptModule record) const {
// 1. Let module script be moduleRecord.[[HostDefined]]. [spec text] // <spec step="1">Let module script be moduleRecord.[[HostDefined]].</spec>
ModuleScript* module_script = script_module_resolver_->GetHostDefined(record); ModuleScript* module_script = script_module_resolver_->GetHostDefined(record);
DCHECK(module_script); DCHECK(module_script);
// 2. Let urlString be module script's base URL, serialized. [spec text] // <spec step="2">Let urlString be module script's base URL,
// serialized.</spec>
String url_string = module_script->BaseURL().GetString(); String url_string = module_script->BaseURL().GetString();
// 3. Return <<Record { [[Key]]: "url", [[Value]]: urlString }>>. [spec text] // <spec step="3">Return « Record { [[Key]]: "url", [[Value]]: urlString }
// ».</spec>
return ModuleImportMeta(url_string); return ModuleImportMeta(url_string);
} }
...@@ -208,63 +208,66 @@ ModulatorImplBase::ModuleRequestsFromScriptModule(ScriptModule script_module) { ...@@ -208,63 +208,66 @@ ModulatorImplBase::ModuleRequestsFromScriptModule(ScriptModule script_module) {
return requests; return requests;
} }
// <specdef href="https://html.spec.whatwg.org/#run-a-module-script">
ScriptValue ModulatorImplBase::ExecuteModule( ScriptValue ModulatorImplBase::ExecuteModule(
const ModuleScript* module_script, const ModuleScript* module_script,
CaptureEvalErrorFlag capture_error) { CaptureEvalErrorFlag capture_error) {
// https://html.spec.whatwg.org/multipage/webappapis.html#run-a-module-script // <spec step="1">If rethrow errors is not given, let it be false.</spec>
// Step 1. "If rethrow errors is not given, let it be false." [spec text]
// Step 2. "Let settings be the settings object of script." [spec text] // <spec step="2">Let settings be the settings object of script.</spec>
//
// The settings object is |this|. // The settings object is |this|.
// Step 3. "Check if we can run script with settings. // <spec step="3">Check if we can run script with settings. If this returns
// If this returns "do not run" then return." [spec text] // "do not run" then return NormalCompletion(empty).</spec>
if (IsScriptingDisabled()) if (IsScriptingDisabled())
return ScriptValue(); return ScriptValue();
// Step 4. "Prepare to run script given settings." [spec text] // <spec step="4">Prepare to run script given settings.</spec>
//
// This is placed here to also cover ScriptModule::ReportException(). // This is placed here to also cover ScriptModule::ReportException().
ScriptState::Scope scope(script_state_); ScriptState::Scope scope(script_state_);
// Step 5. "Let evaluationStatus be null." [spec text] // <spec step="5">Let evaluationStatus be null.</spec>
//
// |error| corresponds to "evaluationStatus of [[Type]]: throw". // |error| corresponds to "evaluationStatus of [[Type]]: throw".
ScriptValue error; ScriptValue error;
// Step 6. "If script's error to rethrow is not null," [spec text] // <spec step="6">If script's error to rethrow is not null, ...</spec>
if (module_script->HasErrorToRethrow()) { if (module_script->HasErrorToRethrow()) {
// Step 6. "then set evaluationStatus to Completion { [[Type]]: throw, // <spec step="6">... then set evaluationStatus to Completion { [[Type]]:
// [[Value]]: script's error to rethrow, [[Target]]: empty }." [spec text] // throw, [[Value]]: script's error to rethrow, [[Target]]: empty }.</spec>
error = module_script->CreateErrorToRethrow(); error = module_script->CreateErrorToRethrow();
} else { } else {
// Step 7. "Otherwise: // <spec step="7">Otherwise:</spec>
// Step 7.1. "Let record be script's record. [spec text] // <spec step="7.1">Let record be script's record.</spec>
const ScriptModule& record = module_script->Record(); const ScriptModule& record = module_script->Record();
CHECK(!record.IsNull()); CHECK(!record.IsNull());
// Step 7.2. "Set evaluationStatus to record.Evaluate()." [spec text] // <spec step="7.2">Set evaluationStatus to record.Evaluate(). ...</spec>
error = record.Evaluate(script_state_); error = record.Evaluate(script_state_);
// "If Evaluate fails to complete as a result of the user agent aborting the // <spec step="7.2">... If Evaluate fails to complete as a result of the
// running script, then set evaluationStatus to Completion { [[Type]]: // user agent aborting the running script, then set evaluationStatus to
// throw, [[Value]]: a new "QuotaExceededError" DOMException, [[Target]]: // Completion { [[Type]]: throw, [[Value]]: a new "QuotaExceededError"
// empty }." [spec text] // DOMException, [[Target]]: empty }.</spec>
} }
// Step 8. "If evaluationStatus is an abrupt completion, then:" [spec text] // <spec step="8">If evaluationStatus is an abrupt completion, then:</spec>
if (!error.IsEmpty()) { if (!error.IsEmpty()) {
// Step 8.1. "If rethrow errors is true, rethrow the exception given by // <spec step="8.1">If rethrow errors is true, rethrow the exception given
// evaluationStatus.[[Value]]." [spec text] // by evaluationStatus.[[Value]].</spec>
if (capture_error == CaptureEvalErrorFlag::kCapture) if (capture_error == CaptureEvalErrorFlag::kCapture)
return error; return error;
// Step 8.2. "Otherwise, report the exception given by // <spec step="8.2">Otherwise, report the exception given by
// evaluationStatus.[[Value]] for script." [spec text] // evaluationStatus.[[Value]] for script.</spec>
ScriptModule::ReportException(script_state_, error.V8Value()); ScriptModule::ReportException(script_state_, error.V8Value());
} }
// Step 9. "Clean up after running script with settings." [spec text] // <spec step="9">Clean up after running script with settings.</spec>
//
// Implemented as the ScriptState::Scope destructor. // Implemented as the ScriptState::Scope destructor.
return ScriptValue(); return ScriptValue();
} }
......
...@@ -108,7 +108,7 @@ void ModuleMap::Trace(blink::Visitor* visitor) { ...@@ -108,7 +108,7 @@ void ModuleMap::Trace(blink::Visitor* visitor) {
visitor->Trace(loader_registry_); visitor->Trace(loader_registry_);
} }
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-single-module-script // <specdef href="https://html.spec.whatwg.org/#fetch-a-single-module-script">
void ModuleMap::FetchSingleModuleScript( void ModuleMap::FetchSingleModuleScript(
const ModuleScriptFetchRequest& request, const ModuleScriptFetchRequest& request,
FetchClientSettingsObjectSnapshot* fetch_client_settings_object, FetchClientSettingsObjectSnapshot* fetch_client_settings_object,
...@@ -139,7 +139,7 @@ void ModuleMap::FetchSingleModuleScript( ...@@ -139,7 +139,7 @@ void ModuleMap::FetchSingleModuleScript(
// <spec step="3">If moduleMap[url] exists, asynchronously complete this // <spec step="3">If moduleMap[url] exists, asynchronously complete this
// algorithm with moduleMap[url], and abort these steps.</spec> // algorithm with moduleMap[url], and abort these steps.</spec>
// //
// <spec step="11">Set moduleMap[url] to module script, and asynchronously // <spec step="12">Set moduleMap[url] to module script, and asynchronously
// complete this algorithm with module script.</spec> // complete this algorithm with module script.</spec>
if (client) if (client)
entry->AddClient(client); entry->AddClient(client);
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
namespace blink { namespace blink {
// https://html.spec.whatwg.org/multipage/webappapis.html#creating-a-module-script // <specdef href="https://html.spec.whatwg.org/#creating-a-module-script">
ModuleScript* ModuleScript::Create(const ParkableString& original_source_text, ModuleScript* ModuleScript::Create(const ParkableString& original_source_text,
Modulator* modulator, Modulator* modulator,
const KURL& source_url, const KURL& source_url,
...@@ -72,7 +72,7 @@ ModuleScript* ModuleScript::Create(const ParkableString& original_source_text, ...@@ -72,7 +72,7 @@ ModuleScript* ModuleScript::Create(const ParkableString& original_source_text,
for (const auto& requested : for (const auto& requested :
modulator->ModuleRequestsFromScriptModule(result)) { modulator->ModuleRequestsFromScriptModule(result)) {
// <spec step="9.1">Let url be the result of resolving a module specifier // <spec step="9.1">Let url be the result of resolving a module specifier
// given script and requested.</spec> // given script's base URL and requested.</spec>
// //
// <spec step="9.2">If url is failure, then:</spec> // <spec step="9.2">If url is failure, then:</spec>
String failure_reason; String failure_reason;
...@@ -107,7 +107,7 @@ ModuleScript* ModuleScript::CreateForTest(Modulator* modulator, ...@@ -107,7 +107,7 @@ ModuleScript* ModuleScript::CreateForTest(Modulator* modulator,
base_url, options, TextPosition::MinimumPosition()); base_url, options, TextPosition::MinimumPosition());
} }
// https://html.spec.whatwg.org/multipage/webappapis.html#creating-a-module-script // <specdef href="https://html.spec.whatwg.org/#creating-a-module-script">
ModuleScript* ModuleScript::CreateInternal(const ParkableString& source_text, ModuleScript* ModuleScript::CreateInternal(const ParkableString& source_text,
Modulator* modulator, Modulator* modulator,
ScriptModule result, ScriptModule result,
......
...@@ -124,7 +124,7 @@ void PendingScript::MarkParserBlockingLoadStartTime() { ...@@ -124,7 +124,7 @@ void PendingScript::MarkParserBlockingLoadStartTime() {
parser_blocking_load_start_time_ = CurrentTimeTicks(); parser_blocking_load_start_time_ = CurrentTimeTicks();
} }
// https://html.spec.whatwg.org/multipage/scripting.html#execute-the-script-block // <specdef href="https://html.spec.whatwg.org/#execute-the-script-block">
void PendingScript::ExecuteScriptBlock(const KURL& document_url) { void PendingScript::ExecuteScriptBlock(const KURL& document_url) {
Document* context_document = element_->GetDocument().ContextDocument(); Document* context_document = element_->GetDocument().ContextDocument();
if (!context_document) { if (!context_document) {
...@@ -161,8 +161,12 @@ void PendingScript::ExecuteScriptBlock(const KURL& document_url) { ...@@ -161,8 +161,12 @@ void PendingScript::ExecuteScriptBlock(const KURL& document_url) {
!element_->AllowInlineScriptForCSP( !element_->AllowInlineScriptForCSP(
nonce, StartingPosition().line_, script->InlineSourceTextForCSP(), nonce, StartingPosition().line_, script->InlineSourceTextForCSP(),
ContentSecurityPolicy::InlineType::kBlock)) { ContentSecurityPolicy::InlineType::kBlock)) {
// Consider as if "the script's script is null" retrospectively, // Consider as if:
// if the CSP check fails, which is considered as load failure. //
// <spec step="2">If the script's script is null, ...</spec>
//
// retrospectively, if the CSP check fails, which is considered as load
// failure.
script = nullptr; script = nullptr;
} }
} }
...@@ -183,6 +187,7 @@ void PendingScript::ExecuteScriptBlock(const KURL& document_url) { ...@@ -183,6 +187,7 @@ void PendingScript::ExecuteScriptBlock(const KURL& document_url) {
parser_blocking_load_start_time, is_controlled_by_script_runner); parser_blocking_load_start_time, is_controlled_by_script_runner);
} }
// <specdef href="https://html.spec.whatwg.org/#execute-the-script-block">
void PendingScript::ExecuteScriptBlockInternal( void PendingScript::ExecuteScriptBlockInternal(
Script* script, Script* script,
ScriptElementBase* element, ScriptElementBase* element,
...@@ -240,13 +245,13 @@ void PendingScript::ExecuteScriptBlockInternal( ...@@ -240,13 +245,13 @@ void PendingScript::ExecuteScriptBlockInternal(
// <spec step="5">Switch on the script's type:</spec> // <spec step="5">Switch on the script's type:</spec>
// //
// Step 5.A. "classic" [spec text] // <spec step="5.A">"classic"</spec>
// //
// <spec step="5.A.1">If the script element's root is not a shadow root, // <spec step="5.A.1">If the script element's root is not a shadow root,
// then set the script element's node document's currentScript attribute to // then set the script element's node document's currentScript attribute to
// the script element. Otherwise, set it to null.</spec> // the script element. Otherwise, set it to null.</spec>
// //
// Step 5.B. "module" [spec text] // <spec step="5.B">"module"</spec>
// //
// <spec step="5.B.1">Set the script element's node document's currentScript // <spec step="5.B.1">Set the script element's node document's currentScript
// attribute to null.</spec> // attribute to null.</spec>
...@@ -255,14 +260,14 @@ void PendingScript::ExecuteScriptBlockInternal( ...@@ -255,14 +260,14 @@ void PendingScript::ExecuteScriptBlockInternal(
current_script = element; current_script = element;
context_document->PushCurrentScript(current_script); context_document->PushCurrentScript(current_script);
// Step 5.A. "classic" [spec text] // <spec step="5.A">"classic"</spec>
// //
// <spec step="5.A.2">Run the classic script given by the script's // <spec step="5.A.2">Run the classic script given by the script's
// script.</spec> // script.</spec>
// //
// Note: This is where the script is compiled and actually executed. // Note: This is where the script is compiled and actually executed.
// //
// Step 5.B. "module" [spec text] // <spec step="5.B">"module"</spec>
// //
// <spec step="5.B.2">Run the module script given by the script's // <spec step="5.B.2">Run the module script given by the script's
// script.</spec> // script.</spec>
......
...@@ -69,10 +69,9 @@ ScriptLoader::ScriptLoader(ScriptElementBase* element, ...@@ -69,10 +69,9 @@ ScriptLoader::ScriptLoader(ScriptElementBase* element,
: element_(element), : element_(element),
will_be_parser_executed_(false), will_be_parser_executed_(false),
will_execute_when_document_finished_parsing_(false) { will_execute_when_document_finished_parsing_(false) {
// <spec // <spec href="https://html.spec.whatwg.org/#already-started">... The cloning
// href="https://html.spec.whatwg.org/multipage/scripting.html#already-started"> // steps for script elements must set the "already started" flag on the copy
// ... The cloning steps for script elements must set the "already started" // if it is set on the element being cloned.</spec>
// flag on the copy if it is set on the element being cloned.</spec>
// //
// TODO(hiroshige): Cloning is implemented together with // TODO(hiroshige): Cloning is implemented together with
// {HTML,SVG}ScriptElement::cloneElementWithoutAttributesAndChildren(). // {HTML,SVG}ScriptElement::cloneElementWithoutAttributesAndChildren().
...@@ -81,16 +80,14 @@ ScriptLoader::ScriptLoader(ScriptElementBase* element, ...@@ -81,16 +80,14 @@ ScriptLoader::ScriptLoader(ScriptElementBase* element,
already_started_ = true; already_started_ = true;
if (parser_inserted) { if (parser_inserted) {
// <spec // <spec href="https://html.spec.whatwg.org/#parser-inserted">... It is set
// href="https://html.spec.whatwg.org/multipage/scripting.html#parser-inserted"> // by the HTML parser and the XML parser on script elements they insert
// ... It is set by the HTML parser and the XML parser on script elements // ...</spec>
// they insert ...</spec>
parser_inserted_ = true; parser_inserted_ = true;
// <spec // <spec href="https://html.spec.whatwg.org/#non-blocking">... It is unset
// href="https://html.spec.whatwg.org/multipage/scripting.html#non-blocking"> // by the HTML parser and the XML parser on script elements they insert.
// ... It is unset by the HTML parser and the XML parser on script elements // ...</spec>
// they insert. ...</spec>
non_blocking_ = false; non_blocking_ = false;
} }
} }
...@@ -122,12 +119,11 @@ void ScriptLoader::HandleSourceAttribute(const String& source_url) { ...@@ -122,12 +119,11 @@ void ScriptLoader::HandleSourceAttribute(const String& source_url) {
PrepareScript(); // FIXME: Provide a real starting line number here. PrepareScript(); // FIXME: Provide a real starting line number here.
} }
// <specdef href="https://html.spec.whatwg.org/#non-blocking">
void ScriptLoader::HandleAsyncAttribute() { void ScriptLoader::HandleAsyncAttribute() {
// <spec // <spec>... In addition, whenever a script element whose "non-blocking" flag
// href="https://html.spec.whatwg.org/multipage/scripting.html#non-blocking"> // is set has an async content attribute added, the element's "non-blocking"
// ... In addition, whenever a script element whose "non-blocking" flag is set // flag must be unset.</spec>
// has an async content attribute added, the element's "non-blocking" flag
// must be unset.</spec>
non_blocking_ = false; non_blocking_ = false;
} }
...@@ -169,7 +165,7 @@ bool IsValidClassicScriptTypeAndLanguage( ...@@ -169,7 +165,7 @@ bool IsValidClassicScriptTypeAndLanguage(
} // namespace } // namespace
// https://html.spec.whatwg.org/multipage/scripting.html#prepare-a-script // <specdef href="https://html.spec.whatwg.org/#prepare-a-script">
bool ScriptLoader::IsValidScriptTypeAndLanguage( bool ScriptLoader::IsValidScriptTypeAndLanguage(
const String& type, const String& type,
const String& language, const String& language,
...@@ -241,7 +237,7 @@ bool ShouldBlockSyncScriptForFeaturePolicy(const ScriptElementBase* element, ...@@ -241,7 +237,7 @@ bool ShouldBlockSyncScriptForFeaturePolicy(const ScriptElementBase* element,
return !element->DeferAttributeValue() && !element->AsyncAttributeValue(); return !element->DeferAttributeValue() && !element->AsyncAttributeValue();
} }
// https://html.spec.whatwg.org/multipage/scripting.html#prepare-a-script // <specdef href="https://html.spec.whatwg.org/#prepare-a-script">
bool ScriptLoader::PrepareScript(const TextPosition& script_start_position, bool ScriptLoader::PrepareScript(const TextPosition& script_start_position,
LegacyTypeSupport support_legacy_types) { LegacyTypeSupport support_legacy_types) {
// <spec step="1">If the script element is marked as having "already started", // <spec step="1">If the script element is marked as having "already started",
...@@ -310,11 +306,9 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position, ...@@ -310,11 +306,9 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position,
// <spec step="11">If scripting is disabled for the script element, then // <spec step="11">If scripting is disabled for the script element, then
// return. The script is not executed.</spec> // return. The script is not executed.</spec>
// //
// <spec // <spec href="https://html.spec.whatwg.org/#concept-n-noscript">Scripting is
// href="https://html.spec.whatwg.org/multipage/webappapis.html#concept-n-noscript"> // disabled for a node if there is no such browsing context, or if scripting
// Scripting is disabled for a node if [the node's node document has no // is disabled in that browsing context.</spec>
// browsing context], or if scripting is disabled in that browsing context.
// </spec>
Document& element_document = element_->GetDocument(); Document& element_document = element_->GetDocument();
// TODO(timothygu): Investigate if we could switch from ExecutingFrame() to // TODO(timothygu): Investigate if we could switch from ExecutingFrame() to
// ExecutingWindow(). // ExecutingWindow().
...@@ -417,8 +411,8 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position, ...@@ -417,8 +411,8 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position,
ScriptFetchOptions options(nonce, integrity_metadata, integrity_attr, ScriptFetchOptions options(nonce, integrity_metadata, integrity_attr,
parser_state, credentials_mode, referrer_policy); parser_state, credentials_mode, referrer_policy);
// <spec step="23">Let settings object be the element's node document's Window // <spec step="23">Let settings object be the element's node document's
// object's environment settings object.</spec> // relevant settings object.</spec>
// //
// Note: We use |element_document| as "settings object" in the steps below. // Note: We use |element_document| as "settings object" in the steps below.
auto* settings_object = auto* settings_object =
...@@ -511,7 +505,7 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position, ...@@ -511,7 +505,7 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position,
// <spec step="25">If the element does not have a src content attribute, run // <spec step="25">If the element does not have a src content attribute, run
// these substeps:</spec> // these substeps:</spec>
if (!element_->HasSourceAttribute()) { if (!element_->HasSourceAttribute()) {
// <spec step="25.1">Let src be the value of the element's src // <spec step="24.1">Let src be the value of the element's src
// attribute.</spec> // attribute.</spec>
// //
// This step is done later as ScriptElementBase::TextFromChildren(): // This step is done later as ScriptElementBase::TextFromChildren():
...@@ -529,7 +523,7 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position, ...@@ -529,7 +523,7 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position,
// <spec step="25.2">Switch on the script's type:</spec> // <spec step="25.2">Switch on the script's type:</spec>
switch (GetScriptType()) { switch (GetScriptType()) {
// Step 25.2.A. "classic" [spec text] // <spec step="25.2.A">"classic"</spec>
case ScriptType::kClassic: { case ScriptType::kClassic: {
// <spec step="25.2.A.1">Let script be the result of creating a classic // <spec step="25.2.A.1">Let script be the result of creating a classic
// script using source text, settings object, base URL, and // script using source text, settings object, base URL, and
...@@ -556,7 +550,7 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position, ...@@ -556,7 +550,7 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position,
break; break;
} }
// Step 25.2.B. "module" [spec text] // <spec step="25.2.B">"module"</spec>
case ScriptType::kModule: { case ScriptType::kModule: {
// <spec step="25.2.B.1">Let script be the result of creating a module // <spec step="25.2.B.1">Let script be the result of creating a module
// script using source text, settings object, base URL, and // script using source text, settings object, base URL, and
...@@ -574,9 +568,9 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position, ...@@ -574,9 +568,9 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position,
return false; return false;
// <spec step="25.2.B.3">Fetch the descendants of and instantiate // <spec step="25.2.B.3">Fetch the descendants of and instantiate
// script, given the destination "script". When this asynchronously // script, given settings object and the destination "script". When this
// completes, set the script's script to the result. At that time, the // asynchronously completes, set the script's script to the result. At
// script is ready.</spec> // that time, the script is ready.</spec>
auto* module_tree_client = ModulePendingScriptTreeClient::Create(); auto* module_tree_client = ModulePendingScriptTreeClient::Create();
modulator->FetchDescendantsForInlineScript( modulator->FetchDescendantsForInlineScript(
module_script, settings_object, mojom::RequestContextType::SCRIPT, module_script, settings_object, mojom::RequestContextType::SCRIPT,
...@@ -704,7 +698,8 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position, ...@@ -704,7 +698,8 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position,
// or XML parser that created the script element has a style sheet that is // or XML parser that created the script element has a style sheet that is
// blocking scripts ...</spec> // blocking scripts ...</spec>
// //
// The last part "... has a style sheet that is blocking scripts" // <spec step="26.E">... has a style sheet that is blocking scripts ...</spec>
//
// is implemented in Document::isScriptExecutionReady(). // is implemented in Document::isScriptExecutionReady().
// Part of the condition check is done in // Part of the condition check is done in
// HTMLParserScriptRunner::processScriptElementInternal(). // HTMLParserScriptRunner::processScriptElementInternal().
...@@ -756,14 +751,13 @@ void ScriptLoader::FetchClassicScript(const KURL& url, ...@@ -756,14 +751,13 @@ void ScriptLoader::FetchClassicScript(const KURL& url,
resource_keep_alive_ = pending_script->GetResource(); resource_keep_alive_ = pending_script->GetResource();
} }
// <specdef href="https://html.spec.whatwg.org/#prepare-a-script">
void ScriptLoader::FetchModuleScriptTree( void ScriptLoader::FetchModuleScriptTree(
const KURL& url, const KURL& url,
FetchClientSettingsObjectSnapshot* settings_object, FetchClientSettingsObjectSnapshot* settings_object,
Modulator* modulator, Modulator* modulator,
const ScriptFetchOptions& options) { const ScriptFetchOptions& options) {
// <spec // <spec step="24.6.B">"module"
// href="https://html.spec.whatwg.org/multipage/scripting.html#prepare-a-script"
// step="23.6.B">"module"
// //
// Fetch a module script graph given url, settings object, "script", and // Fetch a module script graph given url, settings object, "script", and
// options.</spec> // options.</spec>
...@@ -828,7 +822,7 @@ bool ScriptLoader::IgnoresLoadRequest() const { ...@@ -828,7 +822,7 @@ bool ScriptLoader::IgnoresLoadRequest() const {
!element_->IsConnected(); !element_->IsConnected();
} }
// https://html.spec.whatwg.org/multipage/scripting.html#prepare-a-script // <specdef href="https://html.spec.whatwg.org/#prepare-a-script">
bool ScriptLoader::IsScriptForEventSupported() const { bool ScriptLoader::IsScriptForEventSupported() const {
// <spec step="14.1">Let for be the value of the for attribute.</spec> // <spec step="14.1">Let for be the value of the for attribute.</spec>
String event_attribute = element_->EventAttributeValue(); String event_attribute = element_->EventAttributeValue();
......
...@@ -50,7 +50,8 @@ ModuleScript* ScriptModuleResolverImpl::GetHostDefined( ...@@ -50,7 +50,8 @@ ModuleScript* ScriptModuleResolverImpl::GetHostDefined(
return it->value; return it->value;
} }
// https://html.spec.whatwg.org/multipage/webappapis.html#hostresolveimportedmodule(referencingscriptormodule,-specifier) // <specdef
// href="https://html.spec.whatwg.org/#hostresolveimportedmodule(referencingscriptormodule,-specifier)">
ScriptModule ScriptModuleResolverImpl::Resolve( ScriptModule ScriptModuleResolverImpl::Resolve(
const String& specifier, const String& specifier,
const ScriptModule& referrer, const ScriptModule& referrer,
...@@ -58,32 +59,37 @@ ScriptModule ScriptModuleResolverImpl::Resolve( ...@@ -58,32 +59,37 @@ ScriptModule ScriptModuleResolverImpl::Resolve(
DVLOG(1) << "ScriptModuleResolverImpl::resolve(specifier=\"" << specifier DVLOG(1) << "ScriptModuleResolverImpl::resolve(specifier=\"" << specifier
<< ", referrer.hash=" << ScriptModuleHash::GetHash(referrer) << ")"; << ", referrer.hash=" << ScriptModuleHash::GetHash(referrer) << ")";
// Step 1. Let referencing module script be referencingModule.[[HostDefined]]. // <spec step="1">Let referencing script be
// referencingScriptOrModule.[[HostDefined]].</spec>
ModuleScript* referrer_module = GetHostDefined(referrer); ModuleScript* referrer_module = GetHostDefined(referrer);
// Step 2. Let moduleMap be referencing module script's settings object's // <spec step="2">Let moduleMap be referencing script's settings object's
// module map. Note: Blink finds out "module script's settings object" // module map.</spec>
//
// Note: Blink finds out "module script's settings object"
// (Modulator) from context where HostResolveImportedModule was called. // (Modulator) from context where HostResolveImportedModule was called.
// Step 3. Let url be the result of resolving a module specifier given // <spec step="3">Let url be the result of resolving a module specifier given
// referencing module script and specifier. // referencing script's base URL and specifier.</spec>
KURL url = referrer_module->ResolveModuleSpecifier(specifier); KURL url = referrer_module->ResolveModuleSpecifier(specifier);
// Step 4. Assert: url is never failure, because resolving a module specifier // <spec step="4">Assert: url is never failure, because resolving a module
// must have been previously successful with these same two arguments. // specifier must have been previously successful with these same two
// arguments.</spec>
DCHECK(url.IsValid()); DCHECK(url.IsValid());
// Step 5. Let resolved module script be moduleMap[url]. (This entry must // <spec step="5">Let resolved module script be moduleMap[url]. (This entry
// exist for us to have gotten to this point.) // must exist for us to have gotten to this point.)</spec>
ModuleScript* module_script = modulator_->GetFetchedModuleScript(url); ModuleScript* module_script = modulator_->GetFetchedModuleScript(url);
// Step 6. Assert: resolved module script is a module script (i.e., is not // <spec step="6">Assert: resolved module script is a module script (i.e., is
// null or "fetching"). // not null or "fetching").</spec>
// Step 7. Assert: resolved module script's record is not null. //
// <spec step="7">Assert: resolved module script's record is not null.</spec>
DCHECK(module_script); DCHECK(module_script);
CHECK(!module_script->Record().IsNull()); CHECK(!module_script->Record().IsNull());
// Step 8. Return resolved module script's module record. // <spec step="8">Return resolved module script's record.</spec>
return module_script->Record(); return module_script->Record();
} }
......
...@@ -13,10 +13,10 @@ ...@@ -13,10 +13,10 @@
namespace blink { namespace blink {
// Spec links: // Spec links:
// [Parsing] // <specdef label="Parsing"
// https://html.spec.whatwg.org/multipage/xhtml.html#parsing-xhtml-documents // href="https://html.spec.whatwg.org/multipage/xhtml.html#parsing-xhtml-documents">
// [Prepare] // <specdef label="Prepare"
// https://html.spec.whatwg.org/multipage/scripting.html#prepare-a-script // href="https://html.spec.whatwg.org/multipage/scripting.html#prepare-a-script">
XMLParserScriptRunner::XMLParserScriptRunner(XMLParserScriptRunnerHost* host) XMLParserScriptRunner::XMLParserScriptRunner(XMLParserScriptRunnerHost* host)
: host_(host) {} : host_(host) {}
...@@ -48,15 +48,16 @@ void XMLParserScriptRunner::PendingScriptFinished( ...@@ -48,15 +48,16 @@ void XMLParserScriptRunner::PendingScriptFinished(
CHECK_EQ(pending_script->GetScriptType(), ScriptType::kClassic); CHECK_EQ(pending_script->GetScriptType(), ScriptType::kClassic);
// [Parsing] 4. Execute the pending parsing-blocking script. [spec text] // <spec label="Parsing" step="4">Execute the pending parsing-blocking
// script.</spec>
pending_script->ExecuteScriptBlock(NullURL()); pending_script->ExecuteScriptBlock(NullURL());
// [Parsing] 5. There is no longer a pending parsing-blocking script. [spec // <spec label="Parsing" step="5">There is no longer a pending
// text] // parsing-blocking script.</spec>
DCHECK(!parser_blocking_script_); DCHECK(!parser_blocking_script_);
// [Parsing] 3. Unblock this instance of the XML parser, such that tasks that // <spec label="Parsing" step="3">Unblock this instance of the XML parser,
// invoke it can again be run. [spec text] // such that tasks that invoke it can again be run.</spec>
host_->NotifyScriptExecuted(); host_->NotifyScriptExecuted();
} }
...@@ -90,10 +91,12 @@ void XMLParserScriptRunner::ProcessScriptElement( ...@@ -90,10 +91,12 @@ void XMLParserScriptRunner::ProcessScriptElement(
// [Parsing] If this causes there to be a pending parsing-blocking script, // [Parsing] If this causes there to be a pending parsing-blocking script,
// then the user agent must run the following steps: [spec text] // then the user agent must run the following steps: [spec text]
if (script_loader->ReadyToBeParserExecuted()) { if (script_loader->ReadyToBeParserExecuted()) {
// [Prepare] 5th Clause, Step 24. // <spec label="Prepare" step="26.E">... The parser will handle executing
// the script.</spec>
//
// <spec label="Parsing" step="4">Execute the pending parsing-blocking
// script.</spec>
// //
// [Parsing] 4. Execute the pending parsing-blocking script. [spec text]
// TODO(hiroshige): XMLParserScriptRunner doesn't check style sheet that // TODO(hiroshige): XMLParserScriptRunner doesn't check style sheet that
// is blocking scripts and thus the script is executed immediately here, // is blocking scripts and thus the script is executed immediately here,
// and thus Steps 1-3 are skipped. // and thus Steps 1-3 are skipped.
...@@ -101,7 +104,7 @@ void XMLParserScriptRunner::ProcessScriptElement( ...@@ -101,7 +104,7 @@ void XMLParserScriptRunner::ProcessScriptElement(
->TakePendingScript(ScriptSchedulingType::kParserBlockingInline) ->TakePendingScript(ScriptSchedulingType::kParserBlockingInline)
->ExecuteScriptBlock(document.Url()); ->ExecuteScriptBlock(document.Url());
} else if (script_loader->WillBeParserExecuted()) { } else if (script_loader->WillBeParserExecuted()) {
// <spec label="Prepare" step="25.B">... The element is the pending // <spec label="Prepare" step="26.B">... The element is the pending
// parsing-blocking script of the Document of the parser that created the // parsing-blocking script of the Document of the parser that created the
// element. (There can only be one such script per Document at a time.) // element. (There can only be one such script per Document at a time.)
// ...</spec> // ...</spec>
...@@ -109,15 +112,16 @@ void XMLParserScriptRunner::ProcessScriptElement( ...@@ -109,15 +112,16 @@ void XMLParserScriptRunner::ProcessScriptElement(
script_loader->TakePendingScript(ScriptSchedulingType::kParserBlocking); script_loader->TakePendingScript(ScriptSchedulingType::kParserBlocking);
parser_blocking_script_->MarkParserBlockingLoadStartTime(); parser_blocking_script_->MarkParserBlockingLoadStartTime();
// [Parsing] 1. Block this instance of the XML parser, such that the event // <spec label="Parsing" step="1">Block this instance of the XML parser,
// loop will not run tasks that invoke it. [spec text] // such that the event loop will not run tasks that invoke it.</spec>
// //
// This is done in XMLDocumentParser::EndElementNs(). // This is done in XMLDocumentParser::EndElementNs().
// [Parsing] 2. Spin the event loop until the parser's Document has no style // <spec label="Parsing" step="2">Spin the event loop until the parser's
// sheet that is blocking scripts and the pending parsing-blocking script's // Document has no style sheet that is blocking scripts and the pending
// "ready to be parser-executed" flag is set. [spec text] // parsing-blocking script's "ready to be parser-executed" flag is
// // set.</spec>
// TODO(hiroshige): XMLParserScriptRunner doesn't check style sheet that // TODO(hiroshige): XMLParserScriptRunner doesn't check style sheet that
// is blocking scripts. // is blocking scripts.
parser_blocking_script_->WatchForLoad(this); parser_blocking_script_->WatchForLoad(this);
......
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