From 87e4f43be04313da7b4b5ede81c9c97b6bd5394c Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sat, 14 Apr 2018 08:40:37 +0200 Subject: Bug 1320993 - Fix exporting default class expression --- js/src/builtin/ModuleObject.cpp | 70 ++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 35 deletions(-) (limited to 'js/src/builtin') diff --git a/js/src/builtin/ModuleObject.cpp b/js/src/builtin/ModuleObject.cpp index 710c7a76c..e2f7f997e 100644 --- a/js/src/builtin/ModuleObject.cpp +++ b/js/src/builtin/ModuleObject.cpp @@ -1164,6 +1164,13 @@ ModuleBuilder::processExport(frontend::ParseNode* pn) bool isDefault = pn->getKind() == PNK_EXPORT_DEFAULT; ParseNode* kid = isDefault ? pn->pn_left : pn->pn_kid; + if (isDefault && pn->pn_right) { + // This is an export default containing an expression. + RootedAtom localName(cx_, cx_->names().starDefaultStar); + RootedAtom exportName(cx_, cx_->names().default_); + return appendExportEntry(exportName, localName); + } + switch (kid->getKind()) { case PNK_EXPORT_SPEC_LIST: MOZ_ASSERT(!isDefault); @@ -1177,53 +1184,46 @@ ModuleBuilder::processExport(frontend::ParseNode* pn) break; case PNK_CLASS: { - const ClassNode& cls = kid->as(); - MOZ_ASSERT(cls.names()); - RootedAtom localName(cx_, cls.names()->innerBinding()->pn_atom); - RootedAtom exportName(cx_, isDefault ? cx_->names().default_ : localName.get()); - if (!appendExportEntry(exportName, localName)) - return false; - break; + const ClassNode& cls = kid->as(); + MOZ_ASSERT(cls.names()); + RootedAtom localName(cx_, cls.names()->innerBinding()->pn_atom); + RootedAtom exportName(cx_, isDefault ? cx_->names().default_ : localName.get()); + if (!appendExportEntry(exportName, localName)) + return false; + break; } case PNK_VAR: case PNK_CONST: case PNK_LET: { - MOZ_ASSERT(kid->isArity(PN_LIST)); - for (ParseNode* var = kid->pn_head; var; var = var->pn_next) { - if (var->isKind(PNK_ASSIGN)) - var = var->pn_left; - MOZ_ASSERT(var->isKind(PNK_NAME)); - RootedAtom localName(cx_, var->pn_atom); - RootedAtom exportName(cx_, isDefault ? cx_->names().default_ : localName.get()); - if (!appendExportEntry(exportName, localName)) - return false; - } - break; + MOZ_ASSERT(kid->isArity(PN_LIST)); + for (ParseNode* var = kid->pn_head; var; var = var->pn_next) { + if (var->isKind(PNK_ASSIGN)) + var = var->pn_left; + MOZ_ASSERT(var->isKind(PNK_NAME)); + RootedAtom localName(cx_, var->pn_atom); + RootedAtom exportName(cx_, isDefault ? cx_->names().default_ : localName.get()); + if (!appendExportEntry(exportName, localName)) + return false; + } + break; } case PNK_FUNCTION: { - RootedFunction func(cx_, kid->pn_funbox->function()); - if (!func->isArrow()) { - RootedAtom localName(cx_, func->explicitName()); - RootedAtom exportName(cx_, isDefault ? cx_->names().default_ : localName.get()); - MOZ_ASSERT_IF(isDefault, localName); - if (!appendExportEntry(exportName, localName)) - return false; - break; - } - } - - MOZ_FALLTHROUGH; // Arrow functions are handled below. - - default: - MOZ_ASSERT(isDefault); - RootedAtom localName(cx_, cx_->names().starDefaultStar); - RootedAtom exportName(cx_, cx_->names().default_); + RootedFunction func(cx_, kid->pn_funbox->function()); + MOZ_ASSERT(!func->isArrow()); + RootedAtom localName(cx_, func->explicitName()); + RootedAtom exportName(cx_, isDefault ? cx_->names().default_ : localName.get()); + MOZ_ASSERT_IF(isDefault, localName); if (!appendExportEntry(exportName, localName)) return false; break; + } + + default: + MOZ_CRASH("Unexpected parse node"); } + return true; } -- cgit v1.2.3 From b2ec36808a240cd8169190168c915cd0463f8c87 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sat, 14 Apr 2018 08:49:15 +0200 Subject: Bug 1326453 - Part 1: Remove @@iterator method from module namespace objects per ES2017 --- js/src/builtin/Module.js | 8 -------- js/src/builtin/ModuleObject.cpp | 30 +----------------------------- js/src/builtin/ModuleObject.h | 7 ------- 3 files changed, 1 insertion(+), 44 deletions(-) (limited to 'js/src/builtin') diff --git a/js/src/builtin/Module.js b/js/src/builtin/Module.js index 7b70a7fe8..a678864d1 100644 --- a/js/src/builtin/Module.js +++ b/js/src/builtin/Module.js @@ -318,11 +318,3 @@ function ModuleEvaluation() return EvaluateModule(module); } _SetCanonicalName(ModuleEvaluation, "ModuleEvaluation"); - -function ModuleNamespaceEnumerate() -{ - if (!IsObject(this) || !IsModuleNamespace(this)) - return callFunction(CallModuleMethodIfWrapped, this, "ModuleNamespaceEnumerate"); - - return CreateListIterator(ModuleNamespaceExports(this)); -} diff --git a/js/src/builtin/ModuleObject.cpp b/js/src/builtin/ModuleObject.cpp index e2f7f997e..921319028 100644 --- a/js/src/builtin/ModuleObject.cpp +++ b/js/src/builtin/ModuleObject.cpp @@ -289,14 +289,6 @@ ModuleNamespaceObject::create(JSContext* cx, HandleModuleObject module) if (!object) return nullptr; - RootedId funName(cx, INTERNED_STRING_TO_JSID(cx, cx->names().Symbol_iterator_fun)); - RootedFunction enumerateFun(cx); - enumerateFun = JS::GetSelfHostedFunction(cx, "ModuleNamespaceEnumerate", funName, 0); - if (!enumerateFun) - return nullptr; - - SetProxyExtra(object, ProxyHandler::EnumerateFunctionSlot, ObjectValue(*enumerateFun)); - return &object->as(); } @@ -341,11 +333,6 @@ ModuleNamespaceObject::ProxyHandler::ProxyHandler() : BaseProxyHandler(&family, true) {} -JS::Value ModuleNamespaceObject::ProxyHandler::getEnumerateFunction(HandleObject proxy) const -{ - return GetProxyExtra(proxy, EnumerateFunctionSlot); -} - bool ModuleNamespaceObject::ProxyHandler::getPrototype(JSContext* cx, HandleObject proxy, MutableHandleObject protop) const @@ -402,15 +389,6 @@ ModuleNamespaceObject::ProxyHandler::getOwnPropertyDescriptor(JSContext* cx, Han Rooted ns(cx, &proxy->as()); if (JSID_IS_SYMBOL(id)) { Rooted symbol(cx, JSID_TO_SYMBOL(id)); - if (symbol == cx->wellKnownSymbols().iterator) { - RootedValue enumerateFun(cx, getEnumerateFunction(proxy)); - desc.object().set(proxy); - desc.setConfigurable(false); - desc.setEnumerable(false); - desc.setValue(enumerateFun); - return true; - } - if (symbol == cx->wellKnownSymbols().toStringTag) { RootedValue value(cx, StringValue(cx->names().Module)); desc.object().set(proxy); @@ -458,8 +436,7 @@ ModuleNamespaceObject::ProxyHandler::has(JSContext* cx, HandleObject proxy, Hand Rooted ns(cx, &proxy->as()); if (JSID_IS_SYMBOL(id)) { Rooted symbol(cx, JSID_TO_SYMBOL(id)); - return symbol == cx->wellKnownSymbols().iterator || - symbol == cx->wellKnownSymbols().toStringTag; + return symbol == cx->wellKnownSymbols().toStringTag; } *bp = ns->bindings().has(id); @@ -473,11 +450,6 @@ ModuleNamespaceObject::ProxyHandler::get(JSContext* cx, HandleObject proxy, Hand Rooted ns(cx, &proxy->as()); if (JSID_IS_SYMBOL(id)) { Rooted symbol(cx, JSID_TO_SYMBOL(id)); - if (symbol == cx->wellKnownSymbols().iterator) { - vp.set(getEnumerateFunction(proxy)); - return true; - } - if (symbol == cx->wellKnownSymbols().toStringTag) { vp.setString(cx->names().Module); return true; diff --git a/js/src/builtin/ModuleObject.h b/js/src/builtin/ModuleObject.h index d0ed8ed08..51a428271 100644 --- a/js/src/builtin/ModuleObject.h +++ b/js/src/builtin/ModuleObject.h @@ -142,15 +142,8 @@ class ModuleNamespaceObject : public ProxyObject private: struct ProxyHandler : public BaseProxyHandler { - enum - { - EnumerateFunctionSlot = 0 - }; - ProxyHandler(); - JS::Value getEnumerateFunction(HandleObject proxy) const; - bool getOwnPropertyDescriptor(JSContext* cx, HandleObject proxy, HandleId id, MutableHandle desc) const override; bool defineProperty(JSContext* cx, HandleObject proxy, HandleId id, -- cgit v1.2.3 From a7f7a2231938e49ca2521fd417be7a313045c006 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sat, 14 Apr 2018 08:50:17 +0200 Subject: Bug 1326453 - Part 2: Change @@toStringTag for module namespace objects to non-configurable --- js/src/builtin/ModuleObject.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/builtin') diff --git a/js/src/builtin/ModuleObject.cpp b/js/src/builtin/ModuleObject.cpp index 921319028..f7323e852 100644 --- a/js/src/builtin/ModuleObject.cpp +++ b/js/src/builtin/ModuleObject.cpp @@ -394,7 +394,7 @@ ModuleNamespaceObject::ProxyHandler::getOwnPropertyDescriptor(JSContext* cx, Han desc.object().set(proxy); desc.setWritable(false); desc.setEnumerable(false); - desc.setConfigurable(true); + desc.setConfigurable(false); desc.setValue(value); return true; } -- cgit v1.2.3 From e2719e1dbf7b706cd5ec8b3ecd899d2fc063c20f Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sat, 14 Apr 2018 08:51:05 +0200 Subject: Bug 1326453 - Part 3: Don't throw a TypeError when SetPrototypeOf for module namespace objects is called with null --- js/src/builtin/ModuleObject.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'js/src/builtin') diff --git a/js/src/builtin/ModuleObject.cpp b/js/src/builtin/ModuleObject.cpp index f7323e852..28a3329a8 100644 --- a/js/src/builtin/ModuleObject.cpp +++ b/js/src/builtin/ModuleObject.cpp @@ -345,6 +345,8 @@ bool ModuleNamespaceObject::ProxyHandler::setPrototype(JSContext* cx, HandleObject proxy, HandleObject proto, ObjectOpResult& result) const { + if (!proto) + return result.succeed(); return result.failCantSetProto(); } -- cgit v1.2.3 From 6452e3c9785260f21c5013d31e855e7b3e0497f4 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sat, 14 Apr 2018 08:52:37 +0200 Subject: Bug 1326453 - Part 4: Return @@toStringTag in [[OwnPropertyKeys]] trap for module namespace objects --- js/src/builtin/ModuleObject.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'js/src/builtin') diff --git a/js/src/builtin/ModuleObject.cpp b/js/src/builtin/ModuleObject.cpp index 28a3329a8..6d42508e0 100644 --- a/js/src/builtin/ModuleObject.cpp +++ b/js/src/builtin/ModuleObject.cpp @@ -500,7 +500,7 @@ ModuleNamespaceObject::ProxyHandler::ownPropertyKeys(JSContext* cx, HandleObject Rooted ns(cx, &proxy->as()); RootedObject exports(cx, &ns->exports()); uint32_t count; - if (!GetLengthProperty(cx, exports, &count) || !props.reserve(props.length() + count)) + if (!GetLengthProperty(cx, exports, &count) || !props.reserve(props.length() + count + 1)) return false; Rooted names(cx, ValueVector(cx)); @@ -510,6 +510,8 @@ ModuleNamespaceObject::ProxyHandler::ownPropertyKeys(JSContext* cx, HandleObject for (uint32_t i = 0; i < count; i++) props.infallibleAppend(AtomToId(&names[i].toString()->asAtom())); + props.infallibleAppend(SYMBOL_TO_JSID(cx->wellKnownSymbols().toStringTag)); + return true; } -- cgit v1.2.3 From ba6602b2de951beb74ef0f43a1cbae33ff0548e2 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sat, 14 Apr 2018 08:55:29 +0200 Subject: Bug 1326453 - Part 5: Remove no longer used ListIterator implementation --- js/src/builtin/Iterator.js | 41 ------------------------------------- js/src/builtin/SelfHostingDefines.h | 2 -- 2 files changed, 43 deletions(-) (limited to 'js/src/builtin') diff --git a/js/src/builtin/Iterator.js b/js/src/builtin/Iterator.js index 735eec7a0..e25b76156 100644 --- a/js/src/builtin/Iterator.js +++ b/js/src/builtin/Iterator.js @@ -84,44 +84,3 @@ function LegacyIteratorShim() { function LegacyGeneratorIteratorShim() { return NewLegacyIterator(ToObject(this), LegacyGeneratorIterator); } - -// 7.4.8 CreateListIterator() -function CreateListIterator(array) { - let iterator = NewListIterator(); - UnsafeSetReservedSlot(iterator, ITERATOR_SLOT_TARGET, array); - UnsafeSetReservedSlot(iterator, ITERATOR_SLOT_NEXT_INDEX, 0); - - // 7.4.8.1 ListIterator next() - // The spec requires that we use a new next function per iterator object. - let next = function() { - if (!IsObject(this) || !IsListIterator(this)) - return callFunction(CallListIteratorMethodIfWrapped, this, "ListIteratorNext"); - - if (ActiveFunction() !== UnsafeGetReservedSlot(this, ITERATOR_SLOT_NEXT_METHOD)) - ThrowTypeError(JSMSG_INCOMPATIBLE_METHOD, "next", "method", ToString(this)); - - let array = UnsafeGetObjectFromReservedSlot(this, ITERATOR_SLOT_TARGET); - let index = UnsafeGetReservedSlot(this, ITERATOR_SLOT_NEXT_INDEX); - - if (index >= ToLength(array.length)) { - UnsafeSetReservedSlot(this, ITERATOR_SLOT_NEXT_INDEX, 1/0); - return { value: undefined, done: true }; - } - - UnsafeSetReservedSlot(this, ITERATOR_SLOT_NEXT_INDEX, index + 1); - return { value: array[index], done: false }; - }; - - UnsafeSetReservedSlot(iterator, ITERATOR_SLOT_NEXT_METHOD, next); - iterator.next = next; - - iterator[std_iterator] = ListIteratorIdentity; - return iterator; -} - -function ListIteratorIdentity() { - if (!IsObject(this) || !IsListIterator(this)) - return callFunction(CallListIteratorMethodIfWrapped, this, "ListIteratorIdentity"); - - return this; -} diff --git a/js/src/builtin/SelfHostingDefines.h b/js/src/builtin/SelfHostingDefines.h index b57c17269..d676270a1 100644 --- a/js/src/builtin/SelfHostingDefines.h +++ b/js/src/builtin/SelfHostingDefines.h @@ -71,8 +71,6 @@ // Used for list, i.e. Array and String, iterators. #define ITERATOR_SLOT_NEXT_INDEX 1 #define ITERATOR_SLOT_ITEM_KIND 2 -// Used for ListIterator. -#define ITERATOR_SLOT_NEXT_METHOD 2 #define ITEM_KIND_KEY 0 #define ITEM_KIND_VALUE 1 -- cgit v1.2.3 From 05505d2e83d0c11beb6bc8b5c5a0daf68934c342 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sat, 14 Apr 2018 08:56:17 +0200 Subject: Bug 1340268 - [[HasProperty]] on module namespace object should work even when binding is uninitialized --- js/src/builtin/ModuleObject.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'js/src/builtin') diff --git a/js/src/builtin/ModuleObject.cpp b/js/src/builtin/ModuleObject.cpp index 6d42508e0..f13a2b78a 100644 --- a/js/src/builtin/ModuleObject.cpp +++ b/js/src/builtin/ModuleObject.cpp @@ -330,7 +330,7 @@ ModuleNamespaceObject::addBinding(JSContext* cx, HandleAtom exportedName, const char ModuleNamespaceObject::ProxyHandler::family = 0; ModuleNamespaceObject::ProxyHandler::ProxyHandler() - : BaseProxyHandler(&family, true) + : BaseProxyHandler(&family, false) {} bool @@ -438,7 +438,8 @@ ModuleNamespaceObject::ProxyHandler::has(JSContext* cx, HandleObject proxy, Hand Rooted ns(cx, &proxy->as()); if (JSID_IS_SYMBOL(id)) { Rooted symbol(cx, JSID_TO_SYMBOL(id)); - return symbol == cx->wellKnownSymbols().toStringTag; + *bp = symbol == cx->wellKnownSymbols().toStringTag; + return true; } *bp = ns->bindings().has(id); @@ -457,7 +458,8 @@ ModuleNamespaceObject::ProxyHandler::get(JSContext* cx, HandleObject proxy, Hand return true; } - return false; + vp.setUndefined(); + return true; } ModuleEnvironmentObject* env; -- cgit v1.2.3 From 3bd16c90800e8ec6ef8d7f135d8435bbbc0b94e6 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sat, 14 Apr 2018 08:57:05 +0200 Subject: Bug 1341256 - Fix module namespace object get handler --- js/src/builtin/ModuleObject.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'js/src/builtin') diff --git a/js/src/builtin/ModuleObject.cpp b/js/src/builtin/ModuleObject.cpp index f13a2b78a..444d8962d 100644 --- a/js/src/builtin/ModuleObject.cpp +++ b/js/src/builtin/ModuleObject.cpp @@ -464,8 +464,10 @@ ModuleNamespaceObject::ProxyHandler::get(JSContext* cx, HandleObject proxy, Hand ModuleEnvironmentObject* env; Shape* shape; - if (!ns->bindings().lookup(id, &env, &shape)) - return false; + if (!ns->bindings().lookup(id, &env, &shape)) { + vp.setUndefined(); + return true; + } RootedValue value(cx, env->getSlot(shape->slot())); if (value.isMagic(JS_UNINITIALIZED_LEXICAL)) { -- cgit v1.2.3 From c60cefb1b02be321f56f64dcccc6d6b7670e4293 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sat, 14 Apr 2018 08:59:22 +0200 Subject: Bug 1339986 - Handle export* when checking for duplicate export --- js/src/builtin/ModuleObject.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/builtin') diff --git a/js/src/builtin/ModuleObject.cpp b/js/src/builtin/ModuleObject.cpp index 444d8962d..7d2204259 100644 --- a/js/src/builtin/ModuleObject.cpp +++ b/js/src/builtin/ModuleObject.cpp @@ -147,7 +147,7 @@ DEFINE_GETTER_FUNCTIONS(ExportEntryObject, moduleRequest, ModuleRequestSlot) DEFINE_GETTER_FUNCTIONS(ExportEntryObject, importName, ImportNameSlot) DEFINE_GETTER_FUNCTIONS(ExportEntryObject, localName, LocalNameSlot) -DEFINE_ATOM_ACCESSOR_METHOD(ExportEntryObject, exportName) +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) -- cgit v1.2.3 From 8af513a2072d7f808f03a44b32130ff6ffcd7daa Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sat, 14 Apr 2018 09:00:53 +0200 Subject: Bug 1341411 - Support circular module dependencies through export* per ES2017 --- js/src/builtin/Module.js | 28 ++++++++++------------------ js/src/builtin/ModuleObject.cpp | 2 +- 2 files changed, 11 insertions(+), 19 deletions(-) (limited to 'js/src/builtin') diff --git a/js/src/builtin/Module.js b/js/src/builtin/Module.js index a678864d1..95f97495d 100644 --- a/js/src/builtin/Module.js +++ b/js/src/builtin/Module.js @@ -65,12 +65,12 @@ function ModuleGetExportedNames(exportStarSet = []) return exportedNames; } -// 15.2.1.16.3 ResolveExport(exportName, resolveSet, exportStarSet) -function ModuleResolveExport(exportName, resolveSet = [], exportStarSet = []) +// 15.2.1.16.3 ResolveExport(exportName, resolveSet) +function ModuleResolveExport(exportName, resolveSet = []) { if (!IsObject(this) || !IsModule(this)) { return callFunction(CallModuleMethodIfWrapped, this, exportName, resolveSet, - exportStarSet, "ModuleResolveExport"); + "ModuleResolveExport"); } // Step 1 @@ -101,37 +101,28 @@ function ModuleResolveExport(exportName, resolveSet = [], exportStarSet = []) if (exportName === e.exportName) { let importedModule = CallModuleResolveHook(module, e.moduleRequest, MODULE_STATE_INSTANTIATED); - let indirectResolution = callFunction(importedModule.resolveExport, importedModule, - e.importName, resolveSet, exportStarSet); - if (indirectResolution !== null) - return indirectResolution; + return callFunction(importedModule.resolveExport, importedModule, e.importName, + resolveSet); } } // Step 6 if (exportName === "default") { // A default export cannot be provided by an export *. - ThrowSyntaxError(JSMSG_BAD_DEFAULT_EXPORT); + return null; } // Step 7 - if (callFunction(ArrayIncludes, exportStarSet, module)) - return null; - - // Step 8 - _DefineDataProperty(exportStarSet, exportStarSet.length, module); - - // Step 9 let starResolution = null; - // Step 10 + // Step 8 let starExportEntries = module.starExportEntries; for (let i = 0; i < starExportEntries.length; i++) { let e = starExportEntries[i]; let importedModule = CallModuleResolveHook(module, e.moduleRequest, MODULE_STATE_INSTANTIATED); let resolution = callFunction(importedModule.resolveExport, importedModule, - exportName, resolveSet, exportStarSet); + exportName, resolveSet); if (resolution === "ambiguous") return resolution; @@ -148,6 +139,7 @@ function ModuleResolveExport(exportName, resolveSet = [], exportStarSet = []) } } + // Step 9 return starResolution; } @@ -279,7 +271,7 @@ function ModuleDeclarationInstantiation() } } - // Step 16.iv + // Step 17.a.iii InstantiateModuleFunctionDeclarations(module); } catch (e) { RecordInstantationFailure(module); diff --git a/js/src/builtin/ModuleObject.cpp b/js/src/builtin/ModuleObject.cpp index 7d2204259..333cb3e11 100644 --- a/js/src/builtin/ModuleObject.cpp +++ b/js/src/builtin/ModuleObject.cpp @@ -994,7 +994,7 @@ GlobalObject::initModuleProto(JSContext* cx, Handle global) static const JSFunctionSpec protoFunctions[] = { JS_SELF_HOSTED_FN("getExportedNames", "ModuleGetExportedNames", 1, 0), - JS_SELF_HOSTED_FN("resolveExport", "ModuleResolveExport", 3, 0), + JS_SELF_HOSTED_FN("resolveExport", "ModuleResolveExport", 2, 0), JS_SELF_HOSTED_FN("declarationInstantiation", "ModuleDeclarationInstantiation", 0, 0), JS_SELF_HOSTED_FN("evaluation", "ModuleEvaluation", 0, 0), JS_FS_END -- cgit v1.2.3 From ad9ee72dcd7981bc47b3844a224d69fadfdfd8ef Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sat, 14 Apr 2018 09:02:03 +0200 Subject: Bug 1341298 - Relax expected module state when resolving modules and circular module dependencies are present --- js/src/builtin/Module.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'js/src/builtin') diff --git a/js/src/builtin/Module.js b/js/src/builtin/Module.js index 95f97495d..5c3d5e147 100644 --- a/js/src/builtin/Module.js +++ b/js/src/builtin/Module.js @@ -100,7 +100,7 @@ function ModuleResolveExport(exportName, resolveSet = []) let e = indirectExportEntries[i]; if (exportName === e.exportName) { let importedModule = CallModuleResolveHook(module, e.moduleRequest, - MODULE_STATE_INSTANTIATED); + MODULE_STATE_PARSED); return callFunction(importedModule.resolveExport, importedModule, e.importName, resolveSet); } @@ -120,7 +120,7 @@ function ModuleResolveExport(exportName, resolveSet = []) for (let i = 0; i < starExportEntries.length; i++) { let e = starExportEntries[i]; let importedModule = CallModuleResolveHook(module, e.moduleRequest, - MODULE_STATE_INSTANTIATED); + MODULE_STATE_PARSED); let resolution = callFunction(importedModule.resolveExport, importedModule, exportName, resolveSet); if (resolution === "ambiguous") @@ -205,8 +205,8 @@ function GetModuleEnvironment(module) function RecordInstantationFailure(module) { - // Set the module's environment slot to 'null' to indicate a failed module - // instantiation. + // Set the module's state to 'failed' to indicate a failed module + // instantiation and reset the environment slot to 'undefined'. assert(IsModule(module), "Non-module passed to RecordInstantationFailure"); SetModuleState(module, MODULE_STATE_FAILED); UnsafeSetReservedSlot(module, MODULE_OBJECT_ENVIRONMENT_SLOT, undefined); @@ -267,6 +267,8 @@ function ModuleDeclarationInstantiation() ThrowSyntaxError(JSMSG_MISSING_IMPORT, imp.importName); if (resolution === "ambiguous") ThrowSyntaxError(JSMSG_AMBIGUOUS_IMPORT, imp.importName); + if (resolution.module.state < MODULE_STATE_INSTANTIATED) + ThrowInternalError(JSMSG_BAD_MODULE_STATE); CreateImportBinding(env, imp.localName, resolution.module, resolution.bindingName); } } -- cgit v1.2.3