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