Jelajahi Sumber

LibWeb: Make factory methods of WebGL::WebGLContextEvent fallible

Kenneth Myhra 2 tahun lalu
induk
melakukan
f918d12655

+ 3 - 3
Userland/Libraries/LibWeb/WebGL/WebGLContextEvent.cpp

@@ -9,12 +9,12 @@
 
 
 namespace Web::WebGL {
 namespace Web::WebGL {
 
 
-WebGLContextEvent* WebGLContextEvent::create(JS::Realm& realm, DeprecatedFlyString const& event_name, WebGLContextEventInit const& event_init)
+WebIDL::ExceptionOr<JS::NonnullGCPtr<WebGLContextEvent>> WebGLContextEvent::create(JS::Realm& realm, DeprecatedFlyString const& event_name, WebGLContextEventInit const& event_init)
 {
 {
-    return realm.heap().allocate<WebGLContextEvent>(realm, realm, event_name, event_init).release_allocated_value_but_fixme_should_propagate_errors();
+    return MUST_OR_THROW_OOM(realm.heap().allocate<WebGLContextEvent>(realm, realm, event_name, event_init));
 }
 }
 
 
-WebGLContextEvent* WebGLContextEvent::construct_impl(JS::Realm& realm, DeprecatedFlyString const& event_name, WebGLContextEventInit const& event_init)
+WebIDL::ExceptionOr<JS::NonnullGCPtr<WebGLContextEvent>> WebGLContextEvent::construct_impl(JS::Realm& realm, DeprecatedFlyString const& event_name, WebGLContextEventInit const& event_init)
 {
 {
     return create(realm, event_name, event_init);
     return create(realm, event_name, event_init);
 }
 }

+ 2 - 2
Userland/Libraries/LibWeb/WebGL/WebGLContextEvent.h

@@ -19,8 +19,8 @@ class WebGLContextEvent final : public DOM::Event {
     WEB_PLATFORM_OBJECT(WebGLContextEvent, DOM::Event);
     WEB_PLATFORM_OBJECT(WebGLContextEvent, DOM::Event);
 
 
 public:
 public:
-    static WebGLContextEvent* create(JS::Realm&, DeprecatedFlyString const& type, WebGLContextEventInit const& event_init);
-    static WebGLContextEvent* construct_impl(JS::Realm&, DeprecatedFlyString const& type, WebGLContextEventInit const& event_init);
+    static WebIDL::ExceptionOr<JS::NonnullGCPtr<WebGLContextEvent>> create(JS::Realm&, DeprecatedFlyString const& type, WebGLContextEventInit const& event_init);
+    static WebIDL::ExceptionOr<JS::NonnullGCPtr<WebGLContextEvent>> construct_impl(JS::Realm&, DeprecatedFlyString const& type, WebGLContextEventInit const& event_init);
 
 
     virtual ~WebGLContextEvent() override;
     virtual ~WebGLContextEvent() override;
 
 

+ 1 - 1
Userland/Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp

@@ -17,7 +17,7 @@ static void fire_webgl_context_event(HTML::HTMLCanvasElement& canvas_element, De
 {
 {
     // To fire a WebGL context event named e means that an event using the WebGLContextEvent interface, with its type attribute [DOM4] initialized to e, its cancelable attribute initialized to true, and its isTrusted attribute [DOM4] initialized to true, is to be dispatched at the given object.
     // To fire a WebGL context event named e means that an event using the WebGLContextEvent interface, with its type attribute [DOM4] initialized to e, its cancelable attribute initialized to true, and its isTrusted attribute [DOM4] initialized to true, is to be dispatched at the given object.
     // FIXME: Consider setting a status message.
     // FIXME: Consider setting a status message.
-    auto event = WebGLContextEvent::create(canvas_element.realm(), type, WebGLContextEventInit {});
+    auto event = WebGLContextEvent::create(canvas_element.realm(), type, WebGLContextEventInit {}).release_value_but_fixme_should_propagate_errors();
     event->set_is_trusted(true);
     event->set_is_trusted(true);
     event->set_cancelable(true);
     event->set_cancelable(true);
     canvas_element.dispatch_event(*event);
     canvas_element.dispatch_event(*event);