Bug 1881887 - Part 2: Remove support for component JSMs. r=mccr8

Differential Revision: https://phabricator.services.mozilla.com/D233365
This commit is contained in:
Tooru Fujisawa
2025-01-21 13:37:19 +00:00
parent de3747ba1c
commit 9a53dd3fa6
5 changed files with 6 additions and 101 deletions

View File

@@ -83,15 +83,6 @@ const nsXPTInterface gInterfaces[] = {
//# @interfaces@
};
//# @define_has_component_jsms@
#ifdef HAS_COMPONENT_JSMS
// TODO: Remove this once m-c and c-c migrations finish (bug 1881887).
const StringOffset gComponentJSMs[] = {
//# @component_jsms@
};
#endif
const StringOffset gComponentESModules[] = {
//# @component_esmodules@
};
@@ -116,12 +107,9 @@ bool ContractEntry::Matches(const nsACString& aContractID) const {
return aContractID == ContractID() && Module().Active();
}
enum class ComponentType { JSM, ESM };
template <ComponentType type>
static nsresult ConstructJSMOrESMComponent(const nsACString& aURI,
const char* aConstructor,
nsISupports** aResult) {
static nsresult ConstructESModuleComponent(const nsACString& aURI,
const char* aConstructor,
nsISupports** aResult) {
if (!nsComponentManagerImpl::JSLoaderReady()) {
return NS_ERROR_NOT_AVAILABLE;
}
@@ -131,12 +119,7 @@ static nsresult ConstructJSMOrESMComponent(const nsACString& aURI,
JSContext* cx = jsapi.cx();
JS::Rooted<JSObject*> exports(cx);
if constexpr (type == ComponentType::JSM) {
JS::Rooted<JSObject*> global(cx);
MOZ_TRY(mozJSModuleLoader::Get()->Import(cx, aURI, &global, &exports));
} else {
MOZ_TRY(mozJSModuleLoader::Get()->ImportESModule(cx, aURI, &exports));
}
MOZ_TRY(mozJSModuleLoader::Get()->ImportESModule(cx, aURI, &exports));
JS::Rooted<JS::Value> ctor(cx);
if (!JS_GetProperty(cx, exports, aConstructor, &ctor) ||
@@ -153,20 +136,6 @@ static nsresult ConstructJSMOrESMComponent(const nsACString& aURI,
(void**)aResult);
}
[[maybe_unused]] static nsresult ConstructJSMComponent(const nsACString& aURI,
const char* aConstructor,
nsISupports** aResult) {
return ConstructJSMOrESMComponent<ComponentType::JSM>(
aURI, aConstructor, aResult);
}
static nsresult ConstructESModuleComponent(const nsACString& aURI,
const char* aConstructor,
nsISupports** aResult) {
return ConstructJSMOrESMComponent<ComponentType::ESM>(
aURI, aConstructor, aResult);
}
//# @module_cid_table@
//# @module_contract_id_table@
@@ -354,24 +323,6 @@ const StaticProtocolHandler* StaticProtocolHandler::Lookup(const nsACString& aSc
return false;
}
/* static */ already_AddRefed<nsIUTF8StringEnumerator>
StaticComponents::GetComponentJSMs() {
#ifdef HAS_COMPONENT_JSMS
auto jsms = MakeUnique<nsTArray<nsCString>>(std::size(gComponentJSMs));
for (const auto& entry : gComponentJSMs) {
jsms->AppendElement(GetString(entry));
}
#else
auto jsms = MakeUnique<nsTArray<nsCString>>(0);
#endif
nsCOMPtr<nsIUTF8StringEnumerator> result;
MOZ_ALWAYS_SUCCEEDS(NS_NewAdoptingUTF8StringEnumerator(getter_AddRefs(result),
jsms.release()));
return result.forget();
}
/* static */ already_AddRefed<nsIUTF8StringEnumerator>
StaticComponents::GetComponentESModules() {
auto esModules = MakeUnique<nsTArray<nsCString>>(std::size(gComponentESModules));

View File

@@ -267,7 +267,6 @@ class StaticComponents final {
static bool InvalidateContractID(const nsACString& aContractID,
bool aInvalid = true);
static already_AddRefed<nsIUTF8StringEnumerator> GetComponentJSMs();
static already_AddRefed<nsIUTF8StringEnumerator> GetComponentESModules();
static Span<const JSServiceEntry> GetJSServices();

View File

@@ -291,7 +291,6 @@ class ModuleEntry(object):
self.legacy_constructor = data.get("legacy_constructor", None)
self.init_method = data.get("init_method", [])
self.jsm = data.get("jsm", None)
self.esModule = data.get("esModule", None)
self.external = data.get(
@@ -316,17 +315,7 @@ class ModuleEntry(object):
% (str(self.cid), ", ".join(map(repr, self.contract_ids)), str_)
)
if self.jsm:
if not self.constructor:
error("JavaScript components must specify a constructor")
for prop in ("init_method", "legacy_constructor", "headers"):
if getattr(self, prop):
error(
"JavaScript components may not specify a '%s' "
"property" % prop
)
elif self.esModule:
if self.esModule:
if not self.constructor:
error("JavaScript components must specify a constructor")
@@ -428,15 +417,7 @@ class ModuleEntry(object):
)
return res
if self.jsm:
res += (
" nsCOMPtr<nsISupports> inst;\n"
" MOZ_TRY(ConstructJSMComponent(nsLiteralCString(%s),\n"
" %s,\n"
" getter_AddRefs(inst)));"
"\n" % (json.dumps(self.jsm), json.dumps(self.constructor))
)
elif self.esModule:
if self.esModule:
res += (
" nsCOMPtr<nsISupports> inst;\n"
" MOZ_TRY(ConstructESModuleComponent(nsLiteralCString(%s),\n"
@@ -874,7 +855,6 @@ def gen_substs(manifests):
js_services = {}
protocol_handlers = {}
jsms = set()
esModules = set()
types = set()
@@ -897,9 +877,6 @@ def gen_substs(manifests):
if mod.type and not mod.headers:
types.add(mod.type)
if mod.jsm:
jsms.add(mod.jsm)
if mod.esModule:
esModules.add(mod.esModule)
@@ -955,12 +932,6 @@ def gen_substs(manifests):
gen_includes(substs, headers)
substs["component_jsms"] = (
"\n".join(" %s," % strings.entry_to_cxx(jsm) for jsm in sorted(jsms)) + "\n"
)
substs["define_has_component_jsms"] = (
"#define HAS_COMPONENT_JSMS" if len(jsms) > 0 else ""
)
substs["component_esmodules"] = (
"\n".join(
" %s," % strings.entry_to_cxx(esModule) for esModule in sorted(esModules)

View File

@@ -1471,14 +1471,6 @@ nsComponentManagerImpl::RemoveBootstrappedManifestLocation(nsIFile* aLocation) {
return rv;
}
NS_IMETHODIMP
nsComponentManagerImpl::GetComponentJSMs(nsIUTF8StringEnumerator** aJSMs) {
nsCOMPtr<nsIUTF8StringEnumerator> result =
StaticComponents::GetComponentJSMs();
result.forget(aJSMs);
return NS_OK;
}
NS_IMETHODIMP
nsComponentManagerImpl::GetComponentESModules(
nsIUTF8StringEnumerator** aESModules) {

View File

@@ -96,14 +96,6 @@ interface nsIComponentManager : nsISupports
*/
nsIArray getManifestLocations();
/**
* Returns a list of JSM URLs which are used to create components. This
* should only be used in automation.
*
* TODO: Remove this once m-c and c-c migrations finish (bug 1881887).
*/
nsIUTF8StringEnumerator getComponentJSMs();
/**
* Returns a list of ESM URLs which are used to create components. This
* should only be used in automation.