зеркало из https://github.com/mozilla/gecko-dev.git
Backed out 8 changesets (bug 1771092, bug 1768870
, bug 1771097, bug 1769002, bug 1768819) for causing mochitest failures on browser_sendQuery.js. CLOSED TREE
Backed out changeset 8a4d712f819a (bug 1771092) Backed out changeset f4e27a35c83c (bug 1771092) Backed out changeset 072323bc72cc (bug 1771092) Backed out changeset 2ccf2a00fff7 (bug 1769002) Backed out changeset ba7086fd9b1f (bug 1768819) Backed out changeset 6205d3e2c666 (bug 1771097) Backed out changeset 960f0aee97d5 (bug1768870
) Backed out changeset 5f53760c5637 (bug1768870
)
This commit is contained in:
Родитель
33e4a145c6
Коммит
8fc8ec5d8e
|
@ -832,7 +832,6 @@ add_task(async function checkAllTheFiles() {
|
|||
".mjs",
|
||||
".js",
|
||||
".jsm",
|
||||
".mjs",
|
||||
".json",
|
||||
".html",
|
||||
".xhtml",
|
||||
|
@ -881,9 +880,6 @@ add_task(async function checkAllTheFiles() {
|
|||
for (let jsm of Components.manager.getComponentJSMs()) {
|
||||
gReferencesFromCode.set(jsm, null);
|
||||
}
|
||||
for (let esModule of Components.manager.getComponentESModules()) {
|
||||
gReferencesFromCode.set(esModule, null);
|
||||
}
|
||||
|
||||
// manifest.json is a common name, it is used for WebExtension manifests
|
||||
// but also for other things. To tell them apart, we have to actually
|
||||
|
|
|
@ -33,7 +33,6 @@ The plugin implements the following rules:
|
|||
eslint-plugin-mozilla/import-globals
|
||||
eslint-plugin-mozilla/import-globals-from
|
||||
eslint-plugin-mozilla/import-headjs-globals
|
||||
eslint-plugin-mozilla/lazy-getter-object-name
|
||||
eslint-plugin-mozilla/mark-exported-symbols-as-used
|
||||
eslint-plugin-mozilla/mark-test-function-used
|
||||
eslint-plugin-mozilla/no-aArgs
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
lazy-getter-object-name
|
||||
=============================
|
||||
|
||||
Enforce the standard object variable name ``lazy`` for
|
||||
``ChromeUtils.defineESModuleGetters``
|
||||
|
||||
Examples of incorrect code for this rule:
|
||||
-----------------------------------------
|
||||
|
||||
.. code-block:: js
|
||||
|
||||
const obj = {};
|
||||
ChromeUtils.defineESModuleGetters(obj, {
|
||||
Services: “resource://gre/modules/Services.sys.mjs”,
|
||||
});
|
||||
|
||||
Examples of correct code for this rule:
|
||||
---------------------------------------
|
||||
|
||||
.. code-block:: js
|
||||
|
||||
const lazy = {};
|
||||
ChromeUtils.defineESModuleGetters(lazy, {
|
||||
Services: “resource://gre/modules/Services.sys.mjs”,
|
||||
});
|
|
@ -8,10 +8,9 @@
|
|||
|
||||
#include "js/CharacterEncoding.h"
|
||||
#include "js/Object.h" // JS::GetClass
|
||||
#include "js/PropertyAndElement.h" // JS_DefineProperty, JS_DefinePropertyById, JS_Enumerate, JS_GetProperty, JS_GetPropertyById, JS_SetProperty, JS_SetPropertyById, JS::IdVector
|
||||
#include "js/PropertyAndElement.h" // JS_DefineProperty, JS_DefinePropertyById, JS_Enumerate, JS_GetProperty, JS_GetPropertyById, JS_SetProperty, JS_SetPropertyById
|
||||
#include "js/PropertyDescriptor.h" // JS::PropertyDescriptor, JS_GetOwnPropertyDescriptorById
|
||||
#include "js/SavedFrameAPI.h"
|
||||
#include "js/Value.h" // JS::Value, JS::StringValue
|
||||
#include "jsfriendapi.h"
|
||||
#include "WrapperFactory.h"
|
||||
|
||||
|
@ -627,10 +626,7 @@ static bool ExtractArgs(JSContext* aCx, JS::CallArgs& aArgs,
|
|||
return true;
|
||||
}
|
||||
|
||||
enum class ModuleType { JSM, ESM };
|
||||
|
||||
static bool ModuleGetterImpl(JSContext* aCx, unsigned aArgc, JS::Value* aVp,
|
||||
ModuleType aType) {
|
||||
static bool ModuleGetter(JSContext* aCx, unsigned aArgc, JS::Value* aVp) {
|
||||
JS::CallArgs args = JS::CallArgsFromVp(aArgc, aVp);
|
||||
|
||||
JS::Rooted<JSObject*> callee(aCx);
|
||||
|
@ -651,38 +647,17 @@ static bool ModuleGetterImpl(JSContext* aCx, unsigned aArgc, JS::Value* aVp,
|
|||
RefPtr<mozJSComponentLoader> moduleloader = mozJSComponentLoader::Get();
|
||||
MOZ_ASSERT(moduleloader);
|
||||
|
||||
JS::Rooted<JSObject*> moduleGlobal(aCx);
|
||||
JS::Rooted<JSObject*> moduleExports(aCx);
|
||||
nsresult rv = moduleloader->Import(aCx, uri, &moduleGlobal, &moduleExports);
|
||||
if (NS_FAILED(rv)) {
|
||||
Throw(aCx, rv);
|
||||
return false;
|
||||
}
|
||||
|
||||
JS::Rooted<JS::Value> value(aCx);
|
||||
if (aType == ModuleType::JSM) {
|
||||
JS::Rooted<JSObject*> moduleGlobal(aCx);
|
||||
JS::Rooted<JSObject*> moduleExports(aCx);
|
||||
nsresult rv = moduleloader->Import(aCx, uri, &moduleGlobal, &moduleExports);
|
||||
if (NS_FAILED(rv)) {
|
||||
Throw(aCx, rv);
|
||||
return false;
|
||||
}
|
||||
|
||||
// JSM's exports is from the same realm.
|
||||
if (!JS_GetPropertyById(aCx, moduleExports, id, &value)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
JS::Rooted<JSObject*> moduleNamespace(aCx);
|
||||
nsresult rv = moduleloader->ImportESModule(aCx, uri, &moduleNamespace);
|
||||
if (NS_FAILED(rv)) {
|
||||
Throw(aCx, rv);
|
||||
return false;
|
||||
}
|
||||
|
||||
// ESM's namespace is from the module's realm.
|
||||
{
|
||||
JSAutoRealm ar(aCx, moduleNamespace);
|
||||
if (!JS_GetPropertyById(aCx, moduleNamespace, id, &value)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!JS_WrapValue(aCx, &value)) {
|
||||
return false;
|
||||
}
|
||||
if (!JS_GetPropertyById(aCx, moduleExports, id, &value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!JS_DefinePropertyById(aCx, thisObj, id, value, JSPROP_ENUMERATE)) {
|
||||
|
@ -693,15 +668,7 @@ static bool ModuleGetterImpl(JSContext* aCx, unsigned aArgc, JS::Value* aVp,
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool JSModuleGetter(JSContext* aCx, unsigned aArgc, JS::Value* aVp) {
|
||||
return ModuleGetterImpl(aCx, aArgc, aVp, ModuleType::JSM);
|
||||
}
|
||||
|
||||
static bool ESModuleGetter(JSContext* aCx, unsigned aArgc, JS::Value* aVp) {
|
||||
return ModuleGetterImpl(aCx, aArgc, aVp, ModuleType::ESM);
|
||||
}
|
||||
|
||||
static bool ModuleSetterImpl(JSContext* aCx, unsigned aArgc, JS::Value* aVp) {
|
||||
static bool ModuleSetter(JSContext* aCx, unsigned aArgc, JS::Value* aVp) {
|
||||
JS::CallArgs args = JS::CallArgsFromVp(aArgc, aVp);
|
||||
|
||||
JS::Rooted<JSObject*> callee(aCx);
|
||||
|
@ -714,17 +681,8 @@ static bool ModuleSetterImpl(JSContext* aCx, unsigned aArgc, JS::Value* aVp) {
|
|||
return JS_DefinePropertyById(aCx, thisObj, id, args.get(0), JSPROP_ENUMERATE);
|
||||
}
|
||||
|
||||
static bool JSModuleSetter(JSContext* aCx, unsigned aArgc, JS::Value* aVp) {
|
||||
return ModuleSetterImpl(aCx, aArgc, aVp);
|
||||
}
|
||||
|
||||
static bool ESModuleSetter(JSContext* aCx, unsigned aArgc, JS::Value* aVp) {
|
||||
return ModuleSetterImpl(aCx, aArgc, aVp);
|
||||
}
|
||||
|
||||
static bool DefineJSModuleGetter(JSContext* aCx, JS::Handle<JSObject*> aTarget,
|
||||
const nsAString& aId,
|
||||
const nsAString& aResourceURI) {
|
||||
static bool DefineGetter(JSContext* aCx, JS::Handle<JSObject*> aTarget,
|
||||
const nsAString& aId, const nsAString& aResourceURI) {
|
||||
JS::Rooted<JS::Value> uri(aCx);
|
||||
JS::Rooted<JS::Value> idValue(aCx);
|
||||
JS::Rooted<jsid> id(aCx);
|
||||
|
@ -737,11 +695,11 @@ static bool DefineJSModuleGetter(JSContext* aCx, JS::Handle<JSObject*> aTarget,
|
|||
|
||||
JS::Rooted<JSObject*> getter(
|
||||
aCx, JS_GetFunctionObject(
|
||||
js::NewFunctionByIdWithReserved(aCx, JSModuleGetter, 0, 0, id)));
|
||||
js::NewFunctionByIdWithReserved(aCx, ModuleGetter, 0, 0, id)));
|
||||
|
||||
JS::Rooted<JSObject*> setter(
|
||||
aCx, JS_GetFunctionObject(
|
||||
js::NewFunctionByIdWithReserved(aCx, JSModuleSetter, 0, 0, id)));
|
||||
js::NewFunctionByIdWithReserved(aCx, ModuleSetter, 0, 0, id)));
|
||||
|
||||
if (!getter || !setter) {
|
||||
JS_ReportOutOfMemory(aCx);
|
||||
|
@ -756,33 +714,6 @@ static bool DefineJSModuleGetter(JSContext* aCx, JS::Handle<JSObject*> aTarget,
|
|||
return JS_DefinePropertyById(aCx, aTarget, id, getter, setter,
|
||||
JSPROP_ENUMERATE);
|
||||
}
|
||||
|
||||
static bool DefineESModuleGetter(JSContext* aCx, JS::Handle<JSObject*> aTarget,
|
||||
JS::Handle<JS::PropertyKey> aId,
|
||||
JS::Handle<JS::Value> aResourceURI) {
|
||||
JS::Rooted<JS::Value> idVal(aCx, JS::StringValue(aId.toString()));
|
||||
|
||||
JS::Rooted<JSObject*> getter(
|
||||
aCx, JS_GetFunctionObject(js::NewFunctionByIdWithReserved(
|
||||
aCx, ESModuleGetter, 0, 0, aId)));
|
||||
|
||||
JS::Rooted<JSObject*> setter(
|
||||
aCx, JS_GetFunctionObject(js::NewFunctionByIdWithReserved(
|
||||
aCx, ESModuleSetter, 0, 0, aId)));
|
||||
|
||||
if (!getter || !setter) {
|
||||
JS_ReportOutOfMemory(aCx);
|
||||
return false;
|
||||
}
|
||||
|
||||
js::SetFunctionNativeReserved(getter, SLOT_ID, idVal);
|
||||
js::SetFunctionNativeReserved(setter, SLOT_ID, idVal);
|
||||
|
||||
js::SetFunctionNativeReserved(getter, SLOT_URI, aResourceURI);
|
||||
|
||||
return JS_DefinePropertyById(aCx, aTarget, aId, getter, setter,
|
||||
JSPROP_ENUMERATE);
|
||||
}
|
||||
} // namespace module_getter
|
||||
|
||||
/* static */
|
||||
|
@ -791,48 +722,11 @@ void ChromeUtils::DefineModuleGetter(const GlobalObject& global,
|
|||
const nsAString& id,
|
||||
const nsAString& resourceURI,
|
||||
ErrorResult& aRv) {
|
||||
if (!module_getter::DefineJSModuleGetter(global.Context(), target, id,
|
||||
resourceURI)) {
|
||||
if (!module_getter::DefineGetter(global.Context(), target, id, resourceURI)) {
|
||||
aRv.NoteJSContextException(global.Context());
|
||||
}
|
||||
}
|
||||
|
||||
/* static */
|
||||
void ChromeUtils::DefineESModuleGetters(const GlobalObject& global,
|
||||
JS::Handle<JSObject*> target,
|
||||
JS::Handle<JSObject*> modules,
|
||||
ErrorResult& aRv) {
|
||||
auto cx = global.Context();
|
||||
|
||||
JS::Rooted<JS::IdVector> props(cx, JS::IdVector(cx));
|
||||
if (!JS_Enumerate(cx, modules, &props)) {
|
||||
aRv.NoteJSContextException(cx);
|
||||
return;
|
||||
}
|
||||
|
||||
JS::Rooted<JS::PropertyKey> prop(cx);
|
||||
JS::Rooted<JS::Value> resourceURIVal(cx);
|
||||
for (JS::PropertyKey tmp : props) {
|
||||
prop = tmp;
|
||||
|
||||
if (!prop.isString()) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!JS_GetPropertyById(cx, modules, prop, &resourceURIVal)) {
|
||||
aRv.NoteJSContextException(cx);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!module_getter::DefineESModuleGetter(cx, target, prop,
|
||||
resourceURIVal)) {
|
||||
aRv.NoteJSContextException(cx);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* static */
|
||||
void ChromeUtils::OriginAttributesToSuffix(
|
||||
dom::GlobalObject& aGlobal, const dom::OriginAttributesDictionary& aAttrs,
|
||||
|
|
|
@ -211,11 +211,6 @@ class ChromeUtils {
|
|||
const nsAString& resourceURI,
|
||||
ErrorResult& aRv);
|
||||
|
||||
static void DefineESModuleGetters(const GlobalObject& global,
|
||||
JS::Handle<JSObject*> target,
|
||||
JS::Handle<JSObject*> modules,
|
||||
ErrorResult& aRv);
|
||||
|
||||
static void GetCallerLocation(const GlobalObject& global,
|
||||
nsIPrincipal* principal,
|
||||
JS::MutableHandle<JSObject*> aRetval);
|
||||
|
|
|
@ -475,18 +475,6 @@ partial namespace ChromeUtils {
|
|||
[Throws]
|
||||
void defineModuleGetter(object target, DOMString id, DOMString resourceURI);
|
||||
|
||||
/**
|
||||
* Defines propertys on the given target which lazily imports a ES module
|
||||
* when accessed.
|
||||
*
|
||||
* @param target The target object on which to define the property.
|
||||
* @param modules An object with a property for each module property to be
|
||||
* imported, where the property name is the name of the
|
||||
* imported symbol and the value is the module URI.
|
||||
*/
|
||||
[Throws]
|
||||
void defineESModuleGetters(object target, object modules);
|
||||
|
||||
/**
|
||||
* Returns the scripted location of the first ancestor stack frame with a
|
||||
* principal which is subsumed by the given principal. If no such frame
|
||||
|
|
|
@ -62,24 +62,10 @@ dictionary ProcessActorOptions {
|
|||
dictionary ProcessActorSidedOptions {
|
||||
/**
|
||||
* The JSM path which should be loaded for the actor on this side.
|
||||
*
|
||||
* Mutually exclusive with `esModuleURI`.
|
||||
*
|
||||
* If neither this nor `esModuleURI` is passed, the specified side cannot receive
|
||||
* messages, but may send them using `sendAsyncMessage` or `sendQuery`.
|
||||
* If not passed, the specified side cannot receive messages, but may send
|
||||
* them using `sendAsyncMessage` or `sendQuery`.
|
||||
*/
|
||||
ByteString moduleURI;
|
||||
|
||||
/**
|
||||
* The ESM path which should be loaded for the actor on this side.
|
||||
*
|
||||
* Mutually exclusive with `moduleURI`.
|
||||
*
|
||||
* If neither this nor `moduleURI` is passed, the specified side cannot
|
||||
* receive messages, but may send them using `sendAsyncMessage` or
|
||||
* `sendQuery`.
|
||||
*/
|
||||
ByteString esModuleURI;
|
||||
required ByteString moduleURI;
|
||||
};
|
||||
|
||||
dictionary ProcessActorChildOptions : ProcessActorSidedOptions {
|
||||
|
|
|
@ -127,24 +127,10 @@ dictionary WindowActorOptions {
|
|||
dictionary WindowActorSidedOptions {
|
||||
/**
|
||||
* The JSM path which should be loaded for the actor on this side.
|
||||
*
|
||||
* Mutually exclusive with `esModuleURI`.
|
||||
*
|
||||
* If neither this nor `esModuleURI` is passed, the specified side cannot receive
|
||||
* messages, but may send them using `sendAsyncMessage` or `sendQuery`.
|
||||
* If not passed, the specified side cannot receive messages, but may send
|
||||
* them using `sendAsyncMessage` or `sendQuery`.
|
||||
*/
|
||||
ByteString moduleURI;
|
||||
|
||||
/**
|
||||
* The ESM path which should be loaded for the actor on this side.
|
||||
*
|
||||
* Mutually exclusive with `moduleURI`.
|
||||
*
|
||||
* If neither this nor `moduleURI` is passed, the specified side cannot
|
||||
* receive messages, but may send them using `sendAsyncMessage` or
|
||||
* `sendQuery`.
|
||||
*/
|
||||
ByteString esModuleURI;
|
||||
required ByteString moduleURI;
|
||||
};
|
||||
|
||||
dictionary WindowActorEventListenerOptions : AddEventListenerOptions {
|
||||
|
|
|
@ -294,10 +294,6 @@ struct JSWindowActorInfo
|
|||
nsCString name;
|
||||
bool allFrames;
|
||||
|
||||
// True if `url` is for ESM.
|
||||
// False if `url` is for JSM or nothing.
|
||||
bool isESModule;
|
||||
|
||||
// The module of the url.
|
||||
nsCString? url;
|
||||
|
||||
|
@ -314,11 +310,6 @@ struct JSProcessActorInfo
|
|||
{
|
||||
// The name of the actor.
|
||||
nsCString name;
|
||||
|
||||
// True if `url` is for ESM.
|
||||
// False if `url` is for JSM or nothing.
|
||||
bool isESModule;
|
||||
|
||||
// The module of the url.
|
||||
nsCString? url;
|
||||
|
||||
|
|
|
@ -65,25 +65,18 @@ already_AddRefed<JSActor> JSActorManager::GetActor(JSContext* aCx,
|
|||
MOZ_ASSERT(loader);
|
||||
|
||||
// If a module URI was provided, use it to construct an instance of the actor.
|
||||
JS::Rooted<JSObject*> actorObj(aCx);
|
||||
if (side.mModuleURI || side.mESModuleURI) {
|
||||
JS::Rooted<JSObject*> exports(aCx);
|
||||
if (side.mModuleURI) {
|
||||
JS::Rooted<JSObject*> global(aCx);
|
||||
aRv = loader->Import(aCx, side.mModuleURI.ref(), &global, &exports);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
aRv = loader->ImportESModule(aCx, side.mESModuleURI.ref(), &exports);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
JS::RootedObject actorObj(aCx);
|
||||
if (side.mModuleURI) {
|
||||
JS::RootedObject global(aCx);
|
||||
JS::RootedObject exports(aCx);
|
||||
aRv = loader->Import(aCx, side.mModuleURI.ref(), &global, &exports);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
MOZ_ASSERT(exports, "null exports!");
|
||||
|
||||
// Load the specific property from our module.
|
||||
JS::Rooted<JS::Value> ctor(aCx);
|
||||
JS::RootedValue ctor(aCx);
|
||||
nsAutoCString ctorName(aName);
|
||||
ctorName.Append(isParent ? "Parent"_ns : "Child"_ns);
|
||||
if (!JS_GetProperty(aCx, exports, ctorName.get(), &ctor)) {
|
||||
|
|
|
@ -1,117 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_dom_JSActorProtocolUtils_h
|
||||
#define mozilla_dom_JSActorProtocolUtils_h
|
||||
|
||||
#include "mozilla/Assertions.h" // MOZ_ASSERT
|
||||
#include "mozilla/ErrorResult.h" // ErrorResult
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
namespace dom {
|
||||
|
||||
class JSActorProtocolUtils {
|
||||
public:
|
||||
template <typename ProtoT, typename ActorInfoT>
|
||||
static void FromIPCShared(ProtoT& aProto, const ActorInfoT& aInfo) {
|
||||
aProto->mRemoteTypes = aInfo.remoteTypes().Clone();
|
||||
|
||||
if (aInfo.isESModule()) {
|
||||
aProto->mChild.mESModuleURI = aInfo.url();
|
||||
} else {
|
||||
aProto->mChild.mModuleURI = aInfo.url();
|
||||
}
|
||||
|
||||
aProto->mChild.mObservers = aInfo.observers().Clone();
|
||||
}
|
||||
|
||||
template <typename ProtoT, typename ActorInfoT>
|
||||
static void ToIPCShared(ActorInfoT& aInfo, const ProtoT& aProto) {
|
||||
aInfo.name() = aProto->mName;
|
||||
|
||||
aInfo.remoteTypes() = aProto->mRemoteTypes.Clone();
|
||||
|
||||
if (aProto->mChild.mModuleURI) {
|
||||
aInfo.url() = aProto->mChild.mModuleURI;
|
||||
aInfo.isESModule() = false;
|
||||
} else {
|
||||
aInfo.url() = aProto->mChild.mESModuleURI;
|
||||
aInfo.isESModule() = true;
|
||||
}
|
||||
|
||||
aInfo.observers() = aProto->mChild.mObservers.Clone();
|
||||
}
|
||||
|
||||
template <typename ProtoT, typename ActorOptionsT>
|
||||
static bool FromWebIDLOptionsShared(ProtoT& aProto,
|
||||
const ActorOptionsT& aOptions,
|
||||
ErrorResult& aRv) {
|
||||
if (aOptions.mRemoteTypes.WasPassed()) {
|
||||
MOZ_ASSERT(aOptions.mRemoteTypes.Value().Length());
|
||||
aProto->mRemoteTypes = aOptions.mRemoteTypes.Value();
|
||||
}
|
||||
|
||||
if (aOptions.mParent.WasPassed()) {
|
||||
const auto& parentOptions = aOptions.mParent.Value();
|
||||
|
||||
if (parentOptions.mModuleURI.WasPassed()) {
|
||||
if (parentOptions.mEsModuleURI.WasPassed()) {
|
||||
aRv.ThrowNotSupportedError(
|
||||
"moduleURI and esModuleURI are mutually exclusive.");
|
||||
return false;
|
||||
}
|
||||
|
||||
aProto->mParent.mModuleURI.emplace(parentOptions.mModuleURI.Value());
|
||||
} else if (parentOptions.mEsModuleURI.WasPassed()) {
|
||||
aProto->mParent.mESModuleURI.emplace(
|
||||
parentOptions.mEsModuleURI.Value());
|
||||
} else {
|
||||
aRv.ThrowNotSupportedError(
|
||||
"Either moduleURI or esModuleURI is required.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (aOptions.mChild.WasPassed()) {
|
||||
const auto& childOptions = aOptions.mChild.Value();
|
||||
|
||||
if (childOptions.mModuleURI.WasPassed()) {
|
||||
if (childOptions.mEsModuleURI.WasPassed()) {
|
||||
aRv.ThrowNotSupportedError(
|
||||
"moduleURI and esModuleURI are exclusive.");
|
||||
return false;
|
||||
}
|
||||
|
||||
aProto->mChild.mModuleURI.emplace(childOptions.mModuleURI.Value());
|
||||
} else if (childOptions.mEsModuleURI.WasPassed()) {
|
||||
aProto->mChild.mESModuleURI.emplace(childOptions.mEsModuleURI.Value());
|
||||
} else {
|
||||
aRv.ThrowNotSupportedError(
|
||||
"Either moduleURI or esModuleURI is required.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!aOptions.mChild.WasPassed() && !aOptions.mParent.WasPassed()) {
|
||||
aRv.ThrowNotSupportedError(
|
||||
"No point registering an actor with neither child nor parent "
|
||||
"specifications.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (aOptions.mChild.WasPassed() &&
|
||||
aOptions.mChild.Value().mObservers.WasPassed()) {
|
||||
aProto->mChild.mObservers = aOptions.mChild.Value().mObservers.Value();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_JSActorProtocolUtils_h
|
|
@ -99,7 +99,6 @@ class JSActorProtocol : public nsISupports {
|
|||
public:
|
||||
struct Sided {
|
||||
Maybe<nsCString> mModuleURI;
|
||||
Maybe<nsCString> mESModuleURI;
|
||||
};
|
||||
|
||||
virtual const Sided& Parent() const = 0;
|
||||
|
|
|
@ -12,9 +12,7 @@
|
|||
#include "mozilla/dom/ContentParent.h"
|
||||
#include "mozilla/dom/JSActorBinding.h"
|
||||
#include "mozilla/dom/PContent.h"
|
||||
|
||||
#include "nsContentUtils.h"
|
||||
#include "JSActorProtocolUtils.h"
|
||||
|
||||
namespace mozilla::dom {
|
||||
|
||||
|
@ -33,11 +31,13 @@ JSProcessActorProtocol::FromIPC(const JSProcessActorInfo& aInfo) {
|
|||
|
||||
RefPtr<JSProcessActorProtocol> proto =
|
||||
new JSProcessActorProtocol(aInfo.name());
|
||||
JSActorProtocolUtils::FromIPCShared(proto, aInfo);
|
||||
|
||||
// Content processes aren't the parent process, so this flag is irrelevant and
|
||||
// not propagated.
|
||||
proto->mIncludeParent = false;
|
||||
proto->mRemoteTypes = aInfo.remoteTypes().Clone();
|
||||
proto->mChild.mModuleURI = aInfo.url();
|
||||
proto->mChild.mObservers = aInfo.observers().Clone();
|
||||
|
||||
return proto.forget();
|
||||
}
|
||||
|
@ -46,8 +46,10 @@ JSProcessActorInfo JSProcessActorProtocol::ToIPC() {
|
|||
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess());
|
||||
|
||||
JSProcessActorInfo info;
|
||||
JSActorProtocolUtils::ToIPCShared(info, this);
|
||||
|
||||
info.name() = mName;
|
||||
info.remoteTypes() = mRemoteTypes.Clone();
|
||||
info.url() = mChild.mModuleURI;
|
||||
info.observers() = mChild.mObservers.Clone();
|
||||
return info;
|
||||
}
|
||||
|
||||
|
@ -58,11 +60,31 @@ JSProcessActorProtocol::FromWebIDLOptions(const nsACString& aName,
|
|||
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess());
|
||||
|
||||
RefPtr<JSProcessActorProtocol> proto = new JSProcessActorProtocol(aName);
|
||||
if (!JSActorProtocolUtils::FromWebIDLOptionsShared(proto, aOptions, aRv)) {
|
||||
proto->mIncludeParent = aOptions.mIncludeParent;
|
||||
|
||||
if (aOptions.mRemoteTypes.WasPassed()) {
|
||||
MOZ_ASSERT(aOptions.mRemoteTypes.Value().Length());
|
||||
proto->mRemoteTypes = aOptions.mRemoteTypes.Value();
|
||||
}
|
||||
|
||||
if (aOptions.mParent.WasPassed()) {
|
||||
proto->mParent.mModuleURI.emplace(aOptions.mParent.Value().mModuleURI);
|
||||
}
|
||||
if (aOptions.mChild.WasPassed()) {
|
||||
proto->mChild.mModuleURI.emplace(aOptions.mChild.Value().mModuleURI);
|
||||
}
|
||||
|
||||
if (!aOptions.mChild.WasPassed() && !aOptions.mParent.WasPassed()) {
|
||||
aRv.ThrowNotSupportedError(
|
||||
"No point registering an actor with neither child nor parent "
|
||||
"specifications.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
proto->mIncludeParent = aOptions.mIncludeParent;
|
||||
if (aOptions.mChild.WasPassed() &&
|
||||
aOptions.mChild.Value().mObservers.WasPassed()) {
|
||||
proto->mChild.mObservers = aOptions.mChild.Value().mObservers.Value();
|
||||
}
|
||||
|
||||
return proto.forget();
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ namespace dom {
|
|||
struct ProcessActorOptions;
|
||||
class JSProcessActorInfo;
|
||||
class EventTarget;
|
||||
class JSActorProtocolUtils;
|
||||
|
||||
/**
|
||||
* Object corresponding to a single process actor protocol
|
||||
|
@ -67,8 +66,6 @@ class JSProcessActorProtocol final : public JSActorProtocol,
|
|||
nsTArray<nsCString> mRemoteTypes;
|
||||
bool mIncludeParent = false;
|
||||
|
||||
friend class JSActorProtocolUtils;
|
||||
|
||||
ParentSide mParent;
|
||||
ChildSide mChild;
|
||||
};
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#include "mozilla/dom/WindowGlobalChild.h"
|
||||
|
||||
#include "nsContentUtils.h"
|
||||
#include "JSActorProtocolUtils.h"
|
||||
|
||||
namespace mozilla::dom {
|
||||
|
||||
|
@ -35,14 +34,14 @@ JSWindowActorProtocol::FromIPC(const JSWindowActorInfo& aInfo) {
|
|||
MOZ_DIAGNOSTIC_ASSERT(XRE_IsContentProcess());
|
||||
|
||||
RefPtr<JSWindowActorProtocol> proto = new JSWindowActorProtocol(aInfo.name());
|
||||
JSActorProtocolUtils::FromIPCShared(proto, aInfo);
|
||||
|
||||
// Content processes cannot load chrome browsing contexts, so this flag is
|
||||
// irrelevant and not propagated.
|
||||
proto->mIncludeChrome = false;
|
||||
proto->mAllFrames = aInfo.allFrames();
|
||||
proto->mMatches = aInfo.matches().Clone();
|
||||
proto->mRemoteTypes = aInfo.remoteTypes().Clone();
|
||||
proto->mMessageManagerGroups = aInfo.messageManagerGroups().Clone();
|
||||
proto->mChild.mModuleURI = aInfo.url();
|
||||
|
||||
proto->mChild.mEvents.SetCapacity(aInfo.events().Length());
|
||||
for (auto& ipc : aInfo.events()) {
|
||||
|
@ -57,6 +56,7 @@ JSWindowActorProtocol::FromIPC(const JSWindowActorInfo& aInfo) {
|
|||
event->mCreateActor = ipc.createActor();
|
||||
}
|
||||
|
||||
proto->mChild.mObservers = aInfo.observers().Clone();
|
||||
return proto.forget();
|
||||
}
|
||||
|
||||
|
@ -64,11 +64,12 @@ JSWindowActorInfo JSWindowActorProtocol::ToIPC() {
|
|||
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess());
|
||||
|
||||
JSWindowActorInfo info;
|
||||
JSActorProtocolUtils::ToIPCShared(info, this);
|
||||
|
||||
info.name() = mName;
|
||||
info.allFrames() = mAllFrames;
|
||||
info.matches() = mMatches.Clone();
|
||||
info.remoteTypes() = mRemoteTypes.Clone();
|
||||
info.messageManagerGroups() = mMessageManagerGroups.Clone();
|
||||
info.url() = mChild.mModuleURI;
|
||||
|
||||
info.events().SetCapacity(mChild.mEvents.Length());
|
||||
for (auto& event : mChild.mEvents) {
|
||||
|
@ -83,6 +84,7 @@ JSWindowActorInfo JSWindowActorProtocol::ToIPC() {
|
|||
ipc->createActor() = event.mCreateActor;
|
||||
}
|
||||
|
||||
info.observers() = mChild.mObservers.Clone();
|
||||
return info;
|
||||
}
|
||||
|
||||
|
@ -93,10 +95,6 @@ JSWindowActorProtocol::FromWebIDLOptions(const nsACString& aName,
|
|||
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess());
|
||||
|
||||
RefPtr<JSWindowActorProtocol> proto = new JSWindowActorProtocol(aName);
|
||||
if (!JSActorProtocolUtils::FromWebIDLOptionsShared(proto, aOptions, aRv)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
proto->mAllFrames = aOptions.mAllFrames;
|
||||
proto->mIncludeChrome = aOptions.mIncludeChrome;
|
||||
|
||||
|
@ -105,10 +103,29 @@ JSWindowActorProtocol::FromWebIDLOptions(const nsACString& aName,
|
|||
proto->mMatches = aOptions.mMatches.Value();
|
||||
}
|
||||
|
||||
if (aOptions.mRemoteTypes.WasPassed()) {
|
||||
MOZ_ASSERT(aOptions.mRemoteTypes.Value().Length());
|
||||
proto->mRemoteTypes = aOptions.mRemoteTypes.Value();
|
||||
}
|
||||
|
||||
if (aOptions.mMessageManagerGroups.WasPassed()) {
|
||||
proto->mMessageManagerGroups = aOptions.mMessageManagerGroups.Value();
|
||||
}
|
||||
|
||||
if (aOptions.mParent.WasPassed()) {
|
||||
proto->mParent.mModuleURI.emplace(aOptions.mParent.Value().mModuleURI);
|
||||
}
|
||||
if (aOptions.mChild.WasPassed()) {
|
||||
proto->mChild.mModuleURI.emplace(aOptions.mChild.Value().mModuleURI);
|
||||
}
|
||||
|
||||
if (!aOptions.mChild.WasPassed() && !aOptions.mParent.WasPassed()) {
|
||||
aRv.ThrowNotSupportedError(
|
||||
"No point registering an actor with neither child nor parent "
|
||||
"specifications.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// For each event declared in the source dictionary, initialize the
|
||||
// corresponding event declaration entry in the JSWindowActorProtocol.
|
||||
if (aOptions.mChild.WasPassed() &&
|
||||
|
@ -140,6 +157,11 @@ JSWindowActorProtocol::FromWebIDLOptions(const nsACString& aName,
|
|||
}
|
||||
}
|
||||
|
||||
if (aOptions.mChild.WasPassed() &&
|
||||
aOptions.mChild.Value().mObservers.WasPassed()) {
|
||||
proto->mChild.mObservers = aOptions.mChild.Value().mObservers.Value();
|
||||
}
|
||||
|
||||
return proto.forget();
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ namespace dom {
|
|||
struct WindowActorOptions;
|
||||
class JSWindowActorInfo;
|
||||
class EventTarget;
|
||||
class JSActorProtocolUtils;
|
||||
|
||||
/**
|
||||
* Object corresponding to a single window actor protocol. This object acts as
|
||||
|
@ -89,8 +88,6 @@ class JSWindowActorProtocol final : public JSActorProtocol,
|
|||
nsTArray<nsCString> mRemoteTypes;
|
||||
nsTArray<nsString> mMessageManagerGroups;
|
||||
|
||||
friend class JSActorProtocolUtils;
|
||||
|
||||
ParentSide mParent;
|
||||
ChildSide mChild;
|
||||
|
||||
|
|
|
@ -8,4 +8,4 @@ support-files =
|
|||
[browser_registerProcessActor.js]
|
||||
[browser_sendAsyncMessage.js]
|
||||
[browser_sendQuery.js]
|
||||
[browser_uri_combination.js]
|
||||
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
"use strict";
|
||||
|
||||
declTest("double register", {
|
||||
async test(_browser, _window, fileExt) {
|
||||
async test() {
|
||||
SimpleTest.doesThrow(
|
||||
() =>
|
||||
ChromeUtils.registerContentActor(
|
||||
"TestProcessActor",
|
||||
processActorOptions[fileExt]
|
||||
processActorOptions
|
||||
),
|
||||
"Should throw if register has duplicate name."
|
||||
);
|
||||
|
|
|
@ -2,23 +2,6 @@
|
|||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
"use strict";
|
||||
|
||||
const ERROR_LINE_NUMBERS = {
|
||||
jsm: 33,
|
||||
"sys.mjs": 31,
|
||||
};
|
||||
const EXCEPTION_LINE_NUMBERS = {
|
||||
jsm: ERROR_LINE_NUMBERS.jsm + 3,
|
||||
"sys.mjs": ERROR_LINE_NUMBERS["sys.mjs"] + 3,
|
||||
};
|
||||
const ERROR_COLUMN_NUMBERS = {
|
||||
jsm: 31,
|
||||
"sys.mjs": 31,
|
||||
};
|
||||
const EXCEPTION_COLUMN_NUMBERS = {
|
||||
jsm: 22,
|
||||
"sys.mjs": 22,
|
||||
};
|
||||
|
||||
function maybeAsyncStack(offset, column) {
|
||||
if (
|
||||
Services.prefs.getBoolPref(
|
||||
|
@ -39,7 +22,7 @@ function maybeAsyncStack(offset, column) {
|
|||
}
|
||||
|
||||
declTest("sendQuery Error", {
|
||||
async test(browser, _window, fileExt) {
|
||||
async test(browser) {
|
||||
let parent = browser.browsingContext.currentWindowGlobal.domProcess;
|
||||
let actorParent = parent.getActor("TestProcessActor");
|
||||
|
||||
|
@ -52,7 +35,7 @@ declTest("sendQuery Error", {
|
|||
is(error.name, "SyntaxError", "Error should have the correct name");
|
||||
is(
|
||||
error.stack,
|
||||
`receiveMessage@resource://testing-common/TestProcessActorChild.${fileExt}:${ERROR_LINE_NUMBERS[fileExt]}:${ERROR_COLUMN_NUMBERS[fileExt]}\n` +
|
||||
"receiveMessage@resource://testing-common/TestProcessActorChild.jsm:33:31\n" +
|
||||
asyncStack,
|
||||
"Error should have the correct stack"
|
||||
);
|
||||
|
@ -60,7 +43,7 @@ declTest("sendQuery Error", {
|
|||
});
|
||||
|
||||
declTest("sendQuery Exception", {
|
||||
async test(browser, _window, fileExt) {
|
||||
async test(browser) {
|
||||
let parent = browser.browsingContext.currentWindowGlobal.domProcess;
|
||||
let actorParent = parent.getActor("TestProcessActor");
|
||||
|
||||
|
@ -80,7 +63,7 @@ declTest("sendQuery Exception", {
|
|||
);
|
||||
is(
|
||||
error.stack,
|
||||
`receiveMessage@resource://testing-common/TestProcessActorChild.${fileExt}:${EXCEPTION_LINE_NUMBERS[fileExt]}:${EXCEPTION_COLUMN_NUMBERS[fileExt]}\n` +
|
||||
"receiveMessage@resource://testing-common/TestProcessActorChild.jsm:36:22\n" +
|
||||
asyncStack,
|
||||
"Error should have the correct stack"
|
||||
);
|
||||
|
|
|
@ -1,81 +0,0 @@
|
|||
add_task(function specify_both() {
|
||||
// Specifying both should throw.
|
||||
|
||||
SimpleTest.doesThrow(() => {
|
||||
ChromeUtils.registerProcessActor("TestProcessActor", {
|
||||
parent: {
|
||||
moduleURI: "resource://testing-common/TestProcessActorParent.jsm",
|
||||
},
|
||||
child: {
|
||||
moduleURI: "resource://testing-common/TestProcessActorChild.jsm",
|
||||
esModuleURI: "resource://testing-common/TestProcessActorChild.sys.mjs",
|
||||
},
|
||||
});
|
||||
}, "Should throw if both moduleURI and esModuleURI are specified.");
|
||||
|
||||
SimpleTest.doesThrow(() => {
|
||||
ChromeUtils.registerProcessActor("TestProcessActor", {
|
||||
parent: {
|
||||
esModuleURI: "resource://testing-common/TestProcessActorParent.sys.mjs",
|
||||
},
|
||||
child: {
|
||||
moduleURI: "resource://testing-common/TestProcessActorChild.jsm",
|
||||
esModuleURI: "resource://testing-common/TestProcessActorChild.sys.mjs",
|
||||
},
|
||||
});
|
||||
}, "Should throw if both moduleURI and esModuleURI are specified.");
|
||||
|
||||
SimpleTest.doesThrow(() => {
|
||||
ChromeUtils.registerProcessActor("TestProcessActor", {
|
||||
parent: {
|
||||
moduleURI: "resource://testing-common/TestProcessActorParent.jsm",
|
||||
esModuleURI: "resource://testing-common/TestProcessActorParent.sys.mjs",
|
||||
},
|
||||
child: {
|
||||
moduleURI: "resource://testing-common/TestProcessActorChild.jsm",
|
||||
},
|
||||
});
|
||||
}, "Should throw if both moduleURI and esModuleURI are specified.");
|
||||
|
||||
SimpleTest.doesThrow(() => {
|
||||
ChromeUtils.registerProcessActor("TestProcessActor", {
|
||||
parent: {
|
||||
moduleURI: "resource://testing-common/TestProcessActorParent.jsm",
|
||||
esModuleURI: "resource://testing-common/TestProcessActorParent.sys.mjs",
|
||||
},
|
||||
child: {
|
||||
esModuleURI: "resource://testing-common/TestProcessActorChild.sys.mjs",
|
||||
},
|
||||
});
|
||||
}, "Should throw if both moduleURI and esModuleURI are specified.");
|
||||
});
|
||||
|
||||
add_task(function specify_mixed() {
|
||||
// Mixing JSM and ESM should work.
|
||||
|
||||
try {
|
||||
ChromeUtils.registerProcessActor("TestProcessActor", {
|
||||
parent: {
|
||||
moduleURI: "resource://testing-common/TestProcessActorParent.jsm",
|
||||
},
|
||||
child: {
|
||||
esModuleURI: "resource://testing-common/TestProcessActorChild.sys.mjs",
|
||||
},
|
||||
});
|
||||
} finally {
|
||||
ChromeUtils.unregisterProcessActor("TestProcessActor");
|
||||
}
|
||||
|
||||
try {
|
||||
ChromeUtils.registerProcessActor("TestProcessActor", {
|
||||
parent: {
|
||||
esModuleURI: "resource://testing-common/TestProcessActorParent.sys.mjs",
|
||||
},
|
||||
child: {
|
||||
moduleURI: "resource://testing-common/TestProcessActorChild.jsm",
|
||||
},
|
||||
});
|
||||
} finally {
|
||||
ChromeUtils.unregisterProcessActor("TestProcessActor");
|
||||
}
|
||||
});
|
|
@ -8,23 +8,12 @@
|
|||
const URL = "about:blank";
|
||||
const TEST_URL = "http://test2.example.org/";
|
||||
let processActorOptions = {
|
||||
jsm: {
|
||||
parent: {
|
||||
moduleURI: "resource://testing-common/TestProcessActorParent.jsm",
|
||||
},
|
||||
child: {
|
||||
moduleURI: "resource://testing-common/TestProcessActorChild.jsm",
|
||||
observers: ["test-js-content-actor-child-observer"],
|
||||
},
|
||||
parent: {
|
||||
moduleURI: "resource://testing-common/TestProcessActorParent.jsm",
|
||||
},
|
||||
"sys.mjs": {
|
||||
parent: {
|
||||
esModuleURI: "resource://testing-common/TestProcessActorParent.sys.mjs",
|
||||
},
|
||||
child: {
|
||||
esModuleURI: "resource://testing-common/TestProcessActorChild.sys.mjs",
|
||||
observers: ["test-js-content-actor-child-observer"],
|
||||
},
|
||||
child: {
|
||||
moduleURI: "resource://testing-common/TestProcessActorChild.jsm",
|
||||
observers: ["test-js-content-actor-child-observer"],
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -44,18 +33,13 @@ function promiseNotification(aNotification) {
|
|||
}
|
||||
|
||||
function declTest(name, cfg) {
|
||||
declTestWithOptions(name, cfg, "jsm");
|
||||
declTestWithOptions(name, cfg, "sys.mjs");
|
||||
}
|
||||
|
||||
function declTestWithOptions(name, cfg, fileExt) {
|
||||
let { url = "about:blank", includeParent = false, remoteTypes, test } = cfg;
|
||||
|
||||
// Build the actor options object which will be used to register & unregister
|
||||
// our process actor.
|
||||
let actorOptions = {
|
||||
parent: Object.assign({}, processActorOptions[fileExt].parent),
|
||||
child: Object.assign({}, processActorOptions[fileExt].child),
|
||||
parent: Object.assign({}, processActorOptions.parent),
|
||||
child: Object.assign({}, processActorOptions.child),
|
||||
};
|
||||
actorOptions.includeParent = includeParent;
|
||||
if (remoteTypes !== undefined) {
|
||||
|
@ -71,7 +55,7 @@ function declTestWithOptions(name, cfg, fileExt) {
|
|||
try {
|
||||
await BrowserTestUtils.withNewTab(url, async browser => {
|
||||
info("browser ready");
|
||||
await Promise.resolve(test(browser, window, fileExt));
|
||||
await Promise.resolve(test(browser, window));
|
||||
});
|
||||
} finally {
|
||||
// Unregister the actor after the test is complete.
|
||||
|
|
|
@ -19,4 +19,3 @@ support-files=
|
|||
[browser_registerWindowActor.js]
|
||||
[browser_sendAsyncMessage.js]
|
||||
[browser_sendQuery.js]
|
||||
[browser_uri_combination.js]
|
||||
|
|
|
@ -3,13 +3,9 @@
|
|||
"use strict";
|
||||
|
||||
declTest("double register", {
|
||||
async test(_browser, _window, fileExt) {
|
||||
async test() {
|
||||
SimpleTest.doesThrow(
|
||||
() =>
|
||||
ChromeUtils.registerWindowActor(
|
||||
"TestWindow",
|
||||
windowActorOptions[fileExt]
|
||||
),
|
||||
() => ChromeUtils.registerWindowActor("TestWindow", windowActorOptions),
|
||||
"Should throw if register has duplicate name."
|
||||
);
|
||||
},
|
||||
|
|
|
@ -2,22 +2,8 @@
|
|||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
"use strict";
|
||||
|
||||
const ERROR_LINE_NUMBERS = {
|
||||
jsm: 41,
|
||||
"sys.mjs": 39,
|
||||
};
|
||||
const EXCEPTION_LINE_NUMBERS = {
|
||||
jsm: ERROR_LINE_NUMBERS.jsm + 3,
|
||||
"sys.mjs": ERROR_LINE_NUMBERS["sys.mjs"] + 3,
|
||||
};
|
||||
const ERROR_COLUMN_NUMBERS = {
|
||||
jsm: 31,
|
||||
"sys.mjs": 31,
|
||||
};
|
||||
const EXCEPTION_COLUMN_NUMBERS = {
|
||||
jsm: 22,
|
||||
"sys.mjs": 22,
|
||||
};
|
||||
const ERROR_LINE_NUMBER = 41;
|
||||
const EXCEPTION_LINE_NUMBER = ERROR_LINE_NUMBER + 3;
|
||||
|
||||
function maybeAsyncStack(offset, column) {
|
||||
if (
|
||||
|
@ -39,7 +25,7 @@ function maybeAsyncStack(offset, column) {
|
|||
}
|
||||
|
||||
declTest("sendQuery Error", {
|
||||
async test(browser, _window, fileExt) {
|
||||
async test(browser) {
|
||||
let parent = browser.browsingContext.currentWindowGlobal;
|
||||
let actorParent = parent.getActor("TestWindow");
|
||||
|
||||
|
@ -52,7 +38,7 @@ declTest("sendQuery Error", {
|
|||
is(error.name, "SyntaxError", "Error should have the correct name");
|
||||
is(
|
||||
error.stack,
|
||||
`receiveMessage@resource://testing-common/TestWindowChild.${fileExt}:${ERROR_LINE_NUMBERS[fileExt]}:${ERROR_COLUMN_NUMBERS[fileExt]}\n` +
|
||||
`receiveMessage@resource://testing-common/TestWindowChild.jsm:${ERROR_LINE_NUMBER}:31\n` +
|
||||
asyncStack,
|
||||
"Error should have the correct stack"
|
||||
);
|
||||
|
@ -60,7 +46,7 @@ declTest("sendQuery Error", {
|
|||
});
|
||||
|
||||
declTest("sendQuery Exception", {
|
||||
async test(browser, _window, fileExt) {
|
||||
async test(browser) {
|
||||
let parent = browser.browsingContext.currentWindowGlobal;
|
||||
let actorParent = parent.getActor("TestWindow");
|
||||
|
||||
|
@ -80,7 +66,7 @@ declTest("sendQuery Exception", {
|
|||
);
|
||||
is(
|
||||
error.stack,
|
||||
`receiveMessage@resource://testing-common/TestWindowChild.${fileExt}:${EXCEPTION_LINE_NUMBERS[fileExt]}:${EXCEPTION_COLUMN_NUMBERS[fileExt]}\n` +
|
||||
`receiveMessage@resource://testing-common/TestWindowChild.jsm:${EXCEPTION_LINE_NUMBER}:22\n` +
|
||||
asyncStack,
|
||||
"Error should have the correct stack"
|
||||
);
|
||||
|
|
|
@ -1,81 +0,0 @@
|
|||
add_task(function specify_both() {
|
||||
// Specifying both should throw.
|
||||
|
||||
SimpleTest.doesThrow(() => {
|
||||
ChromeUtils.registerWindowActor("TestWindow", {
|
||||
parent: {
|
||||
moduleURI: "resource://testing-common/TestWindowParent.jsm",
|
||||
},
|
||||
child: {
|
||||
moduleURI: "resource://testing-common/TestWindowChild.jsm",
|
||||
esModuleURI: "resource://testing-common/TestWindowChild.sys.mjs",
|
||||
},
|
||||
});
|
||||
}, "Should throw if both moduleURI and esModuleURI are specified.");
|
||||
|
||||
SimpleTest.doesThrow(() => {
|
||||
ChromeUtils.registerWindowActor("TestWindow", {
|
||||
parent: {
|
||||
esModuleURI: "resource://testing-common/TestWindowParent.sys.mjs",
|
||||
},
|
||||
child: {
|
||||
moduleURI: "resource://testing-common/TestWindowChild.jsm",
|
||||
esModuleURI: "resource://testing-common/TestWindowChild.sys.mjs",
|
||||
},
|
||||
});
|
||||
}, "Should throw if both moduleURI and esModuleURI are specified.");
|
||||
|
||||
SimpleTest.doesThrow(() => {
|
||||
ChromeUtils.registerWindowActor("TestWindow", {
|
||||
parent: {
|
||||
moduleURI: "resource://testing-common/TestWindowParent.jsm",
|
||||
esModuleURI: "resource://testing-common/TestWindowParent.sys.mjs",
|
||||
},
|
||||
child: {
|
||||
moduleURI: "resource://testing-common/TestWindowChild.jsm",
|
||||
},
|
||||
});
|
||||
}, "Should throw if both moduleURI and esModuleURI are specified.");
|
||||
|
||||
SimpleTest.doesThrow(() => {
|
||||
ChromeUtils.registerWindowActor("TestWindow", {
|
||||
parent: {
|
||||
moduleURI: "resource://testing-common/TestWindowParent.jsm",
|
||||
esModuleURI: "resource://testing-common/TestWindowParent.sys.mjs",
|
||||
},
|
||||
child: {
|
||||
esModuleURI: "resource://testing-common/TestWindowChild.sys.mjs",
|
||||
},
|
||||
});
|
||||
}, "Should throw if both moduleURI and esModuleURI are specified.");
|
||||
});
|
||||
|
||||
add_task(function specify_mixed() {
|
||||
// Mixing JSM and ESM should work.
|
||||
|
||||
try {
|
||||
ChromeUtils.registerWindowActor("TestWindow", {
|
||||
parent: {
|
||||
moduleURI: "resource://testing-common/TestWindowParent.jsm",
|
||||
},
|
||||
child: {
|
||||
esModuleURI: "resource://testing-common/TestWindowChild.sys.mjs",
|
||||
},
|
||||
});
|
||||
} finally {
|
||||
ChromeUtils.unregisterWindowActor("TestWindow");
|
||||
}
|
||||
|
||||
try {
|
||||
ChromeUtils.registerWindowActor("TestWindow", {
|
||||
parent: {
|
||||
esModuleURI: "resource://testing-common/TestWindowParent.sys.mjs",
|
||||
},
|
||||
child: {
|
||||
moduleURI: "resource://testing-common/TestWindowChild.jsm",
|
||||
},
|
||||
});
|
||||
} finally {
|
||||
ChromeUtils.unregisterWindowActor("TestWindow");
|
||||
}
|
||||
});
|
|
@ -8,30 +8,15 @@
|
|||
const URL = "about:blank";
|
||||
const TEST_URL = "http://test2.example.org/";
|
||||
let windowActorOptions = {
|
||||
jsm: {
|
||||
parent: {
|
||||
moduleURI: "resource://testing-common/TestWindowParent.jsm",
|
||||
},
|
||||
child: {
|
||||
moduleURI: "resource://testing-common/TestWindowChild.jsm",
|
||||
},
|
||||
parent: {
|
||||
moduleURI: "resource://testing-common/TestWindowParent.jsm",
|
||||
},
|
||||
"sys.mjs": {
|
||||
parent: {
|
||||
esModuleURI: "resource://testing-common/TestWindowParent.sys.mjs",
|
||||
},
|
||||
child: {
|
||||
esModuleURI: "resource://testing-common/TestWindowChild.sys.mjs",
|
||||
},
|
||||
child: {
|
||||
moduleURI: "resource://testing-common/TestWindowChild.jsm",
|
||||
},
|
||||
};
|
||||
|
||||
function declTest(name, cfg) {
|
||||
declTestWithOptions(name, cfg, "jsm");
|
||||
declTestWithOptions(name, cfg, "sys.mjs");
|
||||
}
|
||||
|
||||
function declTestWithOptions(name, cfg, fileExt) {
|
||||
let {
|
||||
url = "about:blank",
|
||||
allFrames = false,
|
||||
|
@ -47,8 +32,8 @@ function declTestWithOptions(name, cfg, fileExt) {
|
|||
// Build the actor options object which will be used to register & unregister
|
||||
// our window actor.
|
||||
let actorOptions = {
|
||||
parent: { ...windowActorOptions[fileExt].parent },
|
||||
child: { ...windowActorOptions[fileExt].child, events, observers },
|
||||
parent: { ...windowActorOptions.parent },
|
||||
child: { ...windowActorOptions.child, events, observers },
|
||||
};
|
||||
actorOptions.allFrames = allFrames;
|
||||
actorOptions.includeChrome = includeChrome;
|
||||
|
@ -71,7 +56,7 @@ function declTestWithOptions(name, cfg, fileExt) {
|
|||
try {
|
||||
await BrowserTestUtils.withNewTab(url, async browser => {
|
||||
info("browser ready");
|
||||
await Promise.resolve(test(browser, window, fileExt));
|
||||
await Promise.resolve(test(browser, window));
|
||||
});
|
||||
} finally {
|
||||
// Unregister the actor after the test is complete.
|
||||
|
|
|
@ -213,8 +213,8 @@ interface nsIXPCComponents_Utils : nsISupports
|
|||
jsval import(in AUTF8String aResourceURI, [optional] in jsval targetObj);
|
||||
|
||||
/**
|
||||
* Returns true if the JSM is loaded into the system global previously via
|
||||
* the import method above, or corresponding ESM is loaded. Returns false
|
||||
* Returns true if the js file located at 'registryLocation' location has
|
||||
* been loaded previously via the import method above. Returns false
|
||||
* otherwise.
|
||||
*
|
||||
* @param resourceURI A resource:// URI string representing the location of
|
||||
|
@ -224,19 +224,6 @@ interface nsIXPCComponents_Utils : nsISupports
|
|||
*/
|
||||
boolean isModuleLoaded(in AUTF8String aResourceURI);
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the JSM is loaded into the system global previously via
|
||||
* the import method above. Returns false otherwise.
|
||||
*/
|
||||
boolean isJSModuleLoaded(in AUTF8String aResourceURI);
|
||||
|
||||
/**
|
||||
* Returns true if the ESM is loaded into the system global previously via
|
||||
* the ChromeUtils.importESModule method etc. Returns false otherwise.
|
||||
*/
|
||||
boolean isESModuleLoaded(in AUTF8String aResourceURI);
|
||||
|
||||
/*
|
||||
* Unloads the JS module at 'registryLocation'. Existing references to the
|
||||
* module will continue to work but any subsequent import of the module will
|
||||
|
@ -720,19 +707,9 @@ interface nsIXPCComponents_Utils : nsISupports
|
|||
|
||||
// These attributes are for startup testing purposes. They are not expected
|
||||
// to be used for production code.
|
||||
|
||||
// Array of the URI of JSM and ESM loaded, converting ESM URI into JSM URI.
|
||||
readonly attribute Array<ACString> loadedModules;
|
||||
|
||||
readonly attribute Array<ACString> loadedComponents;
|
||||
|
||||
// Array of the URI of JSM loaded.
|
||||
readonly attribute Array<ACString> loadedJSModules;
|
||||
|
||||
// Array of the URI of ESM loaded.
|
||||
readonly attribute Array<ACString> loadedESModules;
|
||||
|
||||
|
||||
// These 2 functions will only return useful values if the
|
||||
// "browser.startup.record" preference was true at the time the JS file
|
||||
// was loaded.
|
||||
|
|
|
@ -1188,40 +1188,6 @@ nsresult mozJSComponentLoader::IsModuleLoaded(const nsACString& aLocation,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult mozJSComponentLoader::IsJSModuleLoaded(const nsACString& aLocation,
|
||||
bool* retval) {
|
||||
MOZ_ASSERT(nsContentUtils::IsCallerChrome());
|
||||
|
||||
mInitialized = true;
|
||||
ComponentLoaderInfo info(aLocation);
|
||||
if (mImports.Get(info.Key())) {
|
||||
*retval = true;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
*retval = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult mozJSComponentLoader::IsESModuleLoaded(const nsACString& aLocation,
|
||||
bool* retval) {
|
||||
MOZ_ASSERT(nsContentUtils::IsCallerChrome());
|
||||
|
||||
mInitialized = true;
|
||||
ComponentLoaderInfo info(aLocation);
|
||||
|
||||
nsresult rv = info.EnsureURI();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (mModuleLoader->IsModuleFetched(info.URI())) {
|
||||
*retval = true;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
*retval = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void mozJSComponentLoader::GetLoadedModules(
|
||||
nsTArray<nsCString>& aLoadedModules) {
|
||||
aLoadedModules.SetCapacity(mImports.Count());
|
||||
|
|
|
@ -92,8 +92,6 @@ class mozJSComponentLoader final : public nsIMemoryReporter {
|
|||
|
||||
nsresult Unload(const nsACString& aResourceURI);
|
||||
nsresult IsModuleLoaded(const nsACString& aResourceURI, bool* aRetval);
|
||||
nsresult IsJSModuleLoaded(const nsACString& aResourceURI, bool* aRetval);
|
||||
nsresult IsESModuleLoaded(const nsACString& aResourceURI, bool* aRetval);
|
||||
bool IsLoaderGlobal(JSObject* aObj) { return mLoaderGlobal == aObj; }
|
||||
|
||||
// Public methods for use from ComponentModuleLoader.
|
||||
|
|
|
@ -1561,27 +1561,11 @@ nsXPCComponents_Utils::Import(const nsACString& registryLocation,
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXPCComponents_Utils::IsModuleLoaded(const nsACString& aResourceURI,
|
||||
nsXPCComponents_Utils::IsModuleLoaded(const nsACString& registryLocation,
|
||||
bool* retval) {
|
||||
RefPtr<mozJSComponentLoader> moduleloader = mozJSComponentLoader::Get();
|
||||
MOZ_ASSERT(moduleloader);
|
||||
return moduleloader->IsModuleLoaded(aResourceURI, retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXPCComponents_Utils::IsJSModuleLoaded(const nsACString& aResourceURI,
|
||||
bool* retval) {
|
||||
RefPtr<mozJSComponentLoader> moduleloader = mozJSComponentLoader::Get();
|
||||
MOZ_ASSERT(moduleloader);
|
||||
return moduleloader->IsJSModuleLoaded(aResourceURI, retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXPCComponents_Utils::IsESModuleLoaded(const nsACString& aResourceURI,
|
||||
bool* retval) {
|
||||
RefPtr<mozJSComponentLoader> moduleloader = mozJSComponentLoader::Get();
|
||||
MOZ_ASSERT(moduleloader);
|
||||
return moduleloader->IsESModuleLoaded(aResourceURI, retval);
|
||||
return moduleloader->IsModuleLoaded(registryLocation, retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -2548,19 +2532,6 @@ nsXPCComponents_Utils::GetLoadedComponents(
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXPCComponents_Utils::GetLoadedJSModules(
|
||||
nsTArray<nsCString>& aLoadedJSModules) {
|
||||
mozJSComponentLoader::Get()->GetLoadedModules(aLoadedJSModules);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXPCComponents_Utils::GetLoadedESModules(
|
||||
nsTArray<nsCString>& aLoadedESModules) {
|
||||
return mozJSComponentLoader::Get()->GetLoadedESModules(aLoadedESModules);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXPCComponents_Utils::GetModuleImportStack(const nsACString& aLocation,
|
||||
nsACString& aRetval) {
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
export function test() {}
|
|
@ -1 +0,0 @@
|
|||
export function test() {}
|
|
@ -1 +0,0 @@
|
|||
export function test() {}
|
|
@ -1,4 +0,0 @@
|
|||
export let X = 10;
|
||||
function GetX() {
|
||||
return X;
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
export let Y = 20;
|
||||
export function AddY(n) {
|
||||
Y += n;
|
||||
};
|
|
@ -1,2 +0,0 @@
|
|||
function test() {}
|
||||
var EXPORTED_SYMBOLS = ["test"];
|
|
@ -1,2 +0,0 @@
|
|||
function test() {}
|
||||
var EXPORTED_SYMBOLS = ["test"];
|
|
@ -1,2 +0,0 @@
|
|||
function test() {}
|
||||
var EXPORTED_SYMBOLS = ["test"];
|
|
@ -1,76 +0,0 @@
|
|||
function assertAccessor(lazy, name) {
|
||||
let desc = Object.getOwnPropertyDescriptor(lazy, name);
|
||||
Assert.equal(typeof desc.get, "function");
|
||||
Assert.equal(desc.get.name, name);
|
||||
Assert.equal(typeof desc.set, "function");
|
||||
Assert.equal(desc.set.name, name);
|
||||
Assert.equal(desc.enumerable, true);
|
||||
Assert.equal(desc.configurable, true);
|
||||
}
|
||||
|
||||
function assertDataProperty(lazy, name, value) {
|
||||
let desc = Object.getOwnPropertyDescriptor(lazy, name);
|
||||
Assert.equal(desc.value, value);
|
||||
Assert.equal(desc.writable, true);
|
||||
Assert.equal(desc.enumerable, true);
|
||||
Assert.equal(desc.configurable, true);
|
||||
}
|
||||
|
||||
add_task(function test_getter() {
|
||||
// The property should be defined as getter, and getting it should make it
|
||||
// a data property.
|
||||
|
||||
const lazy = {};
|
||||
ChromeUtils.defineESModuleGetters(lazy, {
|
||||
X: "resource://test/esm_lazy-1.sys.mjs",
|
||||
});
|
||||
|
||||
assertAccessor(lazy, "X");
|
||||
|
||||
Assert.equal(lazy.X, 10);
|
||||
assertDataProperty(lazy, "X", 10);
|
||||
});
|
||||
|
||||
add_task(function test_setter() {
|
||||
// Setting the value before the first get should result in a data property.
|
||||
const lazy = {};
|
||||
ChromeUtils.defineESModuleGetters(lazy, {
|
||||
X: "resource://test/esm_lazy-1.sys.mjs",
|
||||
});
|
||||
|
||||
assertAccessor(lazy, "X");
|
||||
lazy.X = 20;
|
||||
Assert.equal(lazy.X, 20);
|
||||
assertDataProperty(lazy, "X", 20);
|
||||
|
||||
// The above set shouldn't affect the module's value.
|
||||
const lazy2 = {};
|
||||
ChromeUtils.defineESModuleGetters(lazy2, {
|
||||
X: "resource://test/esm_lazy-1.sys.mjs",
|
||||
});
|
||||
|
||||
Assert.equal(lazy2.X, 10);
|
||||
});
|
||||
|
||||
add_task(function test_order() {
|
||||
// The change to the exported value should be reflected until it's accessed.
|
||||
|
||||
const lazy = {};
|
||||
ChromeUtils.defineESModuleGetters(lazy, {
|
||||
Y: "resource://test/esm_lazy-2.sys.mjs",
|
||||
AddY: "resource://test/esm_lazy-2.sys.mjs",
|
||||
});
|
||||
|
||||
assertAccessor(lazy, "Y");
|
||||
assertAccessor(lazy, "AddY");
|
||||
|
||||
// The change before getting the value should be reflected.
|
||||
lazy.AddY(2);
|
||||
Assert.equal(lazy.Y, 22);
|
||||
assertDataProperty(lazy, "Y", 22);
|
||||
|
||||
// Change after getting the value shouldn't be reflected.
|
||||
lazy.AddY(2);
|
||||
Assert.equal(lazy.Y, 22);
|
||||
assertDataProperty(lazy, "Y", 22);
|
||||
});
|
|
@ -1,127 +0,0 @@
|
|||
add_task(function test_JSModule() {
|
||||
const URL1 = "resource://test/jsm_loaded-1.jsm";
|
||||
const URL2 = "resource://test/jsm_loaded-2.jsm";
|
||||
const URL3 = "resource://test/jsm_loaded-3.jsm";
|
||||
|
||||
Assert.ok(!Cu.loadedJSModules.includes(URL1));
|
||||
Assert.ok(!Cu.isJSModuleLoaded(URL1));
|
||||
Assert.ok(!Cu.loadedJSModules.includes(URL2));
|
||||
Assert.ok(!Cu.isJSModuleLoaded(URL2));
|
||||
Assert.ok(!Cu.loadedJSModules.includes(URL3));
|
||||
Assert.ok(!Cu.isJSModuleLoaded(URL3));
|
||||
Assert.ok(!Cu.loadedESModules.includes(URL1));
|
||||
Assert.ok(!Cu.isESModuleLoaded(URL1));
|
||||
Assert.ok(!Cu.loadedESModules.includes(URL2));
|
||||
Assert.ok(!Cu.isESModuleLoaded(URL2));
|
||||
Assert.ok(!Cu.loadedESModules.includes(URL3));
|
||||
Assert.ok(!Cu.isESModuleLoaded(URL3));
|
||||
|
||||
ChromeUtils.import(URL1);
|
||||
|
||||
Assert.ok(Cu.loadedJSModules.includes(URL1));
|
||||
Assert.ok(Cu.isJSModuleLoaded(URL1));
|
||||
Assert.ok(!Cu.loadedJSModules.includes(URL2));
|
||||
Assert.ok(!Cu.isJSModuleLoaded(URL2));
|
||||
Assert.ok(!Cu.loadedJSModules.includes(URL3));
|
||||
Assert.ok(!Cu.isJSModuleLoaded(URL3));
|
||||
Assert.ok(!Cu.loadedESModules.includes(URL1));
|
||||
Assert.ok(!Cu.isESModuleLoaded(URL1));
|
||||
Assert.ok(!Cu.loadedESModules.includes(URL2));
|
||||
Assert.ok(!Cu.isESModuleLoaded(URL2));
|
||||
Assert.ok(!Cu.loadedESModules.includes(URL3));
|
||||
Assert.ok(!Cu.isESModuleLoaded(URL3));
|
||||
|
||||
ChromeUtils.import(URL2);
|
||||
|
||||
Assert.ok(Cu.loadedJSModules.includes(URL1));
|
||||
Assert.ok(Cu.isJSModuleLoaded(URL1));
|
||||
Assert.ok(Cu.loadedJSModules.includes(URL2));
|
||||
Assert.ok(Cu.isJSModuleLoaded(URL2));
|
||||
Assert.ok(!Cu.loadedJSModules.includes(URL3));
|
||||
Assert.ok(!Cu.isJSModuleLoaded(URL3));
|
||||
Assert.ok(!Cu.loadedESModules.includes(URL1));
|
||||
Assert.ok(!Cu.isESModuleLoaded(URL1));
|
||||
Assert.ok(!Cu.loadedESModules.includes(URL2));
|
||||
Assert.ok(!Cu.isESModuleLoaded(URL2));
|
||||
Assert.ok(!Cu.loadedESModules.includes(URL3));
|
||||
Assert.ok(!Cu.isESModuleLoaded(URL3));
|
||||
|
||||
ChromeUtils.import(URL3);
|
||||
|
||||
Assert.ok(Cu.loadedJSModules.includes(URL1));
|
||||
Assert.ok(Cu.isJSModuleLoaded(URL1));
|
||||
Assert.ok(Cu.loadedJSModules.includes(URL2));
|
||||
Assert.ok(Cu.isJSModuleLoaded(URL2));
|
||||
Assert.ok(Cu.loadedJSModules.includes(URL3));
|
||||
Assert.ok(Cu.isJSModuleLoaded(URL3));
|
||||
Assert.ok(!Cu.loadedESModules.includes(URL1));
|
||||
Assert.ok(!Cu.isESModuleLoaded(URL1));
|
||||
Assert.ok(!Cu.loadedESModules.includes(URL2));
|
||||
Assert.ok(!Cu.isESModuleLoaded(URL2));
|
||||
Assert.ok(!Cu.loadedESModules.includes(URL3));
|
||||
Assert.ok(!Cu.isESModuleLoaded(URL3));
|
||||
});
|
||||
|
||||
add_task(function test_ESModule() {
|
||||
const URL1 = "resource://test/es6module_loaded-1.sys.mjs";
|
||||
const URL2 = "resource://test/es6module_loaded-2.sys.mjs";
|
||||
const URL3 = "resource://test/es6module_loaded-3.sys.mjs";
|
||||
|
||||
Assert.ok(!Cu.loadedJSModules.includes(URL1));
|
||||
Assert.ok(!Cu.isJSModuleLoaded(URL1));
|
||||
Assert.ok(!Cu.loadedJSModules.includes(URL2));
|
||||
Assert.ok(!Cu.isJSModuleLoaded(URL2));
|
||||
Assert.ok(!Cu.loadedJSModules.includes(URL3));
|
||||
Assert.ok(!Cu.isJSModuleLoaded(URL3));
|
||||
Assert.ok(!Cu.loadedESModules.includes(URL1));
|
||||
Assert.ok(!Cu.isESModuleLoaded(URL1));
|
||||
Assert.ok(!Cu.loadedESModules.includes(URL2));
|
||||
Assert.ok(!Cu.isESModuleLoaded(URL2));
|
||||
Assert.ok(!Cu.loadedESModules.includes(URL3));
|
||||
Assert.ok(!Cu.isESModuleLoaded(URL3));
|
||||
|
||||
ChromeUtils.importESModule(URL1);
|
||||
|
||||
Assert.ok(!Cu.loadedJSModules.includes(URL1));
|
||||
Assert.ok(!Cu.isJSModuleLoaded(URL1));
|
||||
Assert.ok(!Cu.loadedJSModules.includes(URL2));
|
||||
Assert.ok(!Cu.isJSModuleLoaded(URL2));
|
||||
Assert.ok(!Cu.loadedJSModules.includes(URL3));
|
||||
Assert.ok(!Cu.isJSModuleLoaded(URL3));
|
||||
Assert.ok(Cu.loadedESModules.includes(URL1));
|
||||
Assert.ok(Cu.isESModuleLoaded(URL1));
|
||||
Assert.ok(!Cu.loadedESModules.includes(URL2));
|
||||
Assert.ok(!Cu.isESModuleLoaded(URL2));
|
||||
Assert.ok(!Cu.loadedESModules.includes(URL3));
|
||||
Assert.ok(!Cu.isESModuleLoaded(URL3));
|
||||
|
||||
ChromeUtils.importESModule(URL2);
|
||||
|
||||
Assert.ok(!Cu.loadedJSModules.includes(URL1));
|
||||
Assert.ok(!Cu.isJSModuleLoaded(URL1));
|
||||
Assert.ok(!Cu.loadedJSModules.includes(URL2));
|
||||
Assert.ok(!Cu.isJSModuleLoaded(URL2));
|
||||
Assert.ok(!Cu.loadedJSModules.includes(URL3));
|
||||
Assert.ok(!Cu.isJSModuleLoaded(URL3));
|
||||
Assert.ok(Cu.loadedESModules.includes(URL1));
|
||||
Assert.ok(Cu.isESModuleLoaded(URL1));
|
||||
Assert.ok(Cu.loadedESModules.includes(URL2));
|
||||
Assert.ok(Cu.isESModuleLoaded(URL2));
|
||||
Assert.ok(!Cu.loadedESModules.includes(URL3));
|
||||
Assert.ok(!Cu.isESModuleLoaded(URL3));
|
||||
|
||||
ChromeUtils.importESModule(URL3);
|
||||
|
||||
Assert.ok(!Cu.loadedJSModules.includes(URL1));
|
||||
Assert.ok(!Cu.isJSModuleLoaded(URL1));
|
||||
Assert.ok(!Cu.loadedJSModules.includes(URL2));
|
||||
Assert.ok(!Cu.isJSModuleLoaded(URL2));
|
||||
Assert.ok(!Cu.loadedJSModules.includes(URL3));
|
||||
Assert.ok(!Cu.isJSModuleLoaded(URL3));
|
||||
Assert.ok(Cu.loadedESModules.includes(URL1));
|
||||
Assert.ok(Cu.isESModuleLoaded(URL1));
|
||||
Assert.ok(Cu.loadedESModules.includes(URL2));
|
||||
Assert.ok(Cu.isESModuleLoaded(URL2));
|
||||
Assert.ok(Cu.loadedESModules.includes(URL3));
|
||||
Assert.ok(Cu.isESModuleLoaded(URL3));
|
||||
});
|
|
@ -36,14 +36,6 @@ support-files =
|
|||
esmified-6.sys.mjs
|
||||
esmified-not-exported.sys.mjs
|
||||
not-esmified-not-exported.jsm
|
||||
esm_lazy-1.sys.mjs
|
||||
esm_lazy-2.sys.mjs
|
||||
jsm_loaded-1.jsm
|
||||
jsm_loaded-2.jsm
|
||||
jsm_loaded-3.jsm
|
||||
es6module_loaded-1.sys.mjs
|
||||
es6module_loaded-2.sys.mjs
|
||||
es6module_loaded-3.sys.mjs
|
||||
|
||||
[test_allowWaivers.js]
|
||||
[test_bogus_files.js]
|
||||
|
@ -188,5 +180,3 @@ head = head_watchdog.js
|
|||
[test_print_stderr.js]
|
||||
[test_import_es6_modules.js]
|
||||
[test_import_shim.js]
|
||||
[test_defineESModuleGetters.js]
|
||||
[test_loadedESModules.js]
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
/* vim: set ts=2 sw=2 sts=2 et tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
"use strict";
|
||||
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export class TestProcessActorChild extends JSProcessActorChild {
|
||||
constructor() {
|
||||
super();
|
||||
this.sawActorCreated = false;
|
||||
}
|
||||
|
||||
actorCreated() {
|
||||
this.sawActorCreated = true;
|
||||
}
|
||||
|
||||
receiveMessage(aMessage) {
|
||||
switch (aMessage.name) {
|
||||
case "toChild":
|
||||
aMessage.data.toChild = true;
|
||||
this.sendAsyncMessage("toParent", aMessage.data);
|
||||
break;
|
||||
case "asyncAdd":
|
||||
let { a, b } = aMessage.data;
|
||||
return new Promise(resolve => {
|
||||
resolve({ result: a + b });
|
||||
});
|
||||
case "error":
|
||||
return Promise.reject(new SyntaxError(aMessage.data.message));
|
||||
case "exception":
|
||||
return Promise.reject(
|
||||
Components.Exception(aMessage.data.message, aMessage.data.result)
|
||||
);
|
||||
case "done":
|
||||
this.done(aMessage.data);
|
||||
break;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
observe(subject, topic, data) {
|
||||
this.lastObserved = { subject, topic, data };
|
||||
}
|
||||
|
||||
show() {
|
||||
return "TestProcessActorChild";
|
||||
}
|
||||
|
||||
didDestroy() {
|
||||
Services.obs.notifyObservers(
|
||||
this,
|
||||
"test-js-content-actor-diddestroy",
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
/* vim: set ts=2 sw=2 sts=2 et tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
"use strict";
|
||||
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export class TestProcessActorParent extends JSProcessActorParent {
|
||||
constructor() {
|
||||
super();
|
||||
this.wrappedJSObject = this;
|
||||
this.sawActorCreated = false;
|
||||
}
|
||||
|
||||
actorCreated() {
|
||||
this.sawActorCreated = true;
|
||||
}
|
||||
|
||||
receiveMessage(aMessage) {
|
||||
switch (aMessage.name) {
|
||||
case "init":
|
||||
aMessage.data.initial = true;
|
||||
this.sendAsyncMessage("toChild", aMessage.data);
|
||||
break;
|
||||
case "toParent":
|
||||
aMessage.data.toParent = true;
|
||||
this.sendAsyncMessage("done", aMessage.data);
|
||||
break;
|
||||
case "asyncMul":
|
||||
let { a, b } = aMessage.data;
|
||||
return { result: a * b };
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
show() {
|
||||
return "TestProcessActorParent";
|
||||
}
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
/* vim: set ts=2 sw=2 sts=2 et tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
"use strict";
|
||||
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
var docShellThunks = new Map();
|
||||
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export class TestWindowChild extends JSWindowActorChild {
|
||||
constructor() {
|
||||
super();
|
||||
this.sawActorCreated = false;
|
||||
|
||||
try {
|
||||
void this.contentWindow;
|
||||
} catch (e) {
|
||||
this.uninitializedGetterError = e;
|
||||
}
|
||||
}
|
||||
|
||||
actorCreated() {
|
||||
this.sawActorCreated = true;
|
||||
}
|
||||
|
||||
receiveMessage(aMessage) {
|
||||
switch (aMessage.name) {
|
||||
case "toChild":
|
||||
aMessage.data.toChild = true;
|
||||
this.sendAsyncMessage("toParent", aMessage.data);
|
||||
break;
|
||||
case "asyncAdd":
|
||||
let { a, b } = aMessage.data;
|
||||
return new Promise(resolve => {
|
||||
resolve({ result: a + b });
|
||||
});
|
||||
case "error":
|
||||
return Promise.reject(new SyntaxError(aMessage.data.message));
|
||||
case "exception":
|
||||
return Promise.reject(
|
||||
Components.Exception(aMessage.data.message, aMessage.data.result)
|
||||
);
|
||||
case "done":
|
||||
this.done(aMessage.data);
|
||||
break;
|
||||
case "noncloneReply":
|
||||
// Return a value which is non-cloneable, like a WindowProxy.
|
||||
return this.contentWindow;
|
||||
case "storeActor":
|
||||
docShellThunks.set(this.docShell, this);
|
||||
break;
|
||||
case "checkActor": {
|
||||
let actor = docShellThunks.get(this.docShell);
|
||||
docShellThunks.delete(this.docShell);
|
||||
|
||||
let contentWindow;
|
||||
let error;
|
||||
try {
|
||||
contentWindow = actor.contentWindow;
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
if (error) {
|
||||
return {
|
||||
status: "error",
|
||||
errorType: error.name,
|
||||
};
|
||||
}
|
||||
return {
|
||||
status: "success",
|
||||
valueIsNull: contentWindow === null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
handleEvent(aEvent) {
|
||||
this.sendAsyncMessage("event", { type: aEvent.type });
|
||||
}
|
||||
|
||||
observe(subject, topic, data) {
|
||||
switch (topic) {
|
||||
case "audio-playback":
|
||||
this.done({ subject, topic, data });
|
||||
break;
|
||||
default:
|
||||
this.lastObserved = { subject, topic, data };
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
show() {
|
||||
return "TestWindowChild";
|
||||
}
|
||||
|
||||
didDestroy() {
|
||||
Services.obs.notifyObservers(this, "test-js-window-actor-diddestroy", true);
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
/* vim: set ts=2 sw=2 sts=2 et tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
"use strict";
|
||||
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export class TestWindowParent extends JSWindowActorParent {
|
||||
constructor() {
|
||||
super();
|
||||
this.wrappedJSObject = this;
|
||||
this.sawActorCreated = false;
|
||||
}
|
||||
|
||||
actorCreated() {
|
||||
this.sawActorCreated = true;
|
||||
}
|
||||
|
||||
receiveMessage(aMessage) {
|
||||
switch (aMessage.name) {
|
||||
case "init":
|
||||
aMessage.data.initial = true;
|
||||
this.sendAsyncMessage("toChild", aMessage.data);
|
||||
break;
|
||||
case "toParent":
|
||||
aMessage.data.toParent = true;
|
||||
this.sendAsyncMessage("done", aMessage.data);
|
||||
break;
|
||||
case "asyncMul":
|
||||
let { a, b } = aMessage.data;
|
||||
return { result: a * b };
|
||||
|
||||
case "event":
|
||||
Services.obs.notifyObservers(
|
||||
this,
|
||||
"test-js-window-actor-parent-event",
|
||||
aMessage.data.type
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
show() {
|
||||
return "TestWindowParent";
|
||||
}
|
||||
}
|
|
@ -23,13 +23,9 @@ SPHINX_TREES["actors"] = "docs"
|
|||
|
||||
TESTING_JS_MODULES += [
|
||||
"TestProcessActorChild.jsm",
|
||||
"TestProcessActorChild.sys.mjs",
|
||||
"TestProcessActorParent.jsm",
|
||||
"TestProcessActorParent.sys.mjs",
|
||||
"TestWindowChild.jsm",
|
||||
"TestWindowChild.sys.mjs",
|
||||
"TestWindowParent.jsm",
|
||||
"TestWindowParent.sys.mjs",
|
||||
]
|
||||
|
||||
FINAL_TARGET_FILES.actors += [
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
/* globals WebExtensionPolicy */
|
||||
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { XPCOMUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
|
@ -26,6 +25,7 @@ ChromeUtils.defineModuleGetter(
|
|||
"NetUtil",
|
||||
"resource://gre/modules/NetUtil.jsm"
|
||||
);
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
lazy,
|
||||
|
@ -46,7 +46,7 @@ const ArrayBufferInputStream = Components.Constructor(
|
|||
* See SubstituteChannel in netwerk/protocol/res/ExtensionProtocolHandler.cpp
|
||||
* for usage.
|
||||
*/
|
||||
export function AddonLocalizationConverter() {}
|
||||
function AddonLocalizationConverter() {}
|
||||
|
||||
AddonLocalizationConverter.prototype = {
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIStreamConverter"]),
|
||||
|
@ -137,7 +137,7 @@ AddonLocalizationConverter.prototype = {
|
|||
},
|
||||
};
|
||||
|
||||
export function HttpIndexViewer() {}
|
||||
function HttpIndexViewer() {}
|
||||
|
||||
HttpIndexViewer.prototype = {
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIDocumentLoaderFactory"]),
|
||||
|
@ -180,3 +180,5 @@ HttpIndexViewer.prototype = {
|
|||
return res;
|
||||
},
|
||||
};
|
||||
|
||||
var EXPORTED_SYMBOLS = ["AddonLocalizationConverter", "HttpIndexViewer"];
|
|
@ -8,13 +8,13 @@ Classes = [
|
|||
{
|
||||
'cid': '{ded150e3-c92e-4077-a396-0dba9953e39f}',
|
||||
'contract_ids': ['@mozilla.org/streamconv;1?from=application/vnd.mozilla.webext.unlocalized&to=text/css'],
|
||||
'esModule': 'resource://gre/modules/SimpleServices.sys.mjs',
|
||||
'jsm': 'resource://gre/modules/SimpleServices.jsm',
|
||||
'constructor': 'AddonLocalizationConverter',
|
||||
},
|
||||
{
|
||||
'cid': '{742ad274-34c5-43d1-a8b7-293eaf8962d6}',
|
||||
'contract_ids': ['@mozilla.org/content-viewers/http-index-format'],
|
||||
'esModule': 'resource://gre/modules/SimpleServices.sys.mjs',
|
||||
'jsm': 'resource://gre/modules/SimpleServices.jsm',
|
||||
'constructor': 'HttpIndexViewer',
|
||||
'categories': {'Gecko-Content-Viewers': 'application/http-index-format'},
|
||||
},
|
||||
|
|
|
@ -8,7 +8,7 @@ with Files("**"):
|
|||
BUG_COMPONENT = ("Toolkit", "General")
|
||||
|
||||
EXTRA_JS_MODULES += [
|
||||
"SimpleServices.sys.mjs",
|
||||
"SimpleServices.jsm",
|
||||
]
|
||||
|
||||
EXTRA_JS_MODULES["components-utils"] = [
|
||||
|
|
|
@ -50,7 +50,6 @@ module.exports = {
|
|||
},
|
||||
files: ["**/*.sys.mjs", "**/*.jsm", "**/*.jsm.js"],
|
||||
rules: {
|
||||
"mozilla/lazy-getter-object-name": "error",
|
||||
"mozilla/reject-global-this": "error",
|
||||
"mozilla/reject-globalThis-modification": "error",
|
||||
"mozilla/reject-top-level-await": "error",
|
||||
|
|
|
@ -39,7 +39,6 @@ module.exports = {
|
|||
"import-content-task-globals": require("../lib/rules/import-content-task-globals"),
|
||||
"import-globals": require("../lib/rules/import-globals"),
|
||||
"import-headjs-globals": require("../lib/rules/import-headjs-globals"),
|
||||
"lazy-getter-object-name": require("../lib/rules/lazy-getter-object-name"),
|
||||
"mark-exported-symbols-as-used": require("../lib/rules/mark-exported-symbols-as-used"),
|
||||
"mark-test-function-used": require("../lib/rules/mark-test-function-used"),
|
||||
"no-aArgs": require("../lib/rules/no-aArgs"),
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
/**
|
||||
* @fileoverview Enforce the standard object name for
|
||||
* ChromeUtils.defineESModuleGetters
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
function isIdentifier(node, id) {
|
||||
return node.type === "Identifier" && node.name === id;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
meta: {
|
||||
docs: {
|
||||
url:
|
||||
"https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint-plugin-mozilla/lazy-getter-object-name.html",
|
||||
},
|
||||
type: "problem",
|
||||
},
|
||||
|
||||
create(context) {
|
||||
return {
|
||||
CallExpression(node) {
|
||||
let { callee } = node;
|
||||
if (
|
||||
callee.type === "MemberExpression" &&
|
||||
isIdentifier(callee.object, "ChromeUtils") &&
|
||||
isIdentifier(callee.property, "defineESModuleGetters") &&
|
||||
node.arguments.length >= 1 &&
|
||||
!isIdentifier(node.arguments[0], "lazy")
|
||||
) {
|
||||
context.report({
|
||||
node,
|
||||
message:
|
||||
"The variable name of the object passed to ChromeUtils.defineESModuleGetters must be `lazy`",
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
|
@ -1,50 +0,0 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
var rule = require("../lib/rules/lazy-getter-object-name");
|
||||
var RuleTester = require("eslint").RuleTester;
|
||||
|
||||
const ruleTester = new RuleTester();
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Tests
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
function invalidCode(code) {
|
||||
let message =
|
||||
"The variable name of the object passed to ChromeUtils.defineESModuleGetters must be `lazy`";
|
||||
return { code, errors: [{ message, type: "CallExpression" }] };
|
||||
}
|
||||
|
||||
ruleTester.run("lazy-getter-object-name", rule, {
|
||||
valid: [
|
||||
`
|
||||
ChromeUtils.defineESModuleGetters(lazy, {
|
||||
Services: "resource://gre/modules/Services.sys.mjs",
|
||||
});
|
||||
`,
|
||||
],
|
||||
invalid: [
|
||||
invalidCode(`
|
||||
ChromeUtils.defineESModuleGetters(obj, {
|
||||
Services: "resource://gre/modules/Services.sys.mjs",
|
||||
});
|
||||
`),
|
||||
invalidCode(`
|
||||
ChromeUtils.defineESModuleGetters(this, {
|
||||
Services: "resource://gre/modules/Services.sys.mjs",
|
||||
});
|
||||
`),
|
||||
invalidCode(`
|
||||
ChromeUtils.defineESModuleGetters(window, {
|
||||
Services: "resource://gre/modules/Services.sys.mjs",
|
||||
});
|
||||
`),
|
||||
],
|
||||
});
|
|
@ -87,10 +87,6 @@ const StringOffset gComponentJSMs[] = {
|
|||
//# @component_jsms@
|
||||
};
|
||||
|
||||
const StringOffset gComponentESModules[] = {
|
||||
//# @component_esmodules@
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a nsCString corresponding to the given entry in the `gStrings` string
|
||||
* table. The resulting nsCString points directly to static storage, and does
|
||||
|
@ -111,12 +107,10 @@ 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 ConstructJSMComponent(const nsACString& aURI,
|
||||
const char* aConstructor,
|
||||
nsISupports** aResult) {
|
||||
if (!nsComponentManagerImpl::JSLoaderReady()) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
@ -125,21 +119,17 @@ static nsresult ConstructJSMOrESMComponent(const nsACString& aURI,
|
|||
MOZ_ALWAYS_TRUE(jsapi.Init(xpc::PrivilegedJunkScope()));
|
||||
JSContext* cx = jsapi.cx();
|
||||
|
||||
JS::Rooted<JSObject*> exports(cx);
|
||||
if constexpr (type == ComponentType::JSM) {
|
||||
JS::Rooted<JSObject*> global(cx);
|
||||
MOZ_TRY(mozJSComponentLoader::Get()->Import(cx, aURI, &global, &exports));
|
||||
} else {
|
||||
MOZ_TRY(mozJSComponentLoader::Get()->ImportESModule(cx, aURI, &exports));
|
||||
}
|
||||
JS::RootedObject global(cx);
|
||||
JS::RootedObject exports(cx);
|
||||
MOZ_TRY(mozJSComponentLoader::Get()->Import(cx, aURI, &global, &exports));
|
||||
|
||||
JS::Rooted<JS::Value> ctor(cx);
|
||||
JS::RootedValue ctor(cx);
|
||||
if (!JS_GetProperty(cx, exports, aConstructor, &ctor) ||
|
||||
!ctor.isObject()) {
|
||||
return NS_ERROR_XPC_JSOBJECT_HAS_NO_FUNCTION_NAMED;
|
||||
}
|
||||
|
||||
JS::Rooted<JSObject*> inst(cx);
|
||||
JS::RootedObject inst(cx);
|
||||
if (!JS::Construct(cx, ctor, JS::HandleValueArray::empty(), &inst)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -148,19 +138,6 @@ static nsresult ConstructJSMOrESMComponent(const nsACString& aURI,
|
|||
(void**)aResult);
|
||||
}
|
||||
|
||||
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@
|
||||
|
||||
|
@ -353,20 +330,6 @@ StaticComponents::GetComponentJSMs() {
|
|||
return result.forget();
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<nsIUTF8StringEnumerator>
|
||||
StaticComponents::GetComponentESModules() {
|
||||
auto esModules = MakeUnique<nsTArray<nsCString>>(MOZ_ARRAY_LENGTH(gComponentESModules));
|
||||
|
||||
for (const auto& entry : gComponentESModules) {
|
||||
esModules->AppendElement(GetString(entry));
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIUTF8StringEnumerator> result;
|
||||
MOZ_ALWAYS_SUCCEEDS(NS_NewAdoptingUTF8StringEnumerator(getter_AddRefs(result),
|
||||
esModules.release()));
|
||||
return result.forget();
|
||||
}
|
||||
|
||||
/* static */ Span<const JSServiceEntry> StaticComponents::GetJSServices() {
|
||||
return { gJSServices, ArrayLength(gJSServices) };
|
||||
}
|
||||
|
|
|
@ -243,7 +243,6 @@ class StaticComponents final {
|
|||
bool aInvalid = true);
|
||||
|
||||
static already_AddRefed<nsIUTF8StringEnumerator> GetComponentJSMs();
|
||||
static already_AddRefed<nsIUTF8StringEnumerator> GetComponentESModules();
|
||||
|
||||
static Span<const JSServiceEntry> GetJSServices();
|
||||
|
||||
|
|
|
@ -282,7 +282,6 @@ class ModuleEntry(object):
|
|||
self.init_method = data.get("init_method", [])
|
||||
|
||||
self.jsm = data.get("jsm", None)
|
||||
self.esModule = data.get("esModule", None)
|
||||
|
||||
self.external = data.get(
|
||||
"external", not (self.headers or self.legacy_constructor)
|
||||
|
@ -308,16 +307,6 @@ class ModuleEntry(object):
|
|||
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 not self.constructor:
|
||||
error("JavaScript components must specify a constructor")
|
||||
|
||||
for prop in ("init_method", "legacy_constructor", "headers"):
|
||||
if getattr(self, prop):
|
||||
error(
|
||||
|
@ -424,14 +413,6 @@ class ModuleEntry(object):
|
|||
" getter_AddRefs(inst)));"
|
||||
"\n" % (json.dumps(self.jsm), json.dumps(self.constructor))
|
||||
)
|
||||
elif self.esModule:
|
||||
res += (
|
||||
" nsCOMPtr<nsISupports> inst;\n"
|
||||
" MOZ_TRY(ConstructESModuleComponent(nsLiteralCString(%s),\n"
|
||||
" %s,\n"
|
||||
" getter_AddRefs(inst)));"
|
||||
"\n" % (json.dumps(self.esModule), json.dumps(self.constructor))
|
||||
)
|
||||
elif self.external:
|
||||
res += (
|
||||
" nsCOMPtr<nsISupports> inst = "
|
||||
|
@ -762,7 +743,6 @@ def gen_substs(manifests):
|
|||
js_services = {}
|
||||
|
||||
jsms = set()
|
||||
esModules = set()
|
||||
|
||||
types = set()
|
||||
|
||||
|
@ -787,9 +767,6 @@ def gen_substs(manifests):
|
|||
if mod.jsm:
|
||||
jsms.add(mod.jsm)
|
||||
|
||||
if mod.esModule:
|
||||
esModules.add(mod.esModule)
|
||||
|
||||
if mod.js_name:
|
||||
if mod.js_name in js_services:
|
||||
raise Exception("Duplicate JS service name: %s" % mod.js_name)
|
||||
|
@ -828,12 +805,6 @@ def gen_substs(manifests):
|
|||
substs["component_jsms"] = (
|
||||
"\n".join(" %s," % strings.entry_to_cxx(jsm) for jsm in sorted(jsms)) + "\n"
|
||||
)
|
||||
substs["component_esmodules"] = (
|
||||
"\n".join(
|
||||
" %s," % strings.entry_to_cxx(esModule) for esModule in sorted(esModules)
|
||||
)
|
||||
+ "\n"
|
||||
)
|
||||
|
||||
substs["interfaces"] = gen_interfaces(interfaces)
|
||||
|
||||
|
|
|
@ -1877,15 +1877,6 @@ nsComponentManagerImpl::GetComponentJSMs(nsIUTF8StringEnumerator** aJSMs) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComponentManagerImpl::GetComponentESModules(
|
||||
nsIUTF8StringEnumerator** aESModules) {
|
||||
nsCOMPtr<nsIUTF8StringEnumerator> result =
|
||||
StaticComponents::GetComponentESModules();
|
||||
result.forget(aESModules);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComponentManagerImpl::GetManifestLocations(nsIArray** aLocations) {
|
||||
NS_ENSURE_ARG_POINTER(aLocations);
|
||||
|
|
|
@ -101,12 +101,6 @@ interface nsIComponentManager : nsISupports
|
|||
* should only be used in automation.
|
||||
*/
|
||||
nsIUTF8StringEnumerator getComponentJSMs();
|
||||
|
||||
/**
|
||||
* Returns a list of ESM URLs which are used to create components. This
|
||||
* should only be used in automation.
|
||||
*/
|
||||
nsIUTF8StringEnumerator getComponentESModules();
|
||||
};
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче