2021-09-26 14:53:28 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
|
2022-08-16 20:33:17 +01:00
|
|
|
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
|
2021-09-26 14:53:28 +01:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-12-13 22:07:04 +00:00
|
|
|
#include <AK/Forward.h>
|
2021-09-26 14:53:28 +01:00
|
|
|
#include <LibJS/Forward.h>
|
2021-10-14 18:03:08 +01:00
|
|
|
#include <LibJS/Runtime/AbstractOperations.h>
|
|
|
|
#include <LibJS/Runtime/FunctionObject.h>
|
2022-09-24 15:39:23 -06:00
|
|
|
#include <LibWeb/Bindings/HostDefined.h>
|
2021-10-14 18:03:08 +01:00
|
|
|
#include <LibWeb/HTML/Scripting/Environments.h>
|
2022-09-24 16:02:41 +01:00
|
|
|
#include <LibWeb/WebIDL/CallbackType.h>
|
2021-09-26 14:53:28 +01:00
|
|
|
|
2022-09-24 16:14:37 +01:00
|
|
|
namespace Web::WebIDL {
|
2021-09-26 14:53:28 +01:00
|
|
|
|
2022-07-22 21:01:36 +02:00
|
|
|
ErrorOr<ByteBuffer> get_buffer_source_copy(JS::Object const& buffer_source);
|
2021-09-26 14:53:28 +01:00
|
|
|
|
2023-03-29 23:39:59 +01:00
|
|
|
JS::Completion call_user_object_operation(WebIDL::CallbackType& callback, DeprecatedString const& operation_name, Optional<JS::Value> this_argument, JS::MarkedVector<JS::Value> args);
|
2021-10-14 18:03:08 +01:00
|
|
|
|
|
|
|
// https://webidl.spec.whatwg.org/#call-a-user-objects-operation
|
|
|
|
template<typename... Args>
|
2022-12-04 18:02:33 +00:00
|
|
|
JS::Completion call_user_object_operation(WebIDL::CallbackType& callback, DeprecatedString const& operation_name, Optional<JS::Value> this_argument, Args&&... args)
|
2021-10-14 18:03:08 +01:00
|
|
|
{
|
2023-03-29 23:39:59 +01:00
|
|
|
auto& function_object = callback.callback;
|
2021-10-14 18:03:08 +01:00
|
|
|
|
2023-03-29 23:39:59 +01:00
|
|
|
JS::MarkedVector<JS::Value> arguments_list { function_object->heap() };
|
|
|
|
(arguments_list.append(forward<Args>(args)), ...);
|
2021-10-14 18:03:08 +01:00
|
|
|
|
2023-03-29 23:39:59 +01:00
|
|
|
return call_user_object_operation(callback, operation_name, move(this_argument), move(arguments_list));
|
2021-10-14 18:03:08 +01:00
|
|
|
}
|
|
|
|
|
2022-09-24 16:02:41 +01:00
|
|
|
JS::Completion invoke_callback(WebIDL::CallbackType& callback, Optional<JS::Value> this_argument, JS::MarkedVector<JS::Value> args);
|
2022-03-03 14:20:45 -05:00
|
|
|
|
2021-10-14 18:03:08 +01:00
|
|
|
// https://webidl.spec.whatwg.org/#invoke-a-callback-function
|
|
|
|
template<typename... Args>
|
2022-09-24 16:02:41 +01:00
|
|
|
JS::Completion invoke_callback(WebIDL::CallbackType& callback, Optional<JS::Value> this_argument, Args&&... args)
|
2021-10-14 18:03:08 +01:00
|
|
|
{
|
2022-08-08 14:12:01 +02:00
|
|
|
auto& function_object = callback.callback;
|
2021-10-14 18:03:08 +01:00
|
|
|
|
2023-03-29 23:39:59 +01:00
|
|
|
JS::MarkedVector<JS::Value> arguments_list { function_object->heap() };
|
2022-03-03 14:20:45 -05:00
|
|
|
(arguments_list.append(forward<Args>(args)), ...);
|
2021-10-14 18:03:08 +01:00
|
|
|
|
2022-03-03 14:20:45 -05:00
|
|
|
return invoke_callback(callback, move(this_argument), move(arguments_list));
|
2021-10-14 18:03:08 +01:00
|
|
|
}
|
|
|
|
|
2021-09-26 14:53:28 +01:00
|
|
|
}
|