From b8bf9f960f96846ba14577f2ab88dd5cd3715684 Mon Sep 17 00:00:00 2001 From: Jon Coppeard Date: Wed, 28 Mar 2018 16:40:17 +0100 Subject: [PATCH] Bug 1449153 - Handle errored module in GetModuleNamespace() r=anba --- js/src/builtin/Module.js | 8 +++-- js/src/jit-test/tests/modules/bug1449153.js | 35 +++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 js/src/jit-test/tests/modules/bug1449153.js diff --git a/js/src/builtin/Module.js b/js/src/builtin/Module.js index 7f2db6d5edb7..b8c86aeeb847 100644 --- a/js/src/builtin/Module.js +++ b/js/src/builtin/Module.js @@ -188,9 +188,13 @@ function GetModuleNamespace(module) // Step 1 assert(IsModule(module), "GetModuleNamespace called with non-module"); + // Until issue https://github.com/tc39/ecma262/issues/1155 is resolved, + // violate the spec here and throw if called on an errored module. + if (module.status === MODULE_STATUS_EVALUATED_ERROR) + throw GetModuleEvaluationError(module); + // Steps 2-3 - assert(module.status !== MODULE_STATUS_UNINSTANTIATED && - module.status !== MODULE_STATUS_EVALUATED_ERROR, + assert(module.status !== MODULE_STATUS_UNINSTANTIATED, "Bad module state in GetModuleNamespace"); // Step 4 diff --git a/js/src/jit-test/tests/modules/bug1449153.js b/js/src/jit-test/tests/modules/bug1449153.js new file mode 100644 index 000000000000..bf8a2251799a --- /dev/null +++ b/js/src/jit-test/tests/modules/bug1449153.js @@ -0,0 +1,35 @@ +// Test performing GetModuleNamespace on an errored module. + +class MyError {} + +function assertThrowsMyError(f) +{ + let caught = false; + try { + f(); + } catch (e) { + caught = true; + assertEq(e.constructor, MyError); + } + assertEq(caught, true); +} + +let moduleRepo = {}; +setModuleResolveHook(function(module, specifier) { + return moduleRepo[specifier]; +}); + +moduleRepo["a"] = parseModule(` + throw new MyError(); +`); + +let c = moduleRepo["c"] = parseModule(` + import "a"; +`); +c.declarationInstantiation(); +assertThrowsMyError(() => c.evaluation()); + +let b = moduleRepo['b'] = parseModule(` + import * as ns0 from 'a' +`); +assertThrowsMyError(() => b.declarationInstantiation());