• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <unordered_map>
35 
36 #include "src/base/macros.h"
37 #include "src/inspector/protocol/Forward.h"
38 #include "src/inspector/protocol/Runtime.h"
39 
40 #include "include/v8.h"
41 
42 namespace v8_inspector {
43 
44 class InjectedScript;
45 class InspectedContext;
46 class RemoteObjectIdBase;
47 class V8ConsoleMessage;
48 class V8InspectorImpl;
49 class V8InspectorSessionImpl;
50 
51 using protocol::Response;
52 using protocol::Maybe;
53 
54 class V8RuntimeAgentImpl : public protocol::Runtime::Backend {
55  public:
56   V8RuntimeAgentImpl(V8InspectorSessionImpl*, protocol::FrontendChannel*,
57                      protocol::DictionaryValue* state);
58   ~V8RuntimeAgentImpl() override;
59   void restore();
60 
61   // Part of the protocol.
62   Response enable() override;
63   Response disable() override;
64   void evaluate(const String16& expression, Maybe<String16> objectGroup,
65                 Maybe<bool> includeCommandLineAPI, Maybe<bool> silent,
66                 Maybe<int> executionContextId, Maybe<bool> returnByValue,
67                 Maybe<bool> generatePreview, Maybe<bool> userGesture,
68                 Maybe<bool> awaitPromise, Maybe<bool> throwOnSideEffect,
69                 Maybe<double> timeout,
70                 std::unique_ptr<EvaluateCallback>) override;
71   void awaitPromise(const String16& promiseObjectId, Maybe<bool> returnByValue,
72                     Maybe<bool> generatePreview,
73                     std::unique_ptr<AwaitPromiseCallback>) override;
74   void callFunctionOn(
75       const String16& expression, Maybe<String16> objectId,
76       Maybe<protocol::Array<protocol::Runtime::CallArgument>> optionalArguments,
77       Maybe<bool> silent, Maybe<bool> returnByValue,
78       Maybe<bool> generatePreview, Maybe<bool> userGesture,
79       Maybe<bool> awaitPromise, Maybe<int> executionContextId,
80       Maybe<String16> objectGroup,
81       std::unique_ptr<CallFunctionOnCallback>) override;
82   Response releaseObject(const String16& objectId) override;
83   Response getProperties(
84       const String16& objectId, Maybe<bool> ownProperties,
85       Maybe<bool> accessorPropertiesOnly, Maybe<bool> generatePreview,
86       std::unique_ptr<protocol::Array<protocol::Runtime::PropertyDescriptor>>*
87           result,
88       Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>*
89           internalProperties,
90       Maybe<protocol::Runtime::ExceptionDetails>*) override;
91   Response releaseObjectGroup(const String16& objectGroup) override;
92   Response runIfWaitingForDebugger() override;
93   Response setCustomObjectFormatterEnabled(bool) override;
94   Response setMaxCallStackSizeToCapture(int) override;
95   Response discardConsoleEntries() override;
96   Response compileScript(const String16& expression, const String16& sourceURL,
97                          bool persistScript, Maybe<int> executionContextId,
98                          Maybe<String16>*,
99                          Maybe<protocol::Runtime::ExceptionDetails>*) override;
100   void runScript(const String16&, Maybe<int> executionContextId,
101                  Maybe<String16> objectGroup, Maybe<bool> silent,
102                  Maybe<bool> includeCommandLineAPI, Maybe<bool> returnByValue,
103                  Maybe<bool> generatePreview, Maybe<bool> awaitPromise,
104                  std::unique_ptr<RunScriptCallback>) override;
105   Response queryObjects(
106       const String16& prototypeObjectId, Maybe<String16> objectGroup,
107       std::unique_ptr<protocol::Runtime::RemoteObject>* objects) override;
108   Response globalLexicalScopeNames(
109       Maybe<int> executionContextId,
110       std::unique_ptr<protocol::Array<String16>>* outNames) override;
111   Response getIsolateId(String16* outIsolateId) override;
112   Response getHeapUsage(double* out_usedSize, double* out_totalSize) override;
113   void terminateExecution(
114       std::unique_ptr<TerminateExecutionCallback> callback) override;
115 
116   Response addBinding(const String16& name,
117                       Maybe<int> executionContextId) override;
118   Response removeBinding(const String16& name) override;
119   void addBindings(InspectedContext* context);
120 
121   void reset();
122   void reportExecutionContextCreated(InspectedContext*);
123   void reportExecutionContextDestroyed(InspectedContext*);
124   void inspect(std::unique_ptr<protocol::Runtime::RemoteObject> objectToInspect,
125                std::unique_ptr<protocol::DictionaryValue> hints);
126   void messageAdded(V8ConsoleMessage*);
enabled()127   bool enabled() const { return m_enabled; }
128 
129  private:
130   bool reportMessage(V8ConsoleMessage*, bool generatePreview);
131 
132   static void bindingCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
133   void bindingCalled(const String16& name, const String16& payload,
134                      int executionContextId);
135   void addBinding(InspectedContext* context, const String16& name);
136 
137   V8InspectorSessionImpl* m_session;
138   protocol::DictionaryValue* m_state;
139   protocol::Runtime::Frontend m_frontend;
140   V8InspectorImpl* m_inspector;
141   bool m_enabled;
142   std::unordered_map<String16, std::unique_ptr<v8::Global<v8::Script>>>
143       m_compiledScripts;
144 
145   DISALLOW_COPY_AND_ASSIGN(V8RuntimeAgentImpl);
146 };
147 
148 }  // namespace v8_inspector
149 
150 #endif  // V8_INSPECTOR_V8_RUNTIME_AGENT_IMPL_H_
151