Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/bindings/nsScriptError.h
Line
Count
Source (jump to first uncovered line)
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/. */
6
7
#ifndef mozilla_dom_nsScriptError_h
8
#define mozilla_dom_nsScriptError_h
9
10
#include "mozilla/Atomics.h"
11
12
#include <stdint.h>
13
14
#include "jsapi.h"
15
#include "js/RootingAPI.h"
16
17
#include "nsCOMArray.h"
18
#include "nsCycleCollectionParticipant.h"
19
#include "nsIScriptError.h"
20
#include "nsString.h"
21
22
class nsScriptErrorNote final : public nsIScriptErrorNote {
23
 public:
24
  nsScriptErrorNote();
25
26
  NS_DECL_THREADSAFE_ISUPPORTS
27
  NS_DECL_NSISCRIPTERRORNOTE
28
29
  void Init(const nsAString& message, const nsAString& sourceName,
30
            uint32_t lineNumber, uint32_t columnNumber);
31
32
 private:
33
  virtual ~nsScriptErrorNote();
34
35
  nsString mMessage;
36
  nsString mSourceName;
37
  nsString mSourceLine;
38
  uint32_t mLineNumber;
39
  uint32_t mColumnNumber;
40
};
41
42
// Definition of nsScriptError..
43
class nsScriptErrorBase : public nsIScriptError {
44
public:
45
  nsScriptErrorBase();
46
47
  NS_DECL_NSICONSOLEMESSAGE
48
  NS_DECL_NSISCRIPTERROR
49
50
  void AddNote(nsIScriptErrorNote* note);
51
52
protected:
53
  virtual ~nsScriptErrorBase();
54
55
  void
56
  InitializeOnMainThread();
57
58
  void InitializationHelper(const nsAString& message,
59
                            const nsAString& sourceLine, uint32_t lineNumber,
60
                            uint32_t columnNumber, uint32_t flags,
61
                            const nsACString& category,
62
                            uint64_t aInnerWindowID);
63
64
  nsCOMArray<nsIScriptErrorNote> mNotes;
65
  nsString mMessage;
66
  nsString mMessageName;
67
  nsString mSourceName;
68
  uint32_t mLineNumber;
69
  nsString mSourceLine;
70
  uint32_t mColumnNumber;
71
  uint32_t mFlags;
72
  nsCString mCategory;
73
  // mOuterWindowID is set on the main thread from InitializeOnMainThread().
74
  uint64_t mOuterWindowID;
75
  uint64_t mInnerWindowID;
76
  int64_t mTimeStamp;
77
  uint64_t mTimeWarpTarget;
78
  // mInitializedOnMainThread and mIsFromPrivateWindow are set on the main
79
  // thread from InitializeOnMainThread().
80
  mozilla::Atomic<bool> mInitializedOnMainThread;
81
  bool mIsFromPrivateWindow;
82
};
83
84
class nsScriptError final : public nsScriptErrorBase {
85
public:
86
0
  nsScriptError() {}
87
  NS_DECL_THREADSAFE_ISUPPORTS
88
89
private:
90
0
  virtual ~nsScriptError() {}
91
};
92
93
class nsScriptErrorWithStack : public nsScriptErrorBase {
94
public:
95
  nsScriptErrorWithStack(JS::HandleObject aStack, JS::HandleObject aStackGlobal);
96
97
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
98
  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsScriptErrorWithStack)
99
100
  NS_IMETHOD GetStack(JS::MutableHandleValue) override;
101
  NS_IMETHOD GetStackGlobal(JS::MutableHandleValue) override;
102
  NS_IMETHOD ToString(nsACString& aResult) override;
103
104
private:
105
  virtual ~nsScriptErrorWithStack();
106
  // Complete stackframe where the error happened.
107
  // Must be a (possibly wrapped) SavedFrame object.
108
  JS::Heap<JSObject*> mStack;
109
  // Global object that must be same-compartment with mStack.
110
  JS::Heap<JSObject*> mStackGlobal;
111
};
112
113
#endif /* mozilla_dom_nsScriptError_h */