Chromium Code Reviews| Index: third_party/WebKit/Source/platform/v8_inspector/V8RuntimeAgentImpl.cpp |
| diff --git a/third_party/WebKit/Source/platform/v8_inspector/V8RuntimeAgentImpl.cpp b/third_party/WebKit/Source/platform/v8_inspector/V8RuntimeAgentImpl.cpp |
| index e9785ae3f07036442c0dabb6f282c7383df49b10..e1d37a2d6f963c3975f13e4e5f5b32ba2d356674 100644 |
| --- a/third_party/WebKit/Source/platform/v8_inspector/V8RuntimeAgentImpl.cpp |
| +++ b/third_party/WebKit/Source/platform/v8_inspector/V8RuntimeAgentImpl.cpp |
| @@ -145,14 +145,86 @@ void V8RuntimeAgentImpl::callFunctionOn(ErrorString* errorString, |
| InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript(errorString, remoteId.get()); |
| if (!injectedScript) |
| return; |
| - String16 arguments; |
| - if (optionalArguments.isJust()) |
| - arguments = protocol::toValue(optionalArguments.fromJust())->toJSONString(); |
| - IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false) ? m_debugger : nullptr); |
|
dgozman
2016/03/18 00:38:32
Bring it back.
kozy
2016/03/18 06:01:56
Done.
|
| - injectedScript->callFunctionOn(errorString, objectId, expression, arguments, returnByValue.fromMaybe(false), generatePreview.fromMaybe(false), result, wasThrown); |
| + v8::HandleScope scope(injectedScript->isolate()); |
| + v8::Local<v8::Context> localContext = injectedScript->context(); |
| + v8::Context::Scope contextScope(localContext); |
| + |
| + if (!injectedScript->canAccessInspectedWindow()) { |
| + *errorString = "Can not access given context"; |
| + return; |
| + } |
| + |
| + v8::Local<v8::Value> object = injectedScript->findObject(*remoteId); |
| + if (object.IsEmpty()) { |
| + *errorString = "Could not find object with given id"; |
| + return; |
| + } |
| + |
| + String16 objectGroupName = injectedScript->objectGroupName(*remoteId); |
| + v8::MaybeLocal<v8::Object> remoteObjectAPI = injectedScript->remoteObjectAPI(errorString); |
| + if (remoteObjectAPI.IsEmpty()) |
| + return; |
| + |
| + v8::Local<v8::Function> function; |
| + if (!compileFunction(errorString, remoteId.get(), expression, objectGroupName, remoteObjectAPI, result, wasThrown).ToLocal(&function)) |
|
dgozman
2016/03/18 00:38:32
Let's compile after resolving arguments.
kozy
2016/03/18 06:01:56
Done.
|
| + return; |
| + |
| + OwnPtr<v8::Local<v8::Value>[]> argv = adoptArrayPtr(new v8::Local<v8::Value>[0]); |
|
dgozman
2016/03/18 00:38:32
nullptr
kozy
2016/03/18 06:01:55
Done.
|
| + int argc = 0; |
| + if (optionalArguments.isJust()) { |
| + protocol::Array<protocol::Runtime::CallArgument>* arguments = optionalArguments.fromJust(); |
| + argc = arguments->length(); |
| + argv = adoptArrayPtr(new v8::Local<v8::Value>[argc]); |
| + for (int i = 0; i < argc; ++i) { |
| + v8::Local<v8::Value> argumentValue; |
| + if (!injectedScript->resolveCallArgument(errorString, arguments->get(i)).ToLocal(&argumentValue)) |
| + return; |
| + argv[i] = argumentValue; |
| + } |
| + } |
| + |
| + v8::TryCatch tryCatch(injectedScript->isolate()); |
| + v8::MaybeLocal<v8::Value> maybeResultValue = function->Call(injectedScript->context(), object, argc, argv.get()); |
|
dgozman
2016/03/18 00:38:32
debugger->callFunction()
kozy
2016/03/18 06:01:56
Done.
|
| + |
| + // InjectedScript may be gone after any evaluate call - find it again. |
| + injectedScript = m_injectedScriptManager->findInjectedScript(errorString, remoteId.get()); |
| + if (!injectedScript) |
| + return; |
| + |
| + injectedScript->wrapEvaluateResult(errorString, maybeResultValue, tryCatch, objectGroupName, returnByValue.fromMaybe(false), generatePreview.fromMaybe(false), result, wasThrown, nullptr); |
| +} |
| + |
| +v8::MaybeLocal<v8::Function> V8RuntimeAgentImpl::compileFunction(ErrorString* errorString, RemoteObjectIdBase* remoteId, const String16& expression, const String16& objectGroupName, v8::MaybeLocal<v8::Object> extension, OwnPtr<protocol::Runtime::RemoteObject>* result, Maybe<bool>* wasThrown) |
|
dgozman
2016/03/18 00:38:32
Can we reuse evaluate() here?
kozy
2016/03/18 06:01:55
Extracted evaluateInternal
|
| +{ |
| + InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript(errorString, remoteId); |
| + if (!injectedScript) |
| + return v8::MaybeLocal<v8::Function>(); |
| + |
| + InjectedScriptManager::ScopedGlobalObjectExtension scopeExtension(injectedScript, nullptr, extension); |
| + |
| + v8::TryCatch tryCatch(injectedScript->isolate()); |
| + v8::MaybeLocal<v8::Value> maybeFunctionValue = m_debugger->compileAndRunInternalScript(injectedScript->context(), toV8String(injectedScript->isolate(), "(" + expression + ")")); |
| + |
| + // InjectedScript may be gone after any evaluate call - find it again. |
| + injectedScript = m_injectedScriptManager->findInjectedScript(errorString, remoteId); |
| + if (!injectedScript) |
| + return v8::MaybeLocal<v8::Function>(); |
| + |
| + if (tryCatch.HasCaught()) { |
| + injectedScript->wrapEvaluateResult(errorString, maybeFunctionValue, tryCatch, objectGroupName, false, false, result, wasThrown, nullptr); |
| + return v8::MaybeLocal<v8::Function>(); |
| + } |
| + |
| + v8::Local<v8::Value> functionValue; |
| + if (!maybeFunctionValue.ToLocal(&functionValue) || !functionValue->IsFunction()) { |
| + *errorString = "Given expression does not evaluate to a function"; |
| + return v8::MaybeLocal<v8::Function>(); |
| + } |
| + return functionValue.As<v8::Function>(); |
| } |
| + |
| void V8RuntimeAgentImpl::getProperties( |
| ErrorString* errorString, |
| const String16& objectId, |