v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
v8-console-message.h
Go to the documentation of this file.
1// Copyright 2016 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_INSPECTOR_V8_CONSOLE_MESSAGE_H_
6#define V8_INSPECTOR_V8_CONSOLE_MESSAGE_H_
7
8#include <deque>
9#include <map>
10#include <memory>
11#include <set>
12#include <tuple>
13
16#include "src/inspector/protocol/Console.h"
17#include "src/inspector/protocol/Forward.h"
18#include "src/inspector/protocol/Runtime.h"
19
20namespace v8_inspector {
21
22class InspectedContext;
23class V8InspectorImpl;
24class V8InspectorSessionImpl;
25class V8StackTraceImpl;
26
28
29enum class ConsoleAPIType {
30 kLog,
31 kDebug,
32 kInfo,
33 kError,
35 kDir,
36 kDirXML,
37 kTable,
38 kTrace,
42 kClear,
43 kAssert,
45 kCount
46};
47
49 public:
51
52 static std::unique_ptr<V8ConsoleMessage> createForConsoleAPI(
53 v8::Local<v8::Context> v8Context, int contextId, int groupId,
54 V8InspectorImpl* inspector, double timestamp, ConsoleAPIType,
55 v8::MemorySpan<const v8::Local<v8::Value>> arguments,
56 const String16& consoleContext, std::unique_ptr<V8StackTraceImpl>);
57
58 static std::unique_ptr<V8ConsoleMessage> createForException(
59 double timestamp, const String16& detailedMessage, const String16& url,
60 unsigned lineNumber, unsigned columnNumber,
61 std::unique_ptr<V8StackTraceImpl>, int scriptId, v8::Isolate*,
62 const String16& message, int contextId, v8::Local<v8::Value> exception,
63 unsigned exceptionId);
64
65 static std::unique_ptr<V8ConsoleMessage> createForRevokedException(
66 double timestamp, const String16& message, unsigned revokedExceptionId);
67
68 V8MessageOrigin origin() const;
69 void reportToFrontend(protocol::Console::Frontend*) const;
70 void reportToFrontend(protocol::Runtime::Frontend*, V8InspectorSessionImpl*,
71 bool generatePreview) const;
72 ConsoleAPIType type() const;
73 void contextDestroyed(int contextId);
74
75 int estimatedSize() const {
76 return m_v8Size + static_cast<int>(m_message.length() * sizeof(UChar));
77 }
78
79 private:
80 V8ConsoleMessage(V8MessageOrigin, double timestamp, const String16& message);
81
82 using Arguments = std::vector<std::unique_ptr<v8::Global<v8::Value>>>;
83 std::unique_ptr<protocol::Array<protocol::Runtime::RemoteObject>>
84 wrapArguments(V8InspectorSessionImpl*, bool generatePreview) const;
85 std::unique_ptr<protocol::Runtime::RemoteObject> wrapException(
86 V8InspectorSessionImpl*, bool generatePreview) const;
87 void setLocation(const String16& url, unsigned lineNumber,
88 unsigned columnNumber, std::unique_ptr<V8StackTraceImpl>,
89 int scriptId);
90 std::unique_ptr<protocol::DictionaryValue> getAssociatedExceptionData(
91 V8InspectorImpl* inspector, V8InspectorSessionImpl* session) const;
92
97 unsigned m_lineNumber;
99 std::unique_ptr<V8StackTraceImpl> m_stackTrace;
105 int m_v8Size = 0;
109};
110
112 public:
115
117 const std::deque<std::unique_ptr<V8ConsoleMessage>>& messages() const {
118 return m_messages;
119 }
120
121 void addMessage(std::unique_ptr<V8ConsoleMessage>);
122 void contextDestroyed(int contextId);
123 void clear();
124
125 bool shouldReportDeprecationMessage(int contextId, const String16& method);
126
127 int count(int contextId, int consoleContextId, const String16& id);
128 bool countReset(int contextId, int consoleContextId, const String16& id);
129
130 bool time(int contextId, int consoleContextId, const String16& label);
131 std::optional<double> timeLog(int contextId, int consoleContextId,
132 const String16& label);
133 std::optional<double> timeEnd(int contextId, int consoleContextId,
134 const String16& label);
135
136 private:
140 std::deque<std::unique_ptr<V8ConsoleMessage>> m_messages;
141
142 // Timers and counters are keyed by their `console.context()` ID
143 // and their label.
144 typedef std::pair<int, String16> LabelKey;
145
148 // Corresponds to https://console.spec.whatwg.org/#count-map
149 std::map<LabelKey, int> m_counters;
150 // Corresponds to https://console.spec.whatwg.org/#timer-table
151 std::map<LabelKey, double> m_timers;
152 };
153 std::map<int, PerContextData> m_data;
154};
155
156} // namespace v8_inspector
157
158#endif // V8_INSPECTOR_V8_CONSOLE_MESSAGE_H_
size_t length() const
Definition string-16.h:58
bool countReset(int contextId, int consoleContextId, const String16 &id)
const std::deque< std::unique_ptr< V8ConsoleMessage > > & messages() const
bool shouldReportDeprecationMessage(int contextId, const String16 &method)
void addMessage(std::unique_ptr< V8ConsoleMessage >)
std::optional< double > timeLog(int contextId, int consoleContextId, const String16 &label)
V8ConsoleMessageStorage(V8InspectorImpl *, int contextGroupId)
std::map< int, PerContextData > m_data
std::optional< double > timeEnd(int contextId, int consoleContextId, const String16 &label)
std::deque< std::unique_ptr< V8ConsoleMessage > > m_messages
static std::unique_ptr< V8ConsoleMessage > createForConsoleAPI(v8::Local< v8::Context > v8Context, int contextId, int groupId, V8InspectorImpl *inspector, double timestamp, ConsoleAPIType, v8::MemorySpan< const v8::Local< v8::Value > > arguments, const String16 &consoleContext, std::unique_ptr< V8StackTraceImpl >)
void reportToFrontend(protocol::Console::Frontend *) const
std::unique_ptr< V8StackTraceImpl > m_stackTrace
std::unique_ptr< protocol::DictionaryValue > getAssociatedExceptionData(V8InspectorImpl *inspector, V8InspectorSessionImpl *session) const
static std::unique_ptr< V8ConsoleMessage > createForRevokedException(double timestamp, const String16 &message, unsigned revokedExceptionId)
std::vector< std::unique_ptr< v8::Global< v8::Value > > > Arguments
static std::unique_ptr< V8ConsoleMessage > createForException(double timestamp, const String16 &detailedMessage, const String16 &url, unsigned lineNumber, unsigned columnNumber, std::unique_ptr< V8StackTraceImpl >, int scriptId, v8::Isolate *, const String16 &message, int contextId, v8::Local< v8::Value > exception, unsigned exceptionId)
std::unique_ptr< protocol::Runtime::RemoteObject > wrapException(V8InspectorSessionImpl *, bool generatePreview) const
std::unique_ptr< protocol::Array< protocol::Runtime::RemoteObject > > wrapArguments(V8InspectorSessionImpl *, bool generatePreview) const
void setLocation(const String16 &url, unsigned lineNumber, unsigned columnNumber, std::unique_ptr< V8StackTraceImpl >, int scriptId)
V8ConsoleMessage(V8MessageOrigin, double timestamp, const String16 &message)
uint32_t count
Label label
TimeRecord time
char16_t UChar
Definition string-16.h:22
Symbol method