v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
v8-runtime-agent-impl.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#ifndef V8_INSPECTOR_V8_RUNTIME_AGENT_IMPL_H_
32#define V8_INSPECTOR_V8_RUNTIME_AGENT_IMPL_H_
33
34#include <memory>
35#include <unordered_map>
36
38#include "src/base/macros.h"
39#include "src/inspector/protocol/Forward.h"
40#include "src/inspector/protocol/Runtime.h"
41
42namespace v8 {
43class Script;
44} // namespace v8
45
46namespace v8_inspector {
47
48class InjectedScript;
49class InspectedContext;
50class RemoteObjectIdBase;
51class V8ConsoleMessage;
52class V8DebuggerBarrier;
53class V8InspectorImpl;
54class V8InspectorSessionImpl;
55
56using protocol::Response;
57
58class V8RuntimeAgentImpl : public protocol::Runtime::Backend {
59 public:
60 V8RuntimeAgentImpl(V8InspectorSessionImpl*, protocol::FrontendChannel*,
61 protocol::DictionaryValue* state,
62 std::shared_ptr<V8DebuggerBarrier>);
66 void restore();
67
68 // Part of the protocol.
69 Response enable() override;
70 Response disable() override;
71 void evaluate(
72 const String16& expression, std::optional<String16> objectGroup,
73 std::optional<bool> includeCommandLineAPI, std::optional<bool> silent,
74 std::optional<int> executionContextId, std::optional<bool> returnByValue,
75 std::optional<bool> generatePreview, std::optional<bool> userGesture,
76 std::optional<bool> awaitPromise, std::optional<bool> throwOnSideEffect,
77 std::optional<double> timeout, std::optional<bool> disableBreaks,
78 std::optional<bool> replMode,
79 std::optional<bool> allowUnsafeEvalBlockedByCSP,
80 std::optional<String16> uniqueContextId,
81 std::unique_ptr<protocol::Runtime::SerializationOptions>
82 serializationOptions,
83 std::unique_ptr<EvaluateCallback>) override;
84 void awaitPromise(const String16& promiseObjectId,
85 std::optional<bool> returnByValue,
86 std::optional<bool> generatePreview,
87 std::unique_ptr<AwaitPromiseCallback>) override;
88 void callFunctionOn(
89 const String16& expression, std::optional<String16> objectId,
90 std::unique_ptr<protocol::Array<protocol::Runtime::CallArgument>>
91 optionalArguments,
92 std::optional<bool> silent, std::optional<bool> returnByValue,
93 std::optional<bool> generatePreview, std::optional<bool> userGesture,
94 std::optional<bool> awaitPromise, std::optional<int> executionContextId,
95 std::optional<String16> objectGroup,
96 std::optional<bool> throwOnSideEffect,
97 std::optional<String16> uniqueContextId,
98 std::unique_ptr<protocol::Runtime::SerializationOptions>
99 serializationOptions,
100 std::unique_ptr<CallFunctionOnCallback>) override;
101 Response releaseObject(const String16& objectId) override;
102 Response getProperties(
103 const String16& objectId, std::optional<bool> ownProperties,
104 std::optional<bool> accessorPropertiesOnly,
105 std::optional<bool> generatePreview,
106 std::optional<bool> nonIndexedPropertiesOnly,
107 std::unique_ptr<protocol::Array<protocol::Runtime::PropertyDescriptor>>*
108 result,
109 std::unique_ptr<
110 protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>*
111 internalProperties,
112 std::unique_ptr<
113 protocol::Array<protocol::Runtime::PrivatePropertyDescriptor>>*
114 privateProperties,
115 std::unique_ptr<protocol::Runtime::ExceptionDetails>*) override;
116 Response releaseObjectGroup(const String16& objectGroup) override;
117 Response runIfWaitingForDebugger() override;
118 Response setCustomObjectFormatterEnabled(bool) override;
119 Response setMaxCallStackSizeToCapture(int) override;
120 Response discardConsoleEntries() override;
121 Response compileScript(
122 const String16& expression, const String16& sourceURL, bool persistScript,
123 std::optional<int> executionContextId, std::optional<String16>*,
124 std::unique_ptr<protocol::Runtime::ExceptionDetails>*) override;
125 void runScript(const String16&, std::optional<int> executionContextId,
126 std::optional<String16> objectGroup,
127 std::optional<bool> silent,
128 std::optional<bool> includeCommandLineAPI,
129 std::optional<bool> returnByValue,
130 std::optional<bool> generatePreview,
131 std::optional<bool> awaitPromise,
132 std::unique_ptr<RunScriptCallback>) override;
133 Response queryObjects(
134 const String16& prototypeObjectId, std::optional<String16> objectGroup,
135 std::unique_ptr<protocol::Runtime::RemoteObject>* objects) override;
137 std::optional<int> executionContextId,
138 std::unique_ptr<protocol::Array<String16>>* outNames) override;
139 Response getIsolateId(String16* outIsolateId) override;
140 Response getHeapUsage(double* out_usedSize, double* out_totalSize,
141 double* out_embedderHeapUsedSize,
142 double* out_backingStorageSize) override;
144 std::unique_ptr<TerminateExecutionCallback> callback) override;
145
146 Response addBinding(const String16& name,
147 std::optional<int> executionContextId,
148 std::optional<String16> executionContextName) override;
149 Response removeBinding(const String16& name) override;
150 void addBindings(InspectedContext* context);
151 Response getExceptionDetails(
152 const String16& errorObjectId,
153 std::unique_ptr<protocol::Runtime::ExceptionDetails>*
154 out_exceptionDetails) override;
155
156 void reset();
159 void inspect(std::unique_ptr<protocol::Runtime::RemoteObject> objectToInspect,
160 std::unique_ptr<protocol::DictionaryValue> hints,
161 int executionContextId);
163 bool enabled() const { return m_enabled; }
164
165 private:
166 bool reportMessage(V8ConsoleMessage*, bool generatePreview);
167
169 void bindingCalled(const String16& name, const String16& payload,
170 int executionContextId);
171 void addBinding(InspectedContext* context, const String16& name);
172
174 protocol::DictionaryValue* m_state;
175 protocol::Runtime::Frontend m_frontend;
177 std::shared_ptr<V8DebuggerBarrier> m_debuggerBarrier;
179 std::unordered_map<String16, std::unique_ptr<v8::Global<v8::Script>>>
181 // Binding name -> executionContextIds mapping.
182 std::unordered_map<String16, std::unordered_set<int>> m_activeBindings;
183};
184
185} // namespace v8_inspector
186
187#endif // V8_INSPECTOR_V8_RUNTIME_AGENT_IMPL_H_
std::unordered_map< String16, std::unique_ptr< v8::Global< v8::Script > > > m_compiledScripts
V8RuntimeAgentImpl & operator=(const V8RuntimeAgentImpl &)=delete
V8RuntimeAgentImpl(const V8RuntimeAgentImpl &)=delete
protocol::Runtime::Frontend m_frontend
void bindingCalled(const String16 &name, const String16 &payload, int executionContextId)
std::unordered_map< String16, std::unordered_set< int > > m_activeBindings
void reportExecutionContextDestroyed(InspectedContext *)
Response getProperties(const String16 &objectId, std::optional< bool > ownProperties, std::optional< bool > accessorPropertiesOnly, std::optional< bool > generatePreview, std::optional< bool > nonIndexedPropertiesOnly, std::unique_ptr< protocol::Array< protocol::Runtime::PropertyDescriptor > > *result, std::unique_ptr< protocol::Array< protocol::Runtime::InternalPropertyDescriptor > > *internalProperties, std::unique_ptr< protocol::Array< protocol::Runtime::PrivatePropertyDescriptor > > *privateProperties, std::unique_ptr< protocol::Runtime::ExceptionDetails > *) override
bool reportMessage(V8ConsoleMessage *, bool generatePreview)
static void bindingCallback(const v8::FunctionCallbackInfo< v8::Value > &info)
void addBindings(InspectedContext *context)
Response setMaxCallStackSizeToCapture(int) override
Response addBinding(const String16 &name, std::optional< int > executionContextId, std::optional< String16 > executionContextName) override
void runScript(const String16 &, std::optional< int > executionContextId, std::optional< String16 > objectGroup, std::optional< bool > silent, std::optional< bool > includeCommandLineAPI, std::optional< bool > returnByValue, std::optional< bool > generatePreview, std::optional< bool > awaitPromise, std::unique_ptr< RunScriptCallback >) override
Response globalLexicalScopeNames(std::optional< int > executionContextId, std::unique_ptr< protocol::Array< String16 > > *outNames) override
Response getHeapUsage(double *out_usedSize, double *out_totalSize, double *out_embedderHeapUsedSize, double *out_backingStorageSize) override
Response queryObjects(const String16 &prototypeObjectId, std::optional< String16 > objectGroup, std::unique_ptr< protocol::Runtime::RemoteObject > *objects) override
Response compileScript(const String16 &expression, const String16 &sourceURL, bool persistScript, std::optional< int > executionContextId, std::optional< String16 > *, std::unique_ptr< protocol::Runtime::ExceptionDetails > *) override
std::shared_ptr< V8DebuggerBarrier > m_debuggerBarrier
void awaitPromise(const String16 &promiseObjectId, std::optional< bool > returnByValue, std::optional< bool > generatePreview, std::unique_ptr< AwaitPromiseCallback >) override
void reportExecutionContextCreated(InspectedContext *)
Response releaseObjectGroup(const String16 &objectGroup) override
Response setCustomObjectFormatterEnabled(bool) override
V8RuntimeAgentImpl(V8InspectorSessionImpl *, protocol::FrontendChannel *, protocol::DictionaryValue *state, std::shared_ptr< V8DebuggerBarrier >)
void terminateExecution(std::unique_ptr< TerminateExecutionCallback > callback) override
protocol::DictionaryValue * m_state
void evaluate(const String16 &expression, std::optional< String16 > objectGroup, std::optional< bool > includeCommandLineAPI, std::optional< bool > silent, std::optional< int > executionContextId, std::optional< bool > returnByValue, std::optional< bool > generatePreview, std::optional< bool > userGesture, std::optional< bool > awaitPromise, std::optional< bool > throwOnSideEffect, std::optional< double > timeout, std::optional< bool > disableBreaks, std::optional< bool > replMode, std::optional< bool > allowUnsafeEvalBlockedByCSP, std::optional< String16 > uniqueContextId, std::unique_ptr< protocol::Runtime::SerializationOptions > serializationOptions, std::unique_ptr< EvaluateCallback >) override
void callFunctionOn(const String16 &expression, std::optional< String16 > objectId, std::unique_ptr< protocol::Array< protocol::Runtime::CallArgument > > optionalArguments, std::optional< bool > silent, std::optional< bool > returnByValue, std::optional< bool > generatePreview, std::optional< bool > userGesture, std::optional< bool > awaitPromise, std::optional< int > executionContextId, std::optional< String16 > objectGroup, std::optional< bool > throwOnSideEffect, std::optional< String16 > uniqueContextId, std::unique_ptr< protocol::Runtime::SerializationOptions > serializationOptions, std::unique_ptr< CallFunctionOnCallback >) override
Response getExceptionDetails(const String16 &errorObjectId, std::unique_ptr< protocol::Runtime::ExceptionDetails > *out_exceptionDetails) override
Response getIsolateId(String16 *outIsolateId) override
void inspect(std::unique_ptr< protocol::Runtime::RemoteObject > objectToInspect, std::unique_ptr< protocol::DictionaryValue > hints, int executionContextId)
Response releaseObject(const String16 &objectId) override
Response removeBinding(const String16 &name) override
TNode< Object > callback
ZoneVector< RpoNumber > & result