mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-02 14:19:15 +00:00
LibWeb: Move ad hoc CallbackType helper method to CallbackType header
Abstract operations of a stream does not seem like the correct home for this function.
This commit is contained in:
parent
93f258deb7
commit
99073c0561
Notes:
github-actions[bot]
2024-12-11 14:12:23 +00:00
Author: https://github.com/shannonbooth
Commit: 99073c0561
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2831
Reviewed-by: https://github.com/kennethmyhra ✅
Reviewed-by: https://github.com/trflynn89
7 changed files with 29 additions and 28 deletions
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <LibJS/Runtime/Object.h>
|
||||
#include <LibJS/Runtime/VM.h>
|
||||
#include <LibWeb/HTML/Scripting/Environments.h>
|
||||
#include <LibWeb/WebIDL/CallbackType.h>
|
||||
|
||||
|
@ -26,4 +27,19 @@ void CallbackType::visit_edges(Cell::Visitor& visitor)
|
|||
visitor.visit(callback_context);
|
||||
}
|
||||
|
||||
// Non-standard function to aid in converting a user-provided function into a WebIDL::Callback. This is essentially
|
||||
// what the Bindings generator would do at compile time, but at runtime instead.
|
||||
JS::ThrowCompletionOr<GC::Root<CallbackType>> property_to_callback(JS::VM& vm, JS::Value value, JS::PropertyKey const& property_key, OperationReturnsPromise operation_returns_promise)
|
||||
{
|
||||
auto property = TRY(value.get(vm, property_key));
|
||||
|
||||
if (property.is_undefined())
|
||||
return GC::Root<CallbackType> {};
|
||||
|
||||
if (!property.is_function())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAFunction, property.to_string_without_side_effects());
|
||||
|
||||
return vm.heap().allocate<CallbackType>(property.as_object(), HTML::incumbent_realm(), operation_returns_promise);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,4 +39,6 @@ private:
|
|||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
};
|
||||
|
||||
JS::ThrowCompletionOr<GC::Root<WebIDL::CallbackType>> property_to_callback(JS::VM& vm, JS::Value value, JS::PropertyKey const& property_key, WebIDL::OperationReturnsPromise);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue