Bug 1856663 - Add more chunks for Android mochitest-plain. r=jmaher,taskgraph-reviewe...
[gecko.git] / dom / bindings / nsScriptError.h
blobf00a859a59421f00034392dd206a291c9bf9b2ba
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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_nsScriptError_h
8 #define mozilla_dom_nsScriptError_h
10 #include "mozilla/Atomics.h"
12 #include <stdint.h>
14 #include "jsapi.h"
15 #include "js/RootingAPI.h"
17 #include "nsCOMArray.h"
18 #include "nsCycleCollectionParticipant.h"
19 #include "nsIScriptError.h"
20 #include "nsString.h"
22 class nsGlobalWindowInner;
24 class nsScriptErrorNote final : public nsIScriptErrorNote {
25 public:
26 nsScriptErrorNote();
28 NS_DECL_THREADSAFE_ISUPPORTS
29 NS_DECL_NSISCRIPTERRORNOTE
31 void Init(const nsAString& message, const nsAString& sourceName,
32 uint32_t sourceId, uint32_t lineNumber, uint32_t columnNumber);
34 private:
35 virtual ~nsScriptErrorNote();
37 nsString mMessage;
38 nsString mSourceName;
39 nsString mCssSelectors;
40 nsString mSourceLine;
41 uint32_t mSourceId;
42 uint32_t mLineNumber;
43 uint32_t mColumnNumber;
46 // Definition of nsScriptError..
47 class nsScriptErrorBase : public nsIScriptError {
48 public:
49 nsScriptErrorBase();
51 NS_DECL_NSICONSOLEMESSAGE
52 NS_DECL_NSISCRIPTERROR
54 void AddNote(nsIScriptErrorNote* note);
56 static bool ComputeIsFromPrivateWindow(nsGlobalWindowInner* aWindow);
58 static bool ComputeIsFromChromeContext(nsGlobalWindowInner* aWindow);
60 protected:
61 virtual ~nsScriptErrorBase();
63 void InitializeOnMainThread();
65 void InitializationHelper(const nsAString& message,
66 const nsAString& sourceLine, uint32_t lineNumber,
67 uint32_t columnNumber, uint32_t flags,
68 const nsACString& category, uint64_t aInnerWindowID,
69 bool aFromChromeContext);
71 nsCOMArray<nsIScriptErrorNote> mNotes;
72 nsString mMessage;
73 nsString mMessageName;
74 nsString mSourceName;
75 nsString mCssSelectors;
76 uint32_t mSourceId;
77 uint32_t mLineNumber;
78 nsString mSourceLine;
79 uint32_t mColumnNumber;
80 uint32_t mFlags;
81 nsCString mCategory;
82 // mOuterWindowID is set on the main thread from InitializeOnMainThread().
83 uint64_t mOuterWindowID;
84 uint64_t mInnerWindowID;
85 int64_t mMicroSecondTimeStamp;
86 // mInitializedOnMainThread, mIsFromPrivateWindow and mIsFromChromeContext are
87 // set on the main thread from InitializeOnMainThread().
88 mozilla::Atomic<bool> mInitializedOnMainThread;
89 bool mIsFromPrivateWindow;
90 bool mIsFromChromeContext;
91 bool mIsPromiseRejection;
92 bool mIsForwardedFromContentProcess;
95 class nsScriptError final : public nsScriptErrorBase {
96 public:
97 nsScriptError() = default;
98 NS_DECL_THREADSAFE_ISUPPORTS
100 private:
101 virtual ~nsScriptError() = default;
104 class nsScriptErrorWithStack : public nsScriptErrorBase {
105 public:
106 nsScriptErrorWithStack(JS::Handle<mozilla::Maybe<JS::Value>> aException,
107 JS::Handle<JSObject*> aStack,
108 JS::Handle<JSObject*> aStackGlobal);
110 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
111 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsScriptErrorWithStack)
113 NS_IMETHOD GetHasException(bool*) override;
114 NS_IMETHOD GetException(JS::MutableHandle<JS::Value>) override;
116 NS_IMETHOD GetStack(JS::MutableHandle<JS::Value>) override;
117 NS_IMETHOD GetStackGlobal(JS::MutableHandle<JS::Value>) override;
118 NS_IMETHOD ToString(nsACString& aResult) override;
120 private:
121 virtual ~nsScriptErrorWithStack();
123 // The "exception" value.
124 JS::Heap<JS::Value> mException;
125 bool mHasException;
127 // Complete stackframe where the error happened.
128 // Must be a (possibly wrapped) SavedFrame object.
129 JS::Heap<JSObject*> mStack;
130 // Global object that must be same-compartment with mStack.
131 JS::Heap<JSObject*> mStackGlobal;
134 // Creates either nsScriptErrorWithStack or nsScriptError,
135 // depending on whether |aStack| or |aException| is passed.
136 // Additionally when the first (optional) |win| argument is
137 // provided this function makes sure that the GlobalWindow
138 // isn't already dying to prevent leaks.
139 already_AddRefed<nsScriptErrorBase> CreateScriptError(
140 nsGlobalWindowInner* win, JS::Handle<mozilla::Maybe<JS::Value>> aException,
141 JS::Handle<JSObject*> aStack, JS::Handle<JSObject*> aStackGlobal);
143 #endif /* mozilla_dom_nsScriptError_h */