зеркало из https://github.com/mozilla/gecko-dev.git
Backed out 2 changesets (bug 1668330) for GlobalObject.h related bustage and spidermonkey failures CLOSED TREE
DONTBUILD Backed out changeset 2d76323e5c0c (bug 1668330) Backed out changeset ac4f085c9f32 (bug 1668330)
This commit is contained in:
Родитель
c845650f07
Коммит
d593453f4a
|
@ -1016,12 +1016,12 @@ static LoadedScript* GetLoadedScriptOrNull(
|
|||
return script;
|
||||
}
|
||||
|
||||
// 8.1.3.8.1 HostResolveImportedModule(referencingModule, moduleRequest)
|
||||
// 8.1.3.8.1 HostResolveImportedModule(referencingModule, specifier)
|
||||
JSObject* HostResolveImportedModule(JSContext* aCx,
|
||||
JS::Handle<JS::Value> aReferencingPrivate,
|
||||
JS::Handle<JSObject*> aModuleRequest) {
|
||||
JS::Handle<JSString*> aSpecifier) {
|
||||
JS::Rooted<JSObject*> module(aCx);
|
||||
ScriptLoader::ResolveImportedModule(aCx, aReferencingPrivate, aModuleRequest,
|
||||
ScriptLoader::ResolveImportedModule(aCx, aReferencingPrivate, aSpecifier,
|
||||
&module);
|
||||
return module;
|
||||
}
|
||||
|
@ -1029,22 +1029,15 @@ JSObject* HostResolveImportedModule(JSContext* aCx,
|
|||
/* static */
|
||||
void ScriptLoader::ResolveImportedModule(
|
||||
JSContext* aCx, JS::Handle<JS::Value> aReferencingPrivate,
|
||||
JS::Handle<JSObject*> aModuleRequest,
|
||||
JS::MutableHandle<JSObject*> aModuleOut) {
|
||||
JS::Handle<JSString*> aSpecifier, JS::MutableHandle<JSObject*> aModuleOut) {
|
||||
MOZ_ASSERT(!aModuleOut);
|
||||
|
||||
RefPtr<LoadedScript> script(GetLoadedScriptOrNull(aCx, aReferencingPrivate));
|
||||
|
||||
JS::Rooted<JSString*> specifierString(
|
||||
aCx, JS::GetModuleRequestSpecifier(aCx, aModuleRequest));
|
||||
if (!specifierString) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Let url be the result of resolving a module specifier given referencing
|
||||
// module script and specifier.
|
||||
nsAutoJSString string;
|
||||
if (!string.init(aCx, specifierString)) {
|
||||
if (!string.init(aCx, aSpecifier)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1104,19 +1097,13 @@ bool HostPopulateImportMeta(JSContext* aCx,
|
|||
|
||||
bool HostImportModuleDynamically(JSContext* aCx,
|
||||
JS::Handle<JS::Value> aReferencingPrivate,
|
||||
JS::Handle<JSObject*> aModuleRequest,
|
||||
JS::Handle<JSString*> aSpecifier,
|
||||
JS::Handle<JSObject*> aPromise) {
|
||||
RefPtr<LoadedScript> script(GetLoadedScriptOrNull(aCx, aReferencingPrivate));
|
||||
|
||||
JS::Rooted<JSString*> specifierString(
|
||||
aCx, JS::GetModuleRequestSpecifier(aCx, aModuleRequest));
|
||||
if (!specifierString) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Attempt to resolve the module specifier.
|
||||
nsAutoJSString specifier;
|
||||
if (!specifier.init(aCx, specifierString)) {
|
||||
if (!specifier.init(aCx, aSpecifier)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1172,8 +1159,7 @@ bool HostImportModuleDynamically(JSContext* aCx,
|
|||
}
|
||||
|
||||
RefPtr<ModuleLoadRequest> request = ModuleLoadRequest::CreateDynamicImport(
|
||||
uri, options, baseURL, loader, aReferencingPrivate, specifierString,
|
||||
aPromise);
|
||||
uri, options, baseURL, loader, aReferencingPrivate, aSpecifier, aPromise);
|
||||
|
||||
loader->StartDynamicImport(request);
|
||||
return true;
|
||||
|
@ -1234,14 +1220,8 @@ void ScriptLoader::FinishDynamicImport_NoTLA(JSContext* aCx,
|
|||
JS::Rooted<JSString*> specifier(aCx, aRequest->mDynamicSpecifier);
|
||||
JS::Rooted<JSObject*> promise(aCx, aRequest->mDynamicPromise);
|
||||
|
||||
JS::Rooted<JSObject*> moduleRequest(aCx,
|
||||
JS::CreateModuleRequest(aCx, specifier));
|
||||
if (!moduleRequest) {
|
||||
JS_ReportOutOfMemory(aCx);
|
||||
}
|
||||
|
||||
JS::FinishDynamicModuleImport_NoTLA(aCx, status, referencingScript,
|
||||
moduleRequest, promise);
|
||||
JS::FinishDynamicModuleImport_NoTLA(aCx, status, referencingScript, specifier,
|
||||
promise);
|
||||
|
||||
// FinishDynamicModuleImport clears any pending exception.
|
||||
MOZ_ASSERT(!JS_IsExceptionPending(aCx));
|
||||
|
@ -1274,14 +1254,8 @@ void ScriptLoader::FinishDynamicImport(
|
|||
JS::Rooted<JSString*> specifier(aCx, aRequest->mDynamicSpecifier);
|
||||
JS::Rooted<JSObject*> promise(aCx, aRequest->mDynamicPromise);
|
||||
|
||||
JS::Rooted<JSObject*> moduleRequest(aCx,
|
||||
JS::CreateModuleRequest(aCx, specifier));
|
||||
if (!moduleRequest) {
|
||||
JS_ReportOutOfMemory(aCx);
|
||||
}
|
||||
|
||||
JS::FinishDynamicModuleImport(aCx, aEvaluationPromise, referencingScript,
|
||||
moduleRequest, promise);
|
||||
specifier, promise);
|
||||
|
||||
// FinishDynamicModuleImport clears any pending exception.
|
||||
MOZ_ASSERT(!JS_IsExceptionPending(aCx));
|
||||
|
|
|
@ -403,12 +403,12 @@ class ScriptLoader final : public nsISupports {
|
|||
*
|
||||
* @param aReferencingPrivate A JS::Value which is either undefined
|
||||
* or contains a LoadedScript private pointer.
|
||||
* @param aModuleRequest A module request object.
|
||||
* @param aSpecifier The module specifier.
|
||||
* @param aModuleOut This is set to the module found.
|
||||
*/
|
||||
static void ResolveImportedModule(JSContext* aCx,
|
||||
JS::Handle<JS::Value> aReferencingPrivate,
|
||||
JS::Handle<JSObject*> aModuleRequest,
|
||||
JS::Handle<JSString*> aSpecifier,
|
||||
JS::MutableHandle<JSObject*> aModuleOut);
|
||||
|
||||
void StartDynamicImport(ModuleLoadRequest* aRequest);
|
||||
|
|
|
@ -34,7 +34,7 @@ union Utf8Unit;
|
|||
namespace JS {
|
||||
|
||||
using ModuleResolveHook = JSObject* (*)(JSContext*, Handle<Value>,
|
||||
Handle<JSObject*>);
|
||||
Handle<JSString*>);
|
||||
|
||||
/**
|
||||
* Get the HostResolveImportedModule hook for the runtime.
|
||||
|
@ -64,7 +64,7 @@ extern JS_PUBLIC_API void SetModuleMetadataHook(JSRuntime* rt,
|
|||
|
||||
using ModuleDynamicImportHook = bool (*)(JSContext* cx,
|
||||
Handle<Value> referencingPrivate,
|
||||
Handle<JSObject*> moduleRequest,
|
||||
Handle<JSString*> specifier,
|
||||
Handle<JSObject*> promise);
|
||||
|
||||
/**
|
||||
|
@ -97,7 +97,7 @@ enum class DynamicImportStatus { Failed = 0, Ok };
|
|||
*/
|
||||
extern JS_PUBLIC_API bool FinishDynamicModuleImport(
|
||||
JSContext* cx, Handle<JSObject*> evaluationPromise,
|
||||
Handle<Value> referencingPrivate, Handle<JSObject*> moduleRequest,
|
||||
Handle<Value> referencingPrivate, Handle<JSString*> specifier,
|
||||
Handle<JSObject*> promise);
|
||||
|
||||
/**
|
||||
|
@ -111,7 +111,7 @@ extern JS_PUBLIC_API bool FinishDynamicModuleImport(
|
|||
*/
|
||||
extern JS_PUBLIC_API bool FinishDynamicModuleImport_NoTLA(
|
||||
JSContext* cx, DynamicImportStatus status, Handle<Value> referencingPrivate,
|
||||
Handle<JSObject*> moduleRequest, Handle<JSObject*> promise);
|
||||
Handle<JSString*> specifier, Handle<JSObject*> promise);
|
||||
|
||||
/**
|
||||
* Parse the given source buffer as a module in the scope of the current global
|
||||
|
@ -211,11 +211,6 @@ extern JS_PUBLIC_API void GetRequestedModuleSourcePos(
|
|||
*/
|
||||
extern JS_PUBLIC_API JSScript* GetModuleScript(Handle<JSObject*> moduleRecord);
|
||||
|
||||
extern JS_PUBLIC_API JSObject* CreateModuleRequest(
|
||||
JSContext* cx, Handle<JSString*> specifierArg);
|
||||
extern JS_PUBLIC_API JSString* GetModuleRequestSpecifier(
|
||||
JSContext* cx, Handle<JSObject*> moduleRequestArg);
|
||||
|
||||
} // namespace JS
|
||||
|
||||
#endif // js_Modules_h
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
* 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/. */
|
||||
|
||||
function CallModuleResolveHook(module, moduleRequest, expectedMinimumStatus)
|
||||
function CallModuleResolveHook(module, specifier, expectedMinimumStatus)
|
||||
{
|
||||
let requestedModule = HostResolveImportedModule(module, moduleRequest);
|
||||
let requestedModule = HostResolveImportedModule(module, specifier);
|
||||
if (requestedModule.status < expectedMinimumStatus)
|
||||
ThrowInternalError(JSMSG_BAD_MODULE_STATUS);
|
||||
|
||||
|
@ -390,7 +390,7 @@ function InnerModuleLinking(module, stack, index)
|
|||
let requestedModules = module.requestedModules;
|
||||
for (let i = 0; i < requestedModules.length; i++) {
|
||||
// Step 9.a
|
||||
let required = requestedModules[i].moduleRequest;
|
||||
let required = requestedModules[i].moduleSpecifier;
|
||||
let requiredModule = CallModuleResolveHook(module, required, MODULE_STATUS_UNLINKED);
|
||||
|
||||
// Step 9.b
|
||||
|
@ -690,7 +690,7 @@ function InnerModuleEvaluation(module, stack, index)
|
|||
// Step 10
|
||||
let requestedModules = module.requestedModules;
|
||||
for (let i = 0; i < requestedModules.length; i++) {
|
||||
let required = requestedModules[i].moduleRequest;
|
||||
let required = requestedModules[i].moduleSpecifier;
|
||||
let requiredModule =
|
||||
CallModuleResolveHook(module, required, MODULE_STATUS_LINKED);
|
||||
|
||||
|
|
|
@ -102,16 +102,12 @@ DEFINE_GETTER_FUNCTIONS(ImportEntryObject, localName, LocalNameSlot)
|
|||
DEFINE_GETTER_FUNCTIONS(ImportEntryObject, lineNumber, LineNumberSlot)
|
||||
DEFINE_GETTER_FUNCTIONS(ImportEntryObject, columnNumber, ColumnNumberSlot)
|
||||
|
||||
DEFINE_ATOM_ACCESSOR_METHOD(ImportEntryObject, moduleRequest)
|
||||
DEFINE_ATOM_OR_NULL_ACCESSOR_METHOD(ImportEntryObject, importName)
|
||||
DEFINE_ATOM_ACCESSOR_METHOD(ImportEntryObject, localName)
|
||||
DEFINE_UINT32_ACCESSOR_METHOD(ImportEntryObject, lineNumber)
|
||||
DEFINE_UINT32_ACCESSOR_METHOD(ImportEntryObject, columnNumber)
|
||||
|
||||
ModuleRequestObject* ImportEntryObject::moduleRequest() const {
|
||||
Value value = getReservedSlot(ModuleRequestSlot);
|
||||
return &value.toObject().as<ModuleRequestObject>();
|
||||
}
|
||||
|
||||
/* static */
|
||||
bool ImportEntryObject::isInstance(HandleValue value) {
|
||||
return value.isObject() && value.toObject().is<ImportEntryObject>();
|
||||
|
@ -144,7 +140,7 @@ bool GlobalObject::initImportEntryProto(JSContext* cx,
|
|||
|
||||
/* static */
|
||||
ImportEntryObject* ImportEntryObject::create(
|
||||
JSContext* cx, HandleObject moduleRequest, HandleAtom maybeImportName,
|
||||
JSContext* cx, HandleAtom moduleRequest, HandleAtom maybeImportName,
|
||||
HandleAtom localName, uint32_t lineNumber, uint32_t columnNumber) {
|
||||
RootedObject proto(
|
||||
cx, GlobalObject::getOrCreateImportEntryPrototype(cx, cx->global()));
|
||||
|
@ -158,7 +154,7 @@ ImportEntryObject* ImportEntryObject::create(
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
self->initReservedSlot(ModuleRequestSlot, ObjectValue(*moduleRequest));
|
||||
self->initReservedSlot(ModuleRequestSlot, StringValue(moduleRequest));
|
||||
self->initReservedSlot(ImportNameSlot, StringOrNullValue(maybeImportName));
|
||||
self->initReservedSlot(LocalNameSlot, StringValue(localName));
|
||||
self->initReservedSlot(LineNumberSlot, NumberValue(lineNumber));
|
||||
|
@ -180,16 +176,12 @@ DEFINE_GETTER_FUNCTIONS(ExportEntryObject, lineNumber, LineNumberSlot)
|
|||
DEFINE_GETTER_FUNCTIONS(ExportEntryObject, columnNumber, ColumnNumberSlot)
|
||||
|
||||
DEFINE_ATOM_OR_NULL_ACCESSOR_METHOD(ExportEntryObject, exportName)
|
||||
DEFINE_ATOM_OR_NULL_ACCESSOR_METHOD(ExportEntryObject, moduleRequest)
|
||||
DEFINE_ATOM_OR_NULL_ACCESSOR_METHOD(ExportEntryObject, importName)
|
||||
DEFINE_ATOM_OR_NULL_ACCESSOR_METHOD(ExportEntryObject, localName)
|
||||
DEFINE_UINT32_ACCESSOR_METHOD(ExportEntryObject, lineNumber)
|
||||
DEFINE_UINT32_ACCESSOR_METHOD(ExportEntryObject, columnNumber)
|
||||
|
||||
ModuleRequestObject* ExportEntryObject::moduleRequest() const {
|
||||
Value value = getReservedSlot(ModuleRequestSlot);
|
||||
return &value.toObject().as<ModuleRequestObject>();
|
||||
}
|
||||
|
||||
/* static */
|
||||
bool ExportEntryObject::isInstance(HandleValue value) {
|
||||
return value.isObject() && value.toObject().is<ExportEntryObject>();
|
||||
|
@ -223,7 +215,7 @@ bool GlobalObject::initExportEntryProto(JSContext* cx,
|
|||
|
||||
/* static */
|
||||
ExportEntryObject* ExportEntryObject::create(
|
||||
JSContext* cx, HandleAtom maybeExportName, HandleObject moduleRequest,
|
||||
JSContext* cx, HandleAtom maybeExportName, HandleAtom maybeModuleRequest,
|
||||
HandleAtom maybeImportName, HandleAtom maybeLocalName, uint32_t lineNumber,
|
||||
uint32_t columnNumber) {
|
||||
// Line and column numbers are optional for export entries since direct
|
||||
|
@ -242,7 +234,8 @@ ExportEntryObject* ExportEntryObject::create(
|
|||
}
|
||||
|
||||
self->initReservedSlot(ExportNameSlot, StringOrNullValue(maybeExportName));
|
||||
self->initReservedSlot(ModuleRequestSlot, ObjectValue(*moduleRequest));
|
||||
self->initReservedSlot(ModuleRequestSlot,
|
||||
StringOrNullValue(maybeModuleRequest));
|
||||
self->initReservedSlot(ImportNameSlot, StringOrNullValue(maybeImportName));
|
||||
self->initReservedSlot(LocalNameSlot, StringOrNullValue(maybeLocalName));
|
||||
self->initReservedSlot(LineNumberSlot, NumberValue(lineNumber));
|
||||
|
@ -257,18 +250,15 @@ ExportEntryObject* ExportEntryObject::create(
|
|||
"RequestedModule",
|
||||
JSCLASS_HAS_RESERVED_SLOTS(RequestedModuleObject::SlotCount)};
|
||||
|
||||
DEFINE_GETTER_FUNCTIONS(RequestedModuleObject, moduleRequest, ModuleRequestSlot)
|
||||
DEFINE_GETTER_FUNCTIONS(RequestedModuleObject, moduleSpecifier,
|
||||
ModuleSpecifierSlot)
|
||||
DEFINE_GETTER_FUNCTIONS(RequestedModuleObject, lineNumber, LineNumberSlot)
|
||||
DEFINE_GETTER_FUNCTIONS(RequestedModuleObject, columnNumber, ColumnNumberSlot)
|
||||
|
||||
DEFINE_ATOM_ACCESSOR_METHOD(RequestedModuleObject, moduleSpecifier)
|
||||
DEFINE_UINT32_ACCESSOR_METHOD(RequestedModuleObject, lineNumber)
|
||||
DEFINE_UINT32_ACCESSOR_METHOD(RequestedModuleObject, columnNumber)
|
||||
|
||||
ModuleRequestObject* RequestedModuleObject::moduleRequest() const {
|
||||
Value value = getReservedSlot(ModuleRequestSlot);
|
||||
return &value.toObject().as<ModuleRequestObject>();
|
||||
}
|
||||
|
||||
/* static */
|
||||
bool RequestedModuleObject::isInstance(HandleValue value) {
|
||||
return value.isObject() && value.toObject().is<RequestedModuleObject>();
|
||||
|
@ -278,7 +268,7 @@ bool RequestedModuleObject::isInstance(HandleValue value) {
|
|||
bool GlobalObject::initRequestedModuleProto(JSContext* cx,
|
||||
Handle<GlobalObject*> global) {
|
||||
static const JSPropertySpec protoAccessors[] = {
|
||||
JS_PSG("moduleRequest", RequestedModuleObject_moduleRequestGetter, 0),
|
||||
JS_PSG("moduleSpecifier", RequestedModuleObject_moduleSpecifierGetter, 0),
|
||||
JS_PSG("lineNumber", RequestedModuleObject_lineNumberGetter, 0),
|
||||
JS_PSG("columnNumber", RequestedModuleObject_columnNumberGetter, 0),
|
||||
JS_PS_END};
|
||||
|
@ -299,7 +289,7 @@ bool GlobalObject::initRequestedModuleProto(JSContext* cx,
|
|||
|
||||
/* static */
|
||||
RequestedModuleObject* RequestedModuleObject::create(JSContext* cx,
|
||||
HandleObject moduleRequest,
|
||||
HandleAtom moduleSpecifier,
|
||||
uint32_t lineNumber,
|
||||
uint32_t columnNumber) {
|
||||
RootedObject proto(
|
||||
|
@ -314,66 +304,12 @@ RequestedModuleObject* RequestedModuleObject::create(JSContext* cx,
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
self->initReservedSlot(ModuleRequestSlot, ObjectValue(*moduleRequest));
|
||||
self->initReservedSlot(ModuleSpecifierSlot, StringValue(moduleSpecifier));
|
||||
self->initReservedSlot(LineNumberSlot, NumberValue(lineNumber));
|
||||
self->initReservedSlot(ColumnNumberSlot, NumberValue(columnNumber));
|
||||
return self;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// ModuleRequestObject
|
||||
/* static */ const JSClass ModuleRequestObject::class_ = {
|
||||
"ModuleRequest",
|
||||
JSCLASS_HAS_RESERVED_SLOTS(ModuleRequestObject::SlotCount)};
|
||||
|
||||
DEFINE_GETTER_FUNCTIONS(ModuleRequestObject, specifier, SpecifierSlot)
|
||||
|
||||
DEFINE_ATOM_OR_NULL_ACCESSOR_METHOD(ModuleRequestObject, specifier)
|
||||
|
||||
/* static */
|
||||
bool ModuleRequestObject::isInstance(HandleValue value) {
|
||||
return value.isObject() && value.toObject().is<ModuleRequestObject>();
|
||||
}
|
||||
|
||||
/* static */
|
||||
bool GlobalObject::initModuleRequestProto(JSContext* cx,
|
||||
Handle<GlobalObject*> global) {
|
||||
static const JSPropertySpec protoAccessors[] = {
|
||||
JS_PSG("specifier", ModuleRequestObject_specifierGetter, 0), JS_PS_END};
|
||||
|
||||
RootedObject proto(
|
||||
cx, GlobalObject::createBlankPrototype<PlainObject>(cx, global));
|
||||
if (!proto) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!DefinePropertiesAndFunctions(cx, proto, protoAccessors, nullptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
global->initReservedSlot(MODULE_REQUEST_PROTO, ObjectValue(*proto));
|
||||
return true;
|
||||
}
|
||||
|
||||
/* static */
|
||||
ModuleRequestObject* ModuleRequestObject::create(JSContext* cx,
|
||||
HandleAtom specifier) {
|
||||
RootedObject proto(
|
||||
cx, GlobalObject::getOrCreateModuleRequestPrototype(cx, cx->global()));
|
||||
if (!proto) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ModuleRequestObject* self =
|
||||
NewObjectWithGivenProto<ModuleRequestObject>(cx, proto);
|
||||
if (!self) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
self->initReservedSlot(SpecifierSlot, StringOrNullValue(specifier));
|
||||
return self;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// IndirectBindingMap
|
||||
|
||||
|
@ -1515,7 +1451,6 @@ static ArrayObject* ModuleBuilderInitArray(
|
|||
RootedAtom importName(cx);
|
||||
RootedAtom exportName(cx);
|
||||
RootedObject req(cx);
|
||||
RootedObject moduleRequest(cx);
|
||||
|
||||
for (uint32_t i = 0; i < vector.length(); ++i) {
|
||||
const frontend::StencilModuleEntry& entry = vector[i];
|
||||
|
@ -1548,24 +1483,18 @@ static ArrayObject* ModuleBuilderInitArray(
|
|||
MOZ_ASSERT(!exportName);
|
||||
}
|
||||
|
||||
moduleRequest = ModuleRequestObject::create(cx, specifier);
|
||||
if (!moduleRequest) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
switch (arrayType) {
|
||||
case ModuleArrayType::ImportEntryObject:
|
||||
MOZ_ASSERT(localName);
|
||||
req = ImportEntryObject::create(cx, moduleRequest, importName,
|
||||
localName, entry.lineno, entry.column);
|
||||
req = ImportEntryObject::create(cx, specifier, importName, localName,
|
||||
entry.lineno, entry.column);
|
||||
break;
|
||||
case ModuleArrayType::ExportEntryObject:
|
||||
req =
|
||||
ExportEntryObject::create(cx, exportName, moduleRequest, importName,
|
||||
localName, entry.lineno, entry.column);
|
||||
req = ExportEntryObject::create(cx, exportName, specifier, importName,
|
||||
localName, entry.lineno, entry.column);
|
||||
break;
|
||||
case ModuleArrayType::RequestedModuleObject:
|
||||
req = RequestedModuleObject::create(cx, moduleRequest, entry.lineno,
|
||||
req = RequestedModuleObject::create(cx, specifier, entry.lineno,
|
||||
entry.column);
|
||||
// TODO: Make this consistent with other object types.
|
||||
if (req && !FreezeObject(cx, req)) {
|
||||
|
@ -2059,15 +1988,14 @@ JSObject* js::GetOrCreateModuleMetaObject(JSContext* cx,
|
|||
|
||||
JSObject* js::CallModuleResolveHook(JSContext* cx,
|
||||
HandleValue referencingPrivate,
|
||||
HandleObject moduleRequest) {
|
||||
HandleString specifier) {
|
||||
JS::ModuleResolveHook moduleResolveHook = cx->runtime()->moduleResolveHook;
|
||||
if (!moduleResolveHook) {
|
||||
JS_ReportErrorASCII(cx, "Module resolve hook not set");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RootedObject result(cx,
|
||||
moduleResolveHook(cx, referencingPrivate, moduleRequest));
|
||||
RootedObject result(cx, moduleResolveHook(cx, referencingPrivate, specifier));
|
||||
if (!result) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -2297,24 +2225,7 @@ JSObject* js::StartDynamicModuleImport(JSContext* cx, HandleScript script,
|
|||
script->sourceObject()->canonicalPrivate());
|
||||
cx->runtime()->addRefScriptPrivate(referencingPrivate);
|
||||
|
||||
RootedAtom specifierAtom(cx, AtomizeString(cx, specifier));
|
||||
if (!specifierAtom) {
|
||||
if (!RejectPromiseWithPendingError(cx, promise)) {
|
||||
return nullptr;
|
||||
}
|
||||
return promise;
|
||||
}
|
||||
|
||||
RootedObject moduleRequest(cx,
|
||||
ModuleRequestObject::create(cx, specifierAtom));
|
||||
if (!moduleRequest) {
|
||||
if (!RejectPromiseWithPendingError(cx, promise)) {
|
||||
return nullptr;
|
||||
}
|
||||
return promise;
|
||||
}
|
||||
|
||||
if (!importHook(cx, referencingPrivate, moduleRequest, promise)) {
|
||||
if (!importHook(cx, referencingPrivate, specifier, promise)) {
|
||||
cx->runtime()->releaseScriptPrivate(referencingPrivate);
|
||||
|
||||
// If there's no exception pending then the script is terminating
|
||||
|
@ -2367,25 +2278,15 @@ static bool OnResolvedDynamicModule(JSContext* cx, unsigned argc, Value* vp) {
|
|||
ExtraFromHandler<ListObject>(args));
|
||||
MOZ_ASSERT(resolvedModuleParams->length() == 2);
|
||||
RootedValue referencingPrivate(cx, resolvedModuleParams->get(0));
|
||||
|
||||
RootedAtom specifier(
|
||||
cx, AtomizeString(cx, resolvedModuleParams->get(1).toString()));
|
||||
if (!specifier) {
|
||||
return false;
|
||||
}
|
||||
RootedString specifier(cx, resolvedModuleParams->get(1).toString());
|
||||
|
||||
Rooted<PromiseObject*> promise(cx, TargetFromHandler<PromiseObject>(args));
|
||||
|
||||
auto releasePrivate = mozilla::MakeScopeExit(
|
||||
[&] { cx->runtime()->releaseScriptPrivate(referencingPrivate); });
|
||||
|
||||
RootedObject moduleRequest(cx, ModuleRequestObject::create(cx, specifier));
|
||||
if (!moduleRequest) {
|
||||
return RejectPromiseWithPendingError(cx, promise);
|
||||
}
|
||||
|
||||
RootedObject result(
|
||||
cx, CallModuleResolveHook(cx, referencingPrivate, moduleRequest));
|
||||
RootedObject result(cx,
|
||||
CallModuleResolveHook(cx, referencingPrivate, specifier));
|
||||
|
||||
if (!result) {
|
||||
return RejectPromiseWithPendingError(cx, promise);
|
||||
|
@ -2430,14 +2331,13 @@ static bool OnRejectedDynamicModule(JSContext* cx, unsigned argc, Value* vp) {
|
|||
bool FinishDynamicModuleImport_impl(JSContext* cx,
|
||||
HandleObject evaluationPromise,
|
||||
HandleValue referencingPrivate,
|
||||
HandleObject moduleRequest,
|
||||
HandleString specifier,
|
||||
HandleObject promiseArg) {
|
||||
Rooted<ListObject*> resolutionArgs(cx, ListObject::create(cx));
|
||||
if (!resolutionArgs->append(cx, referencingPrivate)) {
|
||||
return false;
|
||||
}
|
||||
Rooted<Value> stringValue(
|
||||
cx, StringValue(moduleRequest->as<ModuleRequestObject>().specifier()));
|
||||
Rooted<Value> stringValue(cx, StringValue(specifier));
|
||||
if (!resolutionArgs->append(cx, stringValue)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -2465,7 +2365,7 @@ bool FinishDynamicModuleImport_impl(JSContext* cx,
|
|||
bool js::FinishDynamicModuleImport(JSContext* cx,
|
||||
HandleObject evaluationPromise,
|
||||
HandleValue referencingPrivate,
|
||||
HandleObject moduleRequest,
|
||||
HandleString specifier,
|
||||
HandleObject promiseArg) {
|
||||
// If we do not have an evaluation promise for the module, we can assume that
|
||||
// evaluation has failed or been interrupted -- we can reject the dynamic
|
||||
|
@ -2479,7 +2379,7 @@ bool js::FinishDynamicModuleImport(JSContext* cx,
|
|||
}
|
||||
|
||||
if (!FinishDynamicModuleImport_impl(cx, evaluationPromise, referencingPrivate,
|
||||
moduleRequest, promiseArg)) {
|
||||
specifier, promiseArg)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2490,7 +2390,7 @@ bool js::FinishDynamicModuleImport(JSContext* cx,
|
|||
bool js::FinishDynamicModuleImport_NoTLA(JSContext* cx,
|
||||
JS::DynamicImportStatus status,
|
||||
HandleValue referencingPrivate,
|
||||
HandleObject moduleRequest,
|
||||
HandleString specifier,
|
||||
HandleObject promiseArg) {
|
||||
MOZ_ASSERT_IF(cx->isExceptionPending(),
|
||||
status == JS::DynamicImportStatus::Failed);
|
||||
|
@ -2504,8 +2404,8 @@ bool js::FinishDynamicModuleImport_NoTLA(JSContext* cx,
|
|||
return RejectPromiseWithPendingError(cx, promise);
|
||||
}
|
||||
|
||||
RootedObject result(
|
||||
cx, CallModuleResolveHook(cx, referencingPrivate, moduleRequest));
|
||||
RootedObject result(cx,
|
||||
CallModuleResolveHook(cx, referencingPrivate, specifier));
|
||||
if (!result) {
|
||||
return RejectPromiseWithPendingError(cx, promise);
|
||||
}
|
||||
|
@ -2533,7 +2433,7 @@ XDRResult js::XDRExportEntries(XDRState<mode>* xdr,
|
|||
Rooted<GCVector<ExportEntryObject*>> expVec(cx);
|
||||
RootedExportEntryObject expObj(cx);
|
||||
RootedAtom exportName(cx);
|
||||
RootedModuleRequestObject moduleRequest(cx);
|
||||
RootedAtom moduleRequest(cx);
|
||||
RootedAtom importName(cx);
|
||||
RootedAtom localName(cx);
|
||||
|
||||
|
@ -2558,7 +2458,7 @@ XDRResult js::XDRExportEntries(XDRState<mode>* xdr,
|
|||
}
|
||||
|
||||
MOZ_TRY(XDRAtomOrNull(xdr, &exportName));
|
||||
MOZ_TRY(XDRModuleRequestObject(xdr, &moduleRequest, true));
|
||||
MOZ_TRY(XDRAtomOrNull(xdr, &moduleRequest));
|
||||
MOZ_TRY(XDRAtomOrNull(xdr, &importName));
|
||||
MOZ_TRY(XDRAtomOrNull(xdr, &localName));
|
||||
|
||||
|
@ -2593,21 +2493,21 @@ template <XDRMode mode>
|
|||
XDRResult js::XDRRequestedModuleObject(
|
||||
XDRState<mode>* xdr, MutableHandleRequestedModuleObject reqObj) {
|
||||
JSContext* cx = xdr->cx();
|
||||
RootedModuleRequestObject moduleRequest(cx);
|
||||
RootedAtom moduleSpecifier(cx);
|
||||
uint32_t lineNumber = 0;
|
||||
uint32_t columnNumber = 0;
|
||||
if (mode == XDR_ENCODE) {
|
||||
moduleRequest = reqObj->moduleRequest();
|
||||
moduleSpecifier = reqObj->moduleSpecifier();
|
||||
lineNumber = reqObj->lineNumber();
|
||||
columnNumber = reqObj->columnNumber();
|
||||
}
|
||||
|
||||
MOZ_TRY(XDRModuleRequestObject(xdr, &moduleRequest, false));
|
||||
MOZ_TRY(XDRAtom(xdr, &moduleSpecifier));
|
||||
MOZ_TRY(xdr->codeUint32(&lineNumber));
|
||||
MOZ_TRY(xdr->codeUint32(&columnNumber));
|
||||
|
||||
if (mode == XDR_DECODE) {
|
||||
reqObj.set(RequestedModuleObject::create(cx, moduleRequest, lineNumber,
|
||||
reqObj.set(RequestedModuleObject::create(cx, moduleSpecifier, lineNumber,
|
||||
columnNumber));
|
||||
if (!reqObj) {
|
||||
return xdr->fail(JS::TranscodeResult::Throw);
|
||||
|
@ -2617,36 +2517,11 @@ XDRResult js::XDRRequestedModuleObject(
|
|||
return Ok();
|
||||
}
|
||||
|
||||
template <XDRMode mode>
|
||||
XDRResult js::XDRModuleRequestObject(
|
||||
XDRState<mode>* xdr, MutableHandleModuleRequestObject moduleRequestObj,
|
||||
bool allowNullSpecifier) {
|
||||
JSContext* cx = xdr->cx();
|
||||
RootedAtom specifier(cx);
|
||||
if (mode == XDR_ENCODE) {
|
||||
specifier = moduleRequestObj->specifier();
|
||||
}
|
||||
|
||||
MOZ_TRY(XDRAtomOrNull(xdr, &specifier));
|
||||
|
||||
if (mode == XDR_DECODE) {
|
||||
if (!allowNullSpecifier && !specifier) {
|
||||
return xdr->fail(JS::TranscodeResult::Throw);
|
||||
}
|
||||
moduleRequestObj.set(ModuleRequestObject::create(cx, specifier));
|
||||
if (!moduleRequestObj) {
|
||||
return xdr->fail(JS::TranscodeResult::Throw);
|
||||
}
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
template <XDRMode mode>
|
||||
XDRResult js::XDRImportEntryObject(XDRState<mode>* xdr,
|
||||
MutableHandleImportEntryObject impObj) {
|
||||
JSContext* cx = xdr->cx();
|
||||
RootedModuleRequestObject moduleRequest(cx);
|
||||
RootedAtom moduleRequest(cx);
|
||||
RootedAtom importName(cx);
|
||||
RootedAtom localName(cx);
|
||||
uint32_t lineNumber = 0;
|
||||
|
@ -2659,7 +2534,7 @@ XDRResult js::XDRImportEntryObject(XDRState<mode>* xdr,
|
|||
columnNumber = impObj->columnNumber();
|
||||
}
|
||||
|
||||
MOZ_TRY(XDRModuleRequestObject(xdr, &moduleRequest, true));
|
||||
MOZ_TRY(XDRAtomOrNull(xdr, &moduleRequest));
|
||||
MOZ_TRY(XDRAtomOrNull(xdr, &importName));
|
||||
MOZ_TRY(XDRAtomOrNull(xdr, &localName));
|
||||
MOZ_TRY(xdr->codeUint32(&lineNumber));
|
||||
|
|
|
@ -54,18 +54,6 @@ using HandleModuleObject = Handle<ModuleObject*>;
|
|||
using RootedModuleEnvironmentObject = Rooted<ModuleEnvironmentObject*>;
|
||||
using HandleModuleEnvironmentObject = Handle<ModuleEnvironmentObject*>;
|
||||
|
||||
class ModuleRequestObject : public NativeObject {
|
||||
public:
|
||||
enum { SpecifierSlot = 0, SlotCount };
|
||||
|
||||
static const JSClass class_;
|
||||
static bool isInstance(HandleValue value);
|
||||
[[nodiscard]] static ModuleRequestObject* create(JSContext* cx,
|
||||
HandleAtom specifier);
|
||||
|
||||
JSAtom* specifier() const;
|
||||
};
|
||||
|
||||
class ImportEntryObject : public NativeObject {
|
||||
public:
|
||||
enum {
|
||||
|
@ -79,11 +67,11 @@ class ImportEntryObject : public NativeObject {
|
|||
|
||||
static const JSClass class_;
|
||||
static bool isInstance(HandleValue value);
|
||||
static ImportEntryObject* create(JSContext* cx, HandleObject moduleRequest,
|
||||
static ImportEntryObject* create(JSContext* cx, HandleAtom moduleRequest,
|
||||
HandleAtom maybeImportName,
|
||||
HandleAtom localName, uint32_t lineNumber,
|
||||
uint32_t columnNumber);
|
||||
ModuleRequestObject* moduleRequest() const;
|
||||
JSAtom* moduleRequest() const;
|
||||
JSAtom* importName() const;
|
||||
JSAtom* localName() const;
|
||||
uint32_t lineNumber() const;
|
||||
|
@ -114,12 +102,12 @@ class ExportEntryObject : public NativeObject {
|
|||
static const JSClass class_;
|
||||
static bool isInstance(HandleValue value);
|
||||
static ExportEntryObject* create(JSContext* cx, HandleAtom maybeExportName,
|
||||
HandleObject maybeModuleRequest,
|
||||
HandleAtom maybeModuleRequest,
|
||||
HandleAtom maybeImportName,
|
||||
HandleAtom maybeLocalName,
|
||||
uint32_t lineNumber, uint32_t columnNumber);
|
||||
JSAtom* exportName() const;
|
||||
ModuleRequestObject* moduleRequest() const;
|
||||
JSAtom* moduleRequest() const;
|
||||
JSAtom* importName() const;
|
||||
JSAtom* localName() const;
|
||||
uint32_t lineNumber() const;
|
||||
|
@ -134,15 +122,15 @@ using HandleExportEntryObject = Handle<ExportEntryObject*>;
|
|||
|
||||
class RequestedModuleObject : public NativeObject {
|
||||
public:
|
||||
enum { ModuleRequestSlot = 0, LineNumberSlot, ColumnNumberSlot, SlotCount };
|
||||
enum { ModuleSpecifierSlot = 0, LineNumberSlot, ColumnNumberSlot, SlotCount };
|
||||
|
||||
static const JSClass class_;
|
||||
static bool isInstance(HandleValue value);
|
||||
static RequestedModuleObject* create(JSContext* cx,
|
||||
HandleObject moduleRequest,
|
||||
HandleAtom moduleSpecifier,
|
||||
uint32_t lineNumber,
|
||||
uint32_t columnNumber);
|
||||
ModuleRequestObject* moduleRequest() const;
|
||||
JSAtom* moduleSpecifier() const;
|
||||
uint32_t lineNumber() const;
|
||||
uint32_t columnNumber() const;
|
||||
};
|
||||
|
@ -153,18 +141,10 @@ using RootedRequestedModuleVector = Rooted<GCVector<RequestedModuleObject*> >;
|
|||
using MutableHandleRequestedModuleObject =
|
||||
MutableHandle<RequestedModuleObject*>;
|
||||
|
||||
using RootedModuleRequestObject = Rooted<ModuleRequestObject*>;
|
||||
using MutableHandleModuleRequestObject = MutableHandle<ModuleRequestObject*>;
|
||||
|
||||
template <XDRMode mode>
|
||||
XDRResult XDRRequestedModuleObject(XDRState<mode>* xdr,
|
||||
MutableHandleRequestedModuleObject reqObj);
|
||||
|
||||
template <XDRMode mode>
|
||||
XDRResult XDRModuleRequestObject(
|
||||
XDRState<mode>* xdr, MutableHandleModuleRequestObject moduleRequestObj,
|
||||
bool allowNullSpecifier);
|
||||
|
||||
class IndirectBindingMap {
|
||||
public:
|
||||
void trace(JSTracer* trc);
|
||||
|
@ -439,7 +419,7 @@ class ModuleObject : public NativeObject {
|
|||
JSObject* GetOrCreateModuleMetaObject(JSContext* cx, HandleObject module);
|
||||
|
||||
JSObject* CallModuleResolveHook(JSContext* cx, HandleValue referencingPrivate,
|
||||
HandleObject moduleRequest);
|
||||
HandleString specifier);
|
||||
|
||||
// https://tc39.es/proposal-top-level-await/#sec-asyncmodulexecutionfulfilled
|
||||
void AsyncModuleExecutionFulfilled(JSContext* cx, HandleModuleObject module);
|
||||
|
@ -463,15 +443,14 @@ bool OnModuleEvaluationFailure(JSContext* cx, HandleObject evaluationPromise);
|
|||
|
||||
bool FinishDynamicModuleImport(JSContext* cx, HandleObject evaluationPromise,
|
||||
HandleValue referencingPrivate,
|
||||
HandleObject moduleRequest,
|
||||
HandleObject promise);
|
||||
HandleString specifier, HandleObject promise);
|
||||
|
||||
// This is used so that Top Level Await functionality can be turned off
|
||||
// entirely. It will be removed in bug#1676612.
|
||||
bool FinishDynamicModuleImport_NoTLA(JSContext* cx,
|
||||
JS::DynamicImportStatus status,
|
||||
HandleValue referencingPrivate,
|
||||
HandleObject moduleRequest,
|
||||
HandleString specifier,
|
||||
HandleObject promise);
|
||||
|
||||
template <XDRMode mode>
|
||||
|
|
|
@ -1,20 +1,11 @@
|
|||
// Test localExportEntries property
|
||||
|
||||
function testObjectContents(actual, expected) {
|
||||
for (var property in expected) {
|
||||
if(actual[property] instanceof Object) {
|
||||
testObjectContents(actual[property], expected[property]);
|
||||
}
|
||||
else {
|
||||
assertEq(actual[property], expected[property]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function testArrayContents(actual, expected) {
|
||||
assertEq(actual.length, expected.length);
|
||||
for (var i = 0; i < actual.length; i++) {
|
||||
testObjectContents(actual[i], expected[i]);
|
||||
for (var property in expected[i]) {
|
||||
assertEq(actual[i][property], expected[i][property]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,11 +83,11 @@ testIndirectExportEntries(
|
|||
|
||||
testIndirectExportEntries(
|
||||
'export {x} from "mod";',
|
||||
[{exportName: 'x', moduleRequest: {specifier:'mod'}, importName: 'x', localName: null}]);
|
||||
[{exportName: 'x', moduleRequest: 'mod', importName: 'x', localName: null}]);
|
||||
|
||||
testIndirectExportEntries(
|
||||
'export {v as x} from "mod";',
|
||||
[{exportName: 'x', moduleRequest: {specifier:'mod'}, importName: 'v', localName: null}]);
|
||||
[{exportName: 'x', moduleRequest: 'mod', importName: 'v', localName: null}]);
|
||||
|
||||
testIndirectExportEntries(
|
||||
'export * from "mod";',
|
||||
|
@ -104,7 +95,7 @@ testIndirectExportEntries(
|
|||
|
||||
testIndirectExportEntries(
|
||||
'import {v as x} from "mod"; export {x as y};',
|
||||
[{exportName: 'y', moduleRequest: {specifier:'mod'}, importName: 'v', localName: null}]);
|
||||
[{exportName: 'y', moduleRequest: 'mod', importName: 'v', localName: null}]);
|
||||
|
||||
// Test starExportEntries property
|
||||
|
||||
|
@ -127,4 +118,4 @@ testStarExportEntries(
|
|||
|
||||
testStarExportEntries(
|
||||
'export * from "mod";',
|
||||
[{exportName: null, moduleRequest: {specifier:'mod'}, importName: null, localName: null}]);
|
||||
[{exportName: null, moduleRequest: 'mod', importName: null, localName: null}]);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
function importEntryEq(a, b)
|
||||
{
|
||||
return a['moduleRequest']['specifier'] === b['moduleRequest']['specifier'] &&
|
||||
return a['moduleRequest'] === b['moduleRequest'] &&
|
||||
a['importName'] === b['importName'] &&
|
||||
a['localName'] === b['localName'];
|
||||
}
|
||||
|
@ -30,20 +30,20 @@ function testImportEntries(source, expected) {
|
|||
testImportEntries('', []);
|
||||
|
||||
testImportEntries('import v from "mod";',
|
||||
[{moduleRequest: {specifier: 'mod'}, importName: 'default', localName: 'v'}]);
|
||||
[{moduleRequest: 'mod', importName: 'default', localName: 'v'}]);
|
||||
|
||||
testImportEntries('import * as ns from "mod";',
|
||||
[{moduleRequest: {specifier: 'mod'}, importName: null, localName: 'ns'}]);
|
||||
[{moduleRequest: 'mod', importName: null, localName: 'ns'}]);
|
||||
|
||||
testImportEntries('import {x} from "mod";',
|
||||
[{moduleRequest: {specifier: 'mod'}, importName: 'x', localName: 'x'}]);
|
||||
[{moduleRequest: 'mod', importName: 'x', localName: 'x'}]);
|
||||
|
||||
testImportEntries('import {x as v} from "mod";',
|
||||
[{moduleRequest: {specifier: 'mod'}, importName: 'x', localName: 'v'}]);
|
||||
[{moduleRequest: 'mod', importName: 'x', localName: 'v'}]);
|
||||
|
||||
testImportEntries('import "mod";',
|
||||
[]);
|
||||
|
||||
testImportEntries('import {x} from "a"; import {y} from "b";',
|
||||
[{moduleRequest: {specifier: 'a'}, importName: 'x', localName: 'x'},
|
||||
{moduleRequest: {specifier: 'b'}, importName: 'y', localName: 'y'}]);
|
||||
[{moduleRequest: 'a', importName: 'x', localName: 'x'},
|
||||
{moduleRequest: 'b', importName: 'y', localName: 'y'}]);
|
||||
|
|
|
@ -5,7 +5,7 @@ function testRequestedModules(source, expected) {
|
|||
var actual = module.requestedModules;
|
||||
assertEq(actual.length, expected.length);
|
||||
for (var i = 0; i < actual.length; i++) {
|
||||
assertEq(actual[i].moduleRequest.specifier, expected[i]);
|
||||
assertEq(actual[i].moduleSpecifier, expected[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,10 +64,10 @@ bool ModuleLoader::init(JSContext* cx, HandleString loadPath) {
|
|||
// static
|
||||
JSObject* ModuleLoader::ResolveImportedModule(
|
||||
JSContext* cx, JS::HandleValue referencingPrivate,
|
||||
JS::HandleObject moduleRequest) {
|
||||
JS::HandleString specifier) {
|
||||
ShellContext* scx = GetShellContext(cx);
|
||||
return scx->moduleLoader->resolveImportedModule(cx, referencingPrivate,
|
||||
moduleRequest);
|
||||
specifier);
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -81,10 +81,10 @@ bool ModuleLoader::GetImportMetaProperties(JSContext* cx,
|
|||
// static
|
||||
bool ModuleLoader::ImportModuleDynamically(JSContext* cx,
|
||||
JS::HandleValue referencingPrivate,
|
||||
JS::HandleObject moduleRequest,
|
||||
JS::HandleString specifier,
|
||||
JS::HandleObject promise) {
|
||||
ShellContext* scx = GetShellContext(cx);
|
||||
return scx->moduleLoader->dynamicImport(cx, referencingPrivate, moduleRequest,
|
||||
return scx->moduleLoader->dynamicImport(cx, referencingPrivate, specifier,
|
||||
promise);
|
||||
}
|
||||
|
||||
|
@ -105,9 +105,9 @@ bool ModuleLoader::loadRootModule(JSContext* cx, HandleString path) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ModuleLoader::registerTestModule(JSContext* cx, HandleObject moduleRequest,
|
||||
bool ModuleLoader::registerTestModule(JSContext* cx, HandleString specifier,
|
||||
HandleModuleObject module) {
|
||||
RootedLinearString path(cx, resolve(cx, moduleRequest, UndefinedHandleValue));
|
||||
RootedLinearString path(cx, resolve(cx, specifier, UndefinedHandleValue));
|
||||
if (!path) {
|
||||
return false;
|
||||
}
|
||||
|
@ -136,8 +136,8 @@ bool ModuleLoader::loadAndExecute(JSContext* cx, HandleString path,
|
|||
|
||||
JSObject* ModuleLoader::resolveImportedModule(
|
||||
JSContext* cx, JS::HandleValue referencingPrivate,
|
||||
JS::HandleObject moduleRequest) {
|
||||
RootedLinearString path(cx, resolve(cx, moduleRequest, referencingPrivate));
|
||||
JS::HandleString specifier) {
|
||||
RootedLinearString path(cx, resolve(cx, specifier, referencingPrivate));
|
||||
if (!path) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ bool ModuleLoader::populateImportMeta(JSContext* cx,
|
|||
|
||||
bool ModuleLoader::dynamicImport(JSContext* cx,
|
||||
JS::HandleValue referencingPrivate,
|
||||
JS::HandleObject moduleRequest,
|
||||
JS::HandleString specifier,
|
||||
JS::HandleObject promise) {
|
||||
// To make this more realistic, use a promise to delay the import and make it
|
||||
// happen asynchronously. This method packages up the arguments and creates a
|
||||
|
@ -176,13 +176,13 @@ bool ModuleLoader::dynamicImport(JSContext* cx,
|
|||
// original arguments.
|
||||
|
||||
MOZ_ASSERT(promise);
|
||||
RootedValue moduleRequestValue(cx, ObjectValue(*moduleRequest));
|
||||
RootedValue specifierValue(cx, StringValue(specifier));
|
||||
RootedValue promiseValue(cx, ObjectValue(*promise));
|
||||
RootedObject closure(cx, JS_NewPlainObject(cx));
|
||||
if (!closure ||
|
||||
!JS_DefineProperty(cx, closure, "referencingPrivate", referencingPrivate,
|
||||
JSPROP_ENUMERATE) ||
|
||||
!JS_DefineProperty(cx, closure, "moduleRequest", moduleRequestValue,
|
||||
!JS_DefineProperty(cx, closure, "specifier", specifierValue,
|
||||
JSPROP_ENUMERATE) ||
|
||||
!JS_DefineProperty(cx, closure, "promise", promiseValue,
|
||||
JSPROP_ENUMERATE)) {
|
||||
|
@ -217,20 +217,20 @@ bool ModuleLoader::DynamicImportDelayFulfilled(JSContext* cx, unsigned argc,
|
|||
RootedObject closure(cx, &args[0].toObject());
|
||||
|
||||
RootedValue referencingPrivate(cx);
|
||||
RootedValue moduleRequestValue(cx);
|
||||
RootedValue specifierValue(cx);
|
||||
RootedValue promiseValue(cx);
|
||||
if (!JS_GetProperty(cx, closure, "referencingPrivate", &referencingPrivate) ||
|
||||
!JS_GetProperty(cx, closure, "moduleRequest", &moduleRequestValue) ||
|
||||
!JS_GetProperty(cx, closure, "specifier", &specifierValue) ||
|
||||
!JS_GetProperty(cx, closure, "promise", &promiseValue)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
RootedObject moduleRequest(cx, &moduleRequestValue.toObject());
|
||||
RootedString specifier(cx, specifierValue.toString());
|
||||
RootedObject promise(cx, &promiseValue.toObject());
|
||||
|
||||
ShellContext* scx = GetShellContext(cx);
|
||||
return scx->moduleLoader->doDynamicImport(cx, referencingPrivate,
|
||||
moduleRequest, promise);
|
||||
return scx->moduleLoader->doDynamicImport(cx, referencingPrivate, specifier,
|
||||
promise);
|
||||
}
|
||||
|
||||
bool ModuleLoader::DynamicImportDelayRejected(JSContext* cx, unsigned argc,
|
||||
|
@ -240,31 +240,30 @@ bool ModuleLoader::DynamicImportDelayRejected(JSContext* cx, unsigned argc,
|
|||
|
||||
bool ModuleLoader::doDynamicImport(JSContext* cx,
|
||||
JS::HandleValue referencingPrivate,
|
||||
JS::HandleObject moduleRequest,
|
||||
JS::HandleString specifier,
|
||||
JS::HandleObject promise) {
|
||||
// Exceptions during dynamic import are handled by calling
|
||||
// FinishDynamicModuleImport with a pending exception on the context.
|
||||
RootedValue rval(cx);
|
||||
bool ok =
|
||||
tryDynamicImport(cx, referencingPrivate, moduleRequest, promise, &rval);
|
||||
bool ok = tryDynamicImport(cx, referencingPrivate, specifier, promise, &rval);
|
||||
if (cx->options().topLevelAwait()) {
|
||||
JSObject* evaluationObject = ok ? &rval.toObject() : nullptr;
|
||||
RootedObject evaluationPromise(cx, evaluationObject);
|
||||
return JS::FinishDynamicModuleImport(
|
||||
cx, evaluationPromise, referencingPrivate, moduleRequest, promise);
|
||||
cx, evaluationPromise, referencingPrivate, specifier, promise);
|
||||
}
|
||||
JS::DynamicImportStatus status =
|
||||
ok ? JS::DynamicImportStatus::Ok : JS::DynamicImportStatus::Failed;
|
||||
return JS::FinishDynamicModuleImport_NoTLA(cx, status, referencingPrivate,
|
||||
moduleRequest, promise);
|
||||
specifier, promise);
|
||||
}
|
||||
|
||||
bool ModuleLoader::tryDynamicImport(JSContext* cx,
|
||||
JS::HandleValue referencingPrivate,
|
||||
JS::HandleObject moduleRequest,
|
||||
JS::HandleString specifier,
|
||||
JS::HandleObject promise,
|
||||
JS::MutableHandleValue rval) {
|
||||
RootedLinearString path(cx, resolve(cx, moduleRequest, referencingPrivate));
|
||||
RootedLinearString path(cx, resolve(cx, specifier, referencingPrivate));
|
||||
if (!path) {
|
||||
return false;
|
||||
}
|
||||
|
@ -272,18 +271,14 @@ bool ModuleLoader::tryDynamicImport(JSContext* cx,
|
|||
return loadAndExecute(cx, path, rval);
|
||||
}
|
||||
|
||||
JSLinearString* ModuleLoader::resolve(JSContext* cx,
|
||||
HandleObject moduleRequestArg,
|
||||
JSLinearString* ModuleLoader::resolve(JSContext* cx, HandleString nameArg,
|
||||
HandleValue referencingInfo) {
|
||||
ModuleRequestObject* moduleRequest =
|
||||
&moduleRequestArg->as<ModuleRequestObject>();
|
||||
if (moduleRequest->specifier()->length() == 0) {
|
||||
if (nameArg->length() == 0) {
|
||||
JS_ReportErrorASCII(cx, "Invalid module specifier");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RootedLinearString name(
|
||||
cx, JS_EnsureLinearString(cx, moduleRequest->specifier()));
|
||||
RootedLinearString name(cx, JS_EnsureLinearString(cx, nameArg));
|
||||
if (!name) {
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -20,18 +20,18 @@ class ModuleLoader {
|
|||
bool loadRootModule(JSContext* cx, HandleString path);
|
||||
|
||||
// Testing hook to register a module that wasn't loaded by the module loader.
|
||||
bool registerTestModule(JSContext* cx, HandleObject moduleRequest,
|
||||
bool registerTestModule(JSContext* cx, HandleString specifier,
|
||||
HandleModuleObject module);
|
||||
|
||||
private:
|
||||
static JSObject* ResolveImportedModule(JSContext* cx,
|
||||
HandleValue referencingPrivate,
|
||||
HandleObject moduleRequest);
|
||||
HandleString specifier);
|
||||
static bool GetImportMetaProperties(JSContext* cx, HandleValue privateValue,
|
||||
HandleObject metaObject);
|
||||
static bool ImportModuleDynamically(JSContext* cx,
|
||||
HandleValue referencingPrivate,
|
||||
HandleObject moduleRequest,
|
||||
HandleString specifier,
|
||||
HandleObject promise);
|
||||
|
||||
static bool DynamicImportDelayFulfilled(JSContext* cx, unsigned argc,
|
||||
|
@ -41,22 +41,22 @@ class ModuleLoader {
|
|||
|
||||
bool loadAndExecute(JSContext* cx, HandleString path, MutableHandleValue);
|
||||
JSObject* resolveImportedModule(JSContext* cx, HandleValue referencingPrivate,
|
||||
HandleObject moduleRequest);
|
||||
HandleString specifier);
|
||||
bool populateImportMeta(JSContext* cx, HandleValue privateValue,
|
||||
HandleObject metaObject);
|
||||
bool dynamicImport(JSContext* cx, HandleValue referencingPrivate,
|
||||
HandleObject moduleRequest, HandleObject promise);
|
||||
HandleString specifier, HandleObject promise);
|
||||
bool doDynamicImport(JSContext* cx, HandleValue referencingPrivate,
|
||||
HandleObject moduleRequest, HandleObject promise);
|
||||
HandleString specifier, HandleObject promise);
|
||||
bool tryDynamicImport(JSContext* cx, HandleValue referencingPrivate,
|
||||
HandleObject moduleRequest, HandleObject promise,
|
||||
HandleString specifier, HandleObject promise,
|
||||
MutableHandleValue rval);
|
||||
JSObject* loadAndParse(JSContext* cx, HandleString path);
|
||||
bool lookupModuleInRegistry(JSContext* cx, HandleString path,
|
||||
MutableHandleObject moduleOut);
|
||||
bool addModuleToRegistry(JSContext* cx, HandleString path,
|
||||
HandleObject module);
|
||||
JSLinearString* resolve(JSContext* cx, HandleObject moduleRequestArg,
|
||||
JSLinearString* resolve(JSContext* cx, HandleString name,
|
||||
HandleValue referencingInfo);
|
||||
bool getScriptPath(JSContext* cx, HandleValue privateValue,
|
||||
MutableHandle<JSLinearString*> pathOut);
|
||||
|
|
|
@ -5691,19 +5691,10 @@ static bool RegisterModule(JSContext* cx, unsigned argc, Value* vp) {
|
|||
}
|
||||
|
||||
ShellContext* sc = GetShellContext(cx);
|
||||
RootedString specifier(cx, args[0].toString());
|
||||
RootedModuleObject module(cx, &args[1].toObject().as<ModuleObject>());
|
||||
|
||||
RootedAtom specifier(cx, AtomizeString(cx, args[0].toString()));
|
||||
if (!specifier) {
|
||||
return false;
|
||||
}
|
||||
|
||||
RootedObject moduleRequest(cx, ModuleRequestObject::create(cx, specifier));
|
||||
if (!moduleRequest) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!sc->moduleLoader->registerTestModule(cx, moduleRequest, module)) {
|
||||
if (!sc->moduleLoader->registerTestModule(cx, specifier, module)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -115,7 +115,6 @@ class GlobalObject : public NativeObject {
|
|||
IMPORT_ENTRY_PROTO,
|
||||
EXPORT_ENTRY_PROTO,
|
||||
REQUESTED_MODULE_PROTO,
|
||||
MODULE_REQUEST_PROTO,
|
||||
REGEXP_STATICS,
|
||||
RUNTIME_CODEGEN_ENABLED,
|
||||
INTRINSICS,
|
||||
|
@ -519,12 +518,6 @@ class GlobalObject : public NativeObject {
|
|||
initRequestedModuleProto);
|
||||
}
|
||||
|
||||
static JSObject* getOrCreateModuleRequestPrototype(
|
||||
JSContext* cx, Handle<GlobalObject*> global) {
|
||||
return getOrCreateObject(cx, global, MODULE_REQUEST_PROTO,
|
||||
initModuleRequestProto);
|
||||
}
|
||||
|
||||
static JSFunction* getOrCreateTypedArrayConstructor(
|
||||
JSContext* cx, Handle<GlobalObject*> global) {
|
||||
if (!ensureConstructor(cx, global, JSProto_TypedArray)) {
|
||||
|
@ -848,8 +841,6 @@ class GlobalObject : public NativeObject {
|
|||
static bool initExportEntryProto(JSContext* cx, Handle<GlobalObject*> global);
|
||||
static bool initRequestedModuleProto(JSContext* cx,
|
||||
Handle<GlobalObject*> global);
|
||||
static bool initModuleRequestProto(JSContext* cx,
|
||||
Handle<GlobalObject*> global);
|
||||
|
||||
static bool initStandardClasses(JSContext* cx, Handle<GlobalObject*> global);
|
||||
static bool initSelfHostingBuiltins(JSContext* cx,
|
||||
|
|
|
@ -74,26 +74,26 @@ JS_PUBLIC_API void JS::SetModuleDynamicImportHook(
|
|||
|
||||
JS_PUBLIC_API bool JS::FinishDynamicModuleImport(
|
||||
JSContext* cx, Handle<JSObject*> evaluationPromise,
|
||||
Handle<Value> referencingPrivate, Handle<JSObject*> moduleRequest,
|
||||
Handle<Value> referencingPrivate, Handle<JSString*> specifier,
|
||||
Handle<JSObject*> promise) {
|
||||
AssertHeapIsIdle();
|
||||
CHECK_THREAD(cx);
|
||||
cx->check(referencingPrivate, promise);
|
||||
|
||||
return js::FinishDynamicModuleImport(
|
||||
cx, evaluationPromise, referencingPrivate, moduleRequest, promise);
|
||||
return js::FinishDynamicModuleImport(cx, evaluationPromise,
|
||||
referencingPrivate, specifier, promise);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API bool JS::FinishDynamicModuleImport_NoTLA(
|
||||
JSContext* cx, JS::DynamicImportStatus status,
|
||||
Handle<Value> referencingPrivate, Handle<JSObject*> moduleRequest,
|
||||
Handle<Value> referencingPrivate, Handle<JSString*> specifier,
|
||||
Handle<JSObject*> promise) {
|
||||
AssertHeapIsIdle();
|
||||
CHECK_THREAD(cx);
|
||||
cx->check(referencingPrivate, promise);
|
||||
|
||||
return js::FinishDynamicModuleImport_NoTLA(cx, status, referencingPrivate,
|
||||
moduleRequest, promise);
|
||||
specifier, promise);
|
||||
}
|
||||
|
||||
template <typename Unit>
|
||||
|
@ -172,7 +172,7 @@ JS_PUBLIC_API JSString* JS::GetRequestedModuleSpecifier(JSContext* cx,
|
|||
cx->check(value);
|
||||
|
||||
JSObject* obj = &value.toObject();
|
||||
return obj->as<RequestedModuleObject>().moduleRequest()->specifier();
|
||||
return obj->as<RequestedModuleObject>().moduleSpecifier();
|
||||
}
|
||||
|
||||
JS_PUBLIC_API void JS::GetRequestedModuleSourcePos(JSContext* cx,
|
||||
|
@ -195,25 +195,3 @@ JS_PUBLIC_API JSScript* JS::GetModuleScript(JS::HandleObject moduleRecord) {
|
|||
|
||||
return moduleRecord->as<ModuleObject>().script();
|
||||
}
|
||||
|
||||
JS_PUBLIC_API JSObject* JS::CreateModuleRequest(
|
||||
JSContext* cx, Handle<JSString*> specifierArg) {
|
||||
AssertHeapIsIdle();
|
||||
CHECK_THREAD(cx);
|
||||
|
||||
js::RootedAtom specifierAtom(cx, AtomizeString(cx, specifierArg));
|
||||
if (!specifierAtom) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return js::ModuleRequestObject::create(cx, specifierAtom);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API JSString* JS::GetModuleRequestSpecifier(
|
||||
JSContext* cx, Handle<JSObject*> moduleRequestArg) {
|
||||
AssertHeapIsIdle();
|
||||
CHECK_THREAD(cx);
|
||||
cx->check(moduleRequestArg);
|
||||
|
||||
return moduleRequestArg->as<js::ModuleRequestObject>().specifier();
|
||||
}
|
||||
|
|
|
@ -1856,11 +1856,11 @@ static bool intrinsic_HostResolveImportedModule(JSContext* cx, unsigned argc,
|
|||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
MOZ_ASSERT(args.length() == 2);
|
||||
RootedModuleObject module(cx, &args[0].toObject().as<ModuleObject>());
|
||||
RootedObject moduleRequest(cx, &args[1].toObject());
|
||||
RootedString specifier(cx, args[1].toString());
|
||||
|
||||
RootedValue referencingPrivate(cx, JS::GetModulePrivate(module));
|
||||
RootedObject result(
|
||||
cx, CallModuleResolveHook(cx, referencingPrivate, moduleRequest));
|
||||
RootedObject result(cx,
|
||||
CallModuleResolveHook(cx, referencingPrivate, specifier));
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче