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

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

Issue 2206483002: [DevTools] Add awaitPromise flag for Runtime.callFunctionOn protocol method (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove-error-string-from-async
Patch Set: Created 4 years, 4 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 if (hasError) 56 if (hasError)
57 *errorString = "Internal error"; 57 *errorString = "Internal error";
58 return hasError; 58 return hasError;
59 } 59 }
60 60
61 namespace { 61 namespace {
62 62
63 template<typename Callback> 63 template<typename Callback>
64 class ProtocolPromiseHandler { 64 class ProtocolPromiseHandler {
65 public: 65 public:
66 static void add(V8DebuggerImpl* debugger, int contextGroupId, const String16 & promiseObjectId, std::unique_ptr<Callback> callback, bool returnByValue, bool generatePreview) 66 static void add(V8DebuggerImpl* debugger, v8::Local<v8::Context> context, v8 ::Local<v8::Value> value, int contextGroupId, int executionContextId, const Stri ng16& objectGroup, bool returnByValue, bool generatePreview, std::unique_ptr<Cal lback> callback)
67 { 67 {
68 ErrorString errorString; 68 if (!value->IsPromise()) {
dgozman 2016/08/02 16:52:51 Since you already do this check in 2 out of 3 meth
kozy 2016/08/02 17:31:38 Done.
69 InjectedScript::ObjectScope scope(&errorString, debugger, contextGroupId , promiseObjectId);
70 if (!scope.initialize()) {
71 callback->sendFailure(errorString);
72 return;
73 }
74 if (!scope.object()->IsPromise()) {
75 callback->sendFailure("Could not find promise with given id"); 69 callback->sendFailure("Could not find promise with given id");
76 return; 70 return;
77 } 71 }
72 Callback* rawCallback = callback.get();
73 ProtocolPromiseHandler<Callback>* handler = new ProtocolPromiseHandler(d ebugger, contextGroupId, executionContextId, objectGroup, returnByValue, generat ePreview, std::move(callback));
74 v8::Local<v8::Value> wrapper = handler->m_wrapper.Get(debugger->isolate( ));
75 v8::Local<v8::Promise> promise = v8::Local<v8::Promise>::Cast(value);
78 76
79 Callback* rawCallback = callback.get(); 77 v8::Local<v8::Function> thenCallbackFunction = v8::Function::New(context , thenCallback, wrapper, 0, v8::ConstructorBehavior::kThrow).ToLocalChecked();
80 ProtocolPromiseHandler<Callback>* handler = new ProtocolPromiseHandler(d ebugger, contextGroupId, promiseObjectId, std::move(callback), returnByValue, ge neratePreview); 78 if (promise->Then(context, thenCallbackFunction).IsEmpty()) {
81 v8::Local<v8::Value> wrapper = handler->m_wrapper.Get(debugger->isolate( ));
82 v8::Local<v8::Promise> promise = v8::Local<v8::Promise>::Cast(scope.obje ct());
83
84 v8::Local<v8::Function> thenCallbackFunction = v8::Function::New(scope.c ontext(), thenCallback, wrapper, 0, v8::ConstructorBehavior::kThrow).ToLocalChec ked();
85 if (promise->Then(scope.context(), thenCallbackFunction).IsEmpty()) {
86 rawCallback->sendFailure("Internal error"); 79 rawCallback->sendFailure("Internal error");
87 return; 80 return;
88 } 81 }
89 v8::Local<v8::Function> catchCallbackFunction = v8::Function::New(scope. context(), catchCallback, wrapper, 0, v8::ConstructorBehavior::kThrow).ToLocalCh ecked(); 82 v8::Local<v8::Function> catchCallbackFunction = v8::Function::New(contex t, catchCallback, wrapper, 0, v8::ConstructorBehavior::kThrow).ToLocalChecked();
90 if (promise->Catch(scope.context(), catchCallbackFunction).IsEmpty()) { 83 if (promise->Catch(context, catchCallbackFunction).IsEmpty()) {
91 rawCallback->sendFailure("Internal error"); 84 rawCallback->sendFailure("Internal error");
92 return; 85 return;
93 } 86 }
94 } 87 }
95
96 private: 88 private:
97 static void thenCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 89 static void thenCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
98 { 90 {
99 ProtocolPromiseHandler<Callback>* handler = static_cast<ProtocolPromiseH andler<Callback>*>(info.Data().As<v8::External>()->Value()); 91 ProtocolPromiseHandler<Callback>* handler = static_cast<ProtocolPromiseH andler<Callback>*>(info.Data().As<v8::External>()->Value());
100 DCHECK(handler); 92 DCHECK(handler);
101 v8::Local<v8::Value> value = info.Length() > 0 ? info[0] : v8::Local<v8: :Value>::Cast(v8::Undefined(info.GetIsolate())); 93 v8::Local<v8::Value> value = info.Length() > 0 ? info[0] : v8::Local<v8: :Value>::Cast(v8::Undefined(info.GetIsolate()));
102 handler->m_callback->sendSuccess(handler->wrapObject(value), Maybe<bool> (), Maybe<protocol::Runtime::ExceptionDetails>()); 94 handler->m_callback->sendSuccess(handler->wrapObject(value), Maybe<bool> (), Maybe<protocol::Runtime::ExceptionDetails>());
103 } 95 }
104 96
105 static void catchCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 97 static void catchCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
106 { 98 {
107 ProtocolPromiseHandler<Callback>* handler = static_cast<ProtocolPromiseH andler<Callback>*>(info.Data().As<v8::External>()->Value()); 99 ProtocolPromiseHandler<Callback>* handler = static_cast<ProtocolPromiseH andler<Callback>*>(info.Data().As<v8::External>()->Value());
108 DCHECK(handler); 100 DCHECK(handler);
109 v8::Local<v8::Value> value = info.Length() > 0 ? info[0] : v8::Local<v8: :Value>::Cast(v8::Undefined(info.GetIsolate())); 101 v8::Local<v8::Value> value = info.Length() > 0 ? info[0] : v8::Local<v8: :Value>::Cast(v8::Undefined(info.GetIsolate()));
110 102
111 std::unique_ptr<protocol::Runtime::ExceptionDetails> exceptionDetails; 103 std::unique_ptr<protocol::Runtime::ExceptionDetails> exceptionDetails;
112 std::unique_ptr<V8StackTraceImpl> stack = handler->m_debugger->captureSt ackTraceImpl(true); 104 std::unique_ptr<V8StackTraceImpl> stack = handler->m_debugger->captureSt ackTraceImpl(true);
113 if (stack) { 105 if (stack) {
114 exceptionDetails = protocol::Runtime::ExceptionDetails::create() 106 exceptionDetails = protocol::Runtime::ExceptionDetails::create()
115 .setText("Promise was rejected") 107 .setText("Promise was rejected")
116 .setLineNumber(!stack->isEmpty() ? stack->topLineNumber() : 0) 108 .setLineNumber(!stack->isEmpty() ? stack->topLineNumber() : 0)
117 .setColumnNumber(!stack->isEmpty() ? stack->topColumnNumber() : 0) 109 .setColumnNumber(!stack->isEmpty() ? stack->topColumnNumber() : 0)
118 .setScriptId(!stack->isEmpty() ? stack->topScriptId() : String16 ()) 110 .setScriptId(!stack->isEmpty() ? stack->topScriptId() : String16 ())
119 .setStackTrace(stack->buildInspectorObjectImpl()) 111 .setStackTrace(stack->buildInspectorObjectImpl())
120 .build(); 112 .build();
121 } 113 }
122 handler->m_callback->sendSuccess(handler->wrapObject(value), true, std:: move(exceptionDetails)); 114 handler->m_callback->sendSuccess(handler->wrapObject(value), true, std:: move(exceptionDetails));
123 } 115 }
124 116
125 ProtocolPromiseHandler(V8DebuggerImpl* debugger, int contextGroupId, const S tring16& promiseObjectId, std::unique_ptr<Callback> callback, bool returnByValue , bool generatePreview) 117 ProtocolPromiseHandler(V8DebuggerImpl* debugger, int contextGroupId, int exe cutionContextId, const String16& objectGroup, bool returnByValue, bool generateP review, std::unique_ptr<Callback> callback)
126 : m_debugger(debugger) 118 : m_debugger(debugger)
127 , m_contextGroupId(contextGroupId) 119 , m_contextGroupId(contextGroupId)
128 , m_promiseObjectId(promiseObjectId) 120 , m_executionContextId(executionContextId)
129 , m_callback(std::move(callback)) 121 , m_objectGroup(objectGroup)
130 , m_returnByValue(returnByValue) 122 , m_returnByValue(returnByValue)
131 , m_generatePreview(generatePreview) 123 , m_generatePreview(generatePreview)
124 , m_callback(std::move(callback))
132 , m_wrapper(debugger->isolate(), v8::External::New(debugger->isolate(), this)) 125 , m_wrapper(debugger->isolate(), v8::External::New(debugger->isolate(), this))
133 { 126 {
134 m_wrapper.SetWeak(this, cleanup, v8::WeakCallbackType::kParameter); 127 m_wrapper.SetWeak(this, cleanup, v8::WeakCallbackType::kParameter);
135 } 128 }
136 129
137 static void cleanup(const v8::WeakCallbackInfo<ProtocolPromiseHandler<Callba ck>>& data) 130 static void cleanup(const v8::WeakCallbackInfo<ProtocolPromiseHandler<Callba ck>>& data)
138 { 131 {
139 if (!data.GetParameter()->m_wrapper.IsEmpty()) { 132 if (!data.GetParameter()->m_wrapper.IsEmpty()) {
140 data.GetParameter()->m_wrapper.Reset(); 133 data.GetParameter()->m_wrapper.Reset();
141 data.SetSecondPassCallback(cleanup); 134 data.SetSecondPassCallback(cleanup);
142 } else { 135 } else {
143 data.GetParameter()->m_callback->sendFailure("Promise was collected" ); 136 data.GetParameter()->m_callback->sendFailure("Promise was collected" );
144 delete data.GetParameter(); 137 delete data.GetParameter();
145 } 138 }
146 } 139 }
147 140
148 std::unique_ptr<protocol::Runtime::RemoteObject> wrapObject(v8::Local<v8::Va lue> value) 141 std::unique_ptr<protocol::Runtime::RemoteObject> wrapObject(v8::Local<v8::Va lue> value)
149 { 142 {
150 ErrorString errorString; 143 ErrorString errorString;
151 InjectedScript::ObjectScope scope(&errorString, m_debugger, m_contextGro upId, m_promiseObjectId); 144 InjectedScript::ContextScope scope(&errorString, m_debugger, m_contextGr oupId, m_executionContextId);
152 if (!scope.initialize()) { 145 if (!scope.initialize()) {
153 m_callback->sendFailure(errorString); 146 m_callback->sendFailure(errorString);
154 return nullptr; 147 return nullptr;
155 } 148 }
156 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedValue = scope.in jectedScript()->wrapObject(&errorString, value, scope.objectGroupName(), m_retur nByValue, m_generatePreview); 149 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedValue = scope.in jectedScript()->wrapObject(&errorString, value, m_objectGroup, m_returnByValue, m_generatePreview);
157 if (!wrappedValue) { 150 if (!wrappedValue) {
158 m_callback->sendFailure(errorString); 151 m_callback->sendFailure(errorString);
159 return nullptr; 152 return nullptr;
160 } 153 }
161 return wrappedValue; 154 return wrappedValue;
162 } 155 }
163 156
164 V8DebuggerImpl* m_debugger; 157 V8DebuggerImpl* m_debugger;
165 int m_contextGroupId; 158 int m_contextGroupId;
166 String16 m_promiseObjectId; 159 int m_executionContextId;
167 std::unique_ptr<Callback> m_callback; 160 String16 m_objectGroup;
168 bool m_returnByValue; 161 bool m_returnByValue;
169 bool m_generatePreview; 162 bool m_generatePreview;
163 std::unique_ptr<Callback> m_callback;
170 v8::Global<v8::External> m_wrapper; 164 v8::Global<v8::External> m_wrapper;
171 }; 165 };
172 166
167 template<typename Callback>
168 bool wrapEvaluateResultAsync(InjectedScript* injectedScript, v8::MaybeLocal<v8:: Value> maybeResultValue, const v8::TryCatch& tryCatch, const String16& objectGro up, bool returnByValue, bool generatePreview, Callback* callback)
169 {
170 std::unique_ptr<RemoteObject> result;
171 Maybe<bool> wasThrown;
172 Maybe<protocol::Runtime::ExceptionDetails> exceptionDetails;
173
174 ErrorString errorString;
175 injectedScript->wrapEvaluateResult(&errorString,
176 maybeResultValue,
177 tryCatch,
178 objectGroup,
179 returnByValue,
180 generatePreview,
181 &result,
182 &wasThrown,
183 &exceptionDetails);
184 if (errorString.isEmpty()) {
185 callback->sendSuccess(std::move(result), wasThrown, exceptionDetails);
186 return true;
187 }
188 callback->sendFailure(errorString);
189 return false;
190 }
191
173 } // namespace 192 } // namespace
174 193
175 V8RuntimeAgentImpl::V8RuntimeAgentImpl(V8InspectorSessionImpl* session, protocol ::FrontendChannel* FrontendChannel, protocol::DictionaryValue* state) 194 V8RuntimeAgentImpl::V8RuntimeAgentImpl(V8InspectorSessionImpl* session, protocol ::FrontendChannel* FrontendChannel, protocol::DictionaryValue* state)
176 : m_session(session) 195 : m_session(session)
177 , m_state(state) 196 , m_state(state)
178 , m_frontend(FrontendChannel) 197 , m_frontend(FrontendChannel)
179 , m_debugger(session->debugger()) 198 , m_debugger(session->debugger())
180 , m_enabled(false) 199 , m_enabled(false)
181 { 200 {
182 } 201 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 258
240 if (evalIsDisabled) 259 if (evalIsDisabled)
241 scope.context()->AllowCodeGenerationFromStrings(false); 260 scope.context()->AllowCodeGenerationFromStrings(false);
242 261
243 // Re-initialize after running client's code, as it could have destroyed con text or session. 262 // Re-initialize after running client's code, as it could have destroyed con text or session.
244 if (!scope.initialize()) { 263 if (!scope.initialize()) {
245 callback->sendFailure(errorString); 264 callback->sendFailure(errorString);
246 return; 265 return;
247 } 266 }
248 267
249 std::unique_ptr<RemoteObject> result; 268 if (!awaitPromise.fromMaybe(false) || scope.tryCatch().HasCaught()) {
250 Maybe<bool> wasThrown; 269 wrapEvaluateResultAsync(scope.injectedScript(), maybeResultValue, scope. tryCatch(), objectGroup.fromMaybe(""), returnByValue.fromMaybe(false), generateP review.fromMaybe(false), callback.get());
251 Maybe<protocol::Runtime::ExceptionDetails> exceptionDetails;
252
253 scope.injectedScript()->wrapEvaluateResult(&errorString,
254 maybeResultValue,
255 scope.tryCatch(),
256 objectGroup.fromMaybe(""),
257 returnByValue.fromMaybe(false) && !awaitPromise.fromMaybe(false),
258 generatePreview.fromMaybe(false) && !awaitPromise.fromMaybe(false),
259 &result,
260 &wasThrown,
261 &exceptionDetails);
262 if (!errorString.isEmpty()) {
263 callback->sendFailure(errorString);
264 return; 270 return;
265 } 271 }
266 272
267 if (!awaitPromise.fromMaybe(false) || wasThrown.fromMaybe(false)) {
268 callback->sendSuccess(std::move(result), wasThrown, exceptionDetails);
269 return;
270 }
271
272 if (maybeResultValue.IsEmpty()) { 273 if (maybeResultValue.IsEmpty()) {
273 callback->sendFailure("Internal error"); 274 callback->sendFailure("Internal error");
274 return; 275 return;
275 } 276 }
276 277
277 if (!maybeResultValue.ToLocalChecked()->IsPromise()) { 278 if (!maybeResultValue.ToLocalChecked()->IsPromise()) {
278 callback->sendFailure("Result of expression is not a promise."); 279 callback->sendFailure("Result of expression is not a promise.");
279 return; 280 return;
280 } 281 }
281 282
282 ProtocolPromiseHandler<EvaluateCallback>::add(m_debugger, m_session->context GroupId(), result->getObjectId(String16()), std::move(callback), returnByValue.f romMaybe(false), generatePreview.fromMaybe(false)); 283 ProtocolPromiseHandler<EvaluateCallback>::add(
284 m_debugger,
285 scope.context(),
286 maybeResultValue.ToLocalChecked(),
287 m_session->contextGroupId(),
288 scope.injectedScript()->context()->contextId(),
289 objectGroup.fromMaybe(""),
290 returnByValue.fromMaybe(false),
291 generatePreview.fromMaybe(false),
292 std::move(callback));
283 } 293 }
284 294
285 void V8RuntimeAgentImpl::awaitPromise( 295 void V8RuntimeAgentImpl::awaitPromise(
286 const String16& promiseObjectId, 296 const String16& promiseObjectId,
287 const Maybe<bool>& returnByValue, 297 const Maybe<bool>& returnByValue,
288 const Maybe<bool>& generatePreview, 298 const Maybe<bool>& generatePreview,
289 std::unique_ptr<AwaitPromiseCallback> callback) 299 std::unique_ptr<AwaitPromiseCallback> callback)
290 { 300 {
291 ProtocolPromiseHandler<AwaitPromiseCallback>::add(m_debugger, m_session->con textGroupId(), promiseObjectId, std::move(callback), returnByValue.fromMaybe(fal se), generatePreview.fromMaybe(false)); 301 ErrorString errorString;
302 InjectedScript::ObjectScope scope(&errorString, m_debugger, m_session->conte xtGroupId(), promiseObjectId);
303 if (!scope.initialize()) {
304 callback->sendFailure(errorString);
305 return;
306 }
307 ProtocolPromiseHandler<AwaitPromiseCallback>::add(
308 m_debugger,
309 scope.context(),
310 scope.object(),
311 m_session->contextGroupId(),
312 scope.injectedScript()->context()->contextId(),
313 scope.objectGroupName(),
314 returnByValue.fromMaybe(false),
315 generatePreview.fromMaybe(false),
316 std::move(callback));
292 } 317 }
293 318
294 void V8RuntimeAgentImpl::callFunctionOn(ErrorString* errorString, 319 void V8RuntimeAgentImpl::callFunctionOn(
295 const String16& objectId, 320 const String16& objectId,
296 const String16& expression, 321 const String16& expression,
297 const Maybe<protocol::Array<protocol::Runtime::CallArgument>>& optionalArgum ents, 322 const Maybe<protocol::Array<protocol::Runtime::CallArgument>>& optionalArgum ents,
298 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, 323 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole,
299 const Maybe<bool>& returnByValue, 324 const Maybe<bool>& returnByValue,
300 const Maybe<bool>& generatePreview, 325 const Maybe<bool>& generatePreview,
301 const Maybe<bool>& userGesture, 326 const Maybe<bool>& userGesture,
302 std::unique_ptr<RemoteObject>* result, 327 const Maybe<bool>& awaitPromise,
303 Maybe<bool>* wasThrown) 328 std::unique_ptr<CallFunctionOnCallback> callback)
304 { 329 {
305 InjectedScript::ObjectScope scope(errorString, m_debugger, m_session->contex tGroupId(), objectId); 330 ErrorString errorString;
306 if (!scope.initialize()) 331 InjectedScript::ObjectScope scope(&errorString, m_debugger, m_session->conte xtGroupId(), objectId);
332 if (!scope.initialize()) {
333 callback->sendFailure(errorString);
307 return; 334 return;
335 }
308 336
309 std::unique_ptr<v8::Local<v8::Value>[]> argv = nullptr; 337 std::unique_ptr<v8::Local<v8::Value>[]> argv = nullptr;
310 int argc = 0; 338 int argc = 0;
311 if (optionalArguments.isJust()) { 339 if (optionalArguments.isJust()) {
312 protocol::Array<protocol::Runtime::CallArgument>* arguments = optionalAr guments.fromJust(); 340 protocol::Array<protocol::Runtime::CallArgument>* arguments = optionalAr guments.fromJust();
313 argc = arguments->length(); 341 argc = arguments->length();
314 argv.reset(new v8::Local<v8::Value>[argc]); 342 argv.reset(new v8::Local<v8::Value>[argc]);
315 for (int i = 0; i < argc; ++i) { 343 for (int i = 0; i < argc; ++i) {
316 v8::Local<v8::Value> argumentValue; 344 v8::Local<v8::Value> argumentValue;
317 if (!scope.injectedScript()->resolveCallArgument(errorString, argume nts->get(i)).ToLocal(&argumentValue)) 345 if (!scope.injectedScript()->resolveCallArgument(&errorString, argum ents->get(i)).ToLocal(&argumentValue)) {
346 callback->sendFailure(errorString);
318 return; 347 return;
348 }
319 argv[i] = argumentValue; 349 argv[i] = argumentValue;
320 } 350 }
321 } 351 }
322 352
323 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) 353 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false))
324 scope.ignoreExceptionsAndMuteConsole(); 354 scope.ignoreExceptionsAndMuteConsole();
325 if (userGesture.fromMaybe(false)) 355 if (userGesture.fromMaybe(false))
326 scope.pretendUserGesture(); 356 scope.pretendUserGesture();
327 357
328 v8::MaybeLocal<v8::Value> maybeFunctionValue = m_debugger->compileAndRunInte rnalScript(scope.context(), toV8String(m_debugger->isolate(), "(" + expression + ")")); 358 v8::MaybeLocal<v8::Value> maybeFunctionValue = m_debugger->compileAndRunInte rnalScript(scope.context(), toV8String(m_debugger->isolate(), "(" + expression + ")"));
329 // Re-initialize after running client's code, as it could have destroyed con text or session. 359 // Re-initialize after running client's code, as it could have destroyed con text or session.
330 if (!scope.initialize()) 360 if (!scope.initialize()) {
361 callback->sendFailure(errorString);
331 return; 362 return;
363 }
332 364
333 if (scope.tryCatch().HasCaught()) { 365 if (scope.tryCatch().HasCaught()) {
334 scope.injectedScript()->wrapEvaluateResult(errorString, maybeFunctionVal ue, scope.tryCatch(), scope.objectGroupName(), false, false, result, wasThrown, nullptr); 366 wrapEvaluateResultAsync(scope.injectedScript(), maybeFunctionValue, scop e.tryCatch(), scope.objectGroupName(), false, false, callback.get());
335 return; 367 return;
336 } 368 }
337 369
338 v8::Local<v8::Value> functionValue; 370 v8::Local<v8::Value> functionValue;
339 if (!maybeFunctionValue.ToLocal(&functionValue) || !functionValue->IsFunctio n()) { 371 if (!maybeFunctionValue.ToLocal(&functionValue) || !functionValue->IsFunctio n()) {
340 *errorString = "Given expression does not evaluate to a function"; 372 callback->sendFailure("Given expression does not evaluate to a function" );
341 return; 373 return;
342 } 374 }
343 375
344 v8::MaybeLocal<v8::Value> maybeResultValue = m_debugger->callFunction(functi onValue.As<v8::Function>(), scope.context(), scope.object(), argc, argv.get()); 376 v8::MaybeLocal<v8::Value> maybeResultValue = m_debugger->callFunction(functi onValue.As<v8::Function>(), scope.context(), scope.object(), argc, argv.get());
345 // Re-initialize after running client's code, as it could have destroyed con text or session. 377 // Re-initialize after running client's code, as it could have destroyed con text or session.
346 if (!scope.initialize()) 378 if (!scope.initialize()) {
379 callback->sendFailure(errorString);
347 return; 380 return;
381 }
348 382
349 scope.injectedScript()->wrapEvaluateResult(errorString, maybeResultValue, sc ope.tryCatch(), scope.objectGroupName(), returnByValue.fromMaybe(false), generat ePreview.fromMaybe(false), result, wasThrown, nullptr); 383 if (!awaitPromise.fromMaybe(false) || scope.tryCatch().HasCaught()) {
384 wrapEvaluateResultAsync(scope.injectedScript(), maybeResultValue, scope. tryCatch(), scope.objectGroupName(), returnByValue.fromMaybe(false), generatePre view.fromMaybe(false), callback.get());
385 return;
386 }
387
388 if (maybeResultValue.IsEmpty()) {
389 callback->sendFailure("Internal error");
390 return;
391 }
392
393 if (!maybeResultValue.ToLocalChecked()->IsPromise()) {
394 callback->sendFailure("Result of expression is not a promise.");
dgozman 2016/08/02 16:52:51 Result of the function call is not a promise.
kozy 2016/08/02 17:31:38 Done.
395 return;
396 }
397
398 ProtocolPromiseHandler<CallFunctionOnCallback>::add(
399 m_debugger,
400 scope.context(),
401 maybeResultValue.ToLocalChecked(),
402 m_session->contextGroupId(),
403 scope.injectedScript()->context()->contextId(),
404 scope.objectGroupName(),
405 returnByValue.fromMaybe(false),
406 generatePreview.fromMaybe(false),
407 std::move(callback));
350 } 408 }
351 409
352 void V8RuntimeAgentImpl::getProperties( 410 void V8RuntimeAgentImpl::getProperties(
353 ErrorString* errorString, 411 ErrorString* errorString,
354 const String16& objectId, 412 const String16& objectId,
355 const Maybe<bool>& ownProperties, 413 const Maybe<bool>& ownProperties,
356 const Maybe<bool>& accessorPropertiesOnly, 414 const Maybe<bool>& accessorPropertiesOnly,
357 const Maybe<bool>& generatePreview, 415 const Maybe<bool>& generatePreview,
358 std::unique_ptr<protocol::Array<protocol::Runtime::PropertyDescriptor>>* res ult, 416 std::unique_ptr<protocol::Array<protocol::Runtime::PropertyDescriptor>>* res ult,
359 Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>* inter nalProperties, 417 Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>* inter nalProperties,
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 reportMessage(message, true); 650 reportMessage(message, true);
593 } 651 }
594 652
595 void V8RuntimeAgentImpl::reportMessage(V8ConsoleMessage* message, bool generateP review) 653 void V8RuntimeAgentImpl::reportMessage(V8ConsoleMessage* message, bool generateP review)
596 { 654 {
597 message->reportToFrontend(&m_frontend, m_session, generatePreview); 655 message->reportToFrontend(&m_frontend, m_session, generatePreview);
598 m_frontend.flush(); 656 m_frontend.flush();
599 } 657 }
600 658
601 } // namespace blink 659 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698