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

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

Issue 1812983002: [DevTools] Move evaluate from InjectedScriptSource.js to native (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move-evaluate-on-call-frame
Patch Set: Removed _callFrameForId 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 const Maybe<bool>& generatePreview, 81 const Maybe<bool>& generatePreview,
82 const Maybe<bool>& userGesture, 82 const Maybe<bool>& userGesture,
83 OwnPtr<RemoteObject>* result, 83 OwnPtr<RemoteObject>* result,
84 Maybe<bool>* wasThrown, 84 Maybe<bool>* wasThrown,
85 Maybe<ExceptionDetails>* exceptionDetails) 85 Maybe<ExceptionDetails>* exceptionDetails)
86 { 86 {
87 if (!executionContextId.isJust()) { 87 if (!executionContextId.isJust()) {
88 *errorString = "Cannot find default execution context"; 88 *errorString = "Cannot find default execution context";
89 return; 89 return;
90 } 90 }
91 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (executionContextId.fromJust()); 91 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, executionContextId.fromJust());
92 if (!injectedScript) { 92 if (!injectedScript)
93 *errorString = "Cannot find execution context with given id"; 93 return;
94
95 v8::HandleScope scope(injectedScript->isolate());
96 v8::Local<v8::Context> localContext = injectedScript->context();
97 v8::Context::Scope contextScope(localContext);
98
99 if (!injectedScript->canAccessInspectedWindow()) {
100 *errorString = "Can not access given context";
94 return; 101 return;
95 } 102 }
103
104 v8::MaybeLocal<v8::Object> commandLineAPI = includeCommandLineAPI.fromMaybe( false) ? injectedScript->commandLineAPI(errorString) : v8::MaybeLocal<v8::Object >();
105 if (includeCommandLineAPI.fromMaybe(false) && commandLineAPI.IsEmpty())
106 return;
107
108 InjectedScriptManager::ScopedGlobalObjectExtension scopeExtension(injectedSc ript, nullptr, commandLineAPI);
109
96 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon sole.fromMaybe(false) ? m_debugger : nullptr); 110 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon sole.fromMaybe(false) ? m_debugger : nullptr);
97 injectedScript->evaluate(errorString, expression, objectGroup.fromMaybe(""), includeCommandLineAPI.fromMaybe(false), returnByValue.fromMaybe(false), generat ePreview.fromMaybe(false), result, wasThrown, exceptionDetails); 111
112 v8::TryCatch tryCatch(injectedScript->isolate());
113 v8::MaybeLocal<v8::Value> maybeResultValue = m_debugger->compileAndRunIntern alScript(localContext, toV8String(injectedScript->isolate(), expression));
114
115 // InjectedScript may be gone after any evaluate call - find it again.
116 injectedScript = m_injectedScriptManager->findInjectedScript(errorString, ex ecutionContextId.fromJust());
117 if (!injectedScript)
118 return;
119
120 injectedScript->wrapEvaluateResult(errorString,
121 maybeResultValue,
122 tryCatch,
123 objectGroup.fromMaybe(""),
124 returnByValue.fromMaybe(false),
125 generatePreview.fromMaybe(false),
126 result,
127 wasThrown,
128 exceptionDetails);
98 } 129 }
99 130
100 void V8RuntimeAgentImpl::callFunctionOn(ErrorString* errorString, 131 void V8RuntimeAgentImpl::callFunctionOn(ErrorString* errorString,
101 const String16& objectId, 132 const String16& objectId,
102 const String16& expression, 133 const String16& expression,
103 const Maybe<protocol::Array<protocol::Runtime::CallArgument>>& optionalArgum ents, 134 const Maybe<protocol::Array<protocol::Runtime::CallArgument>>& optionalArgum ents,
104 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, 135 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole,
105 const Maybe<bool>& returnByValue, 136 const Maybe<bool>& returnByValue,
106 const Maybe<bool>& generatePreview, 137 const Maybe<bool>& generatePreview,
107 const Maybe<bool>& userGesture, 138 const Maybe<bool>& userGesture,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 const String16& sourceURL, 220 const String16& sourceURL,
190 bool persistScript, 221 bool persistScript,
191 int executionContextId, 222 int executionContextId,
192 Maybe<String16>* scriptId, 223 Maybe<String16>* scriptId,
193 Maybe<ExceptionDetails>* exceptionDetails) 224 Maybe<ExceptionDetails>* exceptionDetails)
194 { 225 {
195 if (!m_enabled) { 226 if (!m_enabled) {
196 *errorString = "Runtime agent is not enabled"; 227 *errorString = "Runtime agent is not enabled";
197 return; 228 return;
198 } 229 }
199 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (executionContextId); 230 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, executionContextId);
200 if (!injectedScript) { 231 if (!injectedScript)
201 *errorString = "Inspected frame has gone";
202 return; 232 return;
203 }
204 233
205 v8::Isolate* isolate = injectedScript->isolate(); 234 v8::Isolate* isolate = injectedScript->isolate();
206 v8::HandleScope handles(isolate); 235 v8::HandleScope handles(isolate);
207 v8::Context::Scope scope(injectedScript->context()); 236 v8::Context::Scope scope(injectedScript->context());
208 v8::TryCatch tryCatch(isolate); 237 v8::TryCatch tryCatch(isolate);
209 v8::Local<v8::Script> script = m_debugger->compileInternalScript(injectedScr ipt->context(), toV8String(isolate, expression), sourceURL); 238 v8::Local<v8::Script> script = m_debugger->compileInternalScript(injectedScr ipt->context(), toV8String(isolate, expression), sourceURL);
210 if (script.IsEmpty()) { 239 if (script.IsEmpty()) {
211 v8::Local<v8::Message> message = tryCatch.Message(); 240 v8::Local<v8::Message> message = tryCatch.Message();
212 if (!message.IsEmpty()) 241 if (!message.IsEmpty())
213 *exceptionDetails = injectedScript->createExceptionDetails(message); 242 *exceptionDetails = injectedScript->createExceptionDetails(message);
(...skipping 17 matching lines...) Expand all
231 const Maybe<String16>& objectGroup, 260 const Maybe<String16>& objectGroup,
232 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, 261 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole,
233 const Maybe<bool>& includeCommandLineAPI, 262 const Maybe<bool>& includeCommandLineAPI,
234 OwnPtr<RemoteObject>* result, 263 OwnPtr<RemoteObject>* result,
235 Maybe<ExceptionDetails>* exceptionDetails) 264 Maybe<ExceptionDetails>* exceptionDetails)
236 { 265 {
237 if (!m_enabled) { 266 if (!m_enabled) {
238 *errorString = "Runtime agent is not enabled"; 267 *errorString = "Runtime agent is not enabled";
239 return; 268 return;
240 } 269 }
241 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (executionContextId); 270 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, executionContextId);
242 if (!injectedScript) { 271 if (!injectedScript)
243 *errorString = "Inspected frame has gone";
244 return; 272 return;
245 }
246 273
247 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon sole.fromMaybe(false) ? m_debugger : nullptr); 274 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon sole.fromMaybe(false) ? m_debugger : nullptr);
248 275
249 if (!m_compiledScripts.contains(scriptId)) { 276 if (!m_compiledScripts.contains(scriptId)) {
250 *errorString = "Script execution failed"; 277 *errorString = "Script execution failed";
251 return; 278 return;
252 } 279 }
253 280
254 v8::Isolate* isolate = injectedScript->isolate(); 281 v8::Isolate* isolate = injectedScript->isolate();
255 v8::HandleScope handles(isolate); 282 v8::HandleScope handles(isolate);
256 v8::Local<v8::Context> context = injectedScript->context(); 283 v8::Local<v8::Context> context = injectedScript->context();
257 v8::Context::Scope scope(context); 284 v8::Context::Scope scope(context);
258 OwnPtr<v8::Global<v8::Script>> scriptWrapper = m_compiledScripts.take(script Id); 285 OwnPtr<v8::Global<v8::Script>> scriptWrapper = m_compiledScripts.take(script Id);
259 v8::Local<v8::Script> script = scriptWrapper->Get(isolate); 286 v8::Local<v8::Script> script = scriptWrapper->Get(isolate);
260 287
261 if (script.IsEmpty()) { 288 if (script.IsEmpty()) {
262 *errorString = "Script execution failed"; 289 *errorString = "Script execution failed";
263 return; 290 return;
264 } 291 }
265 v8::TryCatch tryCatch(isolate);
266 292
267 v8::MaybeLocal<v8::Object> commandLineAPI = includeCommandLineAPI.fromMaybe( false) ? injectedScript->commandLineAPI(errorString) : v8::MaybeLocal<v8::Object >(); 293 v8::MaybeLocal<v8::Object> commandLineAPI = includeCommandLineAPI.fromMaybe( false) ? injectedScript->commandLineAPI(errorString) : v8::MaybeLocal<v8::Object >();
268 if (includeCommandLineAPI.fromMaybe(false) && commandLineAPI.IsEmpty()) 294 if (includeCommandLineAPI.fromMaybe(false) && commandLineAPI.IsEmpty())
269 return; 295 return;
270 296
271 InjectedScriptManager::ScopedGlobalObjectExtension scopeExtension(injectedSc ript, nullptr, commandLineAPI); 297 InjectedScriptManager::ScopedGlobalObjectExtension scopeExtension(injectedSc ript, nullptr, commandLineAPI);
272 298
273 v8::Local<v8::Value> value; 299 v8::TryCatch tryCatch(isolate);
274 v8::MaybeLocal<v8::Value> maybeValue = m_debugger->runCompiledScript(context , script); 300 v8::MaybeLocal<v8::Value> maybeResultValue = m_debugger->runCompiledScript(c ontext, script);
275 if (maybeValue.IsEmpty()) {
276 value = tryCatch.Exception();
277 v8::Local<v8::Message> message = tryCatch.Message();
278 if (!message.IsEmpty())
279 *exceptionDetails = injectedScript->createExceptionDetails(message);
280 } else {
281 value = maybeValue.ToLocalChecked();
282 }
283
284 if (value.IsEmpty()) {
285 *errorString = "Script execution failed";
286 return;
287 }
288 301
289 // InjectedScript may be gone after any evaluate call - find it again. 302 // InjectedScript may be gone after any evaluate call - find it again.
290 injectedScript = m_injectedScriptManager->findInjectedScript(executionContex tId); 303 injectedScript = m_injectedScriptManager->findInjectedScript(errorString, ex ecutionContextId);
291 if (!injectedScript) { 304 if (!injectedScript)
292 *errorString = "Inspected frame has gone during script running";
293 return; 305 return;
294 }
295 306
296 *result = injectedScript->wrapObject(errorString, value, objectGroup.fromMay be("")); 307 injectedScript->wrapEvaluateResult(errorString, maybeResultValue, tryCatch, objectGroup.fromMaybe(""), false, false, result, nullptr, exceptionDetails);
297 } 308 }
298 309
299 void V8RuntimeAgentImpl::setInspectorState(protocol::DictionaryValue* state) 310 void V8RuntimeAgentImpl::setInspectorState(protocol::DictionaryValue* state)
300 { 311 {
301 m_state = state; 312 m_state = state;
302 } 313 }
303 314
304 void V8RuntimeAgentImpl::setFrontend(protocol::Frontend::Runtime* frontend) 315 void V8RuntimeAgentImpl::setFrontend(protocol::Frontend::Runtime* frontend)
305 { 316 {
306 m_frontend = frontend; 317 m_frontend = frontend;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 437
427 void V8RuntimeAgentImpl::reportExecutionContextDestroyed(v8::Local<v8::Context> context) 438 void V8RuntimeAgentImpl::reportExecutionContextDestroyed(v8::Local<v8::Context> context)
428 { 439 {
429 int contextId = m_injectedScriptManager->discardInjectedScriptFor(context); 440 int contextId = m_injectedScriptManager->discardInjectedScriptFor(context);
430 if (!m_enabled) 441 if (!m_enabled)
431 return; 442 return;
432 m_frontend->executionContextDestroyed(contextId); 443 m_frontend->executionContextDestroyed(contextId);
433 } 444 }
434 445
435 } // namespace blink 446 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698