diff options
author | Andreas Kling <kling@serenityos.org> | 2022-11-23 11:32:45 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-11-23 16:05:59 +0000 |
commit | 96cbf368bd6bf051d49784a6db563c630a2b97e5 (patch) | |
tree | bdf85cbaeedaf0ef6820d4577c9f31663c1ee9db | |
parent | 20e51025bb7dab66a5f53e793c035fe49282b138 (diff) | |
download | serenity-96cbf368bd6bf051d49784a6db563c630a2b97e5.zip |
LibJS: Move JobCallback functions out-of-line
This allows JobCallback.h to not include Runtime/AbstractOperations.h
and FunctionObject.h.
4 files changed, 36 insertions, 18 deletions
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 <AK/TypeCasts.h> +#include <LibJS/Runtime/AbstractOperations.h> #include <LibJS/Runtime/FinalizationRegistryPrototype.h> 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 <linusg@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <LibJS/Runtime/AbstractOperations.h> +#include <LibJS/Runtime/FunctionObject.h> +#include <LibJS/Runtime/JobCallback.h> + +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<Value> call_job_callback(VM& vm, JobCallback& job_callback, Value this_value, MarkedVector<Value> 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 <LibJS/Runtime/AbstractOperations.h> +#include <AK/OwnPtr.h> +#include <LibJS/Heap/Handle.h> #include <LibJS/Runtime/Completion.h> -#include <LibJS/Runtime/FunctionObject.h> namespace JS { @@ -22,21 +22,7 @@ struct JobCallback { OwnPtr<CustomData> 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<Value> call_job_callback(VM& vm, JobCallback& job_callback, Value this_value, MarkedVector<Value> 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<Value> call_job_callback(VM&, JobCallback&, Value this_value, MarkedVector<Value> arguments_list); } |