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