Skip to content

Commit 62c0071

Browse files
tcl3gmta
authored andcommitted
LibWeb: Update HTMLScriptElement::prepare_script() spec text
1 parent 24a7eac commit 62c0071

File tree

1 file changed

+31
-26
lines changed

1 file changed

+31
-26
lines changed

Libraries/LibWeb/HTML/HTMLScriptElement.cpp

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -242,51 +242,54 @@ void HTMLScriptElement::prepare_script()
242242
// then set el's type to "importmap".
243243
m_script_type = ScriptType::ImportMap;
244244
}
245-
// 12. Otherwise, return. (No script is executed, and el's type is left as null.)
245+
// FIXME: 12. Otherwise, if the script block's type string is an ASCII case-insensitive match for the string "speculationrules", then set el's type to "speculationrules".
246+
// 13. Otherwise, return. (No script is executed, and el's type is left as null.)
246247
else {
247248
VERIFY(m_script_type == ScriptType::Null);
248249
return;
249250
}
250251

251-
// 13. If parser document is non-null, then set el's parser document back to parser document and set el's force async to false.
252+
// 14. If parser document is non-null, then set el's parser document back to parser document and set el's force async to false.
252253
if (parser_document) {
253254
m_parser_document = parser_document;
254255
m_force_async = false;
255256
}
256257

257-
// 14. Set el's already started to true.
258+
// 15. Set el's already started to true.
258259
m_already_started = true;
259260

260-
// 15. Set el's preparation-time document to its node document.
261+
// 16. Set el's preparation-time document to its node document.
261262
m_preparation_time_document = &document();
262263

263-
// 16. If parser document is non-null, and parser document is not equal to el's preparation-time document, then return.
264+
// 17. If parser document is non-null, and parser document is not equal to el's preparation-time document, then return.
264265
if (parser_document != nullptr && parser_document != m_preparation_time_document) {
265266
dbgln("HTMLScriptElement: Refusing to run script because the parser document is not the same as the preparation time document.");
266267
return;
267268
}
268269

269-
// 17. If scripting is disabled for el, then return.
270+
// 18. If scripting is disabled for el, then return.
270271
if (is_scripting_disabled()) {
271272
dbgln("HTMLScriptElement: Refusing to run script because scripting is disabled.");
272273
return;
273274
}
274275

275-
// 18. If el has a nomodule content attribute and its type is "classic", then return.
276+
// 19. If el has a nomodule content attribute and its type is "classic", then return.
276277
if (m_script_type == ScriptType::Classic && has_attribute(HTML::AttributeNames::nomodule)) {
277278
dbgln("HTMLScriptElement: Refusing to run classic script because it has the nomodule attribute.");
278279
return;
279280
}
280281

281-
// 19. If el does not have a src content attribute, and the Should element's inline behavior be blocked by Content Security Policy?
282-
// algorithm returns "Blocked" when given el, "script", and source text, then return. [CSP]
282+
// FIXME: 20. Let cspType be "script speculationrules" if el's type is "speculationrules"; otherwise, "script".
283+
284+
// 21. If el does not have a src content attribute, and the Should element's inline behavior be blocked by Content
285+
// Security Policy? algorithm returns "Blocked" when given el, cspType, and source text, then return [CSP]
283286
if (!has_attribute(AttributeNames::src)
284287
&& ContentSecurityPolicy::should_elements_inline_type_behavior_be_blocked_by_content_security_policy(realm(), *this, ContentSecurityPolicy::Directives::Directive::InlineType::Script, source_text_utf8) == ContentSecurityPolicy::Directives::Directive::Result::Blocked) {
285288
dbgln("HTMLScriptElement: Refusing to run inline script because it violates the Content Security Policy.");
286289
return;
287290
}
288291

289-
// 20. If el has an event attribute and a for attribute, and el's type is "classic", then:
292+
// 22. If el has an event attribute and a for attribute, and el's type is "classic", then:
290293
if (m_script_type == ScriptType::Classic && has_attribute(HTML::AttributeNames::event) && has_attribute(HTML::AttributeNames::for_)) {
291294
// 1. Let for be the value of el's' for attribute.
292295
auto for_ = get_attribute_value(HTML::AttributeNames::for_);
@@ -312,7 +315,7 @@ void HTMLScriptElement::prepare_script()
312315
}
313316
}
314317

315-
// 21. If el has a charset attribute, then let encoding be the result of getting an encoding from the value of the charset attribute.
318+
// 23. If el has a charset attribute, then let encoding be the result of getting an encoding from the value of the charset attribute.
316319
// If el does not have a charset attribute, or if getting an encoding failed, then let encoding be el's node document's the encoding.
317320
Optional<String> encoding;
318321

@@ -328,34 +331,34 @@ void HTMLScriptElement::prepare_script()
328331

329332
VERIFY(encoding.has_value());
330333

331-
// 22. Let classic script CORS setting be the current state of el's crossorigin content attribute.
334+
// 24. Let classic script CORS setting be the current state of el's crossorigin content attribute.
332335
auto classic_script_cors_setting = m_crossorigin;
333336

