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

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
« no previous file with comments | « third_party/WebKit/Source/platform/v8_inspector/V8RuntimeAgentImpl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 98
99 if (!injectedScript->canAccessInspectedWindow()) { 99 if (!injectedScript->canAccessInspectedWindow()) {
100 *errorString = "Can not access given context"; 100 *errorString = "Can not access given context";
101 return; 101 return;
102 } 102 }
103 103
104 v8::MaybeLocal<v8::Object> commandLineAPI = includeCommandLineAPI.fromMaybe( false) ? injectedScript->commandLineAPI(errorString) : v8::MaybeLocal<v8::Object >(); 104 v8::MaybeLocal<v8::Object> commandLineAPI = includeCommandLineAPI.fromMaybe( false) ? injectedScript->commandLineAPI(errorString) : v8::MaybeLocal<v8::Object >();
105 if (includeCommandLineAPI.fromMaybe(false) && commandLineAPI.IsEmpty()) 105 if (includeCommandLineAPI.fromMaybe(false) && commandLineAPI.IsEmpty())
106 return; 106 return;
107 107
108 InjectedScriptManager::ScopedGlobalObjectExtension scopeExtension(injectedSc ript, nullptr, commandLineAPI);
109
110 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon sole.fromMaybe(false) ? m_debugger : nullptr);
111
112 v8::TryCatch tryCatch(injectedScript->isolate()); 108 v8::TryCatch tryCatch(injectedScript->isolate());
113 v8::MaybeLocal<v8::Value> maybeResultValue = m_debugger->compileAndRunIntern alScript(localContext, toV8String(injectedScript->isolate(), expression)); 109 v8::MaybeLocal<v8::Value> maybeResultValue = evaluateInternal(injectedScript , doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false), expression, commandLine API);
114 110
115 // InjectedScript may be gone after any evaluate call - find it again. 111 // InjectedScript may be gone after any evaluate call - find it again.
116 injectedScript = m_injectedScriptManager->findInjectedScript(errorString, ex ecutionContextId.fromJust()); 112 injectedScript = m_injectedScriptManager->findInjectedScript(errorString, ex ecutionContextId.fromJust());
117 if (!injectedScript) 113 if (!injectedScript)
118 return; 114 return;
119 115
120 injectedScript->wrapEvaluateResult(errorString, 116 injectedScript->wrapEvaluateResult(errorString,
121 maybeResultValue, 117 maybeResultValue,
122 tryCatch, 118 tryCatch,
123 objectGroup.fromMaybe(""), 119 objectGroup.fromMaybe(""),
124 returnByValue.fromMaybe(false), 120 returnByValue.fromMaybe(false),
125 generatePreview.fromMaybe(false), 121 generatePreview.fromMaybe(false),
126 result, 122 result,
127 wasThrown, 123 wasThrown,
128 exceptionDetails); 124 exceptionDetails);
129 } 125 }
130 126
127 v8::MaybeLocal<v8::Value> V8RuntimeAgentImpl::evaluateInternal(InjectedScript* i njectedScript, bool doNotPauseOnExceptionsAndMuteConsole, const String& expressi on, v8::MaybeLocal<v8::Object> extension)
128 {
129 InjectedScriptManager::ScopedGlobalObjectExtension scopeExtension(injectedSc ript, nullptr, extension);
130 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon sole ? m_debugger : nullptr);
131 return m_debugger->compileAndRunInternalScript(injectedScript->context(), to V8String(injectedScript->isolate(), expression));
132 }
133
131 void V8RuntimeAgentImpl::callFunctionOn(ErrorString* errorString, 134 void V8RuntimeAgentImpl::callFunctionOn(ErrorString* errorString,
132 const String16& objectId, 135 const String16& objectId,
133 const String16& expression, 136 const String16& expression,
134 const Maybe<protocol::Array<protocol::Runtime::CallArgument>>& optionalArgum ents, 137 const Maybe<protocol::Array<protocol::Runtime::CallArgument>>& optionalArgum ents,
135 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, 138 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole,
136 const Maybe<bool>& returnByValue, 139 const Maybe<bool>& returnByValue,
137 const Maybe<bool>& generatePreview, 140 const Maybe<bool>& generatePreview,
138 const Maybe<bool>& userGesture, 141 const Maybe<bool>& userGesture,
139 OwnPtr<RemoteObject>* result, 142 OwnPtr<RemoteObject>* result,
140 Maybe<bool>* wasThrown) 143 Maybe<bool>* wasThrown)
141 { 144 {
142 OwnPtr<RemoteObjectId> remoteId = RemoteObjectId::parse(errorString, objectI d); 145 OwnPtr<RemoteObjectId> remoteId = RemoteObjectId::parse(errorString, objectI d);
143 if (!remoteId) 146 if (!remoteId)
144 return; 147 return;
145 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get()); 148 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get());
146 if (!injectedScript) 149 if (!injectedScript)
147 return; 150 return;
148 String16 arguments; 151
149 if (optionalArguments.isJust()) 152 v8::HandleScope scope(injectedScript->isolate());
150 arguments = protocol::toValue(optionalArguments.fromJust())->toJSONStrin g(); 153 v8::Local<v8::Context> localContext = injectedScript->context();
154 v8::Context::Scope contextScope(localContext);
155
156 if (!injectedScript->canAccessInspectedWindow()) {
157 *errorString = "Can not access given context";
158 return;
159 }
160
161 String16 objectGroupName = injectedScript->objectGroupName(*remoteId);
162 v8::Local<v8::Value> object = injectedScript->findObject(*remoteId);
163 if (object.IsEmpty()) {
164 *errorString = "Could not find object with given id";
165 return;
166 }
167 OwnPtr<v8::Local<v8::Value>[]> argv = nullptr;
168 int argc = 0;
169 if (optionalArguments.isJust()) {
170 protocol::Array<protocol::Runtime::CallArgument>* arguments = optionalAr guments.fromJust();
171 argc = arguments->length();
172 argv = adoptArrayPtr(new v8::Local<v8::Value>[argc]);
173 for (int i = 0; i < argc; ++i) {
174 v8::Local<v8::Value> argumentValue;
175 if (!injectedScript->resolveCallArgument(errorString, arguments->get (i)).ToLocal(&argumentValue))
176 return;
177 argv[i] = argumentValue;
178 }
179 }
151 180
152 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon sole.fromMaybe(false) ? m_debugger : nullptr); 181 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon sole.fromMaybe(false) ? m_debugger : nullptr);
153 injectedScript->callFunctionOn(errorString, objectId, expression, arguments, returnByValue.fromMaybe(false), generatePreview.fromMaybe(false), result, wasTh rown); 182
183 v8::MaybeLocal<v8::Object> remoteObjectAPI = injectedScript->remoteObjectAPI (errorString, objectGroupName);
184 if (remoteObjectAPI.IsEmpty())
185 return;
186
187 v8::TryCatch tryCatch(injectedScript->isolate());
188 v8::MaybeLocal<v8::Value> maybeFunctionValue = evaluateInternal(injectedScri pt, doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false), "(" + expression + ") ", remoteObjectAPI);
189 // InjectedScript may be gone after any evaluate call - find it again.
190 injectedScript = m_injectedScriptManager->findInjectedScript(errorString, re moteId.get());
191 if (!injectedScript)
192 return;
193
194 if (tryCatch.HasCaught()) {
195 injectedScript->wrapEvaluateResult(errorString, maybeFunctionValue, tryC atch, objectGroupName, false, false, result, wasThrown, nullptr);
196 return;
197 }
198
199 v8::Local<v8::Value> functionValue;
200 if (!maybeFunctionValue.ToLocal(&functionValue) || !functionValue->IsFunctio n()) {
201 *errorString = "Given expression does not evaluate to a function";
202 return;
203 }
204
205 v8::MaybeLocal<v8::Value> maybeResultValue = m_debugger->callFunction(functi onValue.As<v8::Function>(), injectedScript->context(), object, argc, argv.get()) ;
206 // InjectedScript may be gone after any evaluate call - find it again.
207 injectedScript = m_injectedScriptManager->findInjectedScript(errorString, re moteId.get());
208 if (!injectedScript)
209 return;
210
211 injectedScript->wrapEvaluateResult(errorString, maybeResultValue, tryCatch, objectGroupName, returnByValue.fromMaybe(false), generatePreview.fromMaybe(false ), result, wasThrown, nullptr);
154 } 212 }
155 213
156 void V8RuntimeAgentImpl::getProperties( 214 void V8RuntimeAgentImpl::getProperties(
157 ErrorString* errorString, 215 ErrorString* errorString,
158 const String16& objectId, 216 const String16& objectId,
159 const Maybe<bool>& ownProperties, 217 const Maybe<bool>& ownProperties,
160 const Maybe<bool>& accessorPropertiesOnly, 218 const Maybe<bool>& accessorPropertiesOnly,
161 const Maybe<bool>& generatePreview, 219 const Maybe<bool>& generatePreview,
162 OwnPtr<protocol::Array<protocol::Runtime::PropertyDescriptor>>* result, 220 OwnPtr<protocol::Array<protocol::Runtime::PropertyDescriptor>>* result,
163 Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>* inter nalProperties, 221 Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>* inter nalProperties,
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 495
438 void V8RuntimeAgentImpl::reportExecutionContextDestroyed(v8::Local<v8::Context> context) 496 void V8RuntimeAgentImpl::reportExecutionContextDestroyed(v8::Local<v8::Context> context)
439 { 497 {
440 int contextId = m_injectedScriptManager->discardInjectedScriptFor(context); 498 int contextId = m_injectedScriptManager->discardInjectedScriptFor(context);
441 if (!m_enabled) 499 if (!m_enabled)
442 return; 500 return;
443 m_frontend->executionContextDestroyed(contextId); 501 m_frontend->executionContextDestroyed(contextId);
444 } 502 }
445 503
446 } // namespace blink 504 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/v8_inspector/V8RuntimeAgentImpl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698