| 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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 return !outObject->IsEmpty(); | 259 return !outObject->IsEmpty(); |
| 260 } | 260 } |
| 261 | 261 |
| 262 String16 InjectedScript::objectGroupName(const RemoteObjectId& objectId) const | 262 String16 InjectedScript::objectGroupName(const RemoteObjectId& objectId) const |
| 263 { | 263 { |
| 264 return m_native->groupName(objectId.id()); | 264 return m_native->groupName(objectId.id()); |
| 265 } | 265 } |
| 266 | 266 |
| 267 void InjectedScript::releaseObjectGroup(const String16& objectGroup) | 267 void InjectedScript::releaseObjectGroup(const String16& objectGroup) |
| 268 { | 268 { |
| 269 v8::HandleScope handles(m_context->isolate()); | |
| 270 m_native->releaseObjectGroup(objectGroup); | 269 m_native->releaseObjectGroup(objectGroup); |
| 271 if (objectGroup == "console") { | 270 if (objectGroup == "console") |
| 272 V8FunctionCall function(m_context->debugger(), m_context->context(), v8V
alue(), "clearLastEvaluationResult"); | 271 m_lastEvaluationResult.Reset(); |
| 273 bool hadException = false; | |
| 274 function.call(hadException); | |
| 275 ASSERT(!hadException); | |
| 276 } | |
| 277 } | 272 } |
| 278 | 273 |
| 279 void InjectedScript::setCustomObjectFormatterEnabled(bool enabled) | 274 void InjectedScript::setCustomObjectFormatterEnabled(bool enabled) |
| 280 { | 275 { |
| 281 v8::HandleScope handles(m_context->isolate()); | 276 v8::HandleScope handles(m_context->isolate()); |
| 282 V8FunctionCall function(m_context->debugger(), m_context->context(), v8Value
(), "setCustomObjectFormatterEnabled"); | 277 V8FunctionCall function(m_context->debugger(), m_context->context(), v8Value
(), "setCustomObjectFormatterEnabled"); |
| 283 function.appendArgument(enabled); | 278 function.appendArgument(enabled); |
| 284 bool hadException = false; | 279 bool hadException = false; |
| 285 function.call(hadException); | 280 function.call(hadException); |
| 286 ASSERT(!hadException); | 281 ASSERT(!hadException); |
| 287 } | 282 } |
| 288 | 283 |
| 289 bool InjectedScript::canAccessInspectedWindow() const | 284 bool InjectedScript::canAccessInspectedWindow() const |
| 290 { | 285 { |
| 291 v8::Local<v8::Context> callingContext = m_context->isolate()->GetCallingCont
ext(); | 286 v8::Local<v8::Context> callingContext = m_context->isolate()->GetCallingCont
ext(); |
| 292 if (callingContext.IsEmpty()) | 287 if (callingContext.IsEmpty()) |
| 293 return true; | 288 return true; |
| 294 return m_context->debugger()->client()->callingContextCanAccessContext(calli
ngContext, m_context->context()); | 289 return m_context->debugger()->client()->callingContextCanAccessContext(calli
ngContext, m_context->context()); |
| 295 } | 290 } |
| 296 | 291 |
| 297 v8::Local<v8::Value> InjectedScript::v8Value() const | 292 v8::Local<v8::Value> InjectedScript::v8Value() const |
| 298 { | 293 { |
| 299 return m_value.Get(m_context->isolate()); | 294 return m_value.Get(m_context->isolate()); |
| 300 } | 295 } |
| 301 | 296 |
| 302 bool InjectedScript::setLastEvaluationResult(ErrorString* errorString, v8::Local
<v8::Value> value) | 297 v8::Local<v8::Value> InjectedScript::lastEvaluationResult() const |
| 303 { | 298 { |
| 304 V8FunctionCall function(m_context->debugger(), m_context->context(), v8Value
(), "setLastEvaluationResult"); | 299 if (m_lastEvaluationResult.IsEmpty()) |
| 305 function.appendArgument(value); | 300 return v8::Undefined(m_context->isolate()); |
| 306 bool hadException = false; | 301 return m_lastEvaluationResult.Get(m_context->isolate()); |
| 307 function.call(hadException, false); | |
| 308 return !hasInternalError(errorString, hadException); | |
| 309 } | 302 } |
| 310 | 303 |
| 311 v8::MaybeLocal<v8::Value> InjectedScript::resolveCallArgument(ErrorString* error
String, protocol::Runtime::CallArgument* callArgument) | 304 v8::MaybeLocal<v8::Value> InjectedScript::resolveCallArgument(ErrorString* error
String, protocol::Runtime::CallArgument* callArgument) |
| 312 { | 305 { |
| 313 if (callArgument->hasObjectId()) { | 306 if (callArgument->hasObjectId()) { |
| 314 OwnPtr<RemoteObjectId> remoteObjectId = RemoteObjectId::parse(errorStrin
g, callArgument->getObjectId("")); | 307 OwnPtr<RemoteObjectId> remoteObjectId = RemoteObjectId::parse(errorStrin
g, callArgument->getObjectId("")); |
| 315 if (!remoteObjectId) | 308 if (!remoteObjectId) |
| 316 return v8::MaybeLocal<v8::Value>(); | 309 return v8::MaybeLocal<v8::Value>(); |
| 317 if (remoteObjectId->contextId() != m_context->contextId()) { | 310 if (remoteObjectId->contextId() != m_context->contextId()) { |
| 318 *errorString = "Argument should belong to the same JavaScript world
as target object"; | 311 *errorString = "Argument should belong to the same JavaScript world
as target object"; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 | 351 |
| 359 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) | 352 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) |
| 360 { | 353 { |
| 361 v8::Local<v8::Value> resultValue; | 354 v8::Local<v8::Value> resultValue; |
| 362 if (!tryCatch.HasCaught()) { | 355 if (!tryCatch.HasCaught()) { |
| 363 if (hasInternalError(errorString, !maybeResultValue.ToLocal(&resultValue
))) | 356 if (hasInternalError(errorString, !maybeResultValue.ToLocal(&resultValue
))) |
| 364 return; | 357 return; |
| 365 OwnPtr<RemoteObject> remoteObject = wrapObject(errorString, resultValue,
objectGroup, returnByValue, generatePreview); | 358 OwnPtr<RemoteObject> remoteObject = wrapObject(errorString, resultValue,
objectGroup, returnByValue, generatePreview); |
| 366 if (!remoteObject) | 359 if (!remoteObject) |
| 367 return; | 360 return; |
| 368 if (objectGroup == "console" && !setLastEvaluationResult(errorString, re
sultValue)) | 361 if (objectGroup == "console") |
| 369 return; | 362 m_lastEvaluationResult.Reset(m_context->isolate(), resultValue); |
| 370 *result = remoteObject.release(); | 363 *result = remoteObject.release(); |
| 371 if (wasThrown) | 364 if (wasThrown) |
| 372 *wasThrown = false; | 365 *wasThrown = false; |
| 373 } else { | 366 } else { |
| 374 v8::Local<v8::Value> exception = tryCatch.Exception(); | 367 v8::Local<v8::Value> exception = tryCatch.Exception(); |
| 375 OwnPtr<RemoteObject> remoteObject = wrapObject(errorString, exception, o
bjectGroup, false, generatePreview && !exception->IsNativeError()); | 368 OwnPtr<RemoteObject> remoteObject = wrapObject(errorString, exception, o
bjectGroup, false, generatePreview && !exception->IsNativeError()); |
| 376 if (!remoteObject) | 369 if (!remoteObject) |
| 377 return; | 370 return; |
| 378 *result = remoteObject.release(); | 371 *result = remoteObject.release(); |
| 379 if (exceptionDetails) | 372 if (exceptionDetails) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 409 return false; | 402 return false; |
| 410 m_context = m_injectedScript->context()->context(); | 403 m_context = m_injectedScript->context()->context(); |
| 411 m_context->Enter(); | 404 m_context->Enter(); |
| 412 return true; | 405 return true; |
| 413 } | 406 } |
| 414 | 407 |
| 415 bool InjectedScript::Scope::installCommandLineAPI() | 408 bool InjectedScript::Scope::installCommandLineAPI() |
| 416 { | 409 { |
| 417 ASSERT(m_injectedScript && !m_context.IsEmpty()); | 410 ASSERT(m_injectedScript && !m_context.IsEmpty()); |
| 418 V8FunctionCall function(m_debugger, m_context, m_injectedScript->v8Value(),
"commandLineAPI"); | 411 V8FunctionCall function(m_debugger, m_context, m_injectedScript->v8Value(),
"commandLineAPI"); |
| 419 return installGlobalObjectExtension(function); | 412 v8::Local<v8::Object> extensionObject; |
| 413 if (!installGlobalObjectExtension(function).ToLocal(&extensionObject)) |
| 414 return false; |
| 415 return extensionObject->Set(m_context, toV8StringInternalized(m_context->Get
Isolate(), "$_"), m_injectedScript->lastEvaluationResult()).FromMaybe(false); |
| 420 } | 416 } |
| 421 | 417 |
| 422 bool InjectedScript::Scope::installRemoteObjectAPI(const String16& objectGroupNa
me) | 418 bool InjectedScript::Scope::installRemoteObjectAPI(const String16& objectGroupNa
me) |
| 423 { | 419 { |
| 424 ASSERT(m_injectedScript && !m_context.IsEmpty()); | 420 ASSERT(m_injectedScript && !m_context.IsEmpty()); |
| 425 V8FunctionCall function(m_debugger, m_context, m_injectedScript->v8Value(),
"remoteObjectAPI"); | 421 V8FunctionCall function(m_debugger, m_context, m_injectedScript->v8Value(),
"remoteObjectAPI"); |
| 426 function.appendArgument(objectGroupName); | 422 function.appendArgument(objectGroupName); |
| 427 return installGlobalObjectExtension(function); | 423 v8::Local<v8::Object> extensionObject; |
| 424 return installGlobalObjectExtension(function).ToLocal(&extensionObject); |
| 428 } | 425 } |
| 429 | 426 |
| 430 bool InjectedScript::Scope::installGlobalObjectExtension(V8FunctionCall& functio
n) | 427 v8::MaybeLocal<v8::Object> InjectedScript::Scope::installGlobalObjectExtension(V
8FunctionCall& function) |
| 431 { | 428 { |
| 432 bool hadException = false; | 429 bool hadException = false; |
| 433 v8::Local<v8::Value> extension = function.call(hadException, false); | 430 v8::Local<v8::Value> extension = function.call(hadException, false); |
| 434 if (hadException || extension.IsEmpty()) { | 431 if (hadException || extension.IsEmpty() || !extension->IsObject()) { |
| 435 *m_errorString = "Internal error"; | 432 *m_errorString = "Internal error"; |
| 436 return false; | 433 return v8::MaybeLocal<v8::Object>(); |
| 437 } | 434 } |
| 438 | 435 |
| 439 ASSERT(m_global.IsEmpty()); | 436 ASSERT(m_global.IsEmpty()); |
| 440 m_extensionSymbol = V8Debugger::scopeExtensionSymbol(m_debugger->isolate()); | 437 m_extensionSymbol = V8Debugger::scopeExtensionSymbol(m_debugger->isolate()); |
| 441 v8::Local<v8::Object> global = m_context->Global(); | 438 v8::Local<v8::Object> global = m_context->Global(); |
| 442 if (!global->Set(m_context, m_extensionSymbol, extension).FromMaybe(false))
{ | 439 if (!global->Set(m_context, m_extensionSymbol, extension).FromMaybe(false))
{ |
| 443 *m_errorString = "Internal error"; | 440 *m_errorString = "Internal error"; |
| 444 return false; | 441 return v8::MaybeLocal<v8::Object>(); |
| 445 } | 442 } |
| 446 | 443 |
| 447 m_global = global; | 444 m_global = global; |
| 448 return true; | 445 return extension.As<v8::Object>(); |
| 449 } | 446 } |
| 450 | 447 |
| 451 void InjectedScript::Scope::ignoreExceptionsAndMuteConsole() | 448 void InjectedScript::Scope::ignoreExceptionsAndMuteConsole() |
| 452 { | 449 { |
| 453 ASSERT(!m_ignoreExceptionsAndMuteConsole); | 450 ASSERT(!m_ignoreExceptionsAndMuteConsole); |
| 454 m_ignoreExceptionsAndMuteConsole = true; | 451 m_ignoreExceptionsAndMuteConsole = true; |
| 455 m_debugger->client()->muteConsole(); | 452 m_debugger->client()->muteConsole(); |
| 456 m_previousPauseOnExceptionsState = setPauseOnExceptionsState(V8DebuggerImpl:
:DontPauseOnExceptions); | 453 m_previousPauseOnExceptionsState = setPauseOnExceptionsState(V8DebuggerImpl:
:DontPauseOnExceptions); |
| 457 } | 454 } |
| 458 | 455 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 void InjectedScript::CallFrameScope::findInjectedScript(V8InspectorSessionImpl*
session) | 538 void InjectedScript::CallFrameScope::findInjectedScript(V8InspectorSessionImpl*
session) |
| 542 { | 539 { |
| 543 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(m_errorString,
m_remoteCallFrameId); | 540 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(m_errorString,
m_remoteCallFrameId); |
| 544 if (!remoteId) | 541 if (!remoteId) |
| 545 return; | 542 return; |
| 546 m_frameOrdinal = static_cast<size_t>(remoteId->frameOrdinal()); | 543 m_frameOrdinal = static_cast<size_t>(remoteId->frameOrdinal()); |
| 547 m_injectedScript = session->findInjectedScript(m_errorString, remoteId.get()
); | 544 m_injectedScript = session->findInjectedScript(m_errorString, remoteId.get()
); |
| 548 } | 545 } |
| 549 | 546 |
| 550 } // namespace blink | 547 } // namespace blink |
| OLD | NEW |