Bug 1874684 - Part 6: Limit day length calculations to safe integers. r=mgaudet
[gecko.git] / dom / worklet / Worklet.h
blob1c404da18d173f2c49c25e5275cd2e4f6c049590
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_Worklet_h
8 #define mozilla_dom_Worklet_h
10 #include "mozilla/Attributes.h"
11 #include "nsRefPtrHashtable.h"
12 #include "nsWrapperCache.h"
13 #include "nsCOMPtr.h"
15 class nsPIDOMWindowInner;
17 namespace mozilla {
19 class ErrorResult;
20 class WorkletImpl;
22 namespace dom {
24 class Promise;
25 class WorkletFetchHandler;
26 class WorkletScriptHandler;
27 struct WorkletOptions;
28 enum class CallerType : uint32_t;
30 class Worklet final : public nsISupports, public nsWrapperCache {
31 public:
32 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
33 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(Worklet)
35 // |aOwnedObject| may be provided by the WorkletImpl as a parent thread
36 // object to keep alive and traverse for CC as long as the Worklet has
37 // references remaining.
38 Worklet(nsPIDOMWindowInner* aWindow, RefPtr<WorkletImpl> aImpl,
39 nsISupports* aOwnedObject = nullptr);
41 nsPIDOMWindowInner* GetParentObject() const { return mWindow; }
43 virtual JSObject* WrapObject(JSContext* aCx,
44 JS::Handle<JSObject*> aGivenProto) override;
46 already_AddRefed<Promise> AddModule(JSContext* aCx,
47 const nsAString& aModuleURL,
48 const WorkletOptions& aOptions,
49 CallerType aCallerType, ErrorResult& aRv);
51 WorkletImpl* Impl() const { return mImpl; }
53 const nsTArray<nsString>& GetLocalizedStrings() const {
54 return mLocalizedStrings;
57 private:
58 ~Worklet();
60 WorkletFetchHandler* GetImportFetchHandler(const nsACString& aURI);
62 void AddImportFetchHandler(const nsACString& aURI,
63 WorkletFetchHandler* aHandler);
65 nsCOMPtr<nsPIDOMWindowInner> mWindow;
66 nsCOMPtr<nsISupports> mOwnedObject;
68 nsRefPtrHashtable<nsCStringHashKey, WorkletFetchHandler> mImportHandlers;
70 const RefPtr<WorkletImpl> mImpl;
72 nsTArray<nsString> mLocalizedStrings;
74 friend class WorkletFetchHandler;
75 friend class WorkletScriptHandler;
78 } // namespace dom
79 } // namespace mozilla
81 #endif // mozilla_dom_Worklet_h