summaryrefslogtreecommitdiffstats
path: root/js/src/vm
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-08-06 18:31:36 +0000
committerMoonchild <moonchild@palemoon.org>2020-08-30 09:37:12 +0000
commit10a10fd3757374123eb5e3aab1e4720f86575f47 (patch)
tree2e7d794acdd6105eba65013cff421fe7dad94299 /js/src/vm
parent1012dbe9e5b2d00f967b0523f94ac8cc7ed3118d (diff)
downloadUXP-10a10fd3757374123eb5e3aab1e4720f86575f47.tar
UXP-10a10fd3757374123eb5e3aab1e4720f86575f47.tar.gz
UXP-10a10fd3757374123eb5e3aab1e4720f86575f47.tar.lz
UXP-10a10fd3757374123eb5e3aab1e4720f86575f47.tar.xz
UXP-10a10fd3757374123eb5e3aab1e4720f86575f47.zip
Issue #618 - Simplify module resolve hook to be a function pointer
This is an ahead-of time port to try and address #1624. This is based on BZ 1461751 and Jon Coppeard's work in it.
Diffstat (limited to 'js/src/vm')
-rw-r--r--js/src/vm/GlobalObject.h14
-rw-r--r--js/src/vm/Runtime.cpp6
-rw-r--r--js/src/vm/Runtime.h3
-rw-r--r--js/src/vm/SelfHosting.cpp15
4 files changed, 15 insertions, 23 deletions
diff --git a/js/src/vm/GlobalObject.h b/js/src/vm/GlobalObject.h
index 720f63e69..a9f07d495 100644
--- a/js/src/vm/GlobalObject.h
+++ b/js/src/vm/GlobalObject.h
@@ -119,7 +119,6 @@ class GlobalObject : public NativeObject
DEBUGGERS,
INTRINSICS,
FOR_OF_PIC_CHAIN,
- MODULE_RESOLVE_HOOK,
WINDOW_PROXY,
GLOBAL_THIS_RESOLVED,
@@ -879,19 +878,6 @@ class GlobalObject : public NativeObject
setReservedSlot(WINDOW_PROXY, ObjectValue(*windowProxy));
}
- void setModuleResolveHook(HandleFunction hook) {
- MOZ_ASSERT(hook);
- setSlot(MODULE_RESOLVE_HOOK, ObjectValue(*hook));
- }
-
- JSFunction* moduleResolveHook() {
- Value value = getSlotRef(MODULE_RESOLVE_HOOK);
- if (value.isUndefined())
- return nullptr;
-
- return &value.toObject().as<JSFunction>();
- }
-
// Returns either this global's star-generator function prototype, or null
// if that object was never created. Dodgy; for use only in also-dodgy
// GlobalHelperThreadState::mergeParseTaskCompartment().
diff --git a/js/src/vm/Runtime.cpp b/js/src/vm/Runtime.cpp
index 284a4f3d7..5e0246b85 100644
--- a/js/src/vm/Runtime.cpp
+++ b/js/src/vm/Runtime.cpp
@@ -241,8 +241,10 @@ JSRuntime::JSRuntime(JSRuntime* parentRuntime)
lastAnimationTime(0),
performanceMonitoring(thisFromCtor()),
ionLazyLinkListSize_(0),
- stackFormat_(parentRuntime ? js::StackFormat::Default
- : js::StackFormat::SpiderMonkey)
+ stackFormat_(parentRuntime ?
+ js::StackFormat::Default :
+ js::StackFormat::SpiderMonkey),
+ moduleResolveHook()
{
setGCStoreBufferPtr(&gc.storeBuffer);
diff --git a/js/src/vm/Runtime.h b/js/src/vm/Runtime.h
index e60371e38..247a2dc9d 100644
--- a/js/src/vm/Runtime.h
+++ b/js/src/vm/Runtime.h
@@ -1294,6 +1294,9 @@ struct JSRuntime : public JS::shadow::Runtime,
// For inherited heap state accessors.
friend class js::gc::AutoTraceSession;
friend class JS::AutoEnterCycleCollection;
+
+ // The implementation-defined abstract operation HostResolveImportedModule.
+ JS::ModuleResolveHook moduleResolveHook;
};
namespace js {
diff --git a/js/src/vm/SelfHosting.cpp b/js/src/vm/SelfHosting.cpp
index 50b0c01de..f324a0a67 100644
--- a/js/src/vm/SelfHosting.cpp
+++ b/js/src/vm/SelfHosting.cpp
@@ -2026,25 +2026,26 @@ intrinsic_HostResolveImportedModule(JSContext* cx, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
MOZ_ASSERT(args.length() == 2);
- MOZ_ASSERT(args[0].toObject().is<ModuleObject>());
- MOZ_ASSERT(args[1].isString());
+ RootedModuleObject module(cx, &args[0].toObject().as<ModuleObject>());
+ RootedString specifier(cx, args[1].toString());
- RootedFunction moduleResolveHook(cx, cx->global()->moduleResolveHook());
+ JS::ModuleResolveHook moduleResolveHook = cx->runtime()->moduleResolveHook;
if (!moduleResolveHook) {
JS_ReportErrorASCII(cx, "Module resolve hook not set");
return false;
}
- RootedValue result(cx);
- if (!JS_CallFunction(cx, nullptr, moduleResolveHook, args, &result))
+ RootedObject result(cx);
+ result = moduleResolveHook(cx, module, specifier);
+ if (!result)
return false;
- if (!result.isObject() || !result.toObject().is<ModuleObject>()) {
+ if (!result->is<ModuleObject>()) {
JS_ReportErrorASCII(cx, "Module resolve hook did not return Module object");
return false;
}
- args.rval().set(result);
+ args.rval().setObject(*result);
return true;
}