Skip to content

Commit c5ace57

Browse files
author
Atila Butkovits
committed
Revert "Bug 1720570: apply code formatting via Lando" for causing Hazard failures.
This reverts commit 8267f4a. Revert "Bug 1720570 - Update web-platform test expectations; r=layout-reviewers,emilio" This reverts commit 0a8f6fa. Revert "Bug 1720570 - Use backgroundImage in relative-urls.html; r=layout-reviewers,emilio" This reverts commit 886bec5. Revert "Bug 1720570 - Support fetching css module scripts; r=dom-core,smaug" This reverts commit 161decf. Revert "Bug 1720570 - Add support for css modules in ModuleLoader, WorkerModuleLoader and WorkletModuleLoader; r=allstarschh,dom-core,emilio,smaug" This reverts commit 1c0eba5. Revert "Bug 1720570 - Break out separate method to create constructed stylesheets; r=layout-reviewers,firefox-style-system-reviewers,emilio" This reverts commit 0552b0f. Revert "Bug 1720570 - Move ModuleTypeAllowed check into ModuleLoaderBase; r=allstarschh" This reverts commit b3be3d8. Revert "Bug 1720570 - Handle css module in GetModuleType; r=allstarschh" This reverts commit 6ff53c0. Revert "Bug 1720570 - Add CreateCssModule; r=allstarschh" This reverts commit cf4c677. Revert "Bug 1720570 - Add ModuleType::CSS; r=allstarschh" This reverts commit e5f6251. Revert "Bug 1720570 - Add pref for css module scripts; r=layout-reviewers,emilio" This reverts commit 9155521.
1 parent 7b1759d commit c5ace57

34 files changed

+151
-296
lines changed

dom/base/nsContentUtils.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8659,11 +8659,6 @@ bool nsContentUtils::IsJsonMimeType(const nsAString& aMimeType) {
86598659
return StringEndsWith(subtype, u"+json"_ns);
86608660
}
86618661

