| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 void V8RuntimeAgentImpl::evaluate( | 72 void V8RuntimeAgentImpl::evaluate( |
| 73 ErrorString* errorString, | 73 ErrorString* errorString, |
| 74 const String16& expression, | 74 const String16& expression, |
| 75 const Maybe<String16>& objectGroup, | 75 const Maybe<String16>& objectGroup, |
| 76 const Maybe<bool>& includeCommandLineAPI, | 76 const Maybe<bool>& includeCommandLineAPI, |
| 77 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, | 77 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, |
| 78 const Maybe<int>& executionContextId, | 78 const Maybe<int>& executionContextId, |
| 79 const Maybe<bool>& returnByValue, | 79 const Maybe<bool>& returnByValue, |
| 80 const Maybe<bool>& generatePreview, | 80 const Maybe<bool>& generatePreview, |
| 81 const Maybe<bool>& userGesture, | 81 const Maybe<bool>& userGesture, |
| 82 OwnPtr<RemoteObject>* result, | 82 std::unique_ptr<RemoteObject>* result, |
| 83 Maybe<bool>* wasThrown, | 83 Maybe<bool>* wasThrown, |
| 84 Maybe<ExceptionDetails>* exceptionDetails) | 84 Maybe<ExceptionDetails>* exceptionDetails) |
| 85 { | 85 { |
| 86 int contextId; | 86 int contextId; |
| 87 if (executionContextId.isJust()) { | 87 if (executionContextId.isJust()) { |
| 88 contextId = executionContextId.fromJust(); | 88 contextId = executionContextId.fromJust(); |
| 89 } else { | 89 } else { |
| 90 contextId = m_debugger->client()->ensureDefaultContextInGroup(m_session-
>contextGroupId()); | 90 contextId = m_debugger->client()->ensureDefaultContextInGroup(m_session-
>contextGroupId()); |
| 91 if (!contextId) { | 91 if (!contextId) { |
| 92 *errorString = "Cannot find default execution context"; | 92 *errorString = "Cannot find default execution context"; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 } | 134 } |
| 135 | 135 |
| 136 void V8RuntimeAgentImpl::callFunctionOn(ErrorString* errorString, | 136 void V8RuntimeAgentImpl::callFunctionOn(ErrorString* errorString, |
| 137 const String16& objectId, | 137 const String16& objectId, |
| 138 const String16& expression, | 138 const String16& expression, |
| 139 const Maybe<protocol::Array<protocol::Runtime::CallArgument>>& optionalArgum
ents, | 139 const Maybe<protocol::Array<protocol::Runtime::CallArgument>>& optionalArgum
ents, |
| 140 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, | 140 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, |
| 141 const Maybe<bool>& returnByValue, | 141 const Maybe<bool>& returnByValue, |
| 142 const Maybe<bool>& generatePreview, | 142 const Maybe<bool>& generatePreview, |
| 143 const Maybe<bool>& userGesture, | 143 const Maybe<bool>& userGesture, |
| 144 OwnPtr<RemoteObject>* result, | 144 std::unique_ptr<RemoteObject>* result, |
| 145 Maybe<bool>* wasThrown) | 145 Maybe<bool>* wasThrown) |
| 146 { | 146 { |
| 147 InjectedScript::ObjectScope scope(errorString, m_debugger, m_session->contex
tGroupId(), objectId); | 147 InjectedScript::ObjectScope scope(errorString, m_debugger, m_session->contex
tGroupId(), objectId); |
| 148 if (!scope.initialize()) | 148 if (!scope.initialize()) |
| 149 return; | 149 return; |
| 150 | 150 |
| 151 OwnPtr<v8::Local<v8::Value>[]> argv = nullptr; | 151 std::unique_ptr<v8::Local<v8::Value>[]> argv = nullptr; |
| 152 int argc = 0; | 152 int argc = 0; |
| 153 if (optionalArguments.isJust()) { | 153 if (optionalArguments.isJust()) { |
| 154 protocol::Array<protocol::Runtime::CallArgument>* arguments = optionalAr
guments.fromJust(); | 154 protocol::Array<protocol::Runtime::CallArgument>* arguments = optionalAr
guments.fromJust(); |
| 155 argc = arguments->length(); | 155 argc = arguments->length(); |
| 156 argv = adoptArrayPtr(new v8::Local<v8::Value>[argc]); | 156 argv.reset(new v8::Local<v8::Value>[argc]); |
| 157 for (int i = 0; i < argc; ++i) { | 157 for (int i = 0; i < argc; ++i) { |
| 158 v8::Local<v8::Value> argumentValue; | 158 v8::Local<v8::Value> argumentValue; |
| 159 if (!scope.injectedScript()->resolveCallArgument(errorString, argume
nts->get(i)).ToLocal(&argumentValue)) | 159 if (!scope.injectedScript()->resolveCallArgument(errorString, argume
nts->get(i)).ToLocal(&argumentValue)) |
| 160 return; | 160 return; |
| 161 argv[i] = argumentValue; | 161 argv[i] = argumentValue; |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 | 164 |
| 165 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) | 165 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) |
| 166 scope.ignoreExceptionsAndMuteConsole(); | 166 scope.ignoreExceptionsAndMuteConsole(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 190 | 190 |
| 191 scope.injectedScript()->wrapEvaluateResult(errorString, maybeResultValue, sc
ope.tryCatch(), scope.objectGroupName(), returnByValue.fromMaybe(false), generat
ePreview.fromMaybe(false), result, wasThrown, nullptr); | 191 scope.injectedScript()->wrapEvaluateResult(errorString, maybeResultValue, sc
ope.tryCatch(), scope.objectGroupName(), returnByValue.fromMaybe(false), generat
ePreview.fromMaybe(false), result, wasThrown, nullptr); |
| 192 } | 192 } |
| 193 | 193 |
| 194 void V8RuntimeAgentImpl::getProperties( | 194 void V8RuntimeAgentImpl::getProperties( |
| 195 ErrorString* errorString, | 195 ErrorString* errorString, |
| 196 const String16& objectId, | 196 const String16& objectId, |
| 197 const Maybe<bool>& ownProperties, | 197 const Maybe<bool>& ownProperties, |
| 198 const Maybe<bool>& accessorPropertiesOnly, | 198 const Maybe<bool>& accessorPropertiesOnly, |
| 199 const Maybe<bool>& generatePreview, | 199 const Maybe<bool>& generatePreview, |
| 200 OwnPtr<protocol::Array<protocol::Runtime::PropertyDescriptor>>* result, | 200 std::unique_ptr<protocol::Array<protocol::Runtime::PropertyDescriptor>>* res
ult, |
| 201 Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>* inter
nalProperties, | 201 Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>* inter
nalProperties, |
| 202 Maybe<ExceptionDetails>* exceptionDetails) | 202 Maybe<ExceptionDetails>* exceptionDetails) |
| 203 { | 203 { |
| 204 using protocol::Runtime::InternalPropertyDescriptor; | 204 using protocol::Runtime::InternalPropertyDescriptor; |
| 205 | 205 |
| 206 InjectedScript::ObjectScope scope(errorString, m_debugger, m_session->contex
tGroupId(), objectId); | 206 InjectedScript::ObjectScope scope(errorString, m_debugger, m_session->contex
tGroupId(), objectId); |
| 207 if (!scope.initialize()) | 207 if (!scope.initialize()) |
| 208 return; | 208 return; |
| 209 | 209 |
| 210 scope.ignoreExceptionsAndMuteConsole(); | 210 scope.ignoreExceptionsAndMuteConsole(); |
| 211 if (!scope.object()->IsObject()) { | 211 if (!scope.object()->IsObject()) { |
| 212 *errorString = "Value with given id is not an object"; | 212 *errorString = "Value with given id is not an object"; |
| 213 return; | 213 return; |
| 214 } | 214 } |
| 215 | 215 |
| 216 v8::Local<v8::Object> object = scope.object().As<v8::Object>(); | 216 v8::Local<v8::Object> object = scope.object().As<v8::Object>(); |
| 217 scope.injectedScript()->getProperties(errorString, object, scope.objectGroup
Name(), ownProperties.fromMaybe(false), accessorPropertiesOnly.fromMaybe(false),
generatePreview.fromMaybe(false), result, exceptionDetails); | 217 scope.injectedScript()->getProperties(errorString, object, scope.objectGroup
Name(), ownProperties.fromMaybe(false), accessorPropertiesOnly.fromMaybe(false),
generatePreview.fromMaybe(false), result, exceptionDetails); |
| 218 if (!errorString->isEmpty() || exceptionDetails->isJust() || accessorPropert
iesOnly.fromMaybe(false)) | 218 if (!errorString->isEmpty() || exceptionDetails->isJust() || accessorPropert
iesOnly.fromMaybe(false)) |
| 219 return; | 219 return; |
| 220 v8::Local<v8::Array> propertiesArray; | 220 v8::Local<v8::Array> propertiesArray; |
| 221 if (hasInternalError(errorString, !v8::Debug::GetInternalProperties(m_debugg
er->isolate(), scope.object()).ToLocal(&propertiesArray))) | 221 if (hasInternalError(errorString, !v8::Debug::GetInternalProperties(m_debugg
er->isolate(), scope.object()).ToLocal(&propertiesArray))) |
| 222 return; | 222 return; |
| 223 OwnPtr<protocol::Array<InternalPropertyDescriptor>> propertiesProtocolArray
= protocol::Array<InternalPropertyDescriptor>::create(); | 223 std::unique_ptr<protocol::Array<InternalPropertyDescriptor>> propertiesProto
colArray = protocol::Array<InternalPropertyDescriptor>::create(); |
| 224 for (uint32_t i = 0; i < propertiesArray->Length(); i += 2) { | 224 for (uint32_t i = 0; i < propertiesArray->Length(); i += 2) { |
| 225 v8::Local<v8::Value> name; | 225 v8::Local<v8::Value> name; |
| 226 if (hasInternalError(errorString, !propertiesArray->Get(scope.context(),
i).ToLocal(&name)) || !name->IsString()) | 226 if (hasInternalError(errorString, !propertiesArray->Get(scope.context(),
i).ToLocal(&name)) || !name->IsString()) |
| 227 return; | 227 return; |
| 228 v8::Local<v8::Value> value; | 228 v8::Local<v8::Value> value; |
| 229 if (hasInternalError(errorString, !propertiesArray->Get(scope.context(),
i + 1).ToLocal(&value))) | 229 if (hasInternalError(errorString, !propertiesArray->Get(scope.context(),
i + 1).ToLocal(&value))) |
| 230 return; | 230 return; |
| 231 OwnPtr<RemoteObject> wrappedValue = scope.injectedScript()->wrapObject(e
rrorString, value, scope.objectGroupName()); | 231 std::unique_ptr<RemoteObject> wrappedValue = scope.injectedScript()->wra
pObject(errorString, value, scope.objectGroupName()); |
| 232 if (!wrappedValue) | 232 if (!wrappedValue) |
| 233 return; | 233 return; |
| 234 propertiesProtocolArray->addItem(InternalPropertyDescriptor::create() | 234 propertiesProtocolArray->addItem(InternalPropertyDescriptor::create() |
| 235 .setName(toProtocolString(name.As<v8::String>())) | 235 .setName(toProtocolString(name.As<v8::String>())) |
| 236 .setValue(std::move(wrappedValue)).build()); | 236 .setValue(std::move(wrappedValue)).build()); |
| 237 } | 237 } |
| 238 if (!propertiesProtocolArray->length()) | 238 if (!propertiesProtocolArray->length()) |
| 239 return; | 239 return; |
| 240 *internalProperties = std::move(propertiesProtocolArray); | 240 *internalProperties = std::move(propertiesProtocolArray); |
| 241 } | 241 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 *exceptionDetails = scope.injectedScript()->createExceptionDetails(m
essage); | 287 *exceptionDetails = scope.injectedScript()->createExceptionDetails(m
essage); |
| 288 else | 288 else |
| 289 *errorString = "Script compilation failed"; | 289 *errorString = "Script compilation failed"; |
| 290 return; | 290 return; |
| 291 } | 291 } |
| 292 | 292 |
| 293 if (!persistScript) | 293 if (!persistScript) |
| 294 return; | 294 return; |
| 295 | 295 |
| 296 String16 scriptValueId = String16::number(script->GetUnboundScript()->GetId(
)); | 296 String16 scriptValueId = String16::number(script->GetUnboundScript()->GetId(
)); |
| 297 OwnPtr<v8::Global<v8::Script>> global = adoptPtr(new v8::Global<v8::Script>(
m_debugger->isolate(), script)); | 297 std::unique_ptr<v8::Global<v8::Script>> global(new v8::Global<v8::Script>(m_
debugger->isolate(), script)); |
| 298 m_compiledScripts.set(scriptValueId, std::move(global)); | 298 m_compiledScripts.set(scriptValueId, std::move(global)); |
| 299 *scriptId = scriptValueId; | 299 *scriptId = scriptValueId; |
| 300 } | 300 } |
| 301 | 301 |
| 302 void V8RuntimeAgentImpl::runScript(ErrorString* errorString, | 302 void V8RuntimeAgentImpl::runScript(ErrorString* errorString, |
| 303 const String16& scriptId, | 303 const String16& scriptId, |
| 304 int executionContextId, | 304 int executionContextId, |
| 305 const Maybe<String16>& objectGroup, | 305 const Maybe<String16>& objectGroup, |
| 306 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, | 306 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, |
| 307 const Maybe<bool>& includeCommandLineAPI, | 307 const Maybe<bool>& includeCommandLineAPI, |
| 308 OwnPtr<RemoteObject>* result, | 308 std::unique_ptr<RemoteObject>* result, |
| 309 Maybe<ExceptionDetails>* exceptionDetails) | 309 Maybe<ExceptionDetails>* exceptionDetails) |
| 310 { | 310 { |
| 311 if (!m_enabled) { | 311 if (!m_enabled) { |
| 312 *errorString = "Runtime agent is not enabled"; | 312 *errorString = "Runtime agent is not enabled"; |
| 313 return; | 313 return; |
| 314 } | 314 } |
| 315 | 315 |
| 316 if (!m_compiledScripts.contains(scriptId)) { | 316 if (!m_compiledScripts.contains(scriptId)) { |
| 317 *errorString = "Script execution failed"; | 317 *errorString = "Script execution failed"; |
| 318 return; | 318 return; |
| 319 } | 319 } |
| 320 | 320 |
| 321 InjectedScript::ContextScope scope(errorString, m_debugger, m_session->conte
xtGroupId(), executionContextId); | 321 InjectedScript::ContextScope scope(errorString, m_debugger, m_session->conte
xtGroupId(), executionContextId); |
| 322 if (!scope.initialize()) | 322 if (!scope.initialize()) |
| 323 return; | 323 return; |
| 324 | 324 |
| 325 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) | 325 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) |
| 326 scope.ignoreExceptionsAndMuteConsole(); | 326 scope.ignoreExceptionsAndMuteConsole(); |
| 327 | 327 |
| 328 OwnPtr<v8::Global<v8::Script>> scriptWrapper = m_compiledScripts.take(script
Id); | 328 std::unique_ptr<v8::Global<v8::Script>> scriptWrapper = m_compiledScripts.ta
ke(scriptId); |
| 329 v8::Local<v8::Script> script = scriptWrapper->Get(m_debugger->isolate()); | 329 v8::Local<v8::Script> script = scriptWrapper->Get(m_debugger->isolate()); |
| 330 if (script.IsEmpty()) { | 330 if (script.IsEmpty()) { |
| 331 *errorString = "Script execution failed"; | 331 *errorString = "Script execution failed"; |
| 332 return; | 332 return; |
| 333 } | 333 } |
| 334 | 334 |
| 335 if (includeCommandLineAPI.fromMaybe(false) && !scope.installCommandLineAPI()
) | 335 if (includeCommandLineAPI.fromMaybe(false) && !scope.installCommandLineAPI()
) |
| 336 return; | 336 return; |
| 337 | 337 |
| 338 v8::MaybeLocal<v8::Value> maybeResultValue = m_debugger->runCompiledScript(s
cope.context(), script); | 338 v8::MaybeLocal<v8::Value> maybeResultValue = m_debugger->runCompiledScript(s
cope.context(), script); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 } | 386 } |
| 387 m_frontend->executionContextsCleared(); | 387 m_frontend->executionContextsCleared(); |
| 388 } | 388 } |
| 389 } | 389 } |
| 390 | 390 |
| 391 void V8RuntimeAgentImpl::reportExecutionContextCreated(InspectedContext* context
) | 391 void V8RuntimeAgentImpl::reportExecutionContextCreated(InspectedContext* context
) |
| 392 { | 392 { |
| 393 if (!m_enabled) | 393 if (!m_enabled) |
| 394 return; | 394 return; |
| 395 context->setReported(true); | 395 context->setReported(true); |
| 396 OwnPtr<protocol::Runtime::ExecutionContextDescription> description = protoco
l::Runtime::ExecutionContextDescription::create() | 396 std::unique_ptr<protocol::Runtime::ExecutionContextDescription> description
= protocol::Runtime::ExecutionContextDescription::create() |
| 397 .setId(context->contextId()) | 397 .setId(context->contextId()) |
| 398 .setIsDefault(context->isDefault()) | 398 .setIsDefault(context->isDefault()) |
| 399 .setName(context->humanReadableName()) | 399 .setName(context->humanReadableName()) |
| 400 .setOrigin(context->origin()) | 400 .setOrigin(context->origin()) |
| 401 .setFrameId(context->frameId()).build(); | 401 .setFrameId(context->frameId()).build(); |
| 402 m_frontend->executionContextCreated(std::move(description)); | 402 m_frontend->executionContextCreated(std::move(description)); |
| 403 } | 403 } |
| 404 | 404 |
| 405 void V8RuntimeAgentImpl::reportExecutionContextDestroyed(InspectedContext* conte
xt) | 405 void V8RuntimeAgentImpl::reportExecutionContextDestroyed(InspectedContext* conte
xt) |
| 406 { | 406 { |
| 407 if (m_enabled && context->isReported()) { | 407 if (m_enabled && context->isReported()) { |
| 408 context->setReported(false); | 408 context->setReported(false); |
| 409 m_frontend->executionContextDestroyed(context->contextId()); | 409 m_frontend->executionContextDestroyed(context->contextId()); |
| 410 } | 410 } |
| 411 } | 411 } |
| 412 | 412 |
| 413 void V8RuntimeAgentImpl::inspect(PassOwnPtr<protocol::Runtime::RemoteObject> obj
ectToInspect, PassOwnPtr<protocol::DictionaryValue> hints) | 413 void V8RuntimeAgentImpl::inspect(std::unique_ptr<protocol::Runtime::RemoteObject
> objectToInspect, std::unique_ptr<protocol::DictionaryValue> hints) |
| 414 { | 414 { |
| 415 if (m_enabled) | 415 if (m_enabled) |
| 416 m_frontend->inspectRequested(std::move(objectToInspect), std::move(hints
)); | 416 m_frontend->inspectRequested(std::move(objectToInspect), std::move(hints
)); |
| 417 } | 417 } |
| 418 | 418 |
| 419 } // namespace blink | 419 } // namespace blink |
| OLD | NEW |