| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 , m_native(injectedScriptNative) | 69 , m_native(injectedScriptNative) |
| 70 , m_contextId(contextId) | 70 , m_contextId(contextId) |
| 71 { | 71 { |
| 72 m_context.SetWeak(this, &weakCallback, v8::WeakCallbackType::kParameter); | 72 m_context.SetWeak(this, &weakCallback, v8::WeakCallbackType::kParameter); |
| 73 } | 73 } |
| 74 | 74 |
| 75 InjectedScript::~InjectedScript() | 75 InjectedScript::~InjectedScript() |
| 76 { | 76 { |
| 77 } | 77 } |
| 78 | 78 |
| 79 void InjectedScript::callFunctionOn(ErrorString* errorString, const String16& ob
jectId, const String16& expression, const String16& arguments, bool returnByValu
e, bool generatePreview, OwnPtr<protocol::Runtime::RemoteObject>* result, Maybe<
bool>* wasThrown) | |
| 80 { | |
| 81 v8::HandleScope handles(m_isolate); | |
| 82 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "callFu
nctionOn"); | |
| 83 function.appendArgument(objectId); | |
| 84 function.appendArgument(expression); | |
| 85 function.appendArgument(arguments); | |
| 86 function.appendArgument(returnByValue); | |
| 87 function.appendArgument(generatePreview); | |
| 88 *result = makeEvalCall(errorString, function, wasThrown); | |
| 89 } | |
| 90 | |
| 91 void InjectedScript::getFunctionDetails(ErrorString* errorString, const String16
& functionId, OwnPtr<FunctionDetails>* result) | 79 void InjectedScript::getFunctionDetails(ErrorString* errorString, const String16
& functionId, OwnPtr<FunctionDetails>* result) |
| 92 { | 80 { |
| 93 v8::HandleScope handles(m_isolate); | 81 v8::HandleScope handles(m_isolate); |
| 94 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "getFun
ctionDetails"); | 82 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "getFun
ctionDetails"); |
| 95 function.appendArgument(functionId); | 83 function.appendArgument(functionId); |
| 96 OwnPtr<protocol::Value> resultValue = makeCall(function); | 84 OwnPtr<protocol::Value> resultValue = makeCall(function); |
| 97 protocol::ErrorSupport errors(errorString); | 85 protocol::ErrorSupport errors(errorString); |
| 98 *result = FunctionDetails::parse(resultValue.get(), &errors); | 86 *result = FunctionDetails::parse(resultValue.get(), &errors); |
| 99 } | 87 } |
| 100 | 88 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 if (!hadException) { | 303 if (!hadException) { |
| 316 result = toProtocolValue(function.context(), resultValue); | 304 result = toProtocolValue(function.context(), resultValue); |
| 317 if (!result) | 305 if (!result) |
| 318 result = protocol::StringValue::create("Object has too long referenc
e chain"); | 306 result = protocol::StringValue::create("Object has too long referenc
e chain"); |
| 319 } else { | 307 } else { |
| 320 result = protocol::StringValue::create("Exception while making a call.")
; | 308 result = protocol::StringValue::create("Exception while making a call.")
; |
| 321 } | 309 } |
| 322 return result.release(); | 310 return result.release(); |
| 323 } | 311 } |
| 324 | 312 |
| 325 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::makeEvalCall(ErrorSt
ring* errorString, V8FunctionCall& function, Maybe<bool>* wasThrown) | |
| 326 { | |
| 327 OwnPtr<protocol::Value> result = makeCall(function); | |
| 328 if (!result) { | |
| 329 *errorString = "Internal error: result value is empty"; | |
| 330 return nullptr; | |
| 331 } | |
| 332 if (result->type() == protocol::Value::TypeString) { | |
| 333 result->asString(errorString); | |
| 334 ASSERT(errorString->length()); | |
| 335 return nullptr; | |
| 336 } | |
| 337 protocol::DictionaryValue* resultPair = protocol::DictionaryValue::cast(resu
lt.get()); | |
| 338 if (!resultPair) { | |
| 339 *errorString = "Internal error: result is not an Object"; | |
| 340 return nullptr; | |
| 341 } | |
| 342 protocol::DictionaryValue* resultObj = resultPair->getObject("result"); | |
| 343 bool wasThrownVal = false; | |
| 344 if (!resultObj || !resultPair->getBoolean("wasThrown", &wasThrownVal)) { | |
| 345 *errorString = "Internal error: result is not a pair of value and wasThr
own flag"; | |
| 346 return nullptr; | |
| 347 } | |
| 348 protocol::ErrorSupport errors(errorString); | |
| 349 *wasThrown = wasThrownVal; | |
| 350 return protocol::Runtime::RemoteObject::parse(resultObj, &errors); | |
| 351 } | |
| 352 | |
| 353 PassOwnPtr<protocol::Value> InjectedScript::makeCallWithExceptionDetails(V8Funct
ionCall& function, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) | 313 PassOwnPtr<protocol::Value> InjectedScript::makeCallWithExceptionDetails(V8Funct
ionCall& function, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) |
| 354 { | 314 { |
| 355 OwnPtr<protocol::Value> result; | 315 OwnPtr<protocol::Value> result; |
| 356 v8::HandleScope handles(m_isolate); | 316 v8::HandleScope handles(m_isolate); |
| 357 v8::Context::Scope scope(context()); | 317 v8::Context::Scope scope(context()); |
| 358 v8::TryCatch tryCatch(m_isolate); | 318 v8::TryCatch tryCatch(m_isolate); |
| 359 v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling(); | 319 v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling(); |
| 360 if (tryCatch.HasCaught()) { | 320 if (tryCatch.HasCaught()) { |
| 361 v8::Local<v8::Message> message = tryCatch.Message(); | 321 v8::Local<v8::Message> message = tryCatch.Message(); |
| 362 String16 text = !message.IsEmpty() ? toProtocolStringWithTypeCheck(messa
ge->Get()) : "Internal error"; | 322 String16 text = !message.IsEmpty() ? toProtocolStringWithTypeCheck(messa
ge->Get()) : "Internal error"; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 v8::Local<v8::Value> object; | 369 v8::Local<v8::Value> object; |
| 410 if (!m_manager->debugger()->compileAndRunInternalScript(context(), toV8S
tring(m_isolate, value)).ToLocal(&object)) { | 370 if (!m_manager->debugger()->compileAndRunInternalScript(context(), toV8S
tring(m_isolate, value)).ToLocal(&object)) { |
| 411 *errorString = "Couldn't parse value object in call argument"; | 371 *errorString = "Couldn't parse value object in call argument"; |
| 412 return v8::MaybeLocal<v8::Value>(); | 372 return v8::MaybeLocal<v8::Value>(); |
| 413 } | 373 } |
| 414 return object; | 374 return object; |
| 415 } | 375 } |
| 416 return v8::Undefined(m_isolate); | 376 return v8::Undefined(m_isolate); |
| 417 } | 377 } |
| 418 | 378 |
| 419 v8::MaybeLocal<v8::Object> InjectedScript::commandLineAPI(ErrorString* errorStri
ng) | 379 v8::MaybeLocal<v8::Object> InjectedScript::commandLineAPI(ErrorString* errorStri
ng) const |
| 420 { | 380 { |
| 421 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "comman
dLineAPI"); | 381 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "comman
dLineAPI"); |
| 382 return callFunctionReturnObject(errorString, function); |
| 383 } |
| 384 |
| 385 v8::MaybeLocal<v8::Object> InjectedScript::remoteObjectAPI(ErrorString* errorStr
ing, const String16& groupName) const |
| 386 { |
| 387 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "remote
ObjectAPI"); |
| 388 function.appendArgument(groupName); |
| 389 return callFunctionReturnObject(errorString, function); |
| 390 } |
| 391 |
| 392 v8::MaybeLocal<v8::Object> InjectedScript::callFunctionReturnObject(ErrorString*
errorString, V8FunctionCall& function) const |
| 393 { |
| 422 bool hadException = false; | 394 bool hadException = false; |
| 423 v8::Local<v8::Value> scopeExtensionValue = function.call(hadException, false
); | 395 v8::Local<v8::Value> result = function.call(hadException, false); |
| 424 v8::Local<v8::Object> scopeExtensionObject; | 396 v8::Local<v8::Object> resultObject; |
| 425 if (hadException || scopeExtensionValue.IsEmpty() || !scopeExtensionValue->T
oObject(context()).ToLocal(&scopeExtensionObject)) { | 397 if (hadException || result.IsEmpty() || !result->ToObject(context()).ToLocal
(&resultObject)) { |
| 426 *errorString = "Internal error"; | 398 *errorString = "Internal error"; |
| 427 return v8::MaybeLocal<v8::Object>(); | 399 return v8::MaybeLocal<v8::Object>(); |
| 428 } | 400 } |
| 429 return scopeExtensionObject; | 401 return resultObject; |
| 430 } | 402 } |
| 431 | 403 |
| 432 PassOwnPtr<protocol::Runtime::ExceptionDetails> InjectedScript::createExceptionD
etails(v8::Local<v8::Message> message) | 404 PassOwnPtr<protocol::Runtime::ExceptionDetails> InjectedScript::createExceptionD
etails(v8::Local<v8::Message> message) |
| 433 { | 405 { |
| 434 OwnPtr<protocol::Runtime::ExceptionDetails> exceptionDetailsObject = protoco
l::Runtime::ExceptionDetails::create().setText(toProtocolString(message->Get()))
.build(); | 406 OwnPtr<protocol::Runtime::ExceptionDetails> exceptionDetailsObject = protoco
l::Runtime::ExceptionDetails::create().setText(toProtocolString(message->Get()))
.build(); |
| 435 exceptionDetailsObject->setUrl(toProtocolStringWithTypeCheck(message->GetScr
iptResourceName())); | 407 exceptionDetailsObject->setUrl(toProtocolStringWithTypeCheck(message->GetScr
iptResourceName())); |
| 436 exceptionDetailsObject->setScriptId(String16::number(message->GetScriptOrigi
n().ScriptID()->Value())); | 408 exceptionDetailsObject->setScriptId(String16::number(message->GetScriptOrigi
n().ScriptID()->Value())); |
| 437 | 409 |
| 438 v8::Maybe<int> lineNumber = message->GetLineNumber(context()); | 410 v8::Maybe<int> lineNumber = message->GetLineNumber(context()); |
| 439 if (lineNumber.IsJust()) | 411 if (lineNumber.IsJust()) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 463 return; | 435 return; |
| 464 *result = remoteObject.release(); | 436 *result = remoteObject.release(); |
| 465 if (wasThrown) | 437 if (wasThrown) |
| 466 *wasThrown = false; | 438 *wasThrown = false; |
| 467 } else { | 439 } else { |
| 468 v8::Local<v8::Value> exception = tryCatch.Exception(); | 440 v8::Local<v8::Value> exception = tryCatch.Exception(); |
| 469 OwnPtr<RemoteObject> remoteObject = wrapObject(errorString, exception, o
bjectGroup, false, generatePreview && !exception->IsNativeError()); | 441 OwnPtr<RemoteObject> remoteObject = wrapObject(errorString, exception, o
bjectGroup, false, generatePreview && !exception->IsNativeError()); |
| 470 if (!remoteObject) | 442 if (!remoteObject) |
| 471 return; | 443 return; |
| 472 *result = remoteObject.release(); | 444 *result = remoteObject.release(); |
| 473 *exceptionDetails = createExceptionDetails(tryCatch.Message()); | 445 if (exceptionDetails) |
| 446 *exceptionDetails = createExceptionDetails(tryCatch.Message()); |
| 474 if (wasThrown) | 447 if (wasThrown) |
| 475 *wasThrown = true; | 448 *wasThrown = true; |
| 476 } | 449 } |
| 477 } | 450 } |
| 478 | 451 |
| 479 } // namespace blink | 452 } // namespace blink |
| OLD | NEW |