mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-22 17:31:58 -05:00
LibWeb: Implement AbstractWorker
This effectively implements Worker.onerror, and in future SharedWorker.onerror. (cherry picked from commit 3440d2b843331fca7392d29ea1b776935d1310de)
This commit is contained in:
parent
4afa0a1973
commit
25d3e1fe74
6 changed files with 65 additions and 1 deletions
|
@ -261,6 +261,7 @@ set(SOURCES
|
|||
Geometry/DOMRect.cpp
|
||||
Geometry/DOMRectList.cpp
|
||||
Geometry/DOMRectReadOnly.cpp
|
||||
HTML/AbstractWorker.cpp
|
||||
HTML/AnimatedBitmapDecodedImageData.cpp
|
||||
HTML/AttributeNames.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 <LibWeb/Bindings/MainThreadVM.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/HTML/AbstractWorker.h>
|
||||
#include <LibWeb/HTML/MessageEvent.h>
|
||||
#include <LibWeb/HTML/MessagePort.h>
|
||||
#include <LibWeb/HTML/Scripting/ClassicScript.h>
|
||||
|
@ -27,7 +28,9 @@
|
|||
namespace Web::HTML {
|
||||
|
||||
// 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);
|
||||
JS_DECLARE_ALLOCATOR(Worker);
|
||||
|
||||
|
@ -57,6 +60,9 @@ public:
|
|||
protected:
|
||||
Worker(String const&, WorkerOptions const&, DOM::Document&);
|
||||
|
||||
// ^AbstractWorker
|
||||
virtual DOM::EventTarget& this_event_target() override { return *this; }
|
||||
|
||||
private:
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#import <DOM/EventTarget.idl>
|
||||
#import <DOM/EventHandler.idl>
|
||||
#import <HTML/AbstractWorker.idl>
|
||||
#import <HTML/MessagePort.idl>
|
||||
|
||||
// https://html.spec.whatwg.org/#worker
|
||||
|
@ -21,3 +22,5 @@ dictionary WorkerOptions {
|
|||
USVString credentials = "same-origin";
|
||||
DOMString name = "";
|
||||
};
|
||||
|
||||
Worker includes AbstractWorker;
|
||||
|
|
Loading…
Reference in a new issue