Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/V8RuntimeAgentImpl.cpp

Issue 1809073003: [DevTools] Move callFunctionOn to native (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move-evaluate-v2
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 const Maybe<bool>& userGesture, 138 const Maybe<bool>& userGesture,
139 OwnPtr<RemoteObject>* result, 139 OwnPtr<RemoteObject>* result,
140 Maybe<bool>* wasThrown) 140 Maybe<bool>* wasThrown)
141 { 141 {
142 OwnPtr<RemoteObjectId> remoteId = RemoteObjectId::parse(errorString, objectI d); 142 OwnPtr<RemoteObjectId> remoteId = RemoteObjectId::parse(errorString, objectI d);
143 if (!remoteId) 143 if (!remoteId)
144 return; 144 return;
145 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get()); 145 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get());
146 if (!injectedScript) 146 if (!injectedScript)
147 return; 147 return;
148 String16 arguments;
149 if (optionalArguments.isJust())
150 arguments = protocol::toValue(optionalArguments.fromJust())->toJSONStrin g();
151 148
152 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon sole.fromMaybe(false) ? m_debugger : nullptr); 149 v8::HandleScope scope(injectedScript->isolate());
dgozman 2016/03/18 00:38:32 Bring it back.
kozy 2016/03/18 06:01:56 Done.
153 injectedScript->callFunctionOn(errorString, objectId, expression, arguments, returnByValue.fromMaybe(false), generatePreview.fromMaybe(false), result, wasTh rown); 150 v8::Local<v8::Context> localContext = injectedScript->context();
151 v8::Context::Scope contextScope(localContext);
152
153 if (!injectedScript->canAccessInspectedWindow()) {
154 *errorString = "Can not access given context";
155 return;
156 }
157
158 v8::Local<v8::Value> object = injectedScript->findObject(*remoteId);
159 if (object.IsEmpty()) {
160 *errorString = "Could not find object with given id";
161 return;
162 }
163
164 String16 objectGroupName = injectedScript->objectGroupName(*remoteId);
165 v8::MaybeLocal<v8::Object> remoteObjectAPI = injectedScript->remoteObjectAPI (errorString);
166 if (remoteObjectAPI.IsEmpty())
167 return;
168
169 v8::Local<v8::Function> function;
170 if (!compileFunction(errorString, remoteId.get(), expression, objectGroupNam e, 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.
171 return;
172
173 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.
174 int argc = 0;
175 if (optionalArguments.isJust()) {
176 protocol::Array<protocol::Runtime::CallArgument>* arguments = optionalAr guments.fromJust();
177 argc = arguments->length();
178 argv = adoptArrayPtr(new v8::Local<v8::Value>[argc]);
179 for (int i = 0; i < argc; ++i) {
180 v8::Local<v8::Value> argumentValue;
181 if (!injectedScript->resolveCallArgument(errorString, arguments->get (i)).ToLocal(&argumentValue))
182 return;
183 argv[i] = argumentValue;
184 }
185 }
186
187 v8::TryCatch tryCatch(injectedScript->isolate());
188 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.
189
190 // InjectedScript may be gone after any evaluate call - find it again.
191 injectedScript = m_injectedScriptManager->findInjectedScript(errorString, re moteId.get());
192 if (!injectedScript)
193 return;
194
195 injectedScript->wrapEvaluateResult(errorString, maybeResultValue, tryCatch, objectGroupName, returnByValue.fromMaybe(false), generatePreview.fromMaybe(false ), result, wasThrown, nullptr);
154 } 196 }
155 197
198 v8::MaybeLocal<v8::Function> V8RuntimeAgentImpl::compileFunction(ErrorString* er rorString, RemoteObjectIdBase* remoteId, const String16& expression, const Strin g16& objectGroupName, v8::MaybeLocal<v8::Object> extension, OwnPtr<protocol::Run time::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
199 {
200 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId);
201 if (!injectedScript)
202 return v8::MaybeLocal<v8::Function>();
203
204 InjectedScriptManager::ScopedGlobalObjectExtension scopeExtension(injectedSc ript, nullptr, extension);
205
206 v8::TryCatch tryCatch(injectedScript->isolate());
207 v8::MaybeLocal<v8::Value> maybeFunctionValue = m_debugger->compileAndRunInte rnalScript(injectedScript->context(), toV8String(injectedScript->isolate(), "(" + expression + ")"));
208
209 // InjectedScript may be gone after any evaluate call - find it again.
210 injectedScript = m_injectedScriptManager->findInjectedScript(errorString, re moteId);
211 if (!injectedScript)
212 return v8::MaybeLocal<v8::Function>();
213
214 if (tryCatch.HasCaught()) {
215 injectedScript->wrapEvaluateResult(errorString, maybeFunctionValue, tryC atch, objectGroupName, false, false, result, wasThrown, nullptr);
216 return v8::MaybeLocal<v8::Function>();
217 }
218
219 v8::Local<v8::Value> functionValue;
220 if (!maybeFunctionValue.ToLocal(&functionValue) || !functionValue->IsFunctio n()) {
221 *errorString = "Given expression does not evaluate to a function";
222 return v8::MaybeLocal<v8::Function>();
223 }
224 return functionValue.As<v8::Function>();
225 }
226
227
156 void V8RuntimeAgentImpl::getProperties( 228 void V8RuntimeAgentImpl::getProperties(
157 ErrorString* errorString, 229 ErrorString* errorString,
158 const String16& objectId, 230 const String16& objectId,
159 const Maybe<bool>& ownProperties, 231 const Maybe<bool>& ownProperties,
160 const Maybe<bool>& accessorPropertiesOnly, 232 const Maybe<bool>& accessorPropertiesOnly,
161 const Maybe<bool>& generatePreview, 233 const Maybe<bool>& generatePreview,
162 OwnPtr<protocol::Array<protocol::Runtime::PropertyDescriptor>>* result, 234 OwnPtr<protocol::Array<protocol::Runtime::PropertyDescriptor>>* result,
163 Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>* inter nalProperties, 235 Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>* inter nalProperties,
164 Maybe<ExceptionDetails>* exceptionDetails) 236 Maybe<ExceptionDetails>* exceptionDetails)
165 { 237 {
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 509
438 void V8RuntimeAgentImpl::reportExecutionContextDestroyed(v8::Local<v8::Context> context) 510 void V8RuntimeAgentImpl::reportExecutionContextDestroyed(v8::Local<v8::Context> context)
439 { 511 {
440 int contextId = m_injectedScriptManager->discardInjectedScriptFor(context); 512 int contextId = m_injectedScriptManager->discardInjectedScriptFor(context);
441 if (!m_enabled) 513 if (!m_enabled)
442 return; 514 return;
443 m_frontend->executionContextDestroyed(contextId); 515 m_frontend->executionContextDestroyed(contextId);
444 } 516 }
445 517
446 } // namespace blink 518 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698