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 20 matching lines...) Expand all Loading... |
31 #include "platform/v8_inspector/InjectedScript.h" | 31 #include "platform/v8_inspector/InjectedScript.h" |
32 | 32 |
33 #include "platform/inspector_protocol/Parser.h" | 33 #include "platform/inspector_protocol/Parser.h" |
34 #include "platform/inspector_protocol/String16.h" | 34 #include "platform/inspector_protocol/String16.h" |
35 #include "platform/inspector_protocol/Values.h" | 35 #include "platform/inspector_protocol/Values.h" |
36 #include "platform/v8_inspector/InjectedScriptHost.h" | 36 #include "platform/v8_inspector/InjectedScriptHost.h" |
37 #include "platform/v8_inspector/InjectedScriptManager.h" | 37 #include "platform/v8_inspector/InjectedScriptManager.h" |
38 #include "platform/v8_inspector/RemoteObjectId.h" | 38 #include "platform/v8_inspector/RemoteObjectId.h" |
39 #include "platform/v8_inspector/V8DebuggerImpl.h" | 39 #include "platform/v8_inspector/V8DebuggerImpl.h" |
40 #include "platform/v8_inspector/V8FunctionCall.h" | 40 #include "platform/v8_inspector/V8FunctionCall.h" |
| 41 #include "platform/v8_inspector/V8StackTraceImpl.h" |
41 #include "platform/v8_inspector/V8StringUtil.h" | 42 #include "platform/v8_inspector/V8StringUtil.h" |
42 #include "platform/v8_inspector/public/V8Debugger.h" | 43 #include "platform/v8_inspector/public/V8Debugger.h" |
43 #include "platform/v8_inspector/public/V8DebuggerClient.h" | 44 #include "platform/v8_inspector/public/V8DebuggerClient.h" |
44 #include "platform/v8_inspector/public/V8ToProtocolValue.h" | 45 #include "platform/v8_inspector/public/V8ToProtocolValue.h" |
45 | 46 |
46 using blink::protocol::Array; | 47 using blink::protocol::Array; |
47 using blink::protocol::Debugger::CallFrame; | 48 using blink::protocol::Debugger::CallFrame; |
48 using blink::protocol::Debugger::CollectionEntry; | 49 using blink::protocol::Debugger::CollectionEntry; |
49 using blink::protocol::Debugger::FunctionDetails; | 50 using blink::protocol::Debugger::FunctionDetails; |
50 using blink::protocol::Debugger::GeneratorObjectDetails; | 51 using blink::protocol::Debugger::GeneratorObjectDetails; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 v8::HandleScope handles(m_isolate); | 149 v8::HandleScope handles(m_isolate); |
149 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "callFu
nctionOn"); | 150 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "callFu
nctionOn"); |
150 function.appendArgument(objectId); | 151 function.appendArgument(objectId); |
151 function.appendArgument(expression); | 152 function.appendArgument(expression); |
152 function.appendArgument(arguments); | 153 function.appendArgument(arguments); |
153 function.appendArgument(returnByValue); | 154 function.appendArgument(returnByValue); |
154 function.appendArgument(generatePreview); | 155 function.appendArgument(generatePreview); |
155 *result = makeEvalCall(errorString, function, wasThrown); | 156 *result = makeEvalCall(errorString, function, wasThrown); |
156 } | 157 } |
157 | 158 |
158 void InjectedScript::evaluateOnCallFrame(ErrorString* errorString, v8::Local<v8:
:Object> callFrames, const String16& callFrameId, const String16& expression, co
nst String16& objectGroup, bool includeCommandLineAPI, bool returnByValue, bool
generatePreview, OwnPtr<RemoteObject>* result, Maybe<bool>* wasThrown, Maybe<pro
tocol::Runtime::ExceptionDetails>* exceptionDetails) | |
159 { | |
160 v8::HandleScope handles(m_isolate); | |
161 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "evalua
teOnCallFrame"); | |
162 function.appendArgument(callFrames); | |
163 function.appendArgument(callFrameId); | |
164 function.appendArgument(expression); | |
165 function.appendArgument(objectGroup); | |
166 function.appendArgument(includeCommandLineAPI); | |
167 function.appendArgument(returnByValue); | |
168 function.appendArgument(generatePreview); | |
169 *result = makeEvalCall(errorString, function, wasThrown, exceptionDetails); | |
170 } | |
171 | |
172 void InjectedScript::getFunctionDetails(ErrorString* errorString, const String16
& functionId, OwnPtr<FunctionDetails>* result) | 159 void InjectedScript::getFunctionDetails(ErrorString* errorString, const String16
& functionId, OwnPtr<FunctionDetails>* result) |
173 { | 160 { |
174 v8::HandleScope handles(m_isolate); | 161 v8::HandleScope handles(m_isolate); |
175 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "getFun
ctionDetails"); | 162 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "getFun
ctionDetails"); |
176 function.appendArgument(functionId); | 163 function.appendArgument(functionId); |
177 OwnPtr<protocol::Value> resultValue = makeCall(function); | 164 OwnPtr<protocol::Value> resultValue = makeCall(function); |
178 protocol::ErrorSupport errors(errorString); | 165 protocol::ErrorSupport errors(errorString); |
179 *result = FunctionDetails::parse(resultValue.get(), &errors); | 166 *result = FunctionDetails::parse(resultValue.get(), &errors); |
180 } | 167 } |
181 | 168 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 return; | 217 return; |
231 protocol::DictionaryValue* object = protocol::DictionaryValue::cast(parsedOb
jectId.get()); | 218 protocol::DictionaryValue* object = protocol::DictionaryValue::cast(parsedOb
jectId.get()); |
232 if (!object) | 219 if (!object) |
233 return; | 220 return; |
234 int boundId = 0; | 221 int boundId = 0; |
235 if (!object->getNumber("id", &boundId)) | 222 if (!object->getNumber("id", &boundId)) |
236 return; | 223 return; |
237 m_native->unbind(boundId); | 224 m_native->unbind(boundId); |
238 } | 225 } |
239 | 226 |
240 v8::MaybeLocal<v8::Value> InjectedScript::runCompiledScript(v8::Local<v8::Script
> script, bool includeCommandLineAPI) | |
241 { | |
242 v8::Local<v8::Symbol> commandLineAPISymbolValue = V8Debugger::commandLineAPI
Symbol(m_isolate); | |
243 v8::Local<v8::Object> global = context()->Global(); | |
244 if (includeCommandLineAPI) { | |
245 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "co
mmandLineAPI"); | |
246 bool hadException = false; | |
247 v8::Local<v8::Value> commandLineAPI = function.call(hadException, false)
; | |
248 if (!hadException) | |
249 global->Set(commandLineAPISymbolValue, commandLineAPI); | |
250 } | |
251 | |
252 v8::MaybeLocal<v8::Value> maybeValue = m_manager->debugger()->runCompiledScr
ipt(context(), script); | |
253 if (includeCommandLineAPI) | |
254 global->Delete(context(), commandLineAPISymbolValue); | |
255 | |
256 return maybeValue; | |
257 } | |
258 | |
259 PassOwnPtr<Array<CallFrame>> InjectedScript::wrapCallFrames(v8::Local<v8::Object
> callFrames) | 227 PassOwnPtr<Array<CallFrame>> InjectedScript::wrapCallFrames(v8::Local<v8::Object
> callFrames) |
260 { | 228 { |
261 v8::HandleScope handles(m_isolate); | 229 v8::HandleScope handles(m_isolate); |
262 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "wrapCa
llFrames"); | 230 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "wrapCa
llFrames"); |
263 function.appendArgument(callFrames); | 231 function.appendArgument(callFrames); |
264 bool hadException = false; | 232 bool hadException = false; |
265 v8::Local<v8::Value> callFramesValue = callFunctionWithEvalEnabled(function,
hadException); | 233 v8::Local<v8::Value> callFramesValue = callFunctionWithEvalEnabled(function,
hadException); |
266 ASSERT(!hadException); | 234 ASSERT(!hadException); |
267 OwnPtr<protocol::Value> result = toProtocolValue(context(), callFramesValue)
; | 235 OwnPtr<protocol::Value> result = toProtocolValue(context(), callFramesValue)
; |
268 protocol::ErrorSupport errors; | 236 protocol::ErrorSupport errors; |
269 if (result && result->type() == protocol::Value::TypeArray) | 237 if (result && result->type() == protocol::Value::TypeArray) |
270 return Array<CallFrame>::parse(result.get(), &errors); | 238 return Array<CallFrame>::parse(result.get(), &errors); |
271 return Array<CallFrame>::create(); | 239 return Array<CallFrame>::create(); |
272 } | 240 } |
273 | 241 |
274 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapObject(v8::Local
<v8::Value> value, const String16& groupName, bool generatePreview) const | 242 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapObject(ErrorStri
ng* errorString, v8::Local<v8::Value> value, const String16& groupName, bool for
ceValueType, bool generatePreview) const |
275 { | 243 { |
276 v8::HandleScope handles(m_isolate); | 244 v8::HandleScope handles(m_isolate); |
277 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "wrapOb
ject"); | 245 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "wrapOb
ject"); |
278 v8::Local<v8::Value> wrappedObject; | 246 v8::Local<v8::Value> wrappedObject; |
279 ErrorString errorString; | 247 if (!wrapValue(errorString, value, groupName, forceValueType, generatePrevie
w).ToLocal(&wrappedObject)) |
280 if (!wrapValue(&errorString, value, groupName, generatePreview).ToLocal(&wra
ppedObject)) | |
281 return nullptr; | 248 return nullptr; |
282 protocol::ErrorSupport errors; | 249 protocol::ErrorSupport errors; |
283 return protocol::Runtime::RemoteObject::parse(toProtocolValue(context(), wra
ppedObject).get(), &errors); | 250 OwnPtr<protocol::Runtime::RemoteObject> remoteObject = protocol::Runtime::Re
moteObject::parse(toProtocolValue(context(), wrappedObject).get(), &errors); |
| 251 if (!remoteObject) |
| 252 *errorString = "Object has too long reference chain"; |
| 253 return remoteObject.release(); |
284 } | 254 } |
285 | 255 |
286 bool InjectedScript::wrapObjectProperty(ErrorString* error, v8::Local<v8::Object
> object, v8::Local<v8::Value> key, const String16& groupName, bool generatePrev
iew) const | 256 bool InjectedScript::wrapObjectProperty(ErrorString* error, v8::Local<v8::Object
> object, v8::Local<v8::Value> key, const String16& groupName, bool forceValueTy
pe, bool generatePreview) const |
287 { | 257 { |
288 v8::Local<v8::Value> property; | 258 v8::Local<v8::Value> property; |
289 if (!object->Get(context(), key).ToLocal(&property)) { | 259 if (!object->Get(context(), key).ToLocal(&property)) { |
290 *error = "Internal error."; | 260 *error = "Internal error."; |
291 return false; | 261 return false; |
292 } | 262 } |
293 v8::Local<v8::Value> wrappedProperty; | 263 v8::Local<v8::Value> wrappedProperty; |
294 if (!wrapValue(error, property, groupName, generatePreview).ToLocal(&wrapped
Property)) | 264 if (!wrapValue(error, property, groupName, forceValueType, generatePreview).
ToLocal(&wrappedProperty)) |
295 return false; | 265 return false; |
296 v8::Maybe<bool> success = object->Set(context(), key, wrappedProperty); | 266 v8::Maybe<bool> success = object->Set(context(), key, wrappedProperty); |
297 if (success.IsNothing() || !success.FromJust()) { | 267 if (success.IsNothing() || !success.FromJust()) { |
298 *error = "Internal error."; | 268 *error = "Internal error."; |
299 return false; | 269 return false; |
300 } | 270 } |
301 return true; | 271 return true; |
302 } | 272 } |
303 | 273 |
304 v8::MaybeLocal<v8::Value> InjectedScript::wrapValue(ErrorString* error, v8::Loca
l<v8::Value> value, const String16& groupName, bool generatePreview) const | 274 v8::MaybeLocal<v8::Value> InjectedScript::wrapValue(ErrorString* error, v8::Loca
l<v8::Value> value, const String16& groupName, bool forceValueType, bool generat
ePreview) const |
305 { | 275 { |
306 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "wrapOb
ject"); | 276 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "wrapOb
ject"); |
307 function.appendArgument(value); | 277 function.appendArgument(value); |
308 function.appendArgument(groupName); | 278 function.appendArgument(groupName); |
309 function.appendArgument(canAccessInspectedWindow()); | 279 function.appendArgument(canAccessInspectedWindow()); |
| 280 function.appendArgument(forceValueType); |
310 function.appendArgument(generatePreview); | 281 function.appendArgument(generatePreview); |
311 bool hadException = false; | 282 bool hadException = false; |
312 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException)
; | 283 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException)
; |
313 if (hadException) { | 284 if (hadException) { |
314 *error = "Internal error."; | 285 *error = "Internal error."; |
315 return v8::MaybeLocal<v8::Value>(); | 286 return v8::MaybeLocal<v8::Value>(); |
316 } | 287 } |
317 return r; | 288 return r; |
318 } | 289 } |
319 | 290 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 result = protocol::StringValue::create("Object has too long referenc
e chain"); | 440 result = protocol::StringValue::create("Object has too long referenc
e chain"); |
470 } | 441 } |
471 return result.release(); | 442 return result.release(); |
472 } | 443 } |
473 | 444 |
474 void InjectedScript::dispose() | 445 void InjectedScript::dispose() |
475 { | 446 { |
476 m_manager->discardInjectedScript(m_contextId); | 447 m_manager->discardInjectedScript(m_contextId); |
477 } | 448 } |
478 | 449 |
| 450 bool InjectedScript::setLastEvaluationResult(ErrorString* errorString, v8::Local
<v8::Value> value) |
| 451 { |
| 452 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "setLas
tEvaluationResult"); |
| 453 function.appendArgument(value); |
| 454 bool hadException = false; |
| 455 function.call(hadException, false); |
| 456 if (hadException) |
| 457 *errorString = "Internal error"; |
| 458 return !hadException; |
| 459 } |
| 460 |
479 v8::MaybeLocal<v8::Value> InjectedScript::resolveCallArgument(ErrorString* error
String, protocol::Runtime::CallArgument* callArgument) | 461 v8::MaybeLocal<v8::Value> InjectedScript::resolveCallArgument(ErrorString* error
String, protocol::Runtime::CallArgument* callArgument) |
480 { | 462 { |
481 if (callArgument->hasObjectId()) { | 463 if (callArgument->hasObjectId()) { |
482 OwnPtr<RemoteObjectId> remoteObjectId = RemoteObjectId::parse(errorStrin
g, callArgument->getObjectId("")); | 464 OwnPtr<RemoteObjectId> remoteObjectId = RemoteObjectId::parse(errorStrin
g, callArgument->getObjectId("")); |
483 if (!remoteObjectId) | 465 if (!remoteObjectId) |
484 return v8::MaybeLocal<v8::Value>(); | 466 return v8::MaybeLocal<v8::Value>(); |
485 if (remoteObjectId->contextId() != m_contextId) { | 467 if (remoteObjectId->contextId() != m_contextId) { |
486 *errorString = "Argument should belong to the same JavaScript world
as target object"; | 468 *errorString = "Argument should belong to the same JavaScript world
as target object"; |
487 return v8::MaybeLocal<v8::Value>(); | 469 return v8::MaybeLocal<v8::Value>(); |
488 } | 470 } |
(...skipping 11 matching lines...) Expand all Loading... |
500 v8::Local<v8::Value> object; | 482 v8::Local<v8::Value> object; |
501 if (!m_manager->debugger()->compileAndRunInternalScript(context(), toV8S
tring(m_isolate, value)).ToLocal(&object)) { | 483 if (!m_manager->debugger()->compileAndRunInternalScript(context(), toV8S
tring(m_isolate, value)).ToLocal(&object)) { |
502 *errorString = "Couldn't parse value object in call argument"; | 484 *errorString = "Couldn't parse value object in call argument"; |
503 return v8::MaybeLocal<v8::Value>(); | 485 return v8::MaybeLocal<v8::Value>(); |
504 } | 486 } |
505 return object; | 487 return object; |
506 } | 488 } |
507 return v8::Undefined(m_isolate); | 489 return v8::Undefined(m_isolate); |
508 } | 490 } |
509 | 491 |
| 492 v8::MaybeLocal<v8::Object> InjectedScript::commandLineAPI(ErrorString* errorStri
ng) |
| 493 { |
| 494 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "comman
dLineAPI"); |
| 495 bool hadException = false; |
| 496 v8::Local<v8::Value> scopeExtensionValue = function.call(hadException, false
); |
| 497 v8::Local<v8::Object> scopeExtensionObject; |
| 498 if (hadException || scopeExtensionValue.IsEmpty() || !scopeExtensionValue->T
oObject(context()).ToLocal(&scopeExtensionObject)) { |
| 499 *errorString = "Internal error"; |
| 500 return v8::MaybeLocal<v8::Object>(); |
| 501 } |
| 502 return scopeExtensionObject; |
| 503 } |
| 504 |
| 505 PassOwnPtr<protocol::Runtime::ExceptionDetails> InjectedScript::createExceptionD
etails(v8::Local<v8::Message> message) |
| 506 { |
| 507 OwnPtr<protocol::Runtime::ExceptionDetails> exceptionDetailsObject = protoco
l::Runtime::ExceptionDetails::create().setText(toProtocolString(message->Get()))
.build(); |
| 508 exceptionDetailsObject->setUrl(toProtocolStringWithTypeCheck(message->GetScr
iptResourceName())); |
| 509 exceptionDetailsObject->setScriptId(String16::number(message->GetScriptOrigi
n().ScriptID()->Value())); |
| 510 |
| 511 v8::Maybe<int> lineNumber = message->GetLineNumber(context()); |
| 512 if (lineNumber.IsJust()) |
| 513 exceptionDetailsObject->setLine(lineNumber.FromJust()); |
| 514 v8::Maybe<int> columnNumber = message->GetStartColumn(context()); |
| 515 if (columnNumber.IsJust()) |
| 516 exceptionDetailsObject->setColumn(columnNumber.FromJust()); |
| 517 |
| 518 v8::Local<v8::StackTrace> stackTrace = message->GetStackTrace(); |
| 519 if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0) |
| 520 exceptionDetailsObject->setStack(m_manager->debugger()->createStackTrace
(stackTrace, stackTrace->GetFrameCount())->buildInspectorObject()); |
| 521 return exceptionDetailsObject.release(); |
| 522 } |
| 523 |
| 524 void InjectedScript::wrapEvaluateResult(ErrorString* errorString, v8::MaybeLocal
<v8::Value> maybeResultValue, const v8::TryCatch& tryCatch, const String16& obje
ctGroup, bool returnByValue, bool generatePreview, OwnPtr<protocol::Runtime::Rem
oteObject>* result, Maybe<bool>* wasThrown, Maybe<protocol::Runtime::ExceptionDe
tails>* exceptionDetails) |
| 525 { |
| 526 v8::Local<v8::Value> resultValue; |
| 527 if (!tryCatch.HasCaught()) { |
| 528 if (!maybeResultValue.ToLocal(&resultValue)) { |
| 529 *errorString = "Internal error"; |
| 530 return; |
| 531 } |
| 532 OwnPtr<RemoteObject> remoteObject = wrapObject(errorString, resultValue,
objectGroup, returnByValue, generatePreview); |
| 533 if (!remoteObject) |
| 534 return; |
| 535 if (objectGroup == "console" && !setLastEvaluationResult(errorString, re
sultValue)) |
| 536 return; |
| 537 *result = remoteObject.release(); |
| 538 *wasThrown = false; |
| 539 } else { |
| 540 v8::Local<v8::Value> exception = tryCatch.Exception(); |
| 541 OwnPtr<RemoteObject> remoteObject = wrapObject(errorString, exception, o
bjectGroup, false, generatePreview && !exception->IsNativeError()); |
| 542 if (!remoteObject) |
| 543 return; |
| 544 *result = remoteObject.release(); |
| 545 *exceptionDetails = createExceptionDetails(tryCatch.Message()); |
| 546 *wasThrown = true; |
| 547 } |
| 548 } |
| 549 |
510 } // namespace blink | 550 } // namespace blink |
OLD | NEW |