mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:27:34 +00:00
LibJS: Setup host hooks and have promise jobs work out the realm
This allows the host of LibJS (notably LibWeb in this case) to override certain functions such as HostEnqueuePromiseJob, so it can do it's own thing in certain situations. Notably, LibWeb will override HostEnqueuePromiseJob to put promise jobs on the microtask queue. This also makes promise jobs use AK::Function instead of JS::NativeFunction. This removes the need to go through a JavaScript function and it more closely matches the spec's idea of "abstract closures"
This commit is contained in:
parent
5aacec65ab
commit
4c1c6ef91c
12 changed files with 202 additions and 172 deletions
|
@ -176,16 +176,16 @@ public:
|
|||
CommonPropertyNames names;
|
||||
|
||||
void run_queued_promise_jobs();
|
||||
void enqueue_promise_job(NativeFunction&);
|
||||
void enqueue_promise_job(Function<ThrowCompletionOr<Value>()> job, Realm*);
|
||||
|
||||
void run_queued_finalization_registry_cleanup_jobs();
|
||||
void enqueue_finalization_registry_cleanup_job(FinalizationRegistry&);
|
||||
|
||||
void promise_rejection_tracker(const Promise&, Promise::RejectionOperation) const;
|
||||
void promise_rejection_tracker(Promise&, Promise::RejectionOperation) const;
|
||||
|
||||
Function<void()> on_call_stack_emptied;
|
||||
Function<void(const Promise&)> on_promise_unhandled_rejection;
|
||||
Function<void(const Promise&)> on_promise_rejection_handled;
|
||||
Function<void(Promise&)> on_promise_unhandled_rejection;
|
||||
Function<void(Promise&)> on_promise_rejection_handled;
|
||||
|
||||
ThrowCompletionOr<void> initialize_instance_elements(Object& object, ECMAScriptFunctionObject& constructor);
|
||||
|
||||
|
@ -216,6 +216,12 @@ public:
|
|||
|
||||
void enable_default_host_import_module_dynamically_hook();
|
||||
|
||||
Function<void(Promise&, Promise::RejectionOperation)> host_promise_rejection_tracker;
|
||||
Function<ThrowCompletionOr<Value>(GlobalObject&, JobCallback&, Value, MarkedValueList)> host_call_job_callback;
|
||||
Function<void(FinalizationRegistry&)> host_enqueue_finalization_registry_cleanup_job;
|
||||
Function<void(Function<ThrowCompletionOr<Value>()>, Realm*)> host_enqueue_promise_job;
|
||||
Function<JobCallback(FunctionObject&)> host_make_job_callback;
|
||||
|
||||
private:
|
||||
explicit VM(OwnPtr<CustomData>);
|
||||
|
||||
|
@ -241,7 +247,7 @@ private:
|
|||
|
||||
HashMap<String, Symbol*> m_global_symbol_map;
|
||||
|
||||
Vector<NativeFunction*> m_promise_jobs;
|
||||
Vector<Function<ThrowCompletionOr<Value>()>> m_promise_jobs;
|
||||
|
||||
Vector<FinalizationRegistry*> m_finalization_registry_cleanup_jobs;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue