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_WorkletGlobalScope_h
8 #define mozilla_dom_WorkletGlobalScope_h
10 #include "mozilla/Attributes.h"
11 #include "mozilla/Maybe.h"
12 #include "mozilla/TimeStamp.h"
13 #include "mozilla/dom/BindingDeclarations.h"
14 #include "nsDOMNavigationTiming.h"
15 #include "nsIGlobalObject.h"
16 #include "nsWrapperCache.h"
20 0x1b3f62e7, 0xe357, 0x44be, { \
21 0xbf, 0xe0, 0xdf, 0x85, 0xe6, 0x56, 0x85, 0xac \
34 class WorkletGlobalScope
: public nsIGlobalObject
, public nsWrapperCache
{
36 NS_DECLARE_STATIC_IID_ACCESSOR(WORKLET_IID
)
38 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
39 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(WorkletGlobalScope
)
41 WorkletGlobalScope(const Maybe
<nsID
>& aAgentClusterId
,
42 bool aSharedMemoryAllowed
);
44 nsIGlobalObject
* GetParentObject() const { return nullptr; }
46 virtual JSObject
* WrapObject(JSContext
* aCx
,
47 JS::Handle
<JSObject
*> aGivenProto
) override
;
49 virtual bool WrapGlobalObject(JSContext
* aCx
,
50 JS::MutableHandle
<JSObject
*> aReflector
) = 0;
52 JSObject
* GetGlobalJSObject() override
{ return GetWrapper(); }
53 JSObject
* GetGlobalJSObjectPreserveColor() const override
{
54 return GetWrapperPreserveColor();
57 already_AddRefed
<Console
> GetConsole(JSContext
* aCx
, ErrorResult
& aRv
);
59 virtual WorkletImpl
* Impl() const = 0;
61 void Dump(const Optional
<nsAString
>& aString
) const;
63 DOMHighResTimeStamp
TimeStampToDOMHighRes(const TimeStamp
& aTimeStamp
) const {
64 MOZ_ASSERT(!aTimeStamp
.IsNull());
65 TimeDuration duration
= aTimeStamp
- mCreationTimeStamp
;
66 return duration
.ToMilliseconds();
69 Maybe
<nsID
> GetAgentClusterId() const override
{ return mAgentClusterId
; }
71 bool IsSharedMemoryAllowed() const override
{ return mSharedMemoryAllowed
; }
74 ~WorkletGlobalScope();
78 TimeStamp mCreationTimeStamp
;
79 Maybe
<nsID
> mAgentClusterId
;
80 RefPtr
<Console
> mConsole
;
81 bool mSharedMemoryAllowed
;
84 NS_DEFINE_STATIC_IID_ACCESSOR(WorkletGlobalScope
, WORKLET_IID
)
87 } // namespace mozilla
89 #endif // mozilla_dom_WorkletGlobalScope_h