Bug 1861467 - [wpt-sync] Update web-platform-tests to eedf737ce39c512d0ca3471f988972e...
[gecko.git] / dom / workers / Worker.h
blob14d0630f284a34873a65901518fb33a1a86a1027
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_Worker_h
8 #define mozilla_dom_Worker_h
10 #include "mozilla/Attributes.h"
11 #include "mozilla/dom/DebuggerNotificationBinding.h"
12 #include "mozilla/DOMEventTargetHelper.h"
13 #include "mozilla/RefPtr.h"
14 #include "mozilla/WeakPtr.h"
16 #ifdef XP_WIN
17 # undef PostMessage
18 #endif
20 namespace mozilla::dom {
22 class EventWithOptionsRunnable;
23 struct StructuredSerializeOptions;
24 struct WorkerOptions;
25 class WorkerPrivate;
27 class Worker : public DOMEventTargetHelper, public SupportsWeakPtr {
28 public:
29 NS_DECL_ISUPPORTS_INHERITED
30 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(Worker,
31 DOMEventTargetHelper)
32 static already_AddRefed<Worker> Constructor(const GlobalObject& aGlobal,
33 const nsAString& aScriptURL,
34 const WorkerOptions& aOptions,
35 ErrorResult& aRv);
37 JSObject* WrapObject(JSContext* aCx,
38 JS::Handle<JSObject*> aGivenProto) override;
40 Maybe<EventCallbackDebuggerNotificationType> GetDebuggerNotificationType()
41 const override {
42 return Some(EventCallbackDebuggerNotificationType::Worker);
45 void PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
46 const Sequence<JSObject*>& aTransferable, ErrorResult& aRv);
48 void PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
49 const StructuredSerializeOptions& aOptions,
50 ErrorResult& aRv);
52 void PostEventWithOptions(JSContext* aCx, JS::Handle<JS::Value> aOptions,
53 const Sequence<JSObject*>& aTransferable,
54 EventWithOptionsRunnable* aRunnable,
55 ErrorResult& aRv);
57 void Terminate();
59 IMPL_EVENT_HANDLER(error)
60 IMPL_EVENT_HANDLER(message)
61 IMPL_EVENT_HANDLER(messageerror)
63 protected:
64 Worker(nsIGlobalObject* aGlobalObject,
65 already_AddRefed<WorkerPrivate> aWorkerPrivate);
66 ~Worker();
68 friend class EventWithOptionsRunnable;
69 RefPtr<WorkerPrivate> mWorkerPrivate;
72 } // namespace mozilla::dom
74 #endif /* mozilla_dom_Worker_h */