Bug 1778076 - Part 5: Replace ModuleObject methods with shell functions r=arai

This replaces the methods 'declarationInstantiation' and 'evaluation' with
shell functions moduleLink and moduleEvaluate and updates the test code.

Differential Revision: https://phabricator.services.mozilla.com/D151015
This commit is contained in:
Jon Coppeard
2022-07-05 13:04:55 +00:00
parent 21befd6da6
commit aef7519b4a
77 changed files with 273 additions and 353 deletions

View File

@@ -182,6 +182,7 @@
#include "vm/JSObject.h"
#include "vm/JSScript.h"
#include "vm/ModuleBuilder.h" // js::ModuleBuilder
#include "vm/Modules.h"
#include "vm/Monitor.h"
#include "vm/MutexIDs.h"
#include "vm/Printer.h" // QuoteString
@@ -5589,6 +5590,63 @@ static bool RegisterModule(JSContext* cx, unsigned argc, Value* vp) {
return true;
}
static bool ModuleLink(JSContext* cx, unsigned argc, Value* vp) {
CallArgs args = CallArgsFromVp(argc, vp);
if (args.length() != 1 || !args[0].isObject()) {
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_INVALID_ARGS,
"moduleLink");
return false;
}
RootedObject object(cx, UncheckedUnwrap(&args[0].toObject()));
if (!object->is<ShellModuleObjectWrapper>()) {
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_INVALID_ARGS,
"moduleLink");
return false;
}
AutoRealm ar(cx, object);
Rooted<ModuleObject*> module(cx,
object->as<ShellModuleObjectWrapper>().get());
if (!js::ModuleLink(cx, module)) {
return false;
}
args.rval().setUndefined();
return true;
}
static bool ModuleEvaluate(JSContext* cx, unsigned argc, Value* vp) {
CallArgs args = CallArgsFromVp(argc, vp);
if (args.length() != 1 || !args[0].isObject()) {
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_INVALID_ARGS,
"moduleEvaluate");
return false;
}
RootedObject object(cx, UncheckedUnwrap(&args[0].toObject()));
if (!object->is<ShellModuleObjectWrapper>()) {
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_INVALID_ARGS,
"moduleEvaluate");
return false;
}
{
AutoRealm ar(cx, object);
Rooted<ModuleObject*> module(cx,
object->as<ShellModuleObjectWrapper>().get());
if (!js::ModuleEvaluate(cx, module, args.rval())) {
return false;
}
}
return JS_WrapValue(cx, args.rval());
}
static ModuleEnvironmentObject* GetModuleInitialEnvironment(
JSContext* cx, Handle<ModuleObject*> module) {
// Use the initial environment so that tests can check bindings exists
@@ -9344,6 +9402,14 @@ static const JSFunctionSpecWithHelp shell_functions[] = {
" Register a module with the module loader, so that subsequent import from\n"
" |specifier| will resolve to |module|. Returns |module|."),
JS_FN_HELP("moduleLink", ModuleLink, 1, 0,
"moduleLink(moduleOjbect)",
" Link a module graph, performing the spec's Link method."),
JS_FN_HELP("moduleEvaluate", ModuleEvaluate, 1, 0,
"moduleEvaluate(moduleOjbect)",
" Evaluate a module graph, performing the spec's Evaluate method."),
JS_FN_HELP("getModuleEnvironmentNames", GetModuleEnvironmentNames, 1, 0,
"getModuleEnvironmentNames(module)",
" Get the list of a module environment's bound names for a specified module.\n"),