1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 21:47:45 +00:00

LibJS+LibWeb: Wrap raw JS::Cell*/& fields in GCPtr/NonnullGCPtr

This commit is contained in:
Matthew Olsson 2023-02-26 16:09:02 -07:00 committed by Andreas Kling
parent 1df3652e27
commit 7c0c1c8f49
214 changed files with 825 additions and 827 deletions

View file

@ -95,7 +95,7 @@ JS::Completion invoke_callback(WebIDL::CallbackType& callback, Optional<JS::Valu
auto& function_object = callback.callback;
// 4. If ! IsCallable(F) is false:
if (!function_object.is_function()) {
if (!function_object->is_function()) {
// 1. Note: This is only possible when the callback function came from an attribute marked with [LegacyTreatNonObjectAsNull].
// 2. Return the result of converting undefined to the callback functions return type.
@ -105,7 +105,7 @@ JS::Completion invoke_callback(WebIDL::CallbackType& callback, Optional<JS::Valu
// 5. Let realm be Fs associated Realm.
// See the comment about associated realm on step 4 of call_user_object_operation.
auto& realm = function_object.shape().realm();
auto& realm = function_object->shape().realm();
// 6. Let relevant settings be realms settings object.
auto& relevant_settings = Bindings::host_defined_environment_settings_object(realm);
@ -117,14 +117,14 @@ JS::Completion invoke_callback(WebIDL::CallbackType& callback, Optional<JS::Valu
relevant_settings.prepare_to_run_script();
// 9. Prepare to run a callback with stored settings.
stored_settings.prepare_to_run_callback();
stored_settings->prepare_to_run_callback();
// FIXME: 10. Let esArgs be the result of converting args to an ECMAScript arguments list. If this throws an exception, set completion to the completion value representing the thrown exception and jump to the step labeled return.
// For simplicity, we currently make the caller do this. However, this means we can't throw exceptions at this point like the spec wants us to.
// 11. Let callResult be Call(F, thisArg, esArgs).
auto& vm = function_object.vm();
auto call_result = JS::call(vm, verify_cast<JS::FunctionObject>(function_object), this_argument.value(), move(args));
auto& vm = function_object->vm();
auto call_result = JS::call(vm, verify_cast<JS::FunctionObject>(*function_object), this_argument.value(), move(args));
// 12. If callResult is an abrupt completion, set completion to callResult and jump to the step labeled return.
if (call_result.is_throw_completion()) {

View file

@ -58,7 +58,7 @@ JS::Completion call_user_object_operation(WebIDL::CallbackType& callback, Deprec
auto& object = callback.callback;
// 4. Let realm be Os associated Realm.
auto& realm = object.shape().realm();
auto& realm = object->shape().realm();
// 5. Let relevant settings be realms settings object.
auto& relevant_settings = Bindings::host_defined_environment_settings_object(realm);
@ -70,15 +70,15 @@ JS::Completion call_user_object_operation(WebIDL::CallbackType& callback, Deprec
relevant_settings.prepare_to_run_script();
// 8. Prepare to run a callback with stored settings.
stored_settings.prepare_to_run_callback();
stored_settings->prepare_to_run_callback();
// 9. Let X be O.
auto* actual_function_object = &object;
auto actual_function_object = object;
// 10. If ! IsCallable(O) is false, then:
if (!object.is_function()) {
if (!object->is_function()) {
// 1. Let getResult be Get(O, opName).
auto get_result = object.get(operation_name);
auto get_result = object->get(operation_name);
// 2. If getResult is an abrupt completion, set completion to getResult and jump to the step labeled return.
if (get_result.is_throw_completion()) {
@ -94,10 +94,10 @@ JS::Completion call_user_object_operation(WebIDL::CallbackType& callback, Deprec
// 3. Set X to getResult.[[Value]].
// NOTE: This is done out of order because `actual_function_object` is of type JS::Object and we cannot assign to it until we know for sure getResult.[[Value]] is a JS::Object.
actual_function_object = &get_result.release_value().as_object();
actual_function_object = get_result.release_value().as_object();
// 5. Set thisArg to O (overriding the provided value).
this_argument = &object;
this_argument = object;
}
// FIXME: 11. Let esArgs be the result of converting args to an ECMAScript arguments list. If this throws an exception, set completion to the completion value representing the thrown exception and jump to the step labeled return.
@ -105,7 +105,7 @@ JS::Completion call_user_object_operation(WebIDL::CallbackType& callback, Deprec
// 12. Let callResult be Call(X, thisArg, esArgs).
VERIFY(actual_function_object);
auto& vm = object.vm();
auto& vm = object->vm();
auto call_result = JS::call(vm, verify_cast<JS::FunctionObject>(*actual_function_object), this_argument.value(), forward<Args>(args)...);
// 13. If callResult is an abrupt completion, set completion to callResult and jump to the step labeled return.
@ -129,7 +129,7 @@ JS::Completion invoke_callback(WebIDL::CallbackType& callback, Optional<JS::Valu
{
auto& function_object = callback.callback;
JS::MarkedVector<JS::Value> arguments_list { function_object.vm().heap() };
JS::MarkedVector<JS::Value> arguments_list { function_object->vm().heap() };
(arguments_list.append(forward<Args>(args)), ...);
return invoke_callback(callback, move(this_argument), move(arguments_list));

View file

@ -20,7 +20,7 @@ StringView CallbackType::class_name() const { return "CallbackType"sv; }
void CallbackType::visit_edges(Cell::Visitor& visitor)
{
Cell::visit_edges(visitor);
visitor.visit(&callback);
visitor.visit(callback);
visitor.visit(callback_context);
}

View file

@ -17,10 +17,10 @@ class CallbackType final : public JS::Cell {
public:
CallbackType(JS::Object& callback, HTML::EnvironmentSettingsObject& callback_context);
JS::Object& callback;
JS::NonnullGCPtr<JS::Object> callback;
// https://webidl.spec.whatwg.org/#dfn-callback-context
HTML::EnvironmentSettingsObject& callback_context;
JS::NonnullGCPtr<HTML::EnvironmentSettingsObject> callback_context;
private:
virtual StringView class_name() const override;