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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 #include "include/v8-inspector.h" | 47 #include "include/v8-inspector.h" |
48 | 48 |
49 namespace v8_inspector { | 49 namespace v8_inspector { |
50 | 50 |
51 using protocol::Array; | 51 using protocol::Array; |
52 using protocol::Runtime::PropertyDescriptor; | 52 using protocol::Runtime::PropertyDescriptor; |
53 using protocol::Runtime::InternalPropertyDescriptor; | 53 using protocol::Runtime::InternalPropertyDescriptor; |
54 using protocol::Runtime::RemoteObject; | 54 using protocol::Runtime::RemoteObject; |
55 using protocol::Maybe; | 55 using protocol::Maybe; |
56 | 56 |
57 static bool hasInternalError(ErrorString* errorString, bool hasError) { | |
58 if (hasError) *errorString = "Internal error"; | |
59 return hasError; | |
60 } | |
61 | |
62 std::unique_ptr<InjectedScript> InjectedScript::create( | 57 std::unique_ptr<InjectedScript> InjectedScript::create( |
63 InspectedContext* inspectedContext) { | 58 InspectedContext* inspectedContext) { |
64 v8::Isolate* isolate = inspectedContext->isolate(); | 59 v8::Isolate* isolate = inspectedContext->isolate(); |
65 v8::HandleScope handles(isolate); | 60 v8::HandleScope handles(isolate); |
66 v8::Local<v8::Context> context = inspectedContext->context(); | 61 v8::Local<v8::Context> context = inspectedContext->context(); |
67 v8::Context::Scope scope(context); | 62 v8::Context::Scope scope(context); |
68 | 63 |
69 std::unique_ptr<InjectedScriptNative> injectedScriptNative( | 64 std::unique_ptr<InjectedScriptNative> injectedScriptNative( |
70 new InjectedScriptNative(isolate)); | 65 new InjectedScriptNative(isolate)); |
71 v8::Local<v8::Object> scriptHostWrapper = | 66 v8::Local<v8::Object> scriptHostWrapper = |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 | 112 |
118 InjectedScript::InjectedScript( | 113 InjectedScript::InjectedScript( |
119 InspectedContext* context, v8::Local<v8::Object> object, | 114 InspectedContext* context, v8::Local<v8::Object> object, |
120 std::unique_ptr<InjectedScriptNative> injectedScriptNative) | 115 std::unique_ptr<InjectedScriptNative> injectedScriptNative) |
121 : m_context(context), | 116 : m_context(context), |
122 m_value(context->isolate(), object), | 117 m_value(context->isolate(), object), |
123 m_native(std::move(injectedScriptNative)) {} | 118 m_native(std::move(injectedScriptNative)) {} |
124 | 119 |
125 InjectedScript::~InjectedScript() {} | 120 InjectedScript::~InjectedScript() {} |
126 | 121 |
127 void InjectedScript::getProperties( | 122 Response InjectedScript::getProperties( |
128 ErrorString* errorString, v8::Local<v8::Object> object, | 123 v8::Local<v8::Object> object, const String16& groupName, bool ownProperties, |
129 const String16& groupName, bool ownProperties, bool accessorPropertiesOnly, | 124 bool accessorPropertiesOnly, bool generatePreview, |
130 bool generatePreview, | |
131 std::unique_ptr<Array<PropertyDescriptor>>* properties, | 125 std::unique_ptr<Array<PropertyDescriptor>>* properties, |
132 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) { | 126 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) { |
133 v8::HandleScope handles(m_context->isolate()); | 127 v8::HandleScope handles(m_context->isolate()); |
134 v8::Local<v8::Context> context = m_context->context(); | 128 v8::Local<v8::Context> context = m_context->context(); |
135 V8FunctionCall function(m_context->inspector(), m_context->context(), | 129 V8FunctionCall function(m_context->inspector(), m_context->context(), |
136 v8Value(), "getProperties"); | 130 v8Value(), "getProperties"); |
137 function.appendArgument(object); | 131 function.appendArgument(object); |
138 function.appendArgument(groupName); | 132 function.appendArgument(groupName); |
139 function.appendArgument(ownProperties); | 133 function.appendArgument(ownProperties); |
140 function.appendArgument(accessorPropertiesOnly); | 134 function.appendArgument(accessorPropertiesOnly); |
141 function.appendArgument(generatePreview); | 135 function.appendArgument(generatePreview); |
142 | 136 |
143 v8::TryCatch tryCatch(m_context->isolate()); | 137 v8::TryCatch tryCatch(m_context->isolate()); |
144 v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling(); | 138 v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling(); |
145 if (tryCatch.HasCaught()) { | 139 if (tryCatch.HasCaught()) { |
146 *exceptionDetails = createExceptionDetails(errorString, tryCatch, groupName, | 140 Response response = createExceptionDetails( |
147 generatePreview); | 141 tryCatch, groupName, generatePreview, *exceptionDetails); |
142 if (!response.isSuccess()) return response; | |
148 // FIXME: make properties optional | 143 // FIXME: make properties optional |
149 *properties = Array<PropertyDescriptor>::create(); | 144 *properties = Array<PropertyDescriptor>::create(); |
150 return; | 145 return Response::OK(); |
151 } | 146 } |
152 if (hasInternalError(errorString, resultValue.IsEmpty())) return; | 147 if (resultValue.IsEmpty()) return Response::InternalError(); |
153 std::unique_ptr<protocol::Value> protocolValue = | 148 std::unique_ptr<protocol::Value> protocolValue; |
154 toProtocolValue(errorString, context, resultValue); | 149 Response response = |
155 if (!protocolValue) return; | 150 toProtocolValue(context, resultValue, 1000, protocolValue); |
dgozman
2016/11/02 19:54:00
&protocolValue
kozy
2016/11/02 22:45:13
Done.
| |
156 protocol::ErrorSupport errors(errorString); | 151 if (!response.isSuccess()) return response; |
152 protocol::ErrorSupport errors; | |
157 std::unique_ptr<Array<PropertyDescriptor>> result = | 153 std::unique_ptr<Array<PropertyDescriptor>> result = |
158 Array<PropertyDescriptor>::parse(protocolValue.get(), &errors); | 154 Array<PropertyDescriptor>::parse(protocolValue.get(), &errors); |
159 if (!hasInternalError(errorString, errors.hasErrors())) | 155 if (errors.hasErrors()) return Response::Error(errors.errors()); |
160 *properties = std::move(result); | 156 *properties = std::move(result); |
157 return Response::OK(); | |
161 } | 158 } |
162 | 159 |
163 void InjectedScript::releaseObject(const String16& objectId) { | 160 void InjectedScript::releaseObject(const String16& objectId) { |
164 std::unique_ptr<protocol::Value> parsedObjectId = | 161 std::unique_ptr<protocol::Value> parsedObjectId = |
165 protocol::parseJSON(objectId); | 162 protocol::parseJSON(objectId); |
166 if (!parsedObjectId) return; | 163 if (!parsedObjectId) return; |
167 protocol::DictionaryValue* object = | 164 protocol::DictionaryValue* object = |
168 protocol::DictionaryValue::cast(parsedObjectId.get()); | 165 protocol::DictionaryValue::cast(parsedObjectId.get()); |
169 if (!object) return; | 166 if (!object) return; |
170 int boundId = 0; | 167 int boundId = 0; |
171 if (!object->getInteger("id", &boundId)) return; | 168 if (!object->getInteger("id", &boundId)) return; |
172 m_native->unbind(boundId); | 169 m_native->unbind(boundId); |
173 } | 170 } |
174 | 171 |
175 std::unique_ptr<protocol::Runtime::RemoteObject> InjectedScript::wrapObject( | 172 Response InjectedScript::wrapObject( |
176 ErrorString* errorString, v8::Local<v8::Value> value, | 173 v8::Local<v8::Value> value, const String16& groupName, bool forceValueType, |
177 const String16& groupName, bool forceValueType, | 174 bool generatePreview, |
178 bool generatePreview) const { | 175 std::unique_ptr<protocol::Runtime::RemoteObject>& result) const { |
179 v8::HandleScope handles(m_context->isolate()); | 176 v8::HandleScope handles(m_context->isolate()); |
180 v8::Local<v8::Value> wrappedObject; | 177 v8::Local<v8::Value> wrappedObject; |
181 v8::Local<v8::Context> context = m_context->context(); | 178 v8::Local<v8::Context> context = m_context->context(); |
182 if (!wrapValue(errorString, value, groupName, forceValueType, generatePreview) | 179 Response response = wrapValue(value, groupName, forceValueType, |
183 .ToLocal(&wrappedObject)) | 180 generatePreview, wrappedObject); |
184 return nullptr; | 181 if (!response.isSuccess()) return response; |
185 protocol::ErrorSupport errors; | 182 protocol::ErrorSupport errors; |
186 std::unique_ptr<protocol::Value> protocolValue = | 183 std::unique_ptr<protocol::Value> protocolValue; |
187 toProtocolValue(errorString, context, wrappedObject); | 184 response = toProtocolValue(context, wrappedObject, 1000, protocolValue); |
188 if (!protocolValue) return nullptr; | 185 if (!response.isSuccess()) return response; |
186 | |
189 std::unique_ptr<protocol::Runtime::RemoteObject> remoteObject = | 187 std::unique_ptr<protocol::Runtime::RemoteObject> remoteObject = |
dgozman
2016/11/02 19:53:59
*result = ....
kozy
2016/11/02 22:45:12
Done.
| |
190 protocol::Runtime::RemoteObject::parse(protocolValue.get(), &errors); | 188 protocol::Runtime::RemoteObject::parse(protocolValue.get(), &errors); |
191 if (!remoteObject) *errorString = errors.errors(); | 189 if (!remoteObject) return Response::Error(errors.errors()); |
192 return remoteObject; | 190 result = std::move(remoteObject); |
191 return Response::OK(); | |
193 } | 192 } |
194 | 193 |
195 bool InjectedScript::wrapObjectProperty(ErrorString* errorString, | 194 Response InjectedScript::wrapObjectProperty(v8::Local<v8::Object> object, |
196 v8::Local<v8::Object> object, | 195 v8::Local<v8::Name> key, |
197 v8::Local<v8::Name> key, | 196 const String16& groupName, |
198 const String16& groupName, | 197 bool forceValueType, |
199 bool forceValueType, | 198 bool generatePreview) const { |
200 bool generatePreview) const { | |
201 v8::Local<v8::Value> property; | 199 v8::Local<v8::Value> property; |
202 v8::Local<v8::Context> context = m_context->context(); | 200 v8::Local<v8::Context> context = m_context->context(); |
203 if (hasInternalError(errorString, | 201 if (!object->Get(context, key).ToLocal(&property)) |
204 !object->Get(context, key).ToLocal(&property))) | 202 return Response::InternalError(); |
205 return false; | |
206 v8::Local<v8::Value> wrappedProperty; | 203 v8::Local<v8::Value> wrappedProperty; |
207 if (!wrapValue(errorString, property, groupName, forceValueType, | 204 Response response = wrapValue(property, groupName, forceValueType, |
208 generatePreview) | 205 generatePreview, wrappedProperty); |
209 .ToLocal(&wrappedProperty)) | 206 if (!response.isSuccess()) return response; |
210 return false; | |
211 v8::Maybe<bool> success = | 207 v8::Maybe<bool> success = |
212 createDataProperty(context, object, key, wrappedProperty); | 208 createDataProperty(context, object, key, wrappedProperty); |
213 if (hasInternalError(errorString, success.IsNothing() || !success.FromJust())) | 209 if (success.IsNothing() || !success.FromJust()) |
214 return false; | 210 return Response::InternalError(); |
215 return true; | 211 return Response::OK(); |
216 } | 212 } |
217 | 213 |
218 bool InjectedScript::wrapPropertyInArray(ErrorString* errorString, | 214 Response InjectedScript::wrapPropertyInArray(v8::Local<v8::Array> array, |
219 v8::Local<v8::Array> array, | 215 v8::Local<v8::String> property, |
220 v8::Local<v8::String> property, | 216 const String16& groupName, |
221 const String16& groupName, | 217 bool forceValueType, |
222 bool forceValueType, | 218 bool generatePreview) const { |
223 bool generatePreview) const { | |
224 V8FunctionCall function(m_context->inspector(), m_context->context(), | 219 V8FunctionCall function(m_context->inspector(), m_context->context(), |
225 v8Value(), "wrapPropertyInArray"); | 220 v8Value(), "wrapPropertyInArray"); |
226 function.appendArgument(array); | 221 function.appendArgument(array); |
227 function.appendArgument(property); | 222 function.appendArgument(property); |
228 function.appendArgument(groupName); | 223 function.appendArgument(groupName); |
229 function.appendArgument(forceValueType); | 224 function.appendArgument(forceValueType); |
230 function.appendArgument(generatePreview); | 225 function.appendArgument(generatePreview); |
231 bool hadException = false; | 226 bool hadException = false; |
232 function.call(hadException); | 227 function.call(hadException); |
233 return !hasInternalError(errorString, hadException); | 228 return hadException ? Response::InternalError() : Response::OK(); |
234 } | 229 } |
235 | 230 |
236 bool InjectedScript::wrapObjectsInArray(ErrorString* errorString, | 231 Response InjectedScript::wrapValue(v8::Local<v8::Value> value, |
237 v8::Local<v8::Array> array, | 232 const String16& groupName, |
238 const String16& groupName, | 233 bool forceValueType, bool generatePreview, |
239 bool forceValueType, | 234 v8::Local<v8::Value>& result) const { |
240 bool generatePreview) const { | 235 result = v8::Local<v8::Value>(); |
dgozman
2016/11/02 19:53:59
remove
kozy
2016/11/02 22:45:13
Done.
| |
241 V8FunctionCall function(m_context->inspector(), m_context->context(), | |
242 v8Value(), "wrapObjectsInArray"); | |
243 function.appendArgument(array); | |
244 function.appendArgument(groupName); | |
245 function.appendArgument(forceValueType); | |
246 function.appendArgument(generatePreview); | |
247 bool hadException = false; | |
248 function.call(hadException); | |
249 return !hasInternalError(errorString, hadException); | |
250 } | |
251 | |
252 v8::MaybeLocal<v8::Value> InjectedScript::wrapValue( | |
253 ErrorString* errorString, v8::Local<v8::Value> value, | |
254 const String16& groupName, bool forceValueType, | |
255 bool generatePreview) const { | |
256 V8FunctionCall function(m_context->inspector(), m_context->context(), | 236 V8FunctionCall function(m_context->inspector(), m_context->context(), |
257 v8Value(), "wrapObject"); | 237 v8Value(), "wrapObject"); |
258 function.appendArgument(value); | 238 function.appendArgument(value); |
259 function.appendArgument(groupName); | 239 function.appendArgument(groupName); |
260 function.appendArgument(forceValueType); | 240 function.appendArgument(forceValueType); |
261 function.appendArgument(generatePreview); | 241 function.appendArgument(generatePreview); |
262 bool hadException = false; | 242 bool hadException = false; |
263 v8::Local<v8::Value> r = function.call(hadException); | 243 v8::Local<v8::Value> r = function.call(hadException); |
dgozman
2016/11/02 19:53:59
*result =
kozy
2016/11/02 22:45:13
Done.
| |
264 if (hasInternalError(errorString, hadException || r.IsEmpty())) | 244 if (hadException || r.IsEmpty()) return Response::InternalError(); |
265 return v8::MaybeLocal<v8::Value>(); | 245 result = r; |
266 return r; | 246 return Response::OK(); |
267 } | 247 } |
268 | 248 |
269 std::unique_ptr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable( | 249 std::unique_ptr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable( |
270 v8::Local<v8::Value> table, v8::Local<v8::Value> columns) const { | 250 v8::Local<v8::Value> table, v8::Local<v8::Value> columns) const { |
271 v8::HandleScope handles(m_context->isolate()); | 251 v8::HandleScope handles(m_context->isolate()); |
272 v8::Local<v8::Context> context = m_context->context(); | 252 v8::Local<v8::Context> context = m_context->context(); |
273 V8FunctionCall function(m_context->inspector(), context, v8Value(), | 253 V8FunctionCall function(m_context->inspector(), context, v8Value(), |
274 "wrapTable"); | 254 "wrapTable"); |
275 function.appendArgument(table); | 255 function.appendArgument(table); |
276 if (columns.IsEmpty()) | 256 if (columns.IsEmpty()) |
277 function.appendArgument(false); | 257 function.appendArgument(false); |
278 else | 258 else |
279 function.appendArgument(columns); | 259 function.appendArgument(columns); |
280 bool hadException = false; | 260 bool hadException = false; |
281 v8::Local<v8::Value> r = function.call(hadException); | 261 v8::Local<v8::Value> r = function.call(hadException); |
282 if (hadException || r.IsEmpty()) return nullptr; | 262 if (hadException || r.IsEmpty()) return nullptr; |
283 protocol::ErrorString errorString; | 263 std::unique_ptr<protocol::Value> protocolValue; |
284 std::unique_ptr<protocol::Value> protocolValue = | 264 Response response = toProtocolValue(context, r, 1000, protocolValue); |
285 toProtocolValue(&errorString, context, r); | 265 if (!response.isSuccess()) return nullptr; |
286 if (!protocolValue) return nullptr; | |
287 protocol::ErrorSupport errors; | 266 protocol::ErrorSupport errors; |
288 return protocol::Runtime::RemoteObject::parse(protocolValue.get(), &errors); | 267 return protocol::Runtime::RemoteObject::parse(protocolValue.get(), &errors); |
289 } | 268 } |
290 | 269 |
291 bool InjectedScript::findObject(ErrorString* errorString, | 270 Response InjectedScript::findObject(const RemoteObjectId& objectId, |
292 const RemoteObjectId& objectId, | 271 v8::Local<v8::Value>* outObject) const { |
293 v8::Local<v8::Value>* outObject) const { | |
294 *outObject = m_native->objectForId(objectId.id()); | 272 *outObject = m_native->objectForId(objectId.id()); |
295 if (outObject->IsEmpty()) | 273 if (outObject->IsEmpty()) |
296 *errorString = "Could not find object with given id"; | 274 return Response::Error("Could not find object with given id"); |
297 return !outObject->IsEmpty(); | 275 return Response::OK(); |
298 } | 276 } |
299 | 277 |
300 String16 InjectedScript::objectGroupName(const RemoteObjectId& objectId) const { | 278 String16 InjectedScript::objectGroupName(const RemoteObjectId& objectId) const { |
301 return m_native->groupName(objectId.id()); | 279 return m_native->groupName(objectId.id()); |
302 } | 280 } |
303 | 281 |
304 void InjectedScript::releaseObjectGroup(const String16& objectGroup) { | 282 void InjectedScript::releaseObjectGroup(const String16& objectGroup) { |
305 m_native->releaseObjectGroup(objectGroup); | 283 m_native->releaseObjectGroup(objectGroup); |
306 if (objectGroup == "console") m_lastEvaluationResult.Reset(); | 284 if (objectGroup == "console") m_lastEvaluationResult.Reset(); |
307 } | 285 } |
(...skipping 11 matching lines...) Expand all Loading... | |
319 v8::Local<v8::Value> InjectedScript::v8Value() const { | 297 v8::Local<v8::Value> InjectedScript::v8Value() const { |
320 return m_value.Get(m_context->isolate()); | 298 return m_value.Get(m_context->isolate()); |
321 } | 299 } |
322 | 300 |
323 v8::Local<v8::Value> InjectedScript::lastEvaluationResult() const { | 301 v8::Local<v8::Value> InjectedScript::lastEvaluationResult() const { |
324 if (m_lastEvaluationResult.IsEmpty()) | 302 if (m_lastEvaluationResult.IsEmpty()) |
325 return v8::Undefined(m_context->isolate()); | 303 return v8::Undefined(m_context->isolate()); |
326 return m_lastEvaluationResult.Get(m_context->isolate()); | 304 return m_lastEvaluationResult.Get(m_context->isolate()); |
327 } | 305 } |
328 | 306 |
329 v8::MaybeLocal<v8::Value> InjectedScript::resolveCallArgument( | 307 Response InjectedScript::resolveCallArgument( |
330 ErrorString* errorString, protocol::Runtime::CallArgument* callArgument) { | 308 protocol::Runtime::CallArgument* callArgument, |
309 v8::Local<v8::Value>& result) { | |
dgozman
2016/11/02 19:54:00
v8::Local<>*
kozy
2016/11/02 22:45:12
Done.
| |
310 result = v8::Local<v8::Value>(); | |
331 if (callArgument->hasObjectId()) { | 311 if (callArgument->hasObjectId()) { |
332 std::unique_ptr<RemoteObjectId> remoteObjectId = | 312 std::unique_ptr<RemoteObjectId> remoteObjectId; |
333 RemoteObjectId::parse(errorString, callArgument->getObjectId("")); | 313 Response response = |
334 if (!remoteObjectId) return v8::MaybeLocal<v8::Value>(); | 314 RemoteObjectId::parse(callArgument->getObjectId(""), remoteObjectId); |
335 if (remoteObjectId->contextId() != m_context->contextId()) { | 315 if (!response.isSuccess()) return response; |
336 *errorString = | 316 if (remoteObjectId->contextId() != m_context->contextId()) |
317 return Response::Error( | |
337 "Argument should belong to the same JavaScript world as target " | 318 "Argument should belong to the same JavaScript world as target " |
338 "object"; | 319 "object"); |
339 return v8::MaybeLocal<v8::Value>(); | |
340 } | |
341 v8::Local<v8::Value> object; | 320 v8::Local<v8::Value> object; |
342 if (!findObject(errorString, *remoteObjectId, &object)) | 321 response = findObject(*remoteObjectId, &object); |
dgozman
2016/11/02 19:53:59
&object -> result
kozy
2016/11/02 22:45:13
Done.
| |
343 return v8::MaybeLocal<v8::Value>(); | 322 if (!response.isSuccess()) return response; |
344 return object; | 323 result = object; |
324 return Response::OK(); | |
345 } | 325 } |
346 if (callArgument->hasValue() || callArgument->hasUnserializableValue()) { | 326 if (callArgument->hasValue() || callArgument->hasUnserializableValue()) { |
347 String16 value = | 327 String16 value = |
348 callArgument->hasValue() | 328 callArgument->hasValue() |
349 ? callArgument->getValue(nullptr)->toJSONString() | 329 ? callArgument->getValue(nullptr)->toJSONString() |
350 : "Number(\"" + callArgument->getUnserializableValue("") + "\")"; | 330 : "Number(\"" + callArgument->getUnserializableValue("") + "\")"; |
351 v8::Local<v8::Value> object; | 331 v8::Local<v8::Value> object; |
352 if (!m_context->inspector() | 332 if (!m_context->inspector() |
353 ->compileAndRunInternalScript( | 333 ->compileAndRunInternalScript( |
354 m_context->context(), toV8String(m_context->isolate(), value)) | 334 m_context->context(), toV8String(m_context->isolate(), value)) |
355 .ToLocal(&object)) { | 335 .ToLocal(&object)) { |
dgozman
2016/11/02 19:53:59
.ToLocal(result)
kozy
2016/11/02 22:45:13
Done.
| |
356 *errorString = "Couldn't parse value object in call argument"; | 336 return Response::Error("Couldn't parse value object in call argument"); |
357 return v8::MaybeLocal<v8::Value>(); | |
358 } | 337 } |
359 return object; | 338 result = object; |
339 return Response::OK(); | |
360 } | 340 } |
361 return v8::Undefined(m_context->isolate()); | 341 result = v8::Undefined(m_context->isolate()); |
342 return Response::OK(); | |
362 } | 343 } |
363 | 344 |
364 std::unique_ptr<protocol::Runtime::ExceptionDetails> | 345 Response InjectedScript::createExceptionDetails( |
365 InjectedScript::createExceptionDetails(ErrorString* errorString, | 346 const v8::TryCatch& tryCatch, const String16& objectGroup, |
366 const v8::TryCatch& tryCatch, | 347 bool generatePreview, Maybe<protocol::Runtime::ExceptionDetails>& result) { |
367 const String16& objectGroup, | 348 if (!tryCatch.HasCaught()) return Response::InternalError(); |
368 bool generatePreview) { | |
369 if (!tryCatch.HasCaught()) return nullptr; | |
370 v8::Local<v8::Message> message = tryCatch.Message(); | 349 v8::Local<v8::Message> message = tryCatch.Message(); |
371 v8::Local<v8::Value> exception = tryCatch.Exception(); | 350 v8::Local<v8::Value> exception = tryCatch.Exception(); |
372 String16 messageText = | 351 String16 messageText = |
373 message.IsEmpty() ? String16() : toProtocolString(message->Get()); | 352 message.IsEmpty() ? String16() : toProtocolString(message->Get()); |
374 std::unique_ptr<protocol::Runtime::ExceptionDetails> exceptionDetails = | 353 std::unique_ptr<protocol::Runtime::ExceptionDetails> exceptionDetails = |
dgozman
2016/11/02 19:53:59
*result = ...
kozy
2016/11/02 22:45:12
I preferred to store it in separate variable since
| |
375 protocol::Runtime::ExceptionDetails::create() | 354 protocol::Runtime::ExceptionDetails::create() |
376 .setExceptionId(m_context->inspector()->nextExceptionId()) | 355 .setExceptionId(m_context->inspector()->nextExceptionId()) |
377 .setText(exception.IsEmpty() ? messageText : String16("Uncaught")) | 356 .setText(exception.IsEmpty() ? messageText : String16("Uncaught")) |
378 .setLineNumber( | 357 .setLineNumber( |
379 message.IsEmpty() | 358 message.IsEmpty() |
380 ? 0 | 359 ? 0 |
381 : message->GetLineNumber(m_context->context()).FromMaybe(1) - | 360 : message->GetLineNumber(m_context->context()).FromMaybe(1) - |
382 1) | 361 1) |
383 .setColumnNumber( | 362 .setColumnNumber( |
384 message.IsEmpty() | 363 message.IsEmpty() |
385 ? 0 | 364 ? 0 |
386 : message->GetStartColumn(m_context->context()).FromMaybe(0)) | 365 : message->GetStartColumn(m_context->context()).FromMaybe(0)) |
387 .build(); | 366 .build(); |
388 if (!message.IsEmpty()) { | 367 if (!message.IsEmpty()) { |
389 exceptionDetails->setScriptId(String16::fromInteger( | 368 exceptionDetails->setScriptId(String16::fromInteger( |
390 static_cast<int>(message->GetScriptOrigin().ScriptID()->Value()))); | 369 static_cast<int>(message->GetScriptOrigin().ScriptID()->Value()))); |
391 v8::Local<v8::StackTrace> stackTrace = message->GetStackTrace(); | 370 v8::Local<v8::StackTrace> stackTrace = message->GetStackTrace(); |
392 if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0) | 371 if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0) |
393 exceptionDetails->setStackTrace(m_context->inspector() | 372 exceptionDetails->setStackTrace(m_context->inspector() |
394 ->debugger() | 373 ->debugger() |
395 ->createStackTrace(stackTrace) | 374 ->createStackTrace(stackTrace) |
396 ->buildInspectorObjectImpl()); | 375 ->buildInspectorObjectImpl()); |
397 } | 376 } |
398 if (!exception.IsEmpty()) { | 377 if (!exception.IsEmpty()) { |
399 std::unique_ptr<protocol::Runtime::RemoteObject> wrapped = wrapObject( | 378 std::unique_ptr<protocol::Runtime::RemoteObject> wrapped; |
400 errorString, exception, objectGroup, false /* forceValueType */, | 379 Response response = |
401 generatePreview && !exception->IsNativeError()); | 380 wrapObject(exception, objectGroup, false /* forceValueType */, |
402 if (!wrapped) return nullptr; | 381 generatePreview && !exception->IsNativeError(), wrapped); |
382 if (!response.isSuccess()) return response; | |
403 exceptionDetails->setException(std::move(wrapped)); | 383 exceptionDetails->setException(std::move(wrapped)); |
404 } | 384 } |
405 return exceptionDetails; | 385 result = std::move(exceptionDetails); |
386 return Response::OK(); | |
406 } | 387 } |
407 | 388 |
408 void InjectedScript::wrapEvaluateResult( | 389 Response InjectedScript::wrapEvaluateResult( |
409 ErrorString* errorString, v8::MaybeLocal<v8::Value> maybeResultValue, | 390 v8::MaybeLocal<v8::Value> maybeResultValue, const v8::TryCatch& tryCatch, |
410 const v8::TryCatch& tryCatch, const String16& objectGroup, | 391 const String16& objectGroup, bool returnByValue, bool generatePreview, |
411 bool returnByValue, bool generatePreview, | |
412 std::unique_ptr<protocol::Runtime::RemoteObject>* result, | 392 std::unique_ptr<protocol::Runtime::RemoteObject>* result, |
413 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) { | 393 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) { |
414 v8::Local<v8::Value> resultValue; | 394 v8::Local<v8::Value> resultValue; |
415 if (!tryCatch.HasCaught()) { | 395 if (!tryCatch.HasCaught()) { |
416 if (hasInternalError(errorString, !maybeResultValue.ToLocal(&resultValue))) | 396 if (!maybeResultValue.ToLocal(&resultValue)) |
417 return; | 397 return Response::InternalError(); |
418 std::unique_ptr<RemoteObject> remoteObject = wrapObject( | 398 std::unique_ptr<RemoteObject> remoteObject; |
419 errorString, resultValue, objectGroup, returnByValue, generatePreview); | 399 Response response = wrapObject(resultValue, objectGroup, returnByValue, |
420 if (!remoteObject) return; | 400 generatePreview, remoteObject); |
dgozman
2016/11/02 19:53:59
remoteObject -> result
kozy
2016/11/02 22:45:12
Done.
| |
401 if (!response.isSuccess()) return response; | |
421 if (objectGroup == "console") | 402 if (objectGroup == "console") |
422 m_lastEvaluationResult.Reset(m_context->isolate(), resultValue); | 403 m_lastEvaluationResult.Reset(m_context->isolate(), resultValue); |
423 *result = std::move(remoteObject); | 404 *result = std::move(remoteObject); |
424 } else { | 405 } else { |
425 v8::Local<v8::Value> exception = tryCatch.Exception(); | 406 v8::Local<v8::Value> exception = tryCatch.Exception(); |
426 std::unique_ptr<RemoteObject> remoteObject = | 407 std::unique_ptr<RemoteObject> remoteObject; |
427 wrapObject(errorString, exception, objectGroup, false, | 408 Response response = wrapObject( |
428 generatePreview && !exception->IsNativeError()); | 409 exception, objectGroup, false, |
429 if (!remoteObject) return; | 410 generatePreview && !exception->IsNativeError(), remoteObject); |
dgozman
2016/11/02 19:53:59
ditto
kozy
2016/11/02 22:45:12
Done.
| |
411 if (!response.isSuccess()) return response; | |
430 // We send exception in result for compatibility reasons, even though it's | 412 // We send exception in result for compatibility reasons, even though it's |
431 // accessible through exceptionDetails.exception. | 413 // accessible through exceptionDetails.exception. |
432 *result = std::move(remoteObject); | 414 *result = std::move(remoteObject); |
433 *exceptionDetails = createExceptionDetails(errorString, tryCatch, | 415 response = createExceptionDetails(tryCatch, objectGroup, generatePreview, |
434 objectGroup, generatePreview); | 416 *exceptionDetails); |
417 if (!response.isSuccess()) return response; | |
435 } | 418 } |
419 return Response::OK(); | |
436 } | 420 } |
437 | 421 |
438 v8::Local<v8::Object> InjectedScript::commandLineAPI() { | 422 v8::Local<v8::Object> InjectedScript::commandLineAPI() { |
439 if (m_commandLineAPI.IsEmpty()) | 423 if (m_commandLineAPI.IsEmpty()) |
440 m_commandLineAPI.Reset(m_context->isolate(), | 424 m_commandLineAPI.Reset(m_context->isolate(), |
441 V8Console::createCommandLineAPI(m_context)); | 425 V8Console::createCommandLineAPI(m_context)); |
442 return m_commandLineAPI.Get(m_context->isolate()); | 426 return m_commandLineAPI.Get(m_context->isolate()); |
443 } | 427 } |
444 | 428 |
445 InjectedScript::Scope::Scope(ErrorString* errorString, | 429 InjectedScript::Scope::Scope(V8InspectorImpl* inspector, int contextGroupId) |
446 V8InspectorImpl* inspector, int contextGroupId) | 430 : m_inspector(inspector), |
447 : m_errorString(errorString), | |
448 m_inspector(inspector), | |
449 m_contextGroupId(contextGroupId), | 431 m_contextGroupId(contextGroupId), |
450 m_injectedScript(nullptr), | 432 m_injectedScript(nullptr), |
451 m_handleScope(inspector->isolate()), | 433 m_handleScope(inspector->isolate()), |
452 m_tryCatch(inspector->isolate()), | 434 m_tryCatch(inspector->isolate()), |
453 m_ignoreExceptionsAndMuteConsole(false), | 435 m_ignoreExceptionsAndMuteConsole(false), |
454 m_previousPauseOnExceptionsState(v8::DebugInterface::NoBreakOnException), | 436 m_previousPauseOnExceptionsState(v8::DebugInterface::NoBreakOnException), |
455 m_userGesture(false) {} | 437 m_userGesture(false) {} |
456 | 438 |
457 bool InjectedScript::Scope::initialize() { | 439 Response InjectedScript::Scope::initialize() { |
458 cleanup(); | 440 cleanup(); |
459 // TODO(dgozman): what if we reattach to the same context group during | 441 // TODO(dgozman): what if we reattach to the same context group during |
460 // evaluate? Introduce a session id? | 442 // evaluate? Introduce a session id? |
461 V8InspectorSessionImpl* session = | 443 V8InspectorSessionImpl* session = |
462 m_inspector->sessionForContextGroup(m_contextGroupId); | 444 m_inspector->sessionForContextGroup(m_contextGroupId); |
463 if (!session) { | 445 if (!session) return Response::InternalError(); |
464 *m_errorString = "Internal error"; | 446 Response response = findInjectedScript(session); |
465 return false; | 447 if (!response.isSuccess()) return response; |
466 } | |
467 findInjectedScript(session); | |
468 if (!m_injectedScript) return false; | |
469 m_context = m_injectedScript->context()->context(); | 448 m_context = m_injectedScript->context()->context(); |
470 m_context->Enter(); | 449 m_context->Enter(); |
471 return true; | 450 return Response::OK(); |
472 } | 451 } |
473 | 452 |
474 bool InjectedScript::Scope::installCommandLineAPI() { | 453 void InjectedScript::Scope::installCommandLineAPI() { |
475 DCHECK(m_injectedScript && !m_context.IsEmpty() && | 454 DCHECK(m_injectedScript && !m_context.IsEmpty() && |
476 !m_commandLineAPIScope.get()); | 455 !m_commandLineAPIScope.get()); |
477 m_commandLineAPIScope.reset(new V8Console::CommandLineAPIScope( | 456 m_commandLineAPIScope.reset(new V8Console::CommandLineAPIScope( |
478 m_context, m_injectedScript->commandLineAPI(), m_context->Global())); | 457 m_context, m_injectedScript->commandLineAPI(), m_context->Global())); |
479 return true; | |
480 } | 458 } |
481 | 459 |
482 void InjectedScript::Scope::ignoreExceptionsAndMuteConsole() { | 460 void InjectedScript::Scope::ignoreExceptionsAndMuteConsole() { |
483 DCHECK(!m_ignoreExceptionsAndMuteConsole); | 461 DCHECK(!m_ignoreExceptionsAndMuteConsole); |
484 m_ignoreExceptionsAndMuteConsole = true; | 462 m_ignoreExceptionsAndMuteConsole = true; |
485 m_inspector->client()->muteMetrics(m_contextGroupId); | 463 m_inspector->client()->muteMetrics(m_contextGroupId); |
486 m_inspector->muteExceptions(m_contextGroupId); | 464 m_inspector->muteExceptions(m_contextGroupId); |
487 m_previousPauseOnExceptionsState = | 465 m_previousPauseOnExceptionsState = |
488 setPauseOnExceptionsState(v8::DebugInterface::NoBreakOnException); | 466 setPauseOnExceptionsState(v8::DebugInterface::NoBreakOnException); |
489 } | 467 } |
(...skipping 26 matching lines...) Expand all Loading... | |
516 InjectedScript::Scope::~Scope() { | 494 InjectedScript::Scope::~Scope() { |
517 if (m_ignoreExceptionsAndMuteConsole) { | 495 if (m_ignoreExceptionsAndMuteConsole) { |
518 setPauseOnExceptionsState(m_previousPauseOnExceptionsState); | 496 setPauseOnExceptionsState(m_previousPauseOnExceptionsState); |
519 m_inspector->client()->unmuteMetrics(m_contextGroupId); | 497 m_inspector->client()->unmuteMetrics(m_contextGroupId); |
520 m_inspector->unmuteExceptions(m_contextGroupId); | 498 m_inspector->unmuteExceptions(m_contextGroupId); |
521 } | 499 } |
522 if (m_userGesture) m_inspector->client()->endUserGesture(); | 500 if (m_userGesture) m_inspector->client()->endUserGesture(); |
523 cleanup(); | 501 cleanup(); |
524 } | 502 } |
525 | 503 |
526 InjectedScript::ContextScope::ContextScope(ErrorString* errorString, | 504 InjectedScript::ContextScope::ContextScope(V8InspectorImpl* inspector, |
527 V8InspectorImpl* inspector, | |
528 int contextGroupId, | 505 int contextGroupId, |
529 int executionContextId) | 506 int executionContextId) |
530 : InjectedScript::Scope(errorString, inspector, contextGroupId), | 507 : InjectedScript::Scope(inspector, contextGroupId), |
531 m_executionContextId(executionContextId) {} | 508 m_executionContextId(executionContextId) {} |
532 | 509 |
533 InjectedScript::ContextScope::~ContextScope() {} | 510 InjectedScript::ContextScope::~ContextScope() {} |
534 | 511 |
535 void InjectedScript::ContextScope::findInjectedScript( | 512 Response InjectedScript::ContextScope::findInjectedScript( |
536 V8InspectorSessionImpl* session) { | 513 V8InspectorSessionImpl* session) { |
537 m_injectedScript = | 514 return session->findInjectedScript(m_executionContextId, m_injectedScript); |
538 session->findInjectedScript(m_errorString, m_executionContextId); | |
539 } | 515 } |
540 | 516 |
541 InjectedScript::ObjectScope::ObjectScope(ErrorString* errorString, | 517 InjectedScript::ObjectScope::ObjectScope(V8InspectorImpl* inspector, |
542 V8InspectorImpl* inspector, | |
543 int contextGroupId, | 518 int contextGroupId, |
544 const String16& remoteObjectId) | 519 const String16& remoteObjectId) |
545 : InjectedScript::Scope(errorString, inspector, contextGroupId), | 520 : InjectedScript::Scope(inspector, contextGroupId), |
546 m_remoteObjectId(remoteObjectId) {} | 521 m_remoteObjectId(remoteObjectId) {} |
547 | 522 |
548 InjectedScript::ObjectScope::~ObjectScope() {} | 523 InjectedScript::ObjectScope::~ObjectScope() {} |
549 | 524 |
550 void InjectedScript::ObjectScope::findInjectedScript( | 525 Response InjectedScript::ObjectScope::findInjectedScript( |
551 V8InspectorSessionImpl* session) { | 526 V8InspectorSessionImpl* session) { |
552 std::unique_ptr<RemoteObjectId> remoteId = | 527 std::unique_ptr<RemoteObjectId> remoteId; |
553 RemoteObjectId::parse(m_errorString, m_remoteObjectId); | 528 Response response = RemoteObjectId::parse(m_remoteObjectId, remoteId); |
554 if (!remoteId) return; | 529 if (!response.isSuccess()) return response; |
555 InjectedScript* injectedScript = | 530 InjectedScript* injectedScript = nullptr; |
556 session->findInjectedScript(m_errorString, remoteId.get()); | 531 response = session->findInjectedScript(remoteId.get(), injectedScript); |
557 if (!injectedScript) return; | 532 if (!response.isSuccess()) return response; |
558 m_objectGroupName = injectedScript->objectGroupName(*remoteId); | 533 m_objectGroupName = injectedScript->objectGroupName(*remoteId); |
559 if (!injectedScript->findObject(m_errorString, *remoteId, &m_object)) return; | 534 response = injectedScript->findObject(*remoteId, &m_object); |
535 if (!response.isSuccess()) return response; | |
560 m_injectedScript = injectedScript; | 536 m_injectedScript = injectedScript; |
537 return Response::OK(); | |
561 } | 538 } |
562 | 539 |
563 InjectedScript::CallFrameScope::CallFrameScope(ErrorString* errorString, | 540 InjectedScript::CallFrameScope::CallFrameScope(V8InspectorImpl* inspector, |
564 V8InspectorImpl* inspector, | |
565 int contextGroupId, | 541 int contextGroupId, |
566 const String16& remoteObjectId) | 542 const String16& remoteObjectId) |
567 : InjectedScript::Scope(errorString, inspector, contextGroupId), | 543 : InjectedScript::Scope(inspector, contextGroupId), |
568 m_remoteCallFrameId(remoteObjectId) {} | 544 m_remoteCallFrameId(remoteObjectId) {} |
569 | 545 |
570 InjectedScript::CallFrameScope::~CallFrameScope() {} | 546 InjectedScript::CallFrameScope::~CallFrameScope() {} |
571 | 547 |
572 void InjectedScript::CallFrameScope::findInjectedScript( | 548 Response InjectedScript::CallFrameScope::findInjectedScript( |
573 V8InspectorSessionImpl* session) { | 549 V8InspectorSessionImpl* session) { |
574 std::unique_ptr<RemoteCallFrameId> remoteId = | 550 std::unique_ptr<RemoteCallFrameId> remoteId; |
575 RemoteCallFrameId::parse(m_errorString, m_remoteCallFrameId); | 551 Response response = RemoteCallFrameId::parse(m_remoteCallFrameId, remoteId); |
576 if (!remoteId) return; | 552 if (!response.isSuccess()) return response; |
577 m_frameOrdinal = static_cast<size_t>(remoteId->frameOrdinal()); | 553 m_frameOrdinal = static_cast<size_t>(remoteId->frameOrdinal()); |
578 m_injectedScript = session->findInjectedScript(m_errorString, remoteId.get()); | 554 return session->findInjectedScript(remoteId.get(), m_injectedScript); |
579 } | 555 } |
580 | 556 |
581 } // namespace v8_inspector | 557 } // namespace v8_inspector |
OLD | NEW |