| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 namespace blink { | 43 namespace blink { |
| 44 | 44 |
| 45 namespace V8RuntimeAgentImplState { | 45 namespace V8RuntimeAgentImplState { |
| 46 static const char customObjectFormatterEnabled[] = "customObjectFormatterEnabled
"; | 46 static const char customObjectFormatterEnabled[] = "customObjectFormatterEnabled
"; |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 using protocol::Runtime::ExceptionDetails; | 49 using protocol::Runtime::ExceptionDetails; |
| 50 using protocol::Runtime::RemoteObject; | 50 using protocol::Runtime::RemoteObject; |
| 51 | 51 |
| 52 static bool checkInternalError(ErrorString* errorString, bool success) |
| 53 { |
| 54 if (!success) |
| 55 *errorString = "Internal error"; |
| 56 return success; |
| 57 } |
| 58 |
| 52 PassOwnPtr<V8RuntimeAgent> V8RuntimeAgent::create(V8Debugger* debugger, int cont
extGroupId) | 59 PassOwnPtr<V8RuntimeAgent> V8RuntimeAgent::create(V8Debugger* debugger, int cont
extGroupId) |
| 53 { | 60 { |
| 54 return adoptPtr(new V8RuntimeAgentImpl(static_cast<V8DebuggerImpl*>(debugger
), contextGroupId)); | 61 return adoptPtr(new V8RuntimeAgentImpl(static_cast<V8DebuggerImpl*>(debugger
), contextGroupId)); |
| 55 } | 62 } |
| 56 | 63 |
| 57 V8RuntimeAgentImpl::V8RuntimeAgentImpl(V8DebuggerImpl* debugger, int contextGrou
pId) | 64 V8RuntimeAgentImpl::V8RuntimeAgentImpl(V8DebuggerImpl* debugger, int contextGrou
pId) |
| 58 : m_contextGroupId(contextGroupId) | 65 : m_contextGroupId(contextGroupId) |
| 59 , m_state(nullptr) | 66 , m_state(nullptr) |
| 60 , m_frontend(nullptr) | 67 , m_frontend(nullptr) |
| 61 , m_injectedScriptManager(InjectedScriptManager::create(debugger)) | 68 , m_injectedScriptManager(InjectedScriptManager::create(debugger)) |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 v8::HandleScope scope(injectedScript->isolate()); | 159 v8::HandleScope scope(injectedScript->isolate()); |
| 153 v8::Local<v8::Context> localContext = injectedScript->context(); | 160 v8::Local<v8::Context> localContext = injectedScript->context(); |
| 154 v8::Context::Scope contextScope(localContext); | 161 v8::Context::Scope contextScope(localContext); |
| 155 | 162 |
| 156 if (!injectedScript->canAccessInspectedWindow()) { | 163 if (!injectedScript->canAccessInspectedWindow()) { |
| 157 *errorString = "Can not access given context"; | 164 *errorString = "Can not access given context"; |
| 158 return; | 165 return; |
| 159 } | 166 } |
| 160 | 167 |
| 161 String16 objectGroupName = injectedScript->objectGroupName(*remoteId); | 168 String16 objectGroupName = injectedScript->objectGroupName(*remoteId); |
| 162 v8::Local<v8::Value> object = injectedScript->findObject(*remoteId); | 169 v8::Local<v8::Value> object; |
| 163 if (object.IsEmpty()) { | 170 if (!injectedScript->findObject(errorString, *remoteId, &object)) |
| 164 *errorString = "Could not find object with given id"; | |
| 165 return; | 171 return; |
| 166 } | |
| 167 OwnPtr<v8::Local<v8::Value>[]> argv = nullptr; | 172 OwnPtr<v8::Local<v8::Value>[]> argv = nullptr; |
| 168 int argc = 0; | 173 int argc = 0; |
| 169 if (optionalArguments.isJust()) { | 174 if (optionalArguments.isJust()) { |
| 170 protocol::Array<protocol::Runtime::CallArgument>* arguments = optionalAr
guments.fromJust(); | 175 protocol::Array<protocol::Runtime::CallArgument>* arguments = optionalAr
guments.fromJust(); |
| 171 argc = arguments->length(); | 176 argc = arguments->length(); |
| 172 argv = adoptArrayPtr(new v8::Local<v8::Value>[argc]); | 177 argv = adoptArrayPtr(new v8::Local<v8::Value>[argc]); |
| 173 for (int i = 0; i < argc; ++i) { | 178 for (int i = 0; i < argc; ++i) { |
| 174 v8::Local<v8::Value> argumentValue; | 179 v8::Local<v8::Value> argumentValue; |
| 175 if (!injectedScript->resolveCallArgument(errorString, arguments->get
(i)).ToLocal(&argumentValue)) | 180 if (!injectedScript->resolveCallArgument(errorString, arguments->get
(i)).ToLocal(&argumentValue)) |
| 176 return; | 181 return; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 void V8RuntimeAgentImpl::getProperties( | 215 void V8RuntimeAgentImpl::getProperties( |
| 211 ErrorString* errorString, | 216 ErrorString* errorString, |
| 212 const String16& objectId, | 217 const String16& objectId, |
| 213 const Maybe<bool>& ownProperties, | 218 const Maybe<bool>& ownProperties, |
| 214 const Maybe<bool>& accessorPropertiesOnly, | 219 const Maybe<bool>& accessorPropertiesOnly, |
| 215 const Maybe<bool>& generatePreview, | 220 const Maybe<bool>& generatePreview, |
| 216 OwnPtr<protocol::Array<protocol::Runtime::PropertyDescriptor>>* result, | 221 OwnPtr<protocol::Array<protocol::Runtime::PropertyDescriptor>>* result, |
| 217 Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>* inter
nalProperties, | 222 Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>* inter
nalProperties, |
| 218 Maybe<ExceptionDetails>* exceptionDetails) | 223 Maybe<ExceptionDetails>* exceptionDetails) |
| 219 { | 224 { |
| 225 using protocol::Runtime::InternalPropertyDescriptor; |
| 226 |
| 220 OwnPtr<RemoteObjectId> remoteId = RemoteObjectId::parse(errorString, objectI
d); | 227 OwnPtr<RemoteObjectId> remoteId = RemoteObjectId::parse(errorString, objectI
d); |
| 221 if (!remoteId) | 228 if (!remoteId) |
| 222 return; | 229 return; |
| 223 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript
(errorString, remoteId.get()); | 230 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript
(errorString, remoteId.get()); |
| 224 if (!injectedScript) | 231 if (!injectedScript) |
| 225 return; | 232 return; |
| 226 | 233 |
| 227 IgnoreExceptionsScope ignoreExceptionsScope(m_debugger); | 234 IgnoreExceptionsScope ignoreExceptionsScope(m_debugger); |
| 228 | 235 |
| 236 v8::HandleScope handles(injectedScript->isolate()); |
| 237 v8::Context::Scope scope(injectedScript->context()); |
| 238 v8::Local<v8::Value> object; |
| 239 if (!injectedScript->findObject(errorString, *remoteId, &object)) |
| 240 return; |
| 241 String16 objectGroupName = injectedScript->objectGroupName(*remoteId); |
| 242 |
| 229 injectedScript->getProperties(errorString, objectId, ownProperties.fromMaybe
(false), accessorPropertiesOnly.fromMaybe(false), generatePreview.fromMaybe(fals
e), result, exceptionDetails); | 243 injectedScript->getProperties(errorString, objectId, ownProperties.fromMaybe
(false), accessorPropertiesOnly.fromMaybe(false), generatePreview.fromMaybe(fals
e), result, exceptionDetails); |
| 230 | 244 if (!errorString->isEmpty() || exceptionDetails->isJust() || accessorPropert
iesOnly.fromMaybe(false)) |
| 231 if (errorString->isEmpty() && !exceptionDetails->isJust() && !accessorProper
tiesOnly.fromMaybe(false)) | 245 return; |
| 232 injectedScript->getInternalProperties(errorString, objectId, internalPro
perties, exceptionDetails); | 246 if (object->IsSymbol()) |
| 247 return; |
| 248 v8::Local<v8::Array> propertiesArray; |
| 249 if (!checkInternalError(errorString, v8::Debug::GetInternalProperties(inject
edScript->isolate(), object).ToLocal(&propertiesArray))) |
| 250 return; |
| 251 OwnPtr<protocol::Array<InternalPropertyDescriptor>> propertiesProtocolArray
= protocol::Array<InternalPropertyDescriptor>::create(); |
| 252 for (uint32_t i = 0; i < propertiesArray->Length(); i += 2) { |
| 253 v8::Local<v8::Value> name; |
| 254 if (!checkInternalError(errorString, propertiesArray->Get(injectedScript
->context(), i).ToLocal(&name)) && name->IsString()) |
| 255 return; |
| 256 v8::Local<v8::Value> value; |
| 257 if (!checkInternalError(errorString, propertiesArray->Get(injectedScript
->context(), i + 1).ToLocal(&value))) |
| 258 return; |
| 259 OwnPtr<RemoteObject> wrappedValue = injectedScript->wrapObject(errorStri
ng, value, objectGroupName); |
| 260 if (!wrappedValue) |
| 261 return; |
| 262 propertiesProtocolArray->addItem(InternalPropertyDescriptor::create() |
| 263 .setName(toProtocolString(name.As<v8::String>())) |
| 264 .setValue(wrappedValue.release()).build()); |
| 265 } |
| 266 if (!propertiesProtocolArray->length()) |
| 267 return; |
| 268 *internalProperties = propertiesProtocolArray.release(); |
| 233 } | 269 } |
| 234 | 270 |
| 235 void V8RuntimeAgentImpl::releaseObject(ErrorString* errorString, const String16&
objectId) | 271 void V8RuntimeAgentImpl::releaseObject(ErrorString* errorString, const String16&
objectId) |
| 236 { | 272 { |
| 237 OwnPtr<RemoteObjectId> remoteId = RemoteObjectId::parse(errorString, objectI
d); | 273 OwnPtr<RemoteObjectId> remoteId = RemoteObjectId::parse(errorString, objectI
d); |
| 238 if (!remoteId) | 274 if (!remoteId) |
| 239 return; | 275 return; |
| 240 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript
(errorString, remoteId.get()); | 276 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript
(errorString, remoteId.get()); |
| 241 if (!injectedScript) | 277 if (!injectedScript) |
| 242 return; | 278 return; |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 } | 483 } |
| 448 | 484 |
| 449 v8::Local<v8::Value> V8RuntimeAgentImpl::findObject(ErrorString* errorString, co
nst String16& objectId, v8::Local<v8::Context>* context, String16* groupName) | 485 v8::Local<v8::Value> V8RuntimeAgentImpl::findObject(ErrorString* errorString, co
nst String16& objectId, v8::Local<v8::Context>* context, String16* groupName) |
| 450 { | 486 { |
| 451 OwnPtr<RemoteObjectId> remoteId = RemoteObjectId::parse(errorString, objectI
d); | 487 OwnPtr<RemoteObjectId> remoteId = RemoteObjectId::parse(errorString, objectI
d); |
| 452 if (!remoteId) | 488 if (!remoteId) |
| 453 return v8::Local<v8::Value>(); | 489 return v8::Local<v8::Value>(); |
| 454 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript
(errorString, remoteId.get()); | 490 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript
(errorString, remoteId.get()); |
| 455 if (!injectedScript) | 491 if (!injectedScript) |
| 456 return v8::Local<v8::Value>(); | 492 return v8::Local<v8::Value>(); |
| 493 v8::Local<v8::Value> objectValue; |
| 494 injectedScript->findObject(errorString, *remoteId, &objectValue); |
| 495 if (objectValue.IsEmpty()) |
| 496 return v8::Local<v8::Value>(); |
| 457 if (context) | 497 if (context) |
| 458 *context = injectedScript->context(); | 498 *context = injectedScript->context(); |
| 459 if (groupName) | 499 if (groupName) |
| 460 *groupName = injectedScript->objectGroupName(*remoteId); | 500 *groupName = injectedScript->objectGroupName(*remoteId); |
| 461 return injectedScript->findObject(*remoteId); | 501 return objectValue; |
| 462 } | 502 } |
| 463 | 503 |
| 464 void V8RuntimeAgentImpl::addInspectedObject(PassOwnPtr<Inspectable> inspectable) | 504 void V8RuntimeAgentImpl::addInspectedObject(PassOwnPtr<Inspectable> inspectable) |
| 465 { | 505 { |
| 466 m_injectedScriptManager->injectedScriptHost()->addInspectedObject(inspectabl
e); | 506 m_injectedScriptManager->injectedScriptHost()->addInspectedObject(inspectabl
e); |
| 467 } | 507 } |
| 468 | 508 |
| 469 void V8RuntimeAgentImpl::clearInspectedObjects() | 509 void V8RuntimeAgentImpl::clearInspectedObjects() |
| 470 { | 510 { |
| 471 m_injectedScriptManager->injectedScriptHost()->clearInspectedObjects(); | 511 m_injectedScriptManager->injectedScriptHost()->clearInspectedObjects(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 491 | 531 |
| 492 void V8RuntimeAgentImpl::reportExecutionContextDestroyed(v8::Local<v8::Context>
context) | 532 void V8RuntimeAgentImpl::reportExecutionContextDestroyed(v8::Local<v8::Context>
context) |
| 493 { | 533 { |
| 494 int contextId = m_injectedScriptManager->discardInjectedScriptFor(context); | 534 int contextId = m_injectedScriptManager->discardInjectedScriptFor(context); |
| 495 if (!m_enabled) | 535 if (!m_enabled) |
| 496 return; | 536 return; |
| 497 m_frontend->executionContextDestroyed(contextId); | 537 m_frontend->executionContextDestroyed(contextId); |
| 498 } | 538 } |
| 499 | 539 |
| 500 } // namespace blink | 540 } // namespace blink |
| OLD | NEW |