mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:17:42 +00:00
LibWeb: Stop using Bindings::wrap() in a bunch of places
wrap() is now basically a no-op so we should stop using it everywhere and eventually remove it. This patch removes uses of wrap() in non-generated code.
This commit is contained in:
parent
45425de849
commit
9176a0de99
7 changed files with 32 additions and 56 deletions
|
@ -37,9 +37,9 @@ JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handle<JS::Object
|
|||
// 2. Let data be the result of getting a copy of the bytes held by the data parameter passed to the digest() method.
|
||||
auto data_buffer_or_error = Bindings::IDL::get_buffer_source_copy(*data.cell());
|
||||
if (data_buffer_or_error.is_error()) {
|
||||
auto* error = wrap(realm, DOM::OperationError::create(global_object(), "Failed to copy bytes from ArrayBuffer"));
|
||||
auto error = DOM::OperationError::create(global_object(), "Failed to copy bytes from ArrayBuffer");
|
||||
auto* promise = JS::Promise::create(realm);
|
||||
promise->reject(error);
|
||||
promise->reject(error.ptr());
|
||||
return promise;
|
||||
}
|
||||
auto& data_buffer = data_buffer_or_error.value();
|
||||
|
@ -58,9 +58,9 @@ JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handle<JS::Object
|
|||
}
|
||||
// 4. If an error occurred, return a Promise rejected with normalizedAlgorithm.
|
||||
else {
|
||||
auto* error = wrap(realm, DOM::NotSupportedError::create(global_object(), String::formatted("Invalid hash function '{}'", algorithm)));
|
||||
auto error = DOM::NotSupportedError::create(global_object(), String::formatted("Invalid hash function '{}'", algorithm));
|
||||
auto* promise = JS::Promise::create(realm);
|
||||
promise->reject(error);
|
||||
promise->reject(error.ptr());
|
||||
return promise;
|
||||
}
|
||||
|
||||
|
@ -79,8 +79,8 @@ JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handle<JS::Object
|
|||
auto digest = hash.digest();
|
||||
auto result_buffer = ByteBuffer::copy(digest.immutable_data(), hash.digest_size());
|
||||
if (result_buffer.is_error()) {
|
||||
auto* error = wrap(realm, DOM::OperationError::create(global_object(), "Failed to create result buffer"));
|
||||
promise->reject(error);
|
||||
auto error = DOM::OperationError::create(global_object(), "Failed to create result buffer");
|
||||
promise->reject(error.ptr());
|
||||
return promise;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ void AbortSignal::signal_abort(JS::Value reason)
|
|||
if (!reason.is_undefined())
|
||||
m_abort_reason = reason;
|
||||
else
|
||||
m_abort_reason = wrap(realm(), AbortError::create(global_object(), "Aborted without reason"));
|
||||
m_abort_reason = AbortError::create(global_object(), "Aborted without reason").ptr();
|
||||
|
||||
// 3. For each algorithm in signal’s abort algorithms: run algorithm.
|
||||
for (auto& algorithm : m_abort_algorithms)
|
||||
|
|
|
@ -441,22 +441,16 @@ Bindings::CallbackType* EventTarget::get_current_value_of_event_handler(FlyStrin
|
|||
|
||||
// 3. If eventHandler is an element's event handler, then set scope to NewObjectEnvironment(document, true, scope).
|
||||
// (Otherwise, eventHandler is a Window object's event handler.)
|
||||
if (is<Element>(this)) {
|
||||
auto* wrapped_document = Bindings::wrap(realm, *document);
|
||||
scope = JS::new_object_environment(*wrapped_document, true, scope);
|
||||
}
|
||||
if (is<Element>(this))
|
||||
scope = JS::new_object_environment(*document, true, scope);
|
||||
|
||||
// 4. If form owner is not null, then set scope to NewObjectEnvironment(form owner, true, scope).
|
||||
if (form_owner) {
|
||||
auto* wrapped_form_owner = Bindings::wrap(realm, *form_owner);
|
||||
scope = JS::new_object_environment(*wrapped_form_owner, true, scope);
|
||||
}
|
||||
if (form_owner)
|
||||
scope = JS::new_object_environment(*form_owner, true, scope);
|
||||
|
||||
// 5. If element is not null, then set scope to NewObjectEnvironment(element, true, scope).
|
||||
if (element) {
|
||||
auto* wrapped_element = Bindings::wrap(realm, *element);
|
||||
scope = JS::new_object_environment(*wrapped_element, true, scope);
|
||||
}
|
||||
if (element)
|
||||
scope = JS::new_object_environment(*element, true, scope);
|
||||
|
||||
// 6. Return scope. (NOTE: Not necessary)
|
||||
|
||||
|
@ -625,18 +619,14 @@ JS::ThrowCompletionOr<void> EventTarget::process_event_handler_for_event(FlyStri
|
|||
// 4. Process the Event object event as follows:
|
||||
JS::Completion return_value_or_error;
|
||||
|
||||
// Needed for wrapping.
|
||||
auto* callback_object = &callback->callback;
|
||||
auto& realm = callback_object->shape().realm();
|
||||
|
||||
if (special_error_event_handling) {
|
||||
// -> If special error event handling is true
|
||||
// Invoke callback with five arguments, the first one having the value of event's message attribute, the second having the value of event's filename attribute, the third having the value of event's lineno attribute,
|
||||
// the fourth having the value of event's colno attribute, the fifth having the value of event's error attribute, and with the callback this value set to event's currentTarget.
|
||||
// Let return value be the callback's return value. [WEBIDL]
|
||||
auto& error_event = verify_cast<HTML::ErrorEvent>(event);
|
||||
auto* wrapped_message = JS::js_string(callback_object->heap(), error_event.message());
|
||||
auto* wrapped_filename = JS::js_string(callback_object->heap(), error_event.filename());
|
||||
auto* wrapped_message = JS::js_string(vm(), error_event.message());
|
||||
auto* wrapped_filename = JS::js_string(vm(), error_event.filename());
|
||||
auto wrapped_lineno = JS::Value(error_event.lineno());
|
||||
auto wrapped_colno = JS::Value(error_event.colno());
|
||||
|
||||
|
@ -645,7 +635,7 @@ JS::ThrowCompletionOr<void> EventTarget::process_event_handler_for_event(FlyStri
|
|||
// NOTE: current_target is always non-null here, as the event dispatcher takes care to make sure it's non-null (and uses it as the this value for the callback!)
|
||||
// FIXME: This is rewrapping the this value of the callback defined in activate_event_handler. While I don't think this is observable as the event dispatcher
|
||||
// calls directly into the callback without considering things such as proxies, it is a waste. However, if it observable, then we must reuse the this_value that was given to the callback.
|
||||
auto* this_value = Bindings::wrap(realm, *error_event.current_target());
|
||||
auto* this_value = error_event.current_target().ptr();
|
||||
|
||||
return_value_or_error = Bindings::IDL::invoke_callback(*callback, this_value, wrapped_message, wrapped_filename, wrapped_lineno, wrapped_colno, error_event.error());
|
||||
} else {
|
||||
|
@ -653,10 +643,10 @@ JS::ThrowCompletionOr<void> EventTarget::process_event_handler_for_event(FlyStri
|
|||
// Invoke callback with one argument, the value of which is the Event object event, with the callback this value set to event's currentTarget. Let return value be the callback's return value. [WEBIDL]
|
||||
|
||||
// FIXME: This has the same rewrapping issue as this_value.
|
||||
auto* wrapped_event = Bindings::wrap(realm, event);
|
||||
auto* wrapped_event = &event;
|
||||
|
||||
// FIXME: The comments about this in the special_error_event_handling path also apply here.
|
||||
auto* this_value = Bindings::wrap(realm, *event.current_target());
|
||||
auto* this_value = event.current_target().ptr();
|
||||
|
||||
return_value_or_error = Bindings::IDL::invoke_callback(*callback, this_value, wrapped_event);
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ JS::ThrowCompletionOr<NodeFilter::Result> NodeIterator::filter(Node& node)
|
|||
{
|
||||
// 1. If traverser’s active flag is set, then throw an "InvalidStateError" DOMException.
|
||||
if (m_active)
|
||||
return JS::throw_completion(wrap(shape().realm(), InvalidStateError::create(global_object(), "NodeIterator is already active")));
|
||||
return throw_completion(InvalidStateError::create(global_object(), "NodeIterator is already active"));
|
||||
|
||||
// 2. Let n be node’s nodeType attribute value − 1.
|
||||
auto n = node.node_type() - 1;
|
||||
|
@ -148,7 +148,7 @@ JS::ThrowCompletionOr<NodeFilter::Result> NodeIterator::filter(Node& node)
|
|||
|
||||
// 6. Let result be the return value of call a user object’s operation with traverser’s filter, "acceptNode", and « node ».
|
||||
// If this throws an exception, then unset traverser’s active flag and rethrow the exception.
|
||||
auto result = Bindings::IDL::call_user_object_operation(m_filter->callback(), "acceptNode", {}, wrap(shape().realm(), node));
|
||||
auto result = Bindings::IDL::call_user_object_operation(m_filter->callback(), "acceptNode", {}, &node);
|
||||
if (result.is_abrupt()) {
|
||||
m_active = false;
|
||||
return result;
|
||||
|
|
|
@ -231,7 +231,7 @@ JS::ThrowCompletionOr<NodeFilter::Result> TreeWalker::filter(Node& node)
|
|||
{
|
||||
// 1. If traverser’s active flag is set, then throw an "InvalidStateError" DOMException.
|
||||
if (m_active)
|
||||
return JS::throw_completion(wrap(shape().realm(), InvalidStateError::create(global_object(), "NodeIterator is already active")));
|
||||
return throw_completion(InvalidStateError::create(global_object(), "NodeIterator is already active"));
|
||||
|
||||
// 2. Let n be node’s nodeType attribute value − 1.
|
||||
auto n = node.node_type() - 1;
|
||||
|
@ -249,7 +249,7 @@ JS::ThrowCompletionOr<NodeFilter::Result> TreeWalker::filter(Node& node)
|
|||
|
||||
// 6. Let result be the return value of call a user object’s operation with traverser’s filter, "acceptNode", and « node ».
|
||||
// If this throws an exception, then unset traverser’s active flag and rethrow the exception.
|
||||
auto result = Bindings::IDL::call_user_object_operation(m_filter->callback(), "acceptNode", {}, wrap(shape().realm(), node));
|
||||
auto result = Bindings::IDL::call_user_object_operation(m_filter->callback(), "acceptNode", {}, &node);
|
||||
if (result.is_abrupt()) {
|
||||
m_active = false;
|
||||
return result;
|
||||
|
|
|
@ -689,9 +689,7 @@ u32 Window::request_idle_callback_impl(Bindings::CallbackType& callback)
|
|||
auto handle = window.m_idle_callback_identifier;
|
||||
// 4. Push callback to the end of window's list of idle request callbacks, associated with handle.
|
||||
auto handler = [callback = JS::make_handle(callback)](JS::NonnullGCPtr<RequestIdleCallback::IdleDeadline> deadline) -> JS::Completion {
|
||||
auto& realm = callback->callback.shape().realm();
|
||||
auto* wrapped_deadline = Bindings::wrap(realm, *deadline);
|
||||
return Bindings::IDL::invoke_callback(const_cast<Bindings::CallbackType&>(*callback), {}, JS::Value(wrapped_deadline));
|
||||
return Bindings::IDL::invoke_callback(const_cast<Bindings::CallbackType&>(*callback), {}, deadline.ptr());
|
||||
};
|
||||
window.m_idle_request_callbacks.append(adopt_ref(*new IdleCallback(move(handler), handle)));
|
||||
// 5. Return handle and then continue running this algorithm asynchronously.
|
||||
|
@ -1101,16 +1099,14 @@ JS_DEFINE_NATIVE_FUNCTION(Window::parent_getter)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::document_getter)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto* impl = TRY(impl_from(vm));
|
||||
return wrap(realm, impl->associated_document());
|
||||
return &impl->associated_document();
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::performance_getter)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto* impl = TRY(impl_from(vm));
|
||||
return wrap(realm, impl->performance());
|
||||
return &impl->performance();
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::performance_setter)
|
||||
|
@ -1132,18 +1128,16 @@ JS_DEFINE_NATIVE_FUNCTION(Window::performance_setter)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::screen_getter)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto* impl = TRY(impl_from(vm));
|
||||
return wrap(realm, impl->screen());
|
||||
return &impl->screen();
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::event_getter)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto* impl = TRY(impl_from(vm));
|
||||
if (!impl->current_event())
|
||||
return JS::js_undefined();
|
||||
return wrap(realm, const_cast<DOM::Event&>(*impl->current_event()));
|
||||
return impl->current_event();
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::event_setter)
|
||||
|
@ -1166,9 +1160,8 @@ JS_DEFINE_NATIVE_FUNCTION(Window::location_setter)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::crypto_getter)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto* impl = TRY(impl_from(vm));
|
||||
return wrap(realm, impl->crypto());
|
||||
return &impl->crypto();
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::inner_width_getter)
|
||||
|
@ -1191,23 +1184,18 @@ JS_DEFINE_NATIVE_FUNCTION(Window::device_pixel_ratio_getter)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::get_computed_style)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto* impl = TRY(impl_from(vm));
|
||||
auto* object = TRY(vm.argument(0).to_object(vm));
|
||||
if (!is<DOM::Element>(object))
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "DOM element");
|
||||
|
||||
return wrap(realm, *impl->get_computed_style_impl(*static_cast<DOM::Element*>(object)));
|
||||
return impl->get_computed_style_impl(*static_cast<DOM::Element*>(object));
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::get_selection)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto* impl = TRY(impl_from(vm));
|
||||
auto* selection = impl->get_selection_impl();
|
||||
if (!selection)
|
||||
return JS::js_null();
|
||||
return wrap(realm, *selection);
|
||||
return impl->get_selection_impl();
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::match_media)
|
||||
|
@ -1346,9 +1334,8 @@ JS_DEFINE_NATIVE_FUNCTION(Window::scroll_by)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::history_getter)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto* impl = TRY(impl_from(vm));
|
||||
return wrap(realm, impl->associated_document().history());
|
||||
return impl->associated_document().history();
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::screen_left_getter)
|
||||
|
|
|
@ -94,7 +94,6 @@ JS::ThrowCompletionOr<JS::MarkedVector<JS::Value>> ConsoleGlobalObject::internal
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(ConsoleGlobalObject::inspected_node_getter)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
||||
|
||||
if (!is<ConsoleGlobalObject>(this_object))
|
||||
|
@ -106,7 +105,7 @@ JS_DEFINE_NATIVE_FUNCTION(ConsoleGlobalObject::inspected_node_getter)
|
|||
if (!inspected_node)
|
||||
return JS::js_undefined();
|
||||
|
||||
return Web::Bindings::wrap(realm, *inspected_node);
|
||||
return inspected_node;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue