mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-11 18:50:50 +00:00
LibWeb: Implement AbstractWorker
This effectively implements Worker.onerror, and in future SharedWorker.onerror.
This commit is contained in:
parent
20f68106a7
commit
3440d2b843
Notes:
github-actions[bot]
2024-09-02 11:12:17 +00:00
Author: https://github.com/jamierocks
Commit: 3440d2b843
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1239
6 changed files with 65 additions and 1 deletions
|
@ -258,6 +258,7 @@ set(SOURCES
|
||||||
Geometry/DOMRect.cpp
|
Geometry/DOMRect.cpp
|
||||||
Geometry/DOMRectList.cpp
|
Geometry/DOMRectList.cpp
|
||||||
Geometry/DOMRectReadOnly.cpp
|
Geometry/DOMRectReadOnly.cpp
|
||||||
|
HTML/AbstractWorker.cpp
|
||||||
HTML/AnimatedBitmapDecodedImageData.cpp
|
HTML/AnimatedBitmapDecodedImageData.cpp
|
||||||
HTML/AttributeNames.cpp
|
HTML/AttributeNames.cpp
|
||||||
HTML/AudioTrack.cpp
|
HTML/AudioTrack.cpp
|
||||||
|
|
25
Userland/Libraries/LibWeb/HTML/AbstractWorker.cpp
Normal file
25
Userland/Libraries/LibWeb/HTML/AbstractWorker.cpp
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <LibWeb/DOM/EventTarget.h>
|
||||||
|
#include <LibWeb/HTML/AbstractWorker.h>
|
||||||
|
#include <LibWeb/HTML/EventNames.h>
|
||||||
|
|
||||||
|
namespace Web::HTML {
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/workers.html#handler-abstractworker-onerror
|
||||||
|
WebIDL::CallbackType* AbstractWorker::onerror()
|
||||||
|
{
|
||||||
|
return this_event_target().event_handler_attribute(HTML::EventNames::error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/workers.html#handler-abstractworker-onerror
|
||||||
|
void AbstractWorker::set_onerror(WebIDL::CallbackType* event_handler)
|
||||||
|
{
|
||||||
|
this_event_target().set_event_handler_attribute(HTML::EventNames::error, event_handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
25
Userland/Libraries/LibWeb/HTML/AbstractWorker.h
Normal file
25
Userland/Libraries/LibWeb/HTML/AbstractWorker.h
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibWeb/DOM/EventTarget.h>
|
||||||
|
|
||||||
|
namespace Web::HTML {
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/workers.html#abstractworker
|
||||||
|
class AbstractWorker {
|
||||||
|
public:
|
||||||
|
virtual ~AbstractWorker() = default;
|
||||||
|
|
||||||
|
WebIDL::CallbackType* onerror();
|
||||||
|
void set_onerror(WebIDL::CallbackType*);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual DOM::EventTarget& this_event_target() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
4
Userland/Libraries/LibWeb/HTML/AbstractWorker.idl
Normal file
4
Userland/Libraries/LibWeb/HTML/AbstractWorker.idl
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
// https://html.spec.whatwg.org/multipage/workers.html#abstractworker
|
||||||
|
interface mixin AbstractWorker {
|
||||||
|
attribute EventHandler onerror;
|
||||||
|
};
|
|
@ -10,6 +10,7 @@
|
||||||
#include <LibURL/Parser.h>
|
#include <LibURL/Parser.h>
|
||||||
#include <LibWeb/Bindings/MainThreadVM.h>
|
#include <LibWeb/Bindings/MainThreadVM.h>
|
||||||
#include <LibWeb/Forward.h>
|
#include <LibWeb/Forward.h>
|
||||||
|
#include <LibWeb/HTML/AbstractWorker.h>
|
||||||
#include <LibWeb/HTML/MessageEvent.h>
|
#include <LibWeb/HTML/MessageEvent.h>
|
||||||
#include <LibWeb/HTML/MessagePort.h>
|
#include <LibWeb/HTML/MessagePort.h>
|
||||||
#include <LibWeb/HTML/Scripting/ClassicScript.h>
|
#include <LibWeb/HTML/Scripting/ClassicScript.h>
|
||||||
|
@ -27,7 +28,9 @@
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/workers.html#dedicated-workers-and-the-worker-interface
|
// https://html.spec.whatwg.org/multipage/workers.html#dedicated-workers-and-the-worker-interface
|
||||||
class Worker : public DOM::EventTarget {
|
class Worker
|
||||||
|
: public DOM::EventTarget
|
||||||
|
, public HTML::AbstractWorker {
|
||||||
WEB_PLATFORM_OBJECT(Worker, DOM::EventTarget);
|
WEB_PLATFORM_OBJECT(Worker, DOM::EventTarget);
|
||||||
JS_DECLARE_ALLOCATOR(Worker);
|
JS_DECLARE_ALLOCATOR(Worker);
|
||||||
|
|
||||||
|
@ -57,6 +60,9 @@ public:
|
||||||
protected:
|
protected:
|
||||||
Worker(String const&, WorkerOptions const&, DOM::Document&);
|
Worker(String const&, WorkerOptions const&, DOM::Document&);
|
||||||
|
|
||||||
|
// ^AbstractWorker
|
||||||
|
virtual DOM::EventTarget& this_event_target() override { return *this; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void initialize(JS::Realm&) override;
|
virtual void initialize(JS::Realm&) override;
|
||||||
virtual void visit_edges(Cell::Visitor&) override;
|
virtual void visit_edges(Cell::Visitor&) override;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#import <DOM/EventTarget.idl>
|
#import <DOM/EventTarget.idl>
|
||||||
#import <DOM/EventHandler.idl>
|
#import <DOM/EventHandler.idl>
|
||||||
|
#import <HTML/AbstractWorker.idl>
|
||||||
#import <HTML/MessagePort.idl>
|
#import <HTML/MessagePort.idl>
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/#worker
|
// https://html.spec.whatwg.org/#worker
|
||||||
|
@ -21,3 +22,5 @@ dictionary WorkerOptions {
|
||||||
USVString credentials = "same-origin";
|
USVString credentials = "same-origin";
|
||||||
DOMString name = "";
|
DOMString name = "";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Worker includes AbstractWorker;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue