|
26 | 26 | #include "mozilla/CycleCollectedJSContext.h" |
27 | 27 | #include "mozilla/LoadInfo.h" |
28 | 28 | #include "mozilla/Maybe.h" |
29 | | -#include "mozilla/StyleSheet.h" |
30 | | -#include "mozilla/StyleSheetInlines.h" |
31 | 29 | #include "mozilla/dom/AutoEntryScript.h" |
32 | 30 | #include "mozilla/dom/Document.h" |
33 | 31 | #include "mozilla/dom/Element.h" |
@@ -221,10 +219,9 @@ nsresult ModuleLoader::CompileFetchedModule( |
221 | 219 | MOZ_CRASH("Unexpected module type"); |
222 | 220 | case JS::ModuleType::JavaScript: |
223 | 221 | return CompileJavaScriptModule(aCx, aOptions, aRequest, aModuleOut); |
224 | | - case JS::ModuleType::JSON: |
| 222 | + case JS::ModuleType::JSON: { |
225 | 223 | return CompileJsonModule(aCx, aOptions, aRequest, aModuleOut); |
226 | | - case JS::ModuleType::CSS: |
227 | | - return CompileCssModule(aCx, aOptions, aRequest, aModuleOut); |
| 224 | + } |
228 | 225 | } |
229 | 226 |
|
230 | 227 | MOZ_CRASH("Unhandled module type"); |
@@ -356,89 +353,6 @@ nsresult ModuleLoader::CompileJsonModule( |
356 | 353 | return NS_OK; |
357 | 354 | } |
358 | 355 |
|
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 | | - |
442 | 356 | already_AddRefed<ModuleLoadRequest> ModuleLoader::CreateTopLevel( |
443 | 357 | nsIURI* aURI, nsIScriptElement* aElement, ReferrerPolicy aReferrerPolicy, |
444 | 358 | ScriptFetchOptions* aFetchOptions, const SRIMetadata& aIntegrity, |
|
0 commit comments