From 96cbf368bd6bf051d49784a6db563c630a2b97e5 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 23 Nov 2022 11:32:45 +0100 Subject: LibJS: Move JobCallback functions out-of-line This allows JobCallback.h to not include Runtime/AbstractOperations.h and FunctionObject.h. --- Userland/Libraries/LibJS/CMakeLists.txt | 1 + .../Runtime/FinalizationRegistryPrototype.cpp | 1 + Userland/Libraries/LibJS/Runtime/JobCallback.cpp | 30 ++++++++++++++++++++++ Userland/Libraries/LibJS/Runtime/JobCallback.h | 22 +++------------- 4 files changed, 36 insertions(+), 18 deletions(-) create mode 100644 Userland/Libraries/LibJS/Runtime/JobCallback.cpp diff --git a/Userland/Libraries/LibJS/CMakeLists.txt b/Userland/Libraries/LibJS/CMakeLists.txt index 46b77da9a1..0d57eed794 100644 --- a/Userland/Libraries/LibJS/CMakeLists.txt +++ b/Userland/Libraries/LibJS/CMakeLists.txt @@ -136,6 +136,7 @@ set(SOURCES Runtime/IteratorOperations.cpp Runtime/IteratorPrototype.cpp Runtime/JSONObject.cpp + Runtime/JobCallback.cpp Runtime/Map.cpp Runtime/MapConstructor.cpp Runtime/MapIterator.cpp diff --git a/Userland/Libraries/LibJS/Runtime/FinalizationRegistryPrototype.cpp b/Userland/Libraries/LibJS/Runtime/FinalizationRegistryPrototype.cpp index b10684992e..ee1b76ceb6 100644 --- a/Userland/Libraries/LibJS/Runtime/FinalizationRegistryPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/FinalizationRegistryPrototype.cpp @@ -5,6 +5,7 @@ */ #include +#include #include namespace JS { diff --git a/Userland/Libraries/LibJS/Runtime/JobCallback.cpp b/Userland/Libraries/LibJS/Runtime/JobCallback.cpp new file mode 100644 index 0000000000..fe3d030302 --- /dev/null +++ b/Userland/Libraries/LibJS/Runtime/JobCallback.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2021-2022, Linus Groh + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include + +namespace JS { + +// 9.5.2 HostMakeJobCallback ( callback ), https://tc39.es/ecma262/#sec-hostmakejobcallback +JobCallback make_job_callback(FunctionObject& callback) +{ + // 1. Return the JobCallback Record { [[Callback]]: callback, [[HostDefined]]: empty }. + return { make_handle(&callback) }; +} + +// 9.5.3 HostCallJobCallback ( jobCallback, V, argumentsList ), https://tc39.es/ecma262/#sec-hostcalljobcallback +ThrowCompletionOr call_job_callback(VM& vm, JobCallback& job_callback, Value this_value, MarkedVector arguments_list) +{ + // 1. Assert: IsCallable(jobCallback.[[Callback]]) is true. + VERIFY(!job_callback.callback.is_null()); + + // 2. Return ? Call(jobCallback.[[Callback]], V, argumentsList). + return call(vm, job_callback.callback.cell(), this_value, move(arguments_list)); +} + +} diff --git a/Userland/Libraries/LibJS/Runtime/JobCallback.h b/Userland/Libraries/LibJS/Runtime/JobCallback.h index 88db41bad4..00904127d3 100644 --- a/Userland/Libraries/LibJS/Runtime/JobCallback.h +++ b/Userland/Libraries/LibJS/Runtime/JobCallback.h @@ -6,9 +6,9 @@ #pragma once -#include +#include +#include #include -#include namespace JS { @@ -22,21 +22,7 @@ struct JobCallback { OwnPtr custom_data { nullptr }; }; -// 9.5.2 HostMakeJobCallback ( callback ), https://tc39.es/ecma262/#sec-hostmakejobcallback -inline JobCallback make_job_callback(FunctionObject& callback) -{ - // 1. Return the JobCallback Record { [[Callback]]: callback, [[HostDefined]]: empty }. - return { make_handle(&callback) }; -} - -// 9.5.3 HostCallJobCallback ( jobCallback, V, argumentsList ), https://tc39.es/ecma262/#sec-hostcalljobcallback -inline ThrowCompletionOr call_job_callback(VM& vm, JobCallback& job_callback, Value this_value, MarkedVector arguments_list) -{ - // 1. Assert: IsCallable(jobCallback.[[Callback]]) is true. - VERIFY(!job_callback.callback.is_null()); - - // 2. Return ? Call(jobCallback.[[Callback]], V, argumentsList). - return call(vm, job_callback.callback.cell(), this_value, move(arguments_list)); -} +JobCallback make_job_callback(FunctionObject& callback); +ThrowCompletionOr call_job_callback(VM&, JobCallback&, Value this_value, MarkedVector arguments_list); } -- cgit v1.2.3