From 498b1ab0c8db07784badbd2148f372027ef8cc27 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 8 Jul 2020 12:58:30 +0000 Subject: Issue #618 - Align error handling for module scripts with the spec (again) This updates module implementation to match spec regarding handling of instantiation errors, after it was changed yet again, this time to not remember instantiation errors, but instead immediately rethrow applicable ones. Ref: BZ 1420420 --- js/src/builtin/TestingFunctions.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'js/src/builtin/TestingFunctions.cpp') diff --git a/js/src/builtin/TestingFunctions.cpp b/js/src/builtin/TestingFunctions.cpp index 025620766..e93ebeec3 100644 --- a/js/src/builtin/TestingFunctions.cpp +++ b/js/src/builtin/TestingFunctions.cpp @@ -3585,6 +3585,9 @@ GetModuleEnvironmentNames(JSContext* cx, unsigned argc, Value* vp) return false; } +//- if (module->status() == MODULE_STATUS_ERRORED) { +//+ if (module->hadEvaluationError()) { + RootedModuleEnvironmentObject env(cx, GetModuleEnvironment(cx, args[0])); Rooted ids(cx, IdVector(cx)); if (!JS_Enumerate(cx, env, &ids)) @@ -3622,6 +3625,9 @@ GetModuleEnvironmentValue(JSContext* cx, unsigned argc, Value* vp) return false; } +//- if (module->status() == MODULE_STATUS_ERRORED) { +//+ if (module->hadEvaluationError()) { + RootedModuleEnvironmentObject env(cx, GetModuleEnvironment(cx, args[0])); RootedString name(cx, args[1].toString()); RootedId id(cx); -- cgit v1.2.3 From 70bafe4df514219dfc02185804286d1619290a16 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 8 Jul 2020 14:12:57 +0000 Subject: Issue #618 - Use a single slot for the module's environment object. According to the spec this isn't created until the module is instantiated, but we create it when we compile the module. We stored this previously in InitialEnvironmentSlot and copied it to EnvironmentSlot when it was supposed to be created, but we can just store it in the latter slot straight away and check the module's status and return null if it shouldn't exist yet. This reduces the number of slots needed on a moduleObject to 17. Re: BZ 1420412 Part 1 We can't implement the second part to further reduce our number of slots, because it relies on SetProxyReservedSlot which in turn relies on rearchitecturing JS proxies to make reserved slots dynamic. That's a rabbit hole we really don't want to fall into. So, we'll end up being a bit slower because it can't be in-line allocated with having more than 16 slots, but so be it. I sincerely doubt it will make any practical difference. --- js/src/builtin/TestingFunctions.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'js/src/builtin/TestingFunctions.cpp') diff --git a/js/src/builtin/TestingFunctions.cpp b/js/src/builtin/TestingFunctions.cpp index e93ebeec3..f589b8076 100644 --- a/js/src/builtin/TestingFunctions.cpp +++ b/js/src/builtin/TestingFunctions.cpp @@ -3566,8 +3566,6 @@ GetModuleEnvironment(JSContext* cx, HandleValue moduleValue) // before they have been instantiated. RootedModuleEnvironmentObject env(cx, &module->initialEnvironment()); MOZ_ASSERT(env); - MOZ_ASSERT_IF(module->environment(), module->environment() == env); - return env; } -- cgit v1.2.3