Issue #1691 - Part 6a: Support private values which contain pointers to cycle-collected C++ objects https://bugzilla.mozilla.org/show_bug.cgi?id=1342012

(cherry picked from commit 1286cca73d58332ba0becd0011f747713b8acfac)
This commit is contained in:
Brian Smith 2023-04-09 12:22:33 -05:00 committed by roytam1
commit 1b811bd711
10 changed files with 107 additions and 23 deletions

View file

@ -4327,13 +4327,17 @@ Evaluate(JSContext* cx, const ReadOnlyCompileOptions& options,
using ModuleResolveHook = JSObject* (*)(JSContext*, HandleValue, HandleString);
/**
* Get the HostResolveImportedModule hook for the runtime.
* Get the HostImportModuleDynamically hook for the runtime.
*/
extern JS_PUBLIC_API(ModuleResolveHook)
GetModuleResolveHook(JSRuntime* rt);
/**
* Set the HostResolveImportedModule hook for the runtime to the given function.
* Set the HostImportModuleDynamically hook for the runtime to the given
* function.
*
* If this hook is not set (or set to nullptr) then the JS engine will throw an
* exception if dynamic module import is attempted.
*/
extern JS_PUBLIC_API(void)
SetModuleResolveHook(JSRuntime* rt, ModuleResolveHook func);
@ -4406,6 +4410,26 @@ SetScriptPrivate(JSScript* script, const JS::Value& value);
extern JS_PUBLIC_API(JS::Value)
GetScriptPrivate(JSScript* script);
/**
* A hook that's called whenever a script or module which has a private value
* set with SetScriptPrivate() or SetModulePrivate() is finalized. This can be
* used to clean up the private state. The private value is passed as an
* argument.
*/
using ScriptPrivateFinalizeHook = void (*)(JSFreeOp*, const JS::Value&);
/**
* Get the script private finalize hook for the runtime.
*/
extern JS_PUBLIC_API(ScriptPrivateFinalizeHook)
GetScriptPrivateFinalizeHook(JSContext* cx);
/**
* Set the script private finalize hook for the runtime to the given function.
*/
extern JS_PUBLIC_API(void)
SetScriptPrivateFinalizeHook(JSContext* cx, ScriptPrivateFinalizeHook func);
/*
* Perform the ModuleInstantiate operation on the given source text module
* record.