summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp100
-rw-r--r--Userland/Libraries/LibWeb/Bindings/ExceptionOrUtils.h8
-rw-r--r--Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp4
-rw-r--r--Userland/Libraries/LibWeb/HTML/ImageData.cpp4
-rw-r--r--Userland/Libraries/LibWeb/HTML/ImageData.h2
-rw-r--r--Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp2
-rw-r--r--Userland/Libraries/LibWeb/WebGL/WebGLContextAttributes.cpp4
-rw-r--r--Userland/Libraries/LibWeb/WebGL/WebGLContextAttributes.h2
-rw-r--r--Userland/Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp2
9 files changed, 62 insertions, 66 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp
index 6ffebcf539..4f27362ea6 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp
@@ -1545,7 +1545,7 @@ static void generate_wrap_statement(SourceGenerator& generator, String const& va
)~~~");
} else if (interface.enumerations.contains(type.name)) {
scoped_generator.append(R"~~~(
- @result_expression@ JS::js_string(global_object.heap(), Bindings::idl_enum_to_string(@value@));
+ @result_expression@ JS::js_string(vm, Bindings::idl_enum_to_string(@value@));
)~~~");
} else if (interface.callback_functions.contains(type.name)) {
// https://webidl.spec.whatwg.org/#es-callback-function
@@ -1666,12 +1666,12 @@ static void generate_function(SourceGenerator& generator, IDL::Function const& f
function_generator.append(R"~~~(
JS_DEFINE_NATIVE_FUNCTION(@class_name@::@function.name:snakecase@@overload_suffix@)
{
- [[maybe_unused]] auto& realm = *global_object.associated_realm();
+ [[maybe_unused]] auto& realm = *vm.current_realm();
)~~~");
if (is_static_function == StaticFunction::No) {
function_generator.append(R"~~~(
- auto* impl = TRY(impl_from(vm, global_object));
+ auto* impl = TRY(impl_from(vm));
)~~~");
}
@@ -1685,11 +1685,11 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@function.name:snakecase@@overload_suffi
if (is_static_function == StaticFunction::No) {
function_generator.append(R"~~~(
- [[maybe_unused]] auto retval = TRY(throw_dom_exception_if_needed(global_object, [&] { return impl->@function.cpp_name@(@.arguments@); }));
+ [[maybe_unused]] auto retval = TRY(throw_dom_exception_if_needed(vm, [&] { return impl->@function.cpp_name@(@.arguments@); }));
)~~~");
} else {
function_generator.append(R"~~~(
- [[maybe_unused]] auto retval = TRY(throw_dom_exception_if_needed(global_object, [&] { return @interface_fully_qualified_name@::@function.cpp_name@(@.arguments@); }));
+ [[maybe_unused]] auto retval = TRY(throw_dom_exception_if_needed(vm, [&] { return @interface_fully_qualified_name@::@function.cpp_name@(@.arguments@); }));
)~~~");
}
@@ -1751,7 +1751,7 @@ static void generate_overload_arbiter(SourceGenerator& generator, auto const& ov
function_generator.append(R"~~~(
JS_DEFINE_NATIVE_FUNCTION(@class_name@::@function.name:snakecase@)
{
- [[maybe_unused]] auto& realm = *global_object.associated_realm();
+ [[maybe_unused]] auto& realm = *vm.current_realm();
)~~~");
auto minimum_argument_count = get_shortest_function_length(overload_set.value);
@@ -2071,9 +2071,8 @@ void @wrapper_class@::visit_edges(JS::Cell::Visitor& visitor)
// FIXME: This is a hack to avoid duplicating/refactoring a lot of code.
scoped_generator.append(R"~~~(
-static JS::Value wrap_for_legacy_platform_object_get_own_property(JS::GlobalObject& global_object, [[maybe_unused]] auto& retval)
+static JS::Value wrap_for_legacy_platform_object_get_own_property([[maybe_unused]] JS::VM& vm, [[maybe_unused]] auto& retval)
{
- [[maybe_unused]] auto& vm = global_object.vm();
[[maybe_unused]] auto& realm = *vm.current_realm();
)~~~");
@@ -2168,6 +2167,7 @@ JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> @class_name@::legacy_pla
get_own_property_generator.append(R"~~~(
[[maybe_unused]] auto& global_object = this->global_object();
+ [[maybe_unused]] auto& vm = this->vm();
[[maybe_unused]] auto& realm = *global_object.associated_realm();
)~~~");
@@ -2189,7 +2189,7 @@ JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> @class_name@::legacy_pla
// 3. If operation was defined without an identifier, then set value to the result of performing the steps listed in the interface description to determine the value of an indexed property with index as the index.
if (interface.indexed_property_getter->name.is_empty()) {
get_own_property_generator.append(R"~~~(
- auto value = TRY(throw_dom_exception_if_needed(global_object, [&] { return impl().determine_value_of_indexed_property(index); }));
+ auto value = TRY(throw_dom_exception_if_needed(vm, [&] { return impl().determine_value_of_indexed_property(index); }));
)~~~");
}
@@ -2200,7 +2200,7 @@ JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> @class_name@::legacy_pla
function_scoped_generator.set("function.cpp_name", make_input_acceptable_cpp(interface.indexed_property_getter->name.to_snakecase()));
function_scoped_generator.append(R"~~~(
- auto value = TRY(throw_dom_exception_if_needed(global_object, [&] { return impl().@function.cpp_name@(index); }));
+ auto value = TRY(throw_dom_exception_if_needed(vm, [&] { return impl().@function.cpp_name@(index); }));
)~~~");
}
@@ -2209,7 +2209,7 @@ JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> @class_name@::legacy_pla
JS::PropertyDescriptor descriptor;
// 6. Set desc.[[Value]] to the result of converting value to an ECMAScript value.
- descriptor.value = wrap_for_legacy_platform_object_get_own_property(global_object, value);
+ descriptor.value = wrap_for_legacy_platform_object_get_own_property(vm, value);
)~~~");
// 7. If O implements an interface with an indexed property setter, then set desc.[[Writable]] to true, otherwise set it to false.
@@ -2255,7 +2255,7 @@ JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> @class_name@::legacy_pla
// 3. If operation was defined without an identifier, then set value to the result of performing the steps listed in the interface description to determine the value of a named property with P as the name.
if (interface.named_property_getter->name.is_empty()) {
get_own_property_generator.append(R"~~~(
- auto value = TRY(throw_dom_exception_if_needed(global_object, [&] { return impl().determine_value_of_named_property(property_name_string); }));
+ auto value = TRY(throw_dom_exception_if_needed(vm, [&] { return impl().determine_value_of_named_property(property_name_string); }));
)~~~");
}
@@ -2265,7 +2265,7 @@ JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> @class_name@::legacy_pla
function_scoped_generator.set("function.cpp_name", make_input_acceptable_cpp(interface.named_property_getter->name.to_snakecase()));
function_scoped_generator.append(R"~~~(
- auto value = TRY(throw_dom_exception_if_needed(global_object, [&] { return impl().@function.cpp_name@(property_name_string); }));
+ auto value = TRY(throw_dom_exception_if_needed(vm, [&] { return impl().@function.cpp_name@(property_name_string); }));
)~~~");
}
@@ -2274,7 +2274,7 @@ JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> @class_name@::legacy_pla
JS::PropertyDescriptor descriptor;
// 6. Set desc.[[Value]] to the result of converting value to an ECMAScript value.
- descriptor.value = wrap_for_legacy_platform_object_get_own_property(global_object, value);
+ descriptor.value = wrap_for_legacy_platform_object_get_own_property(vm, value);
)~~~");
// 7. If O implements an interface with a named property setter, then set desc.[[Writable]] to true, otherwise set it to false.
@@ -2328,10 +2328,8 @@ JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> @class_name@::legacy_pla
// FIXME: It's not necessary to determine "creating" if the named property setter specifies an identifier.
// Try avoiding it somehow, e.g. by enforcing supported_property_names doesn't have side effects so it can be skipped.
scoped_generator.append(R"~~~(
-static JS::ThrowCompletionOr<void> invoke_named_property_setter(JS::GlobalObject& global_object, @fully_qualified_name@& impl, String const& property_name, JS::Value value)
+static JS::ThrowCompletionOr<void> invoke_named_property_setter(JS::VM& vm, @fully_qualified_name@& impl, String const& property_name, JS::Value value)
{
- auto& vm = global_object.vm();
-
// 1. Let creating be true if P is not a supported property name, and false otherwise.
// NOTE: This is in it's own variable to enforce the type.
// FIXME: Can this throw?
@@ -2350,10 +2348,10 @@ static JS::ThrowCompletionOr<void> invoke_named_property_setter(JS::GlobalObject
scoped_generator.append(R"~~~(
if (creating) {
// 5.1. If creating is true, then perform the steps listed in the interface description to set the value of a new named property with P as the name and value as the value.
- TRY(throw_dom_exception_if_needed(global_object, [&] { impl.set_value_of_new_named_property(property_name, converted_value); }));
+ TRY(throw_dom_exception_if_needed(vm, [&] { impl.set_value_of_new_named_property(property_name, converted_value); }));
} else {
// 5.2 Otherwise, creating is false. Perform the steps listed in the interface description to set the value of an existing named property with P as the name and value as the value.
- TRY(throw_dom_exception_if_needed(global_object, [&] { impl.set_value_of_existing_named_property(property_name, converted_value); }));
+ TRY(throw_dom_exception_if_needed(vm, [&] { impl.set_value_of_existing_named_property(property_name, converted_value); }));
}
)~~~");
} else {
@@ -2363,7 +2361,7 @@ static JS::ThrowCompletionOr<void> invoke_named_property_setter(JS::GlobalObject
function_scoped_generator.set("function.cpp_name", make_input_acceptable_cpp(interface.named_property_setter->name.to_snakecase()));
function_scoped_generator.append(R"~~~(
- TRY(throw_dom_exception_if_needed(global_object, [&] { impl.@function.cpp_name@(property_name, converted_value); }));
+ TRY(throw_dom_exception_if_needed(vm, [&] { impl.@function.cpp_name@(property_name, converted_value); }));
)~~~");
}
@@ -2379,7 +2377,7 @@ static JS::ThrowCompletionOr<void> invoke_named_property_setter(JS::GlobalObject
// FIXME: It's not necessary to determine "creating" if the indexed property setter specifies an identifier.
// Try avoiding it somehow, e.g. by enforcing supported_property_indices doesn't have side effects so it can be skipped.
scoped_generator.append(R"~~~(
-static JS::ThrowCompletionOr<void> invoke_indexed_property_setter(JS::GlobalObject& global_object, @fully_qualified_name@& impl, JS::PropertyKey const& property_name, JS::Value value)
+static JS::ThrowCompletionOr<void> invoke_indexed_property_setter(JS::VM& vm, @fully_qualified_name@& impl, JS::PropertyKey const& property_name, JS::Value value)
{
// 1. Let index be the result of calling ToUint32(P).
u32 index = property_name.as_number();
@@ -2401,10 +2399,10 @@ static JS::ThrowCompletionOr<void> invoke_indexed_property_setter(JS::GlobalObje
scoped_generator.append(R"~~~(
if (creating) {
// 6.1 If creating is true, then perform the steps listed in the interface description to set the value of a new indexed property with index as the index and value as the value.
- TRY(throw_dom_exception_if_needed(global_object, [&] { impl.set_value_of_new_indexed_property(index, converted_value); }));
+ TRY(throw_dom_exception_if_needed(vm, [&] { impl.set_value_of_new_indexed_property(index, converted_value); }));
} else {
// 6.2 Otherwise, creating is false. Perform the steps listed in the interface description to set the value of an existing indexed property with index as the index and value as the value.
- TRY(throw_dom_exception_if_needed(global_object, [&] { impl.set_value_of_existing_indexed_property(index, converted_value); }));
+ TRY(throw_dom_exception_if_needed(vm, [&] { impl.set_value_of_existing_indexed_property(index, converted_value); }));
}
)~~~");
} else {
@@ -2414,7 +2412,7 @@ static JS::ThrowCompletionOr<void> invoke_indexed_property_setter(JS::GlobalObje
function_scoped_generator.set("function.cpp_name", make_input_acceptable_cpp(interface.indexed_property_setter->name.to_snakecase()));
function_scoped_generator.append(R"~~~(
- TRY(throw_dom_exception_if_needed(global_object, [&] { impl.@function.cpp_name@(index, converted_value); }));
+ TRY(throw_dom_exception_if_needed(vm, [&] { impl.@function.cpp_name@(index, converted_value); }));
)~~~");
}
@@ -2439,6 +2437,7 @@ JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> @class_name@::internal_g
JS::ThrowCompletionOr<bool> @class_name@::internal_set(JS::PropertyKey const& property_name, JS::Value value, JS::Value receiver)
{
[[maybe_unused]] auto& global_object = this->global_object();
+ [[maybe_unused]] auto& vm = this->vm();
[[maybe_unused]] auto& realm = *global_object.associated_realm();
)~~~");
@@ -2455,7 +2454,7 @@ JS::ThrowCompletionOr<bool> @class_name@::internal_set(JS::PropertyKey const& pr
scoped_generator.append(R"~~~(
if (property_name.is_number()) {
// 1. Invoke the indexed property setter on O with P and V.
- TRY(invoke_indexed_property_setter(global_object, impl(), property_name, value));
+ TRY(invoke_indexed_property_setter(vm, impl(), property_name, value));
// 2. Return true.
return true;
@@ -2469,7 +2468,7 @@ JS::ThrowCompletionOr<bool> @class_name@::internal_set(JS::PropertyKey const& pr
scoped_generator.append(R"~~~(
if (property_name.is_string()) {
// 1. Invoke the named property setter on O with P and V.
- TRY(invoke_named_property_setter(global_object, impl(), property_name.as_string(), value));
+ TRY(invoke_named_property_setter(vm, impl(), property_name.as_string(), value));
// 2. Return true.
return true;
@@ -2520,7 +2519,7 @@ JS::ThrowCompletionOr<bool> @class_name@::internal_define_own_property(JS::Prope
} else {
scoped_generator.append(R"~~~(
// 3. Invoke the indexed property setter on O with P and Desc.[[Value]].
- TRY(invoke_indexed_property_setter(global_object, impl(), property_name, *property_descriptor.value));
+ TRY(invoke_indexed_property_setter(vm, impl(), property_name, *property_descriptor.value));
// 4. Return true.
return true;
@@ -2577,7 +2576,7 @@ JS::ThrowCompletionOr<bool> @class_name@::internal_define_own_property(JS::Prope
return false;
// 2. Invoke the named property setter on O with P and Desc.[[Value]].
- TRY(invoke_named_property_setter(global_object, impl(), property_name_as_string, *property_descriptor.value));
+ TRY(invoke_named_property_setter(vm, impl(), property_name_as_string, *property_descriptor.value));
// 3. Return true.
return true;
@@ -2619,6 +2618,7 @@ JS::ThrowCompletionOr<bool> @class_name@::internal_define_own_property(JS::Prope
JS::ThrowCompletionOr<bool> @class_name@::internal_delete(JS::PropertyKey const& property_name)
{
[[maybe_unused]] auto& global_object = this->global_object();
+ [[maybe_unused]] auto& vm = this->vm();
[[maybe_unused]] auto& realm = *global_object.associated_realm();
)~~~");
@@ -2665,7 +2665,7 @@ JS::ThrowCompletionOr<bool> @class_name@::internal_delete(JS::PropertyKey const&
if (interface.named_property_deleter->name.is_empty()) {
scoped_generator.append(R"~~~(
// 1. Perform the steps listed in the interface description to delete an existing named property with P as the name.
- bool succeeded = TRY(throw_dom_exception_if_needed(global_object, [&] { return impl().delete_existing_named_property(property_name_string); }));
+ bool succeeded = TRY(throw_dom_exception_if_needed(vm, [&] { return impl().delete_existing_named_property(property_name_string); }));
// 2. If the steps indicated that the deletion failed, then return false.
if (!succeeded)
@@ -2678,7 +2678,7 @@ JS::ThrowCompletionOr<bool> @class_name@::internal_delete(JS::PropertyKey const&
function_scoped_generator.append(R"~~~(
// 1. Perform method steps of operation with O as this and ยซ P ยป as the argument values.
- [[maybe_unused]] auto result = TRY(throw_dom_exception_if_needed(global_object, [&] { return impl().@function.cpp_name@(property_name_string); }));
+ [[maybe_unused]] auto result = TRY(throw_dom_exception_if_needed(vm, [&] { return impl().@function.cpp_name@(property_name_string); }));
)~~~");
// 2. If operation was declared with a return type of boolean and the steps returned false, then return false.
@@ -2984,11 +2984,11 @@ JS::ThrowCompletionOr<JS::Object*> @constructor_class@::construct(FunctionObject
generator.set(".constructor_arguments", arguments_builder.string_view());
generator.append(R"~~~(
- auto impl = TRY(throw_dom_exception_if_needed(global_object, [&] { return @fully_qualified_name@::create_with_global_object(window, @.constructor_arguments@); }));
+ auto impl = TRY(throw_dom_exception_if_needed(vm, [&] { return @fully_qualified_name@::create_with_global_object(window, @.constructor_arguments@); }));
)~~~");
} else {
generator.append(R"~~~(
- auto impl = TRY(throw_dom_exception_if_needed(global_object, [&] { return @fully_qualified_name@::create_with_global_object(window); }));
+ auto impl = TRY(throw_dom_exception_if_needed(vm, [&] { return @fully_qualified_name@::create_with_global_object(window); }));
)~~~");
}
generator.append(R"~~~(
@@ -3371,7 +3371,7 @@ void @prototype_class@::initialize(JS::Realm& realm)
if (!interface.attributes.is_empty() || !interface.functions.is_empty() || interface.has_stringifier) {
generator.append(R"~~~(
-static JS::ThrowCompletionOr<@fully_qualified_name@*> impl_from(JS::VM& vm, JS::GlobalObject&)
+static JS::ThrowCompletionOr<@fully_qualified_name@*> impl_from(JS::VM& vm)
{
auto this_value = vm.this_value();
JS::Object* this_object = nullptr;
@@ -3424,8 +3424,8 @@ static JS::ThrowCompletionOr<@fully_qualified_name@*> impl_from(JS::VM& vm, JS::
attribute_generator.append(R"~~~(
JS_DEFINE_NATIVE_FUNCTION(@prototype_class@::@attribute.getter_callback@)
{
- [[maybe_unused]] auto& realm = *global_object.associated_realm();
- auto* impl = TRY(impl_from(vm, global_object));
+ [[maybe_unused]] auto& realm = *vm.current_realm();
+ auto* impl = TRY(impl_from(vm));
)~~~");
if (attribute.extended_attributes.contains("Reflect")) {
@@ -3440,7 +3440,7 @@ JS_DEFINE_NATIVE_FUNCTION(@prototype_class@::@attribute.getter_callback@)
}
} else {
attribute_generator.append(R"~~~(
- auto retval = TRY(throw_dom_exception_if_needed(global_object, [&] { return impl->@attribute.cpp_name@(); }));
+ auto retval = TRY(throw_dom_exception_if_needed(vm, [&] { return impl->@attribute.cpp_name@(); }));
)~~~");
}
@@ -3454,8 +3454,8 @@ JS_DEFINE_NATIVE_FUNCTION(@prototype_class@::@attribute.getter_callback@)
attribute_generator.append(R"~~~(
JS_DEFINE_NATIVE_FUNCTION(@prototype_class@::@attribute.setter_callback@)
{
- [[maybe_unused]] auto& realm = *global_object.associated_realm();
- auto* impl = TRY(impl_from(vm, global_object));
+ [[maybe_unused]] auto& realm = *vm.current_realm();
+ auto* impl = TRY(impl_from(vm));
auto value = vm.argument(0);
)~~~");
@@ -3477,7 +3477,7 @@ JS_DEFINE_NATIVE_FUNCTION(@prototype_class@::@attribute.setter_callback@)
}
} else {
attribute_generator.append(R"~~~(
- TRY(throw_dom_exception_if_needed(global_object, [&] { return impl->set_@attribute.cpp_name@(cpp_value); }));
+ TRY(throw_dom_exception_if_needed(vm, [&] { return impl->set_@attribute.cpp_name@(cpp_value); }));
)~~~");
}
@@ -3506,8 +3506,8 @@ JS_DEFINE_NATIVE_FUNCTION(@prototype_class@::@attribute.setter_callback@)
stringifier_generator.append(R"~~~(
JS_DEFINE_NATIVE_FUNCTION(@class_name@::to_string)
{
- [[maybe_unused]] auto& realm = *global_object.associated_realm();
- auto* impl = TRY(impl_from(vm, global_object));
+ [[maybe_unused]] auto& realm = *vm.current_realm();
+ auto* impl = TRY(impl_from(vm));
)~~~");
if (interface.stringifier_attribute.has_value()) {
@@ -3516,7 +3516,7 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::to_string)
)~~~");
} else {
stringifier_generator.append(R"~~~(
- auto retval = TRY(throw_dom_exception_if_needed(global_object, [&] { return impl->to_string(); }));
+ auto retval = TRY(throw_dom_exception_if_needed(vm, [&] { return impl->to_string(); }));
)~~~");
}
stringifier_generator.append(R"~~~(
@@ -3532,15 +3532,15 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::to_string)
JS_DEFINE_NATIVE_FUNCTION(@prototype_class@::entries)
{
auto& realm = *vm.current_realm();
- auto* impl = TRY(impl_from(vm, global_object));
+ auto* impl = TRY(impl_from(vm));
return wrap(realm, @iterator_name@::create(*impl, Object::PropertyKind::KeyAndValue));
}
JS_DEFINE_NATIVE_FUNCTION(@prototype_class@::for_each)
{
- [[maybe_unused]] auto& realm = *global_object.associated_realm();
- auto* impl = TRY(impl_from(vm, global_object));
+ [[maybe_unused]] auto& realm = *vm.current_realm();
+ auto* impl = TRY(impl_from(vm));
auto callback = vm.argument(0);
if (!callback.is_function())
@@ -3562,7 +3562,7 @@ JS_DEFINE_NATIVE_FUNCTION(@prototype_class@::for_each)
JS_DEFINE_NATIVE_FUNCTION(@prototype_class@::keys)
{
auto& realm = *vm.current_realm();
- auto* impl = TRY(impl_from(vm, global_object));
+ auto* impl = TRY(impl_from(vm));
return wrap(realm, @iterator_name@::create(*impl, Object::PropertyKind::Key));
}
@@ -3570,7 +3570,7 @@ JS_DEFINE_NATIVE_FUNCTION(@prototype_class@::keys)
JS_DEFINE_NATIVE_FUNCTION(@prototype_class@::values)
{
auto& realm = *vm.current_realm();
- auto* impl = TRY(impl_from(vm, global_object));
+ auto* impl = TRY(impl_from(vm));
return wrap(realm, @iterator_name@::create(*impl, Object::PropertyKind::Value));
}
@@ -3813,7 +3813,7 @@ void @prototype_class@::initialize(JS::Realm& realm)
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Iterator"), JS::Attribute::Configurable);
}
-static JS::ThrowCompletionOr<@fully_qualified_name@*> impl_from(JS::VM& vm, JS::GlobalObject&)
+static JS::ThrowCompletionOr<@fully_qualified_name@*> impl_from(JS::VM& vm)
{
auto* this_object = TRY(vm.this_value().to_object(vm));
if (!is<@wrapper_class@>(this_object))
@@ -3823,8 +3823,8 @@ static JS::ThrowCompletionOr<@fully_qualified_name@*> impl_from(JS::VM& vm, JS::
JS_DEFINE_NATIVE_FUNCTION(@prototype_class@::next)
{
- auto* impl = TRY(impl_from(vm, global_object));
- return TRY(throw_dom_exception_if_needed(global_object, [&] { return impl->next(); }));
+ auto* impl = TRY(impl_from(vm));
+ return TRY(throw_dom_exception_if_needed(vm, [&] { return impl->next(); }));
}
} // namespace Web::Bindings
diff --git a/Userland/Libraries/LibWeb/Bindings/ExceptionOrUtils.h b/Userland/Libraries/LibWeb/Bindings/ExceptionOrUtils.h
index 9e0bf4e103..52f93a550d 100644
--- a/Userland/Libraries/LibWeb/Bindings/ExceptionOrUtils.h
+++ b/Userland/Libraries/LibWeb/Bindings/ExceptionOrUtils.h
@@ -58,10 +58,8 @@ struct ExtractExceptionOrValueType<DOM::ExceptionOr<void>> {
using Type = JS::Value;
};
-ALWAYS_INLINE JS::Completion dom_exception_to_throw_completion(auto&& global_object, auto&& exception)
+ALWAYS_INLINE JS::Completion dom_exception_to_throw_completion(auto&& vm, auto&& exception)
{
- auto& vm = global_object.vm();
-
return exception.visit(
[&](DOM::SimpleException const& exception) {
switch (exception.type) {
@@ -91,13 +89,13 @@ using ExtractExceptionOrValueType = typename Detail::ExtractExceptionOrValueType
// ExceptionOr<T>: JS::ThrowCompletionOr<T>
// T: JS::ThrowCompletionOr<T>
template<typename F, typename T = decltype(declval<F>()()), typename Ret = Conditional<!IsExceptionOr<T> && !IsVoid<T> && !IsThrowCompletionOr<T>, T, ExtractExceptionOrValueType<T>>>
-JS::ThrowCompletionOr<Ret> throw_dom_exception_if_needed(auto&& global_object, F&& fn)
+JS::ThrowCompletionOr<Ret> throw_dom_exception_if_needed(auto&& vm, F&& fn)
{
if constexpr (IsExceptionOr<T>) {
auto&& result = fn();
if (result.is_exception())
- return Detail::dom_exception_to_throw_completion(global_object, result.exception());
+ return Detail::dom_exception_to_throw_completion(vm, result.exception());
if constexpr (requires(T v) { v.value(); })
return result.value();
diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp
index 2c57335200..ef49495736 100644
--- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp
+++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp
@@ -311,7 +311,7 @@ RefPtr<ImageData> CanvasRenderingContext2D::create_image_data(int width, int hei
dbgln("Hmm! Attempted to create ImageData for wrapper-less CRC2D.");
return {};
}
- return ImageData::create_with_size(wrapper()->global_object(), width, height);
+ return ImageData::create_with_size(wrapper()->vm(), width, height);
}
// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-getimagedata
@@ -327,7 +327,7 @@ DOM::ExceptionOr<RefPtr<ImageData>> CanvasRenderingContext2D::get_image_data(int
// 3. Let imageData be a new ImageData object.
// 4. Initialize imageData given sw, sh, settings set to settings, and defaultColorSpace set to this's color space.
- auto image_data = ImageData::create_with_size(wrapper()->global_object(), width, height);
+ auto image_data = ImageData::create_with_size(wrapper()->vm(), width, height);
// NOTE: We don't attempt to create the underlying bitmap here; if it doesn't exist, it's like copying only transparent black pixels (which is a no-op).
if (!canvas_element().bitmap())
diff --git a/Userland/Libraries/LibWeb/HTML/ImageData.cpp b/Userland/Libraries/LibWeb/HTML/ImageData.cpp
index d6ff365097..7bdadd7aee 100644
--- a/Userland/Libraries/LibWeb/HTML/ImageData.cpp
+++ b/Userland/Libraries/LibWeb/HTML/ImageData.cpp
@@ -10,9 +10,9 @@
namespace Web::HTML {
-RefPtr<ImageData> ImageData::create_with_size(JS::GlobalObject& global_object, int width, int height)
+RefPtr<ImageData> ImageData::create_with_size(JS::VM& vm, int width, int height)
{
- auto& realm = *global_object.associated_realm();
+ auto& realm = *vm.current_realm();
if (width <= 0 || height <= 0)
return nullptr;
diff --git a/Userland/Libraries/LibWeb/HTML/ImageData.h b/Userland/Libraries/LibWeb/HTML/ImageData.h
index 9f5c14d7c0..58896aca1c 100644
--- a/Userland/Libraries/LibWeb/HTML/ImageData.h
+++ b/Userland/Libraries/LibWeb/HTML/ImageData.h
@@ -18,7 +18,7 @@ class ImageData
public:
using WrapperType = Bindings::ImageDataWrapper;
- static RefPtr<ImageData> create_with_size(JS::GlobalObject&, int width, int height);
+ static RefPtr<ImageData> create_with_size(JS::VM&, int width, int height);
~ImageData();
diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp
index 8b19eaeb1c..ea469eb2f1 100644
--- a/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp
@@ -120,7 +120,7 @@ JS::Completion ClassicScript::run(RethrowErrors rethrow_errors)
settings.clean_up_after_running_script();
// 2. Throw a "NetworkError" DOMException.
- return Bindings::throw_dom_exception_if_needed(global_object, [] {
+ return Bindings::throw_dom_exception_if_needed(vm, [] {
return DOM::NetworkError::create("Script error.");
}).release_error();
}
diff --git a/Userland/Libraries/LibWeb/WebGL/WebGLContextAttributes.cpp b/Userland/Libraries/LibWeb/WebGL/WebGLContextAttributes.cpp
index 8bc38c5ebc..4ce9709eda 100644
--- a/Userland/Libraries/LibWeb/WebGL/WebGLContextAttributes.cpp
+++ b/Userland/Libraries/LibWeb/WebGL/WebGLContextAttributes.cpp
@@ -10,10 +10,8 @@
namespace Web::WebGL {
-JS::ThrowCompletionOr<WebGLContextAttributes> convert_value_to_context_attributes_dictionary(JS::GlobalObject& global_object, JS::Value value)
+JS::ThrowCompletionOr<WebGLContextAttributes> convert_value_to_context_attributes_dictionary(JS::VM& vm, JS::Value value)
{
- auto& vm = global_object.vm();
-
// NOTE: This code was generated by the IDL code generator and then cleaned up.
if (!value.is_nullish() && !value.is_object())
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebGLContextAttributes");
diff --git a/Userland/Libraries/LibWeb/WebGL/WebGLContextAttributes.h b/Userland/Libraries/LibWeb/WebGL/WebGLContextAttributes.h
index 8888d0771b..196d1798fb 100644
--- a/Userland/Libraries/LibWeb/WebGL/WebGLContextAttributes.h
+++ b/Userland/Libraries/LibWeb/WebGL/WebGLContextAttributes.h
@@ -29,6 +29,6 @@ struct WebGLContextAttributes {
bool desynchronized { false };
};
-JS::ThrowCompletionOr<WebGLContextAttributes> convert_value_to_context_attributes_dictionary(JS::GlobalObject& global_object, JS::Value value);
+JS::ThrowCompletionOr<WebGLContextAttributes> convert_value_to_context_attributes_dictionary(JS::VM&, JS::Value value);
}
diff --git a/Userland/Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp b/Userland/Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp
index 58416155cf..e20aafb18b 100644
--- a/Userland/Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp
+++ b/Userland/Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp
@@ -33,7 +33,7 @@ JS::ThrowCompletionOr<RefPtr<WebGLRenderingContext>> WebGLRenderingContext::crea
{
// We should be coming here from getContext being called on a wrapped <canvas> element.
VERIFY(canvas_element.wrapper());
- auto context_attributes = TRY(convert_value_to_context_attributes_dictionary(canvas_element.wrapper()->global_object(), options));
+ auto context_attributes = TRY(convert_value_to_context_attributes_dictionary(canvas_element.wrapper()->vm(), options));
bool created_bitmap = canvas_element.create_bitmap(/* minimum_width= */ 1, /* minimum_height= */ 1);
if (!created_bitmap) {