Bug 1874684 - Part 38: Enable now passing tests. r=allstarschh
[gecko.git] / dom / script / nsIScriptElement.cpp
blob7fda6f1fd436a63af8c18b02d4aab60c44aef871
2 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "nsIScriptElement.h"
10 #include "js/loader/ScriptKind.h"
11 #include "mozilla/dom/Document.h"
12 #include "mozilla/dom/ReferrerPolicyBinding.h"
13 #include "nsIParser.h"
14 #include "nsIWeakReference.h"
16 using JS::loader::ScriptKind;
18 bool nsIScriptElement::IsClassicNonAsyncDefer() {
19 return mKind == ScriptKind::eClassic && !mAsync && !mDefer;
22 void nsIScriptElement::SetCreatorParser(nsIParser* aParser) {
23 mCreatorParser = do_GetWeakReference(aParser);
26 void nsIScriptElement::UnblockParser() {
27 if (!IsClassicNonAsyncDefer()) {
28 MOZ_ASSERT_UNREACHABLE(
29 "Tried to unblock parser for a script type that cannot block "
30 "the parser.");
31 return;
33 nsCOMPtr<nsIParser> parser = do_QueryReferent(mCreatorParser);
34 if (parser) {
35 parser->UnblockParser();
39 void nsIScriptElement::ContinueParserAsync() {
40 if (!IsClassicNonAsyncDefer()) {
41 MOZ_ASSERT_UNREACHABLE(
42 "Tried to continue after a script type that cannot block the parser.");
43 return;
45 nsCOMPtr<nsIParser> parser = do_QueryReferent(mCreatorParser);
46 if (parser) {
47 parser->ContinueInterruptedParsingAsync();
51 void nsIScriptElement::BeginEvaluating() {
52 if (!IsClassicNonAsyncDefer()) {
53 return;
55 nsCOMPtr<nsIParser> parser = do_QueryReferent(mCreatorParser);
56 if (parser) {
57 parser->IncrementScriptNestingLevel();
61 void nsIScriptElement::EndEvaluating() {
62 if (!IsClassicNonAsyncDefer()) {
63 return;
65 nsCOMPtr<nsIParser> parser = do_QueryReferent(mCreatorParser);
66 if (parser) {
67 parser->DecrementScriptNestingLevel();
71 already_AddRefed<nsIParser> nsIScriptElement::GetCreatorParser() {
72 nsCOMPtr<nsIParser> parser = do_QueryReferent(mCreatorParser);
73 return parser.forget();
76 mozilla::dom::ReferrerPolicy nsIScriptElement::GetReferrerPolicy() {
77 return mozilla::dom::ReferrerPolicy::_empty;
80 void nsIScriptElement::DetermineKindFromType(
81 const mozilla::dom::Document* aOwnerDoc) {
82 MOZ_ASSERT((mKind != ScriptKind::eModule) &&
83 (mKind != ScriptKind::eImportMap) && !mAsync && !mDefer &&
84 !mExternal);
86 nsAutoString type;
87 GetScriptType(type);
89 if (!type.IsEmpty()) {
90 if (type.LowerCaseEqualsASCII("module")) {
91 mKind = ScriptKind::eModule;
94 // https://html.spec.whatwg.org/multipage/scripting.html#prepare-the-script-element
95 // Step 11. Otherwise, if the script block's type string is an ASCII
96 // case-insensitive match for the string "importmap", then set el's type to
97 // "importmap".
98 if (type.LowerCaseEqualsASCII("importmap")) {
99 mKind = ScriptKind::eImportMap;