OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 #include "include/v8.h" | 42 #include "include/v8.h" |
43 | 43 |
44 namespace v8_inspector { | 44 namespace v8_inspector { |
45 | 45 |
46 class RemoteObjectId; | 46 class RemoteObjectId; |
47 class V8FunctionCall; | 47 class V8FunctionCall; |
48 class V8InspectorImpl; | 48 class V8InspectorImpl; |
49 class V8InspectorSessionImpl; | 49 class V8InspectorSessionImpl; |
50 | 50 |
51 using protocol::ErrorString; | |
52 using protocol::Maybe; | 51 using protocol::Maybe; |
| 52 using protocol::Response; |
53 | 53 |
54 class InjectedScript final { | 54 class InjectedScript final { |
55 public: | 55 public: |
56 static std::unique_ptr<InjectedScript> create(InspectedContext*); | 56 static std::unique_ptr<InjectedScript> create(InspectedContext*); |
57 ~InjectedScript(); | 57 ~InjectedScript(); |
58 | 58 |
59 InspectedContext* context() const { return m_context; } | 59 InspectedContext* context() const { return m_context; } |
60 | 60 |
61 void getProperties( | 61 Response getProperties( |
62 ErrorString*, v8::Local<v8::Object>, const String16& groupName, | 62 v8::Local<v8::Object>, const String16& groupName, bool ownProperties, |
63 bool ownProperties, bool accessorPropertiesOnly, bool generatePreview, | 63 bool accessorPropertiesOnly, bool generatePreview, |
64 std::unique_ptr<protocol::Array<protocol::Runtime::PropertyDescriptor>>* | 64 std::unique_ptr<protocol::Array<protocol::Runtime::PropertyDescriptor>>* |
65 result, | 65 result, |
66 Maybe<protocol::Runtime::ExceptionDetails>*); | 66 Maybe<protocol::Runtime::ExceptionDetails>*); |
67 void releaseObject(const String16& objectId); | 67 void releaseObject(const String16& objectId); |
68 | 68 |
69 std::unique_ptr<protocol::Runtime::RemoteObject> wrapObject( | 69 Response wrapObject( |
70 ErrorString*, v8::Local<v8::Value>, const String16& groupName, | 70 v8::Local<v8::Value>, const String16& groupName, bool forceValueType, |
71 bool forceValueType = false, bool generatePreview = false) const; | 71 bool generatePreview, |
72 bool wrapObjectProperty(ErrorString*, v8::Local<v8::Object>, | 72 std::unique_ptr<protocol::Runtime::RemoteObject>* result) const; |
73 v8::Local<v8::Name> key, const String16& groupName, | 73 Response wrapObjectProperty(v8::Local<v8::Object>, v8::Local<v8::Name> key, |
74 bool forceValueType = false, | 74 const String16& groupName, |
75 bool generatePreview = false) const; | 75 bool forceValueType = false, |
76 bool wrapPropertyInArray(ErrorString*, v8::Local<v8::Array>, | 76 bool generatePreview = false) const; |
77 v8::Local<v8::String> property, | 77 Response wrapPropertyInArray(v8::Local<v8::Array>, |
78 const String16& groupName, | 78 v8::Local<v8::String> property, |
79 bool forceValueType = false, | 79 const String16& groupName, |
80 bool generatePreview = false) const; | 80 bool forceValueType = false, |
81 bool wrapObjectsInArray(ErrorString*, v8::Local<v8::Array>, | 81 bool generatePreview = false) const; |
82 const String16& groupName, | |
83 bool forceValueType = false, | |
84 bool generatePreview = false) const; | |
85 std::unique_ptr<protocol::Runtime::RemoteObject> wrapTable( | 82 std::unique_ptr<protocol::Runtime::RemoteObject> wrapTable( |
86 v8::Local<v8::Value> table, v8::Local<v8::Value> columns) const; | 83 v8::Local<v8::Value> table, v8::Local<v8::Value> columns) const; |
87 | 84 |
88 bool findObject(ErrorString*, const RemoteObjectId&, | 85 Response findObject(const RemoteObjectId&, v8::Local<v8::Value>*) const; |
89 v8::Local<v8::Value>*) const; | |
90 String16 objectGroupName(const RemoteObjectId&) const; | 86 String16 objectGroupName(const RemoteObjectId&) const; |
91 void releaseObjectGroup(const String16&); | 87 void releaseObjectGroup(const String16&); |
92 void setCustomObjectFormatterEnabled(bool); | 88 void setCustomObjectFormatterEnabled(bool); |
93 v8::MaybeLocal<v8::Value> resolveCallArgument( | 89 Response resolveCallArgument(protocol::Runtime::CallArgument*, |
94 ErrorString*, protocol::Runtime::CallArgument*); | 90 v8::Local<v8::Value>* result); |
95 | 91 |
96 std::unique_ptr<protocol::Runtime::ExceptionDetails> createExceptionDetails( | 92 Response createExceptionDetails( |
97 ErrorString*, const v8::TryCatch&, const String16& groupName, | 93 const v8::TryCatch&, const String16& groupName, bool generatePreview, |
98 bool generatePreview); | 94 Maybe<protocol::Runtime::ExceptionDetails>* result); |
99 void wrapEvaluateResult( | 95 Response wrapEvaluateResult( |
100 ErrorString*, v8::MaybeLocal<v8::Value> maybeResultValue, | 96 v8::MaybeLocal<v8::Value> maybeResultValue, const v8::TryCatch&, |
101 const v8::TryCatch&, const String16& objectGroup, bool returnByValue, | 97 const String16& objectGroup, bool returnByValue, bool generatePreview, |
102 bool generatePreview, | |
103 std::unique_ptr<protocol::Runtime::RemoteObject>* result, | 98 std::unique_ptr<protocol::Runtime::RemoteObject>* result, |
104 Maybe<protocol::Runtime::ExceptionDetails>*); | 99 Maybe<protocol::Runtime::ExceptionDetails>*); |
105 v8::Local<v8::Value> lastEvaluationResult() const; | 100 v8::Local<v8::Value> lastEvaluationResult() const; |
106 | 101 |
107 class Scope { | 102 class Scope { |
108 public: | 103 public: |
109 bool initialize(); | 104 Response initialize(); |
110 bool installCommandLineAPI(); | 105 void installCommandLineAPI(); |
111 void ignoreExceptionsAndMuteConsole(); | 106 void ignoreExceptionsAndMuteConsole(); |
112 void pretendUserGesture(); | 107 void pretendUserGesture(); |
113 v8::Local<v8::Context> context() const { return m_context; } | 108 v8::Local<v8::Context> context() const { return m_context; } |
114 InjectedScript* injectedScript() const { return m_injectedScript; } | 109 InjectedScript* injectedScript() const { return m_injectedScript; } |
115 const v8::TryCatch& tryCatch() const { return m_tryCatch; } | 110 const v8::TryCatch& tryCatch() const { return m_tryCatch; } |
116 | 111 |
117 protected: | 112 protected: |
118 Scope(ErrorString*, V8InspectorImpl*, int contextGroupId); | 113 Scope(V8InspectorImpl*, int contextGroupId); |
119 virtual ~Scope(); | 114 virtual ~Scope(); |
120 virtual void findInjectedScript(V8InspectorSessionImpl*) = 0; | 115 virtual Response findInjectedScript(V8InspectorSessionImpl*) = 0; |
121 | 116 |
122 ErrorString* m_errorString; | |
123 V8InspectorImpl* m_inspector; | 117 V8InspectorImpl* m_inspector; |
124 int m_contextGroupId; | 118 int m_contextGroupId; |
125 InjectedScript* m_injectedScript; | 119 InjectedScript* m_injectedScript; |
126 | 120 |
127 private: | 121 private: |
128 void cleanup(); | 122 void cleanup(); |
129 v8::DebugInterface::ExceptionBreakState setPauseOnExceptionsState( | 123 v8::DebugInterface::ExceptionBreakState setPauseOnExceptionsState( |
130 v8::DebugInterface::ExceptionBreakState); | 124 v8::DebugInterface::ExceptionBreakState); |
131 | 125 |
132 v8::HandleScope m_handleScope; | 126 v8::HandleScope m_handleScope; |
133 v8::TryCatch m_tryCatch; | 127 v8::TryCatch m_tryCatch; |
134 v8::Local<v8::Context> m_context; | 128 v8::Local<v8::Context> m_context; |
135 std::unique_ptr<V8Console::CommandLineAPIScope> m_commandLineAPIScope; | 129 std::unique_ptr<V8Console::CommandLineAPIScope> m_commandLineAPIScope; |
136 bool m_ignoreExceptionsAndMuteConsole; | 130 bool m_ignoreExceptionsAndMuteConsole; |
137 v8::DebugInterface::ExceptionBreakState m_previousPauseOnExceptionsState; | 131 v8::DebugInterface::ExceptionBreakState m_previousPauseOnExceptionsState; |
138 bool m_userGesture; | 132 bool m_userGesture; |
139 }; | 133 }; |
140 | 134 |
141 class ContextScope : public Scope { | 135 class ContextScope : public Scope { |
142 public: | 136 public: |
143 ContextScope(ErrorString*, V8InspectorImpl*, int contextGroupId, | 137 ContextScope(V8InspectorImpl*, int contextGroupId, int executionContextId); |
144 int executionContextId); | |
145 ~ContextScope(); | 138 ~ContextScope(); |
146 | 139 |
147 private: | 140 private: |
148 void findInjectedScript(V8InspectorSessionImpl*) override; | 141 Response findInjectedScript(V8InspectorSessionImpl*) override; |
149 int m_executionContextId; | 142 int m_executionContextId; |
150 | 143 |
151 DISALLOW_COPY_AND_ASSIGN(ContextScope); | 144 DISALLOW_COPY_AND_ASSIGN(ContextScope); |
152 }; | 145 }; |
153 | 146 |
154 class ObjectScope : public Scope { | 147 class ObjectScope : public Scope { |
155 public: | 148 public: |
156 ObjectScope(ErrorString*, V8InspectorImpl*, int contextGroupId, | 149 ObjectScope(V8InspectorImpl*, int contextGroupId, |
157 const String16& remoteObjectId); | 150 const String16& remoteObjectId); |
158 ~ObjectScope(); | 151 ~ObjectScope(); |
159 const String16& objectGroupName() const { return m_objectGroupName; } | 152 const String16& objectGroupName() const { return m_objectGroupName; } |
160 v8::Local<v8::Value> object() const { return m_object; } | 153 v8::Local<v8::Value> object() const { return m_object; } |
161 | 154 |
162 private: | 155 private: |
163 void findInjectedScript(V8InspectorSessionImpl*) override; | 156 Response findInjectedScript(V8InspectorSessionImpl*) override; |
164 String16 m_remoteObjectId; | 157 String16 m_remoteObjectId; |
165 String16 m_objectGroupName; | 158 String16 m_objectGroupName; |
166 v8::Local<v8::Value> m_object; | 159 v8::Local<v8::Value> m_object; |
167 | 160 |
168 DISALLOW_COPY_AND_ASSIGN(ObjectScope); | 161 DISALLOW_COPY_AND_ASSIGN(ObjectScope); |
169 }; | 162 }; |
170 | 163 |
171 class CallFrameScope : public Scope { | 164 class CallFrameScope : public Scope { |
172 public: | 165 public: |
173 CallFrameScope(ErrorString*, V8InspectorImpl*, int contextGroupId, | 166 CallFrameScope(V8InspectorImpl*, int contextGroupId, |
174 const String16& remoteCallFrameId); | 167 const String16& remoteCallFrameId); |
175 ~CallFrameScope(); | 168 ~CallFrameScope(); |
176 size_t frameOrdinal() const { return m_frameOrdinal; } | 169 size_t frameOrdinal() const { return m_frameOrdinal; } |
177 | 170 |
178 private: | 171 private: |
179 void findInjectedScript(V8InspectorSessionImpl*) override; | 172 Response findInjectedScript(V8InspectorSessionImpl*) override; |
180 String16 m_remoteCallFrameId; | 173 String16 m_remoteCallFrameId; |
181 size_t m_frameOrdinal; | 174 size_t m_frameOrdinal; |
182 | 175 |
183 DISALLOW_COPY_AND_ASSIGN(CallFrameScope); | 176 DISALLOW_COPY_AND_ASSIGN(CallFrameScope); |
184 }; | 177 }; |
185 | 178 |
186 private: | 179 private: |
187 InjectedScript(InspectedContext*, v8::Local<v8::Object>, | 180 InjectedScript(InspectedContext*, v8::Local<v8::Object>, |
188 std::unique_ptr<InjectedScriptNative>); | 181 std::unique_ptr<InjectedScriptNative>); |
189 v8::Local<v8::Value> v8Value() const; | 182 v8::Local<v8::Value> v8Value() const; |
190 v8::MaybeLocal<v8::Value> wrapValue(ErrorString*, v8::Local<v8::Value>, | 183 Response wrapValue(v8::Local<v8::Value>, const String16& groupName, |
191 const String16& groupName, | 184 bool forceValueType, bool generatePreview, |
192 bool forceValueType, | 185 v8::Local<v8::Value>* result) const; |
193 bool generatePreview) const; | |
194 v8::Local<v8::Object> commandLineAPI(); | 186 v8::Local<v8::Object> commandLineAPI(); |
195 | 187 |
196 InspectedContext* m_context; | 188 InspectedContext* m_context; |
197 v8::Global<v8::Value> m_value; | 189 v8::Global<v8::Value> m_value; |
198 v8::Global<v8::Value> m_lastEvaluationResult; | 190 v8::Global<v8::Value> m_lastEvaluationResult; |
199 std::unique_ptr<InjectedScriptNative> m_native; | 191 std::unique_ptr<InjectedScriptNative> m_native; |
200 v8::Global<v8::Object> m_commandLineAPI; | 192 v8::Global<v8::Object> m_commandLineAPI; |
201 | 193 |
202 DISALLOW_COPY_AND_ASSIGN(InjectedScript); | 194 DISALLOW_COPY_AND_ASSIGN(InjectedScript); |
203 }; | 195 }; |
204 | 196 |
205 } // namespace v8_inspector | 197 } // namespace v8_inspector |
206 | 198 |
207 #endif // V8_INSPECTOR_INJECTEDSCRIPT_H_ | 199 #endif // V8_INSPECTOR_INJECTEDSCRIPT_H_ |
OLD | NEW |