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

LibWeb: Replace GlobalObject with VM in remaining AOs [Part 4/4]

This commit is contained in:
Linus Groh 2022-08-21 21:29:06 +01:00
parent 2d69a3b266
commit 7b990c27a1
9 changed files with 62 additions and 66 deletions

View file

@ -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();

View file

@ -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())

View file

@ -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;

View file

@ -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();

View file

@ -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();
}

View file

@ -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");

View file

@ -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);
}

View file

@ -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) {