Bug 1449153 - Handle errored module in GetModuleNamespace() r=anba

This commit is contained in:
Jon Coppeard 2018-03-28 16:40:17 +01:00
Родитель 619e0c5b90
Коммит b8bf9f960f
2 изменённых файлов: 41 добавлений и 2 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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());