334-
// 23. Let module script credentials mode be the CORS settings attribute credentials mode for el's crossorigin content attribute.
337+
// 25. Let module script credentials mode be the CORS settings attribute credentials mode for el's crossorigin content attribute.
335338
auto module_script_credential_mode = cors_settings_attribute_credentials_mode(m_crossorigin);
336339

337-
// 24. Let cryptographic nonce be el's [[CryptographicNonce]] internal slot's value.
340+
// 26. Let cryptographic nonce be el's [[CryptographicNonce]] internal slot's value.
338341
auto cryptographic_nonce = m_cryptographic_nonce;
339342

340-
// 25. If el has an integrity attribute, then let integrity metadata be that attribute's value.
343+
// 27. If el has an integrity attribute, then let integrity metadata be that attribute's value.
341344
// Otherwise, let integrity metadata be the empty string.
342345
String integrity_metadata;
343346
if (auto maybe_integrity = attribute(HTML::AttributeNames::integrity); maybe_integrity.has_value()) {
344347
integrity_metadata = *maybe_integrity;
345348
}
346349

347-
// 26. Let referrer policy be the current state of el's referrerpolicy content attribute.
350+
// 28. Let referrer policy be the current state of el's referrerpolicy content attribute.
348351
auto referrer_policy = m_referrer_policy;
349352

350-
// 27. Let fetch priority be the current state of el's fetchpriority content attribute.
353+
// 29. Let fetch priority be the current state of el's fetchpriority content attribute.
351354
auto fetch_priority = Fetch::Infrastructure::request_priority_from_string(get_attribute_value(HTML::AttributeNames::fetchpriority)).value_or(Fetch::Infrastructure::Request::Priority::Auto);
352355

353-
// 28. Let parser metadata be "parser-inserted" if el is parser-inserted, and "not-parser-inserted" otherwise.
356+
// 30. Let parser metadata be "parser-inserted" if el is parser-inserted, and "not-parser-inserted" otherwise.
354357
auto parser_metadata = is_parser_inserted()
355358
? Fetch::Infrastructure::Request::ParserMetadata::ParserInserted
356359
: Fetch::Infrastructure::Request::ParserMetadata::NotParserInserted;
357360

358-
// 29. Let options be a script fetch options whose cryptographic nonce is cryptographic nonce,
361+
// 31. Let options be a script fetch options whose cryptographic nonce is cryptographic nonce,
359362
// integrity metadata is integrity metadata, parser metadata is parser metadata,
360363
// credentials mode is module script credentials mode, referrer policy is referrer policy,
361364
// and fetch priority is fetch priority.
@@ -368,12 +371,13 @@ void HTMLScriptElement::prepare_script()
368371
.fetch_priority = move(fetch_priority),
369372
};
370373

371-
// 30. Let settings object be el's node document's relevant settings object.
374+
// 32. Let settings object be el's node document's relevant settings object.
372375
auto& settings_object = document().relevant_settings_object();
373376

374-
// 31. If el has a src content attribute, then:
377+
// 33. If el has a src content attribute, then:
375378
if (has_attribute(HTML::AttributeNames::src)) {
376-
// 1. If el's type is "importmap",
379+
// 1. If el's type is "importmap" or "speculationrules", then:
380+
// FIXME: Add "speculationrules" support.
377381
if (m_script_type == ScriptType::ImportMap) {
378382
// then queue an element task on the DOM manipulation task source given el to fire an event named error at el, and return.
379383
queue_an_element_task(HTML::Task::Source::DOMManipulation, [this] {
@@ -445,9 +449,9 @@ void HTMLScriptElement::prepare_script()
445449
}
446450
}
447451

448-
// 32. If el does not have a src content attribute:
452+
// 34. If el does not have a src content attribute:
449453
if (!has_attribute(HTML::AttributeNames::src)) {
450-
// Let base URL be el's node document's document base URL.
454+
// 1. Let base URL be el's node document's document base URL.
451455
auto base_url = document().base_url();
452456

453457
// 2. Switch on el's type:
@@ -488,9 +492,10 @@ void HTMLScriptElement::prepare_script()
488492
// 2. Mark as ready el given result.
489493
mark_as_ready(Result(move(result)));
490494
}
495+
// FIXME: -> "speculationrules"
491496
}
492497

493-
// 33. If el's type is "classic" and el has a src attribute, or el's type is "module":
498+
// 35. If el's type is "classic" and el has a src attribute, or el's type is "module":
494499
if ((m_script_type == ScriptType::Classic && has_attribute(HTML::AttributeNames::src)) || m_script_type == ScriptType::Module) {
495500
// 1. Assert: el's result is "uninitialized".
496501
// FIXME: I believe this step to be a spec bug, and it should be removed: https://github.com/whatwg/html/issues/8534
@@ -564,7 +569,7 @@ void HTMLScriptElement::prepare_script()
564569
}
565570
}
566571

567-
// 34. Otherwise:
572+
// 36. Otherwise:
568573
else {
569574
// 1. Assert: el's result is not "uninitialized".
570575
VERIFY(!m_result.has<ResultState::Uninitialized>());

0 commit comments

Comments
 (0)