summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2023-05-06 19:52:30 +0000
committerMoonchild <moonchild@palemoon.org>2023-05-06 19:52:30 +0000
commit2971cffab479097415e383366561d514086d0d0b (patch)
tree1927ca65f3808f0cb497eca86895bfb3086ea141
parenta928dac2f16d6ea51c9eeafbe01f7a59328ea5ad (diff)
parentca10d0ad23d8c66f7b1b225515e3f4ff1de8da23 (diff)
downloaduxp-2971cffab479097415e383366561d514086d0d0b.tar.gz
Merge pull request 'Create async function wrapper when instantiating module functions' (#2235) from FranklinDM/UXP-contrib:work_js-async-func-in-modules into master
Reviewed-on: https://repo.palemoon.org/MoonchildProductions/UXP/pulls/2235
-rw-r--r--js/src/builtin/ModuleObject.cpp18
-rw-r--r--js/src/jit-test/tests/modules/bug-1402649.js15
-rw-r--r--js/src/tests/ecma_2017/AsyncFunctions/async-function-declaration-in-modules.js13
-rw-r--r--js/src/tests/ecma_2018/AsyncGenerators/async-generator-declaration-in-modules.js13
-rw-r--r--js/src/tests/ecma_2018/AsyncGenerators/browser.js0
-rw-r--r--js/src/tests/ecma_2018/AsyncGenerators/shell.js0
-rw-r--r--js/src/tests/ecma_2018/browser.js0
-rw-r--r--js/src/tests/ecma_2018/shell.js0
8 files changed, 57 insertions, 2 deletions
diff --git a/js/src/builtin/ModuleObject.cpp b/js/src/builtin/ModuleObject.cpp
index 194959cf31..dd03017fc0 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,27 @@ 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>());
+ }
+ }
+
+ if (!obj)
+ return false;
+
+ value = ObjectValue(*obj);
if (!SetProperty(cx, env, funDecl.name->asPropertyName(), value))
return false;
}
diff --git a/js/src/jit-test/tests/modules/bug-1402649.js b/js/src/jit-test/tests/modules/bug-1402649.js
new file mode 100644
index 0000000000..2e5487210b
--- /dev/null
+++ b/js/src/jit-test/tests/modules/bug-1402649.js
@@ -0,0 +1,15 @@
+if (!('oomTest' in this))
+ quit();
+
+loadFile(`
+function parseAndEvaluate(source) {
+ let m = parseModule(source);
+ m.declarationInstantiation();
+}
+parseAndEvaluate("async function a() { await 2 + 3; }")
+`);
+function loadFile(lfVarx) {
+ oomTest(function() {
+ eval(lfVarx);
+ });
+}
diff --git a/js/src/tests/ecma_2017/AsyncFunctions/async-function-declaration-in-modules.js b/js/src/tests/ecma_2017/AsyncFunctions/async-function-declaration-in-modules.js
new file mode 100644
index 0000000000..41cc37bf33
--- /dev/null
+++ b/js/src/tests/ecma_2017/AsyncFunctions/async-function-declaration-in-modules.js
@@ -0,0 +1,13 @@
+// |reftest| module
+
+async function f() {
+ return "success";
+}
+
+var AsyncFunction = (async function(){}).constructor;
+
+assertEq(f instanceof AsyncFunction, true);
+
+f().then(v => {
+ reportCompare("success", v);
+});
diff --git a/js/src/tests/ecma_2018/AsyncGenerators/async-generator-declaration-in-modules.js b/js/src/tests/ecma_2018/AsyncGenerators/async-generator-declaration-in-modules.js
new file mode 100644
index 0000000000..6cac859579
--- /dev/null
+++ b/js/src/tests/ecma_2018/AsyncGenerators/async-generator-declaration-in-modules.js
@@ -0,0 +1,13 @@
+// |reftest| module skip-if(release_or_beta)
+
+async function* f() {
+ return "success";
+}
+
+var AsyncGenerator = (async function*(){}).constructor;
+
+assertEq(f instanceof AsyncGenerator, true);
+
+f().next().then(v => {
+ reportCompare("success", v.value);
+});
diff --git a/js/src/tests/ecma_2018/AsyncGenerators/browser.js b/js/src/tests/ecma_2018/AsyncGenerators/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/ecma_2018/AsyncGenerators/browser.js
diff --git a/js/src/tests/ecma_2018/AsyncGenerators/shell.js b/js/src/tests/ecma_2018/AsyncGenerators/shell.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/ecma_2018/AsyncGenerators/shell.js
diff --git a/js/src/tests/ecma_2018/browser.js b/js/src/tests/ecma_2018/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/ecma_2018/browser.js
diff --git a/js/src/tests/ecma_2018/shell.js b/js/src/tests/ecma_2018/shell.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/ecma_2018/shell.js