diff options
author | FranklinDM <mrmineshafter17@gmail.com> | 2023-05-07 00:43:59 +0800 |
---|---|---|
committer | FranklinDM <mrmineshafter17@gmail.com> | 2023-05-07 01:01:21 +0800 |
commit | 4b516daf135a58bfc140398ba5ade94fa82583c8 (patch) | |
tree | a758774d81d40d7f43c014a9031ef5609af279dd /js | |
parent | a928dac2f16d6ea51c9eeafbe01f7a59328ea5ad (diff) | |
download | uxp-4b516daf135a58bfc140398ba5ade94fa82583c8.tar.gz |
Issue #2234 - Part 1: Create async function wrapper when instantiating module functions
This excludes the change that removes "excessive" rooting from the Lambda* methods in Interpreter.cpp.
Based on https://bugzilla.mozilla.org/show_bug.cgi?id=1382306
Diffstat (limited to 'js')
-rw-r--r-- | js/src/builtin/ModuleObject.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/js/src/builtin/ModuleObject.cpp b/js/src/builtin/ModuleObject.cpp index 194959cf31..3fc195499f 100644 --- a/js/src/builtin/ModuleObject.cpp +++ b/js/src/builtin/ModuleObject.cpp @@ -12,6 +12,8 @@ #include "gc/Policy.h" #include "gc/Tracer.h" #include "vm/SelfHosting.h" +#include "vm/AsyncFunction.h" +#include "vm/AsyncIteration.h" #include "jsobjinlines.h" #include "jsscriptinlines.h" @@ -954,15 +956,24 @@ ModuleObject::instantiateFunctionDeclarations(JSContext* cx, HandleModuleObject RootedModuleEnvironmentObject env(cx, &self->initialEnvironment()); RootedFunction fun(cx); + RootedObject obj(cx); RootedValue value(cx); for (const auto& funDecl : *funDecls) { fun = funDecl.fun; - RootedObject obj(cx, Lambda(cx, fun, env)); + obj = Lambda(cx, fun, env); if (!obj) return false; - value = ObjectValue(*fun); + if (fun->isAsync()) { + if (fun->isStarGenerator()) { + obj = WrapAsyncGenerator(cx, obj.as<JSFunction>()); + } else { + obj = WrapAsyncFunction(cx, obj.as<JSFunction>()); + } + } + + value = ObjectValue(*obj); if (!SetProperty(cx, env, funDecl.name->asPropertyName(), value)) return false; } |