| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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) |
| 420 { | 380 { |
| 421 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "comman
dLineAPI"); | 381 return callFunctionWithoutArguments(errorString, "commandLineAPI"); |
| 382 } |
| 383 |
| 384 v8::MaybeLocal<v8::Object> InjectedScript::remoteObjectAPI(ErrorString* errorStr
ing) |
| 385 { |
| 386 return callFunctionWithoutArguments(errorString, "remoteObjectAPI"); |
| 387 } |
| 388 |
| 389 v8::MaybeLocal<v8::Object> InjectedScript::callFunctionWithoutArguments(ErrorStr
ing* errorString, const String16& name) |
| 390 { |
| 391 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), name); |
| 422 bool hadException = false; | 392 bool hadException = false; |
| 423 v8::Local<v8::Value> scopeExtensionValue = function.call(hadException, false
); | 393 v8::Local<v8::Value> scopeExtensionValue = function.call(hadException, false
); |
| 424 v8::Local<v8::Object> scopeExtensionObject; | 394 v8::Local<v8::Object> scopeExtensionObject; |
| 425 if (hadException || scopeExtensionValue.IsEmpty() || !scopeExtensionValue->T
oObject(context()).ToLocal(&scopeExtensionObject)) { | 395 if (hadException || scopeExtensionValue.IsEmpty() || !scopeExtensionValue->T
oObject(context()).ToLocal(&scopeExtensionObject)) { |
| 426 *errorString = "Internal error"; | 396 *errorString = "Internal error"; |
| 427 return v8::MaybeLocal<v8::Object>(); | 397 return v8::MaybeLocal<v8::Object>(); |
| 428 } | 398 } |
| 429 return scopeExtensionObject; | 399 return scopeExtensionObject; |
| 430 } | 400 } |
| 431 | 401 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 return; | 433 return; |
| 464 *result = remoteObject.release(); | 434 *result = remoteObject.release(); |
| 465 if (wasThrown) | 435 if (wasThrown) |
| 466 *wasThrown = false; | 436 *wasThrown = false; |
| 467 } else { | 437 } else { |
| 468 v8::Local<v8::Value> exception = tryCatch.Exception(); | 438 v8::Local<v8::Value> exception = tryCatch.Exception(); |
| 469 OwnPtr<RemoteObject> remoteObject = wrapObject(errorString, exception, o
bjectGroup, false, generatePreview && !exception->IsNativeError()); | 439 OwnPtr<RemoteObject> remoteObject = wrapObject(errorString, exception, o
bjectGroup, false, generatePreview && !exception->IsNativeError()); |
| 470 if (!remoteObject) | 440 if (!remoteObject) |
| 471 return; | 441 return; |
| 472 *result = remoteObject.release(); | 442 *result = remoteObject.release(); |
| 473 *exceptionDetails = createExceptionDetails(tryCatch.Message()); | 443 if (exceptionDetails) |
| 444 *exceptionDetails = createExceptionDetails(tryCatch.Message()); |
| 474 if (wasThrown) | 445 if (wasThrown) |
| 475 *wasThrown = true; | 446 *wasThrown = true; |
| 476 } | 447 } |
| 477 } | 448 } |
| 478 | 449 |
| 479 } // namespace blink | 450 } // namespace blink |
| OLD | NEW |