8662-
// https://html.spec.whatwg.org/#fetch-a-single-module-script, 7.3
8663-
bool nsContentUtils::IsCssMimeType(const nsAString& aMimeType) {
8664-
return aMimeType.LowerCaseEqualsLiteral("text/css");
8665-
}
8666-
86678662
bool nsContentUtils::PrefetchPreloadEnabled(nsIDocShell* aDocShell) {
86688663
//
86698664
// SECURITY CHECK: disable prefetching and preloading from mailnews!

dom/base/nsContentUtils.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2740,12 +2740,6 @@ class nsContentUtils {
27402740
*/
27412741
static bool IsJsonMimeType(const nsAString& aMimeType);
27422742

2743-
/**
2744-
* Returns true if the given MIME type string is a valid CSS MIME type,
2745-
* otherwise false.
2746-
*/
2747-
static bool IsCssMimeType(const nsAString& aMimeType);
2748-
27492743
static void SplitMimeType(const nsAString& aValue, nsString& aType,
27502744
nsString& aParams);
27512745

dom/script/ModuleLoader.cpp

Lines changed: 2 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
#include "mozilla/CycleCollectedJSContext.h"
2727
#include "mozilla/LoadInfo.h"
2828
#include "mozilla/Maybe.h"
29-
#include "mozilla/StyleSheet.h"
30-
#include "mozilla/StyleSheetInlines.h"
3129
#include "mozilla/dom/AutoEntryScript.h"
3230
#include "mozilla/dom/Document.h"
3331
#include "mozilla/dom/Element.h"
@@ -221,10 +219,9 @@ nsresult ModuleLoader::CompileFetchedModule(
221219
MOZ_CRASH("Unexpected module type");
222220
case JS::ModuleType::JavaScript:
223221
return CompileJavaScriptModule(aCx, aOptions, aRequest, aModuleOut);
224-
case JS::ModuleType::JSON:
222+
case JS::ModuleType::JSON: {
225223
return CompileJsonModule(aCx, aOptions, aRequest, aModuleOut);
226-
case JS::ModuleType::CSS:
227-
return CompileCssModule(aCx, aOptions, aRequest, aModuleOut);
224+
}
228225
}
229226

230227
MOZ_CRASH("Unhandled module type");
@@ -356,89 +353,6 @@ nsresult ModuleLoader::CompileJsonModule(
356353
return NS_OK;
357354
}
358355

359-
nsresult ModuleLoader::CompileCssModule(
360-
JSContext* aCx, JS::CompileOptions& aOptions, ModuleLoadRequest* aRequest,
361-
JS::MutableHandle<JSObject*> aModuleOut) {
362-
MOZ_ASSERT(!aRequest->GetScriptLoadContext()->mWasCompiledOMT);
363-
MOZ_ASSERT(mozilla::StaticPrefs::layout_css_module_scripts_enabled());
364-
365-
MOZ_ASSERT(aRequest->IsTextSource());
366-
ModuleLoader::MaybeSourceText maybeSource;
367-
nsresult rv = aRequest->GetScriptSource(aCx, &maybeSource,
368-
aRequest->mLoadContext.get());
369-
NS_ENSURE_SUCCESS(rv, rv);
370-
371-
// https://html.spec.whatwg.org/#creating-a-css-module-script
372-
ErrorResult error;
373-
auto compile = [&](auto& source) -> JSObject* {
374-
using T = decltype(source);
375-
static_assert(std::is_same_v<T, JS::SourceText<char16_t>&> ||
376-
std::is_same_v<T, JS::SourceText<Utf8Unit>&>);
377-
378-
nsCOMPtr<nsPIDOMWindowInner> window =
379-
do_QueryInterface(aRequest->GetGlobalObject());
380-
if (!window) {
381-
error.ThrowNotSupportedError("Not supported when there is no document");
382-
return nullptr;
383-
}
384-
385-
Document* constructorDocument = window->GetExtantDoc();
386-
if (!constructorDocument) {
387-
error.ThrowNotSupportedError("Not supported when there is no document");
388-
return nullptr;
389-
}
390-
391-
// 5. Let sheet be the result of running the steps to create a constructed
392-
// CSSStyleSheet
393-
// with an empty dictionary as the argument.
394-
// Note that according to the specification, the baseURL should be the
395-
// baseURL of the document, but that doesn't seem correct (see
396-
// https://github.com/whatwg/html/issues/11629).
397-
dom::CSSStyleSheetInit options;
398-
RefPtr<StyleSheet> sheet = StyleSheet::CreateConstructedSheet(
399-
*constructorDocument, aRequest->mBaseURL, options, error);
400-
if (error.Failed()) {
401-
return nullptr;
402-
}
403-
404-
// 6. Run the steps to synchronously replace the rules of a CSSStyleSheet on
405-
// sheet given source. Ideally we wouldn't run this on the main thread for
406-
// large scripts, see https://bugzilla.mozilla.org/show_bug.cgi?id=1987143.
407-
if constexpr (std::is_same_v<T, JS::SourceText<mozilla::Utf8Unit>&>) {
408-
nsDependentCSubstring text(source.get(), source.length());
409-
sheet->ReplaceSync(text, error);
410-
} else if constexpr (std::is_same_v<T, JS::SourceText<char16_t>&>) {
411-
nsDependentSubstring text(source.get(), source.length());
412-
sheet->ReplaceSync(NS_ConvertUTF16toUTF8(text), error);
413-
}
414-
if (error.Failed()) {
415-
return nullptr;
416-
}
417-
418-
JS::Rooted<JS::Value> val(aCx, JS::NullValue());
419-
if (!GetOrCreateDOMReflector(aCx, sheet, &val) || !val.isObject()) {
420-
if (!JS_IsExceptionPending(aCx)) {
421-
error.ThrowUnknownError("Internal error");
422-
}
423-
return nullptr;
424-
}
425-
426-
// Steps. 1 - 4 (re-ordered), 7, 8
427-
return JS::CreateCssModule(aCx, aOptions, val);
428-
};
429-
430-
auto* cssModule = maybeSource.mapNonEmpty(compile);
431-
if (!cssModule) {
432-
if (error.Failed()) {
433-
MOZ_ALWAYS_TRUE(error.MaybeSetPendingException(aCx));
434-
}
435-
return NS_ERROR_FAILURE;
436-
}
437-
438-
aModuleOut.set(cssModule);
439-
return NS_OK;
440-
}
441-
442356
already_AddRefed<ModuleLoadRequest> ModuleLoader::CreateTopLevel(
443357
nsIURI* aURI, nsIScriptElement* aElement, ReferrerPolicy aReferrerPolicy,
444358
ScriptFetchOptions* aFetchOptions, const SRIMetadata& aIntegrity,

dom/script/ModuleLoader.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ class ModuleLoader final : public JS::loader::ModuleLoaderBase {
9292
nsresult CompileJsonModule(JSContext* aCx, JS::CompileOptions& aOptions,
9393
ModuleLoadRequest* aRequest,
9494
JS::MutableHandle<JSObject*> aModuleOut);
95-
nsresult CompileCssModule(JSContext* aCx, JS::CompileOptions& aOptions,
96-
ModuleLoadRequest* aRequest,
97-
JS::MutableHandle<JSObject*> aModuleOut);
9895

9996
private:
10097
const Kind mKind;

dom/script/ScriptLoader.cpp

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -430,32 +430,20 @@ nsContentPolicyType ScriptLoadRequestToContentPolicyType(
430430
ScriptLoadRequest* aRequest) {
431431
if (aRequest->GetScriptLoadContext()->IsPreload()) {
432432
if (aRequest->IsModuleRequest()) {
433-
switch (aRequest->AsModuleRequest()->mModuleType) {
434-
case JS::ModuleType::JavaScript:
435-
return nsIContentPolicy::TYPE_INTERNAL_MODULE_PRELOAD;
436-
case JS::ModuleType::JSON:
437-
return nsIContentPolicy::TYPE_INTERNAL_JSON_PRELOAD;
438-
case JS::ModuleType::CSS:
439-
return nsIContentPolicy::TYPE_INTERNAL_STYLESHEET_PRELOAD;
440-
case JS::ModuleType::Unknown:
441-
MOZ_ASSERT_UNREACHABLE("Unknown module type");
442-
}
433+
return aRequest->AsModuleRequest()->mModuleType ==
434+
JS::ModuleType::JavaScript
435+
? nsIContentPolicy::TYPE_INTERNAL_MODULE_PRELOAD
436+
: nsIContentPolicy::TYPE_INTERNAL_JSON_PRELOAD;
443437
}
444438

445439
return nsIContentPolicy::TYPE_INTERNAL_SCRIPT_PRELOAD;
446440
}
447441

448442
if (aRequest->IsModuleRequest()) {
449-
switch (aRequest->AsModuleRequest()->mModuleType) {
450-
case JS::ModuleType::Unknown:
451-
MOZ_CRASH("Unexpected module type");
452-
case JS::ModuleType::JavaScript:
453-
return nsIContentPolicy::TYPE_INTERNAL_MODULE;
454-
case JS::ModuleType::JSON:
455-
return nsIContentPolicy::TYPE_JSON;
456-
case JS::ModuleType::CSS:
457-
return nsIContentPolicy::TYPE_STYLESHEET;
458-
}
443+
return aRequest->AsModuleRequest()->mModuleType ==
444+
JS::ModuleType::JavaScript
445+
? nsIContentPolicy::TYPE_INTERNAL_MODULE
446+
: nsIContentPolicy::TYPE_JSON;
459447
}
460448

461449
return nsIContentPolicy::TYPE_INTERNAL_SCRIPT;
@@ -1975,12 +1963,10 @@ nsresult ScriptLoader::AttemptOffThreadScriptCompile(
19751963
return NS_OK;
19761964
}
19771965

1978-
// Don't off-thread compile JSON or CSS modules.
1979-
// https://bugzilla.mozilla.org/show_bug.cgi?id=1912112 (JSON)
1980-
// https://bugzilla.mozilla.org/show_bug.cgi?id=1987143 (CSS)
1966+
// Don't off-thread compile JSON modules.
1967+
// https://bugzilla.mozilla.org/show_bug.cgi?id=1912112
19811968
if (aRequest->IsModuleRequest() &&
1982-
(aRequest->AsModuleRequest()->mModuleType == JS::ModuleType::JSON ||
1983-
aRequest->AsModuleRequest()->mModuleType == JS::ModuleType::CSS)) {
1969+
aRequest->AsModuleRequest()->mModuleType == JS::ModuleType::JSON) {
19841970
return NS_OK;
19851971
}
19861972

@@ -4433,11 +4419,6 @@ static bool MimeTypeMatchesExpectedModuleType(
44334419
return true;
44344420
}
44354421

4436-
if (expectedModuleType == JS::ModuleType::CSS &&
4437-
nsContentUtils::IsCssMimeType(typeString)) {
4438-
return true;
4439-
}
4440-
44414422
return false;
44424423
}
44434424

dom/workers/loader/WorkerModuleLoader.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ nsresult WorkerModuleLoader::CompileFetchedModule(
151151
return CompileJavaScriptModule(aCx, aOptions, aRequest, aModuleScript);
152152
case JS::ModuleType::JSON:
153153
return CompileJsonModule(aCx, aOptions, aRequest, aModuleScript);
154-
case JS::ModuleType::CSS:
155-
MOZ_CRASH("CSS modules are not supported in workers");
156154
}
157155

158156
MOZ_CRASH("Unhandled module type");

dom/workers/loader/WorkerModuleLoader.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,6 @@ class WorkerModuleLoader : public JS::loader::ModuleLoaderBase {
9191
void OnModuleLoadComplete(ModuleLoadRequest* aRequest) override;
9292

9393
bool IsModuleEvaluationAborted(ModuleLoadRequest* aRequest) override;
94-
95-
bool IsModuleTypeAllowed(JS::ModuleType aModuleType) override {
96-
// https://html.spec.whatwg.org/#module-type-allowed
97-
// If moduleType is "css" and the CSSStyleSheet interface is not exposed in
98-
// settings's realm, then return false.
99-
return aModuleType != JS::ModuleType::Unknown &&
100-
aModuleType != JS::ModuleType::CSS;
101-
}
10294
};
10395

10496
} // namespace mozilla::dom::workerinternals::loader

dom/worklet/loader/WorkletModuleLoader.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ nsresult WorkletModuleLoader::CompileFetchedModule(
103103
return CompileJavaScriptModule(aCx, aOptions, aRequest, aModuleScript);
104104
case JS::ModuleType::JSON:
105105
return CompileJsonModule(aCx, aOptions, aRequest, aModuleScript);
106-
case JS::ModuleType::CSS:
107-
MOZ_CRASH("CSS modules are not supported in worklets");
108106
}
109107

110108
MOZ_CRASH("Unhandled module type");

dom/worklet/loader/WorkletModuleLoader.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,6 @@ class WorkletModuleLoader : public JS::loader::ModuleLoaderBase {
9696
const nsAString& aSpecifier,
9797
nsAString& aResult) override;
9898

99-
bool IsModuleTypeAllowed(JS::ModuleType aModuleType) override {
100-
// https://html.spec.whatwg.org/#module-type-allowed
101-
// If moduleType is "css" and the CSSStyleSheet interface is not exposed in
102-
// settings's realm, then return false.
103-
return aModuleType != JS::ModuleType::Unknown &&
104-
aModuleType != JS::ModuleType::CSS;
105-
}
106-
10799
// A hashtable to map a nsIURI(from main thread) to a ModuleLoadRequest(in
108100
// worklet thread).
109101
nsRefPtrHashtable<nsURIHashKey, JS::loader::ModuleLoadRequest>

js/loader/ModuleLoaderBase.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ void ModuleLoaderBase::EnsureModuleHooksInitialized() {
101101
HostReleaseTopLevelScript);
102102
}
103103

104+
static bool ModuleTypeAllowed(ModuleType aModuleType) {
105+
return aModuleType != ModuleType::Unknown;
106+
}
107+
104108
static bool CreateBadModuleTypeError(JSContext* aCx, LoadedScript* aScript,
105109
nsIURI* aURI,
106110
MutableHandle<Value> aErrorOut) {
@@ -215,7 +219,7 @@ bool ModuleLoaderBase::HostLoadImportedModule(JSContext* aCx,
215219
MOZ_ASSERT(uri, "Failed to resolve module specifier");
216220

217221
ModuleType moduleType = GetModuleRequestType(aCx, aModuleRequest);
218-
if (!loader->IsModuleTypeAllowed(moduleType)) {
222+
if (!ModuleTypeAllowed(moduleType)) {
219223
LOG(("ModuleLoaderBase::HostLoadImportedModule uri %s, bad module type",
220224
uri->GetSpecOrDefault().get()));
221225
Rooted<Value> error(aCx);

0 commit comments

Comments
 (0)