| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 static const char runtimeEnabled[] = "runtimeEnabled"; | 54 static const char runtimeEnabled[] = "runtimeEnabled"; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 using protocol::Runtime::RemoteObject; | 57 using protocol::Runtime::RemoteObject; |
| 58 | 58 |
| 59 namespace { | 59 namespace { |
| 60 | 60 |
| 61 template <typename Callback> | 61 template <typename Callback> |
| 62 class ProtocolPromiseHandler { | 62 class ProtocolPromiseHandler { |
| 63 public: | 63 public: |
| 64 static void add(V8InspectorImpl* inspector, v8::Local<v8::Context> context, | 64 static void add(V8InspectorSessionImpl* session, |
| 65 v8::Local<v8::Context> context, |
| 65 v8::MaybeLocal<v8::Value> value, | 66 v8::MaybeLocal<v8::Value> value, |
| 66 const String16& notPromiseError, int contextGroupId, | 67 const String16& notPromiseError, int executionContextId, |
| 67 int executionContextId, const String16& objectGroup, | 68 const String16& objectGroup, bool returnByValue, |
| 68 bool returnByValue, bool generatePreview, | 69 bool generatePreview, std::unique_ptr<Callback> callback) { |
| 69 std::unique_ptr<Callback> callback) { | |
| 70 if (value.IsEmpty()) { | 70 if (value.IsEmpty()) { |
| 71 callback->sendFailure(Response::InternalError()); | 71 callback->sendFailure(Response::InternalError()); |
| 72 return; | 72 return; |
| 73 } | 73 } |
| 74 if (!value.ToLocalChecked()->IsPromise()) { | 74 if (!value.ToLocalChecked()->IsPromise()) { |
| 75 callback->sendFailure(Response::Error(notPromiseError)); | 75 callback->sendFailure(Response::Error(notPromiseError)); |
| 76 return; | 76 return; |
| 77 } | 77 } |
| 78 V8InspectorImpl* inspector = session->inspector(); |
| 78 v8::MicrotasksScope microtasks_scope(inspector->isolate(), | 79 v8::MicrotasksScope microtasks_scope(inspector->isolate(), |
| 79 v8::MicrotasksScope::kRunMicrotasks); | 80 v8::MicrotasksScope::kRunMicrotasks); |
| 80 v8::Local<v8::Promise> promise = | 81 v8::Local<v8::Promise> promise = |
| 81 v8::Local<v8::Promise>::Cast(value.ToLocalChecked()); | 82 v8::Local<v8::Promise>::Cast(value.ToLocalChecked()); |
| 82 Callback* rawCallback = callback.get(); | 83 Callback* rawCallback = callback.get(); |
| 83 ProtocolPromiseHandler<Callback>* handler = new ProtocolPromiseHandler( | 84 ProtocolPromiseHandler<Callback>* handler = new ProtocolPromiseHandler( |
| 84 inspector, contextGroupId, executionContextId, objectGroup, | 85 session, executionContextId, objectGroup, returnByValue, |
| 85 returnByValue, generatePreview, std::move(callback)); | 86 generatePreview, std::move(callback)); |
| 86 v8::Local<v8::Value> wrapper = handler->m_wrapper.Get(inspector->isolate()); | 87 v8::Local<v8::Value> wrapper = handler->m_wrapper.Get(inspector->isolate()); |
| 87 | 88 |
| 88 v8::Local<v8::Function> thenCallbackFunction = | 89 v8::Local<v8::Function> thenCallbackFunction = |
| 89 v8::Function::New(context, thenCallback, wrapper, 0, | 90 v8::Function::New(context, thenCallback, wrapper, 0, |
| 90 v8::ConstructorBehavior::kThrow) | 91 v8::ConstructorBehavior::kThrow) |
| 91 .ToLocalChecked(); | 92 .ToLocalChecked(); |
| 92 if (promise->Then(context, thenCallbackFunction).IsEmpty()) { | 93 if (promise->Then(context, thenCallbackFunction).IsEmpty()) { |
| 93 rawCallback->sendFailure(Response::InternalError()); | 94 rawCallback->sendFailure(Response::InternalError()); |
| 94 return; | 95 return; |
| 95 } | 96 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 .setException(wrappedValue->clone()) | 148 .setException(wrappedValue->clone()) |
| 148 .build(); | 149 .build(); |
| 149 if (stack) | 150 if (stack) |
| 150 exceptionDetails->setStackTrace(stack->buildInspectorObjectImpl()); | 151 exceptionDetails->setStackTrace(stack->buildInspectorObjectImpl()); |
| 151 if (stack && !stack->isEmpty()) | 152 if (stack && !stack->isEmpty()) |
| 152 exceptionDetails->setScriptId(toString16(stack->topScriptId())); | 153 exceptionDetails->setScriptId(toString16(stack->topScriptId())); |
| 153 handler->m_callback->sendSuccess(std::move(wrappedValue), | 154 handler->m_callback->sendSuccess(std::move(wrappedValue), |
| 154 std::move(exceptionDetails)); | 155 std::move(exceptionDetails)); |
| 155 } | 156 } |
| 156 | 157 |
| 157 ProtocolPromiseHandler(V8InspectorImpl* inspector, int contextGroupId, | 158 ProtocolPromiseHandler(V8InspectorSessionImpl* session, |
| 158 int executionContextId, const String16& objectGroup, | 159 int executionContextId, const String16& objectGroup, |
| 159 bool returnByValue, bool generatePreview, | 160 bool returnByValue, bool generatePreview, |
| 160 std::unique_ptr<Callback> callback) | 161 std::unique_ptr<Callback> callback) |
| 161 : m_inspector(inspector), | 162 : m_inspector(session->inspector()), |
| 162 m_contextGroupId(contextGroupId), | 163 m_sessionId(session->sessionId()), |
| 163 m_executionContextId(executionContextId), | 164 m_executionContextId(executionContextId), |
| 164 m_objectGroup(objectGroup), | 165 m_objectGroup(objectGroup), |
| 165 m_returnByValue(returnByValue), | 166 m_returnByValue(returnByValue), |
| 166 m_generatePreview(generatePreview), | 167 m_generatePreview(generatePreview), |
| 167 m_callback(std::move(callback)), | 168 m_callback(std::move(callback)), |
| 168 m_wrapper(inspector->isolate(), | 169 m_wrapper(m_inspector->isolate(), |
| 169 v8::External::New(inspector->isolate(), this)) { | 170 v8::External::New(m_inspector->isolate(), this)) { |
| 170 m_wrapper.SetWeak(this, cleanup, v8::WeakCallbackType::kParameter); | 171 m_wrapper.SetWeak(this, cleanup, v8::WeakCallbackType::kParameter); |
| 171 } | 172 } |
| 172 | 173 |
| 173 static void cleanup( | 174 static void cleanup( |
| 174 const v8::WeakCallbackInfo<ProtocolPromiseHandler<Callback>>& data) { | 175 const v8::WeakCallbackInfo<ProtocolPromiseHandler<Callback>>& data) { |
| 175 if (!data.GetParameter()->m_wrapper.IsEmpty()) { | 176 if (!data.GetParameter()->m_wrapper.IsEmpty()) { |
| 176 data.GetParameter()->m_wrapper.Reset(); | 177 data.GetParameter()->m_wrapper.Reset(); |
| 177 data.SetSecondPassCallback(cleanup); | 178 data.SetSecondPassCallback(cleanup); |
| 178 } else { | 179 } else { |
| 179 data.GetParameter()->m_callback->sendFailure( | 180 data.GetParameter()->m_callback->sendFailure( |
| 180 Response::Error("Promise was collected")); | 181 Response::Error("Promise was collected")); |
| 181 delete data.GetParameter(); | 182 delete data.GetParameter(); |
| 182 } | 183 } |
| 183 } | 184 } |
| 184 | 185 |
| 185 std::unique_ptr<protocol::Runtime::RemoteObject> wrapObject( | 186 std::unique_ptr<protocol::Runtime::RemoteObject> wrapObject( |
| 186 v8::Local<v8::Value> value) { | 187 v8::Local<v8::Value> value) { |
| 187 InjectedScript::ContextScope scope(m_inspector, m_contextGroupId, | 188 V8InspectorSessionImpl* session = m_inspector->sessionById(m_sessionId); |
| 188 m_executionContextId); | 189 if (!session) { |
| 190 m_callback->sendFailure(Response::Error("No session")); |
| 191 return nullptr; |
| 192 } |
| 193 InjectedScript::ContextScope scope(session, m_executionContextId); |
| 189 Response response = scope.initialize(); | 194 Response response = scope.initialize(); |
| 190 if (!response.isSuccess()) { | 195 if (!response.isSuccess()) { |
| 191 m_callback->sendFailure(response); | 196 m_callback->sendFailure(response); |
| 192 return nullptr; | 197 return nullptr; |
| 193 } | 198 } |
| 194 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedValue; | 199 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedValue; |
| 195 response = scope.injectedScript()->wrapObject( | 200 response = scope.injectedScript()->wrapObject( |
| 196 value, m_objectGroup, m_returnByValue, m_generatePreview, | 201 value, m_objectGroup, m_returnByValue, m_generatePreview, |
| 197 &wrappedValue); | 202 &wrappedValue); |
| 198 if (!response.isSuccess()) { | 203 if (!response.isSuccess()) { |
| 199 m_callback->sendFailure(response); | 204 m_callback->sendFailure(response); |
| 200 return nullptr; | 205 return nullptr; |
| 201 } | 206 } |
| 202 return wrappedValue; | 207 return wrappedValue; |
| 203 } | 208 } |
| 204 | 209 |
| 205 V8InspectorImpl* m_inspector; | 210 V8InspectorImpl* m_inspector; |
| 206 int m_contextGroupId; | 211 int m_sessionId; |
| 207 int m_executionContextId; | 212 int m_executionContextId; |
| 208 String16 m_objectGroup; | 213 String16 m_objectGroup; |
| 209 bool m_returnByValue; | 214 bool m_returnByValue; |
| 210 bool m_generatePreview; | 215 bool m_generatePreview; |
| 211 std::unique_ptr<Callback> m_callback; | 216 std::unique_ptr<Callback> m_callback; |
| 212 v8::Global<v8::External> m_wrapper; | 217 v8::Global<v8::External> m_wrapper; |
| 213 }; | 218 }; |
| 214 | 219 |
| 215 template <typename Callback> | 220 template <typename Callback> |
| 216 bool wrapEvaluateResultAsync(InjectedScript* injectedScript, | 221 bool wrapEvaluateResultAsync(InjectedScript* injectedScript, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), | 274 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), |
| 270 "EvaluateScript"); | 275 "EvaluateScript"); |
| 271 int contextId = 0; | 276 int contextId = 0; |
| 272 Response response = ensureContext(m_inspector, m_session->contextGroupId(), | 277 Response response = ensureContext(m_inspector, m_session->contextGroupId(), |
| 273 std::move(executionContextId), &contextId); | 278 std::move(executionContextId), &contextId); |
| 274 if (!response.isSuccess()) { | 279 if (!response.isSuccess()) { |
| 275 callback->sendFailure(response); | 280 callback->sendFailure(response); |
| 276 return; | 281 return; |
| 277 } | 282 } |
| 278 | 283 |
| 279 InjectedScript::ContextScope scope(m_inspector, m_session->contextGroupId(), | 284 InjectedScript::ContextScope scope(m_session, contextId); |
| 280 contextId); | |
| 281 response = scope.initialize(); | 285 response = scope.initialize(); |
| 282 if (!response.isSuccess()) { | 286 if (!response.isSuccess()) { |
| 283 callback->sendFailure(response); | 287 callback->sendFailure(response); |
| 284 return; | 288 return; |
| 285 } | 289 } |
| 286 | 290 |
| 287 if (silent.fromMaybe(false)) scope.ignoreExceptionsAndMuteConsole(); | 291 if (silent.fromMaybe(false)) scope.ignoreExceptionsAndMuteConsole(); |
| 288 if (userGesture.fromMaybe(false)) scope.pretendUserGesture(); | 292 if (userGesture.fromMaybe(false)) scope.pretendUserGesture(); |
| 289 | 293 |
| 290 if (includeCommandLineAPI.fromMaybe(false)) scope.installCommandLineAPI(); | 294 if (includeCommandLineAPI.fromMaybe(false)) scope.installCommandLineAPI(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 313 } | 317 } |
| 314 | 318 |
| 315 if (!awaitPromise.fromMaybe(false) || scope.tryCatch().HasCaught()) { | 319 if (!awaitPromise.fromMaybe(false) || scope.tryCatch().HasCaught()) { |
| 316 wrapEvaluateResultAsync(scope.injectedScript(), maybeResultValue, | 320 wrapEvaluateResultAsync(scope.injectedScript(), maybeResultValue, |
| 317 scope.tryCatch(), objectGroup.fromMaybe(""), | 321 scope.tryCatch(), objectGroup.fromMaybe(""), |
| 318 returnByValue.fromMaybe(false), | 322 returnByValue.fromMaybe(false), |
| 319 generatePreview.fromMaybe(false), callback.get()); | 323 generatePreview.fromMaybe(false), callback.get()); |
| 320 return; | 324 return; |
| 321 } | 325 } |
| 322 ProtocolPromiseHandler<EvaluateCallback>::add( | 326 ProtocolPromiseHandler<EvaluateCallback>::add( |
| 323 m_inspector, scope.context(), maybeResultValue, | 327 m_session, scope.context(), maybeResultValue, |
| 324 "Result of the evaluation is not a promise", m_session->contextGroupId(), | 328 "Result of the evaluation is not a promise", |
| 325 scope.injectedScript()->context()->contextId(), objectGroup.fromMaybe(""), | 329 scope.injectedScript()->context()->contextId(), objectGroup.fromMaybe(""), |
| 326 returnByValue.fromMaybe(false), generatePreview.fromMaybe(false), | 330 returnByValue.fromMaybe(false), generatePreview.fromMaybe(false), |
| 327 std::move(callback)); | 331 std::move(callback)); |
| 328 } | 332 } |
| 329 | 333 |
| 330 void V8RuntimeAgentImpl::awaitPromise( | 334 void V8RuntimeAgentImpl::awaitPromise( |
| 331 const String16& promiseObjectId, Maybe<bool> returnByValue, | 335 const String16& promiseObjectId, Maybe<bool> returnByValue, |
| 332 Maybe<bool> generatePreview, | 336 Maybe<bool> generatePreview, |
| 333 std::unique_ptr<AwaitPromiseCallback> callback) { | 337 std::unique_ptr<AwaitPromiseCallback> callback) { |
| 334 InjectedScript::ObjectScope scope(m_inspector, m_session->contextGroupId(), | 338 InjectedScript::ObjectScope scope(m_session, promiseObjectId); |
| 335 promiseObjectId); | |
| 336 Response response = scope.initialize(); | 339 Response response = scope.initialize(); |
| 337 if (!response.isSuccess()) { | 340 if (!response.isSuccess()) { |
| 338 callback->sendFailure(response); | 341 callback->sendFailure(response); |
| 339 return; | 342 return; |
| 340 } | 343 } |
| 341 ProtocolPromiseHandler<AwaitPromiseCallback>::add( | 344 ProtocolPromiseHandler<AwaitPromiseCallback>::add( |
| 342 m_inspector, scope.context(), scope.object(), | 345 m_session, scope.context(), scope.object(), |
| 343 "Could not find promise with given id", m_session->contextGroupId(), | 346 "Could not find promise with given id", |
| 344 scope.injectedScript()->context()->contextId(), scope.objectGroupName(), | 347 scope.injectedScript()->context()->contextId(), scope.objectGroupName(), |
| 345 returnByValue.fromMaybe(false), generatePreview.fromMaybe(false), | 348 returnByValue.fromMaybe(false), generatePreview.fromMaybe(false), |
| 346 std::move(callback)); | 349 std::move(callback)); |
| 347 } | 350 } |
| 348 | 351 |
| 349 void V8RuntimeAgentImpl::callFunctionOn( | 352 void V8RuntimeAgentImpl::callFunctionOn( |
| 350 const String16& objectId, const String16& expression, | 353 const String16& objectId, const String16& expression, |
| 351 Maybe<protocol::Array<protocol::Runtime::CallArgument>> optionalArguments, | 354 Maybe<protocol::Array<protocol::Runtime::CallArgument>> optionalArguments, |
| 352 Maybe<bool> silent, Maybe<bool> returnByValue, Maybe<bool> generatePreview, | 355 Maybe<bool> silent, Maybe<bool> returnByValue, Maybe<bool> generatePreview, |
| 353 Maybe<bool> userGesture, Maybe<bool> awaitPromise, | 356 Maybe<bool> userGesture, Maybe<bool> awaitPromise, |
| 354 std::unique_ptr<CallFunctionOnCallback> callback) { | 357 std::unique_ptr<CallFunctionOnCallback> callback) { |
| 355 InjectedScript::ObjectScope scope(m_inspector, m_session->contextGroupId(), | 358 InjectedScript::ObjectScope scope(m_session, objectId); |
| 356 objectId); | |
| 357 Response response = scope.initialize(); | 359 Response response = scope.initialize(); |
| 358 if (!response.isSuccess()) { | 360 if (!response.isSuccess()) { |
| 359 callback->sendFailure(response); | 361 callback->sendFailure(response); |
| 360 return; | 362 return; |
| 361 } | 363 } |
| 362 | 364 |
| 363 std::unique_ptr<v8::Local<v8::Value>[]> argv = nullptr; | 365 std::unique_ptr<v8::Local<v8::Value>[]> argv = nullptr; |
| 364 int argc = 0; | 366 int argc = 0; |
| 365 if (optionalArguments.isJust()) { | 367 if (optionalArguments.isJust()) { |
| 366 protocol::Array<protocol::Runtime::CallArgument>* arguments = | 368 protocol::Array<protocol::Runtime::CallArgument>* arguments = |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 | 433 |
| 432 if (!awaitPromise.fromMaybe(false) || scope.tryCatch().HasCaught()) { | 434 if (!awaitPromise.fromMaybe(false) || scope.tryCatch().HasCaught()) { |
| 433 wrapEvaluateResultAsync(scope.injectedScript(), maybeResultValue, | 435 wrapEvaluateResultAsync(scope.injectedScript(), maybeResultValue, |
| 434 scope.tryCatch(), scope.objectGroupName(), | 436 scope.tryCatch(), scope.objectGroupName(), |
| 435 returnByValue.fromMaybe(false), | 437 returnByValue.fromMaybe(false), |
| 436 generatePreview.fromMaybe(false), callback.get()); | 438 generatePreview.fromMaybe(false), callback.get()); |
| 437 return; | 439 return; |
| 438 } | 440 } |
| 439 | 441 |
| 440 ProtocolPromiseHandler<CallFunctionOnCallback>::add( | 442 ProtocolPromiseHandler<CallFunctionOnCallback>::add( |
| 441 m_inspector, scope.context(), maybeResultValue, | 443 m_session, scope.context(), maybeResultValue, |
| 442 "Result of the function call is not a promise", | 444 "Result of the function call is not a promise", |
| 443 m_session->contextGroupId(), | |
| 444 scope.injectedScript()->context()->contextId(), scope.objectGroupName(), | 445 scope.injectedScript()->context()->contextId(), scope.objectGroupName(), |
| 445 returnByValue.fromMaybe(false), generatePreview.fromMaybe(false), | 446 returnByValue.fromMaybe(false), generatePreview.fromMaybe(false), |
| 446 std::move(callback)); | 447 std::move(callback)); |
| 447 } | 448 } |
| 448 | 449 |
| 449 Response V8RuntimeAgentImpl::getProperties( | 450 Response V8RuntimeAgentImpl::getProperties( |
| 450 const String16& objectId, Maybe<bool> ownProperties, | 451 const String16& objectId, Maybe<bool> ownProperties, |
| 451 Maybe<bool> accessorPropertiesOnly, Maybe<bool> generatePreview, | 452 Maybe<bool> accessorPropertiesOnly, Maybe<bool> generatePreview, |
| 452 std::unique_ptr<protocol::Array<protocol::Runtime::PropertyDescriptor>>* | 453 std::unique_ptr<protocol::Array<protocol::Runtime::PropertyDescriptor>>* |
| 453 result, | 454 result, |
| 454 Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>* | 455 Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>* |
| 455 internalProperties, | 456 internalProperties, |
| 456 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) { | 457 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) { |
| 457 using protocol::Runtime::InternalPropertyDescriptor; | 458 using protocol::Runtime::InternalPropertyDescriptor; |
| 458 | 459 |
| 459 InjectedScript::ObjectScope scope(m_inspector, m_session->contextGroupId(), | 460 InjectedScript::ObjectScope scope(m_session, objectId); |
| 460 objectId); | |
| 461 Response response = scope.initialize(); | 461 Response response = scope.initialize(); |
| 462 if (!response.isSuccess()) return response; | 462 if (!response.isSuccess()) return response; |
| 463 | 463 |
| 464 scope.ignoreExceptionsAndMuteConsole(); | 464 scope.ignoreExceptionsAndMuteConsole(); |
| 465 if (!scope.object()->IsObject()) | 465 if (!scope.object()->IsObject()) |
| 466 return Response::Error("Value with given id is not an object"); | 466 return Response::Error("Value with given id is not an object"); |
| 467 | 467 |
| 468 v8::Local<v8::Object> object = scope.object().As<v8::Object>(); | 468 v8::Local<v8::Object> object = scope.object().As<v8::Object>(); |
| 469 response = scope.injectedScript()->getProperties( | 469 response = scope.injectedScript()->getProperties( |
| 470 object, scope.objectGroupName(), ownProperties.fromMaybe(false), | 470 object, scope.objectGroupName(), ownProperties.fromMaybe(false), |
| (...skipping 29 matching lines...) Expand all Loading... |
| 500 .setName(toProtocolString(name.As<v8::String>())) | 500 .setName(toProtocolString(name.As<v8::String>())) |
| 501 .setValue(std::move(wrappedValue)) | 501 .setValue(std::move(wrappedValue)) |
| 502 .build()); | 502 .build()); |
| 503 } | 503 } |
| 504 if (propertiesProtocolArray->length()) | 504 if (propertiesProtocolArray->length()) |
| 505 *internalProperties = std::move(propertiesProtocolArray); | 505 *internalProperties = std::move(propertiesProtocolArray); |
| 506 return Response::OK(); | 506 return Response::OK(); |
| 507 } | 507 } |
| 508 | 508 |
| 509 Response V8RuntimeAgentImpl::releaseObject(const String16& objectId) { | 509 Response V8RuntimeAgentImpl::releaseObject(const String16& objectId) { |
| 510 InjectedScript::ObjectScope scope(m_inspector, m_session->contextGroupId(), | 510 InjectedScript::ObjectScope scope(m_session, objectId); |
| 511 objectId); | |
| 512 Response response = scope.initialize(); | 511 Response response = scope.initialize(); |
| 513 if (!response.isSuccess()) return response; | 512 if (!response.isSuccess()) return response; |
| 514 scope.injectedScript()->releaseObject(objectId); | 513 scope.injectedScript()->releaseObject(objectId); |
| 515 return Response::OK(); | 514 return Response::OK(); |
| 516 } | 515 } |
| 517 | 516 |
| 518 Response V8RuntimeAgentImpl::releaseObjectGroup(const String16& objectGroup) { | 517 Response V8RuntimeAgentImpl::releaseObjectGroup(const String16& objectGroup) { |
| 519 m_session->releaseObjectGroup(objectGroup); | 518 m_session->releaseObjectGroup(objectGroup); |
| 520 return Response::OK(); | 519 return Response::OK(); |
| 521 } | 520 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 543 Response V8RuntimeAgentImpl::compileScript( | 542 Response V8RuntimeAgentImpl::compileScript( |
| 544 const String16& expression, const String16& sourceURL, bool persistScript, | 543 const String16& expression, const String16& sourceURL, bool persistScript, |
| 545 Maybe<int> executionContextId, Maybe<String16>* scriptId, | 544 Maybe<int> executionContextId, Maybe<String16>* scriptId, |
| 546 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) { | 545 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) { |
| 547 if (!m_enabled) return Response::Error("Runtime agent is not enabled"); | 546 if (!m_enabled) return Response::Error("Runtime agent is not enabled"); |
| 548 | 547 |
| 549 int contextId = 0; | 548 int contextId = 0; |
| 550 Response response = ensureContext(m_inspector, m_session->contextGroupId(), | 549 Response response = ensureContext(m_inspector, m_session->contextGroupId(), |
| 551 std::move(executionContextId), &contextId); | 550 std::move(executionContextId), &contextId); |
| 552 if (!response.isSuccess()) return response; | 551 if (!response.isSuccess()) return response; |
| 553 InjectedScript::ContextScope scope(m_inspector, m_session->contextGroupId(), | 552 InjectedScript::ContextScope scope(m_session, contextId); |
| 554 contextId); | |
| 555 response = scope.initialize(); | 553 response = scope.initialize(); |
| 556 if (!response.isSuccess()) return response; | 554 if (!response.isSuccess()) return response; |
| 557 | 555 |
| 558 if (!persistScript) m_inspector->debugger()->muteScriptParsedEvents(); | 556 if (!persistScript) m_inspector->debugger()->muteScriptParsedEvents(); |
| 559 v8::Local<v8::Script> script; | 557 v8::Local<v8::Script> script; |
| 560 bool isOk = m_inspector->compileScript(scope.context(), expression, sourceURL) | 558 bool isOk = m_inspector->compileScript(scope.context(), expression, sourceURL) |
| 561 .ToLocal(&script); | 559 .ToLocal(&script); |
| 562 if (!persistScript) m_inspector->debugger()->unmuteScriptParsedEvents(); | 560 if (!persistScript) m_inspector->debugger()->unmuteScriptParsedEvents(); |
| 563 if (!isOk) { | 561 if (!isOk) { |
| 564 if (scope.tryCatch().HasCaught()) { | 562 if (scope.tryCatch().HasCaught()) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 } | 598 } |
| 601 | 599 |
| 602 int contextId = 0; | 600 int contextId = 0; |
| 603 Response response = ensureContext(m_inspector, m_session->contextGroupId(), | 601 Response response = ensureContext(m_inspector, m_session->contextGroupId(), |
| 604 std::move(executionContextId), &contextId); | 602 std::move(executionContextId), &contextId); |
| 605 if (!response.isSuccess()) { | 603 if (!response.isSuccess()) { |
| 606 callback->sendFailure(response); | 604 callback->sendFailure(response); |
| 607 return; | 605 return; |
| 608 } | 606 } |
| 609 | 607 |
| 610 InjectedScript::ContextScope scope(m_inspector, m_session->contextGroupId(), | 608 InjectedScript::ContextScope scope(m_session, contextId); |
| 611 contextId); | |
| 612 response = scope.initialize(); | 609 response = scope.initialize(); |
| 613 if (!response.isSuccess()) { | 610 if (!response.isSuccess()) { |
| 614 callback->sendFailure(response); | 611 callback->sendFailure(response); |
| 615 return; | 612 return; |
| 616 } | 613 } |
| 617 | 614 |
| 618 if (silent.fromMaybe(false)) scope.ignoreExceptionsAndMuteConsole(); | 615 if (silent.fromMaybe(false)) scope.ignoreExceptionsAndMuteConsole(); |
| 619 | 616 |
| 620 std::unique_ptr<v8::Global<v8::Script>> scriptWrapper = std::move(it->second); | 617 std::unique_ptr<v8::Global<v8::Script>> scriptWrapper = std::move(it->second); |
| 621 m_compiledScripts.erase(it); | 618 m_compiledScripts.erase(it); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 643 } | 640 } |
| 644 | 641 |
| 645 if (!awaitPromise.fromMaybe(false) || scope.tryCatch().HasCaught()) { | 642 if (!awaitPromise.fromMaybe(false) || scope.tryCatch().HasCaught()) { |
| 646 wrapEvaluateResultAsync(scope.injectedScript(), maybeResultValue, | 643 wrapEvaluateResultAsync(scope.injectedScript(), maybeResultValue, |
| 647 scope.tryCatch(), objectGroup.fromMaybe(""), | 644 scope.tryCatch(), objectGroup.fromMaybe(""), |
| 648 returnByValue.fromMaybe(false), | 645 returnByValue.fromMaybe(false), |
| 649 generatePreview.fromMaybe(false), callback.get()); | 646 generatePreview.fromMaybe(false), callback.get()); |
| 650 return; | 647 return; |
| 651 } | 648 } |
| 652 ProtocolPromiseHandler<RunScriptCallback>::add( | 649 ProtocolPromiseHandler<RunScriptCallback>::add( |
| 653 m_inspector, scope.context(), maybeResultValue.ToLocalChecked(), | 650 m_session, scope.context(), maybeResultValue.ToLocalChecked(), |
| 654 "Result of the script execution is not a promise", | 651 "Result of the script execution is not a promise", |
| 655 m_session->contextGroupId(), | |
| 656 scope.injectedScript()->context()->contextId(), objectGroup.fromMaybe(""), | 652 scope.injectedScript()->context()->contextId(), objectGroup.fromMaybe(""), |
| 657 returnByValue.fromMaybe(false), generatePreview.fromMaybe(false), | 653 returnByValue.fromMaybe(false), generatePreview.fromMaybe(false), |
| 658 std::move(callback)); | 654 std::move(callback)); |
| 659 } | 655 } |
| 660 | 656 |
| 661 void V8RuntimeAgentImpl::restore() { | 657 void V8RuntimeAgentImpl::restore() { |
| 662 if (!m_state->booleanProperty(V8RuntimeAgentImplState::runtimeEnabled, false)) | 658 if (!m_state->booleanProperty(V8RuntimeAgentImplState::runtimeEnabled, false)) |
| 663 return; | 659 return; |
| 664 m_frontend.executionContextsCleared(); | 660 m_frontend.executionContextsCleared(); |
| 665 enable(); | 661 enable(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 693 m_session->setCustomObjectFormatterEnabled(false); | 689 m_session->setCustomObjectFormatterEnabled(false); |
| 694 reset(); | 690 reset(); |
| 695 m_inspector->client()->endEnsureAllContextsInGroup( | 691 m_inspector->client()->endEnsureAllContextsInGroup( |
| 696 m_session->contextGroupId()); | 692 m_session->contextGroupId()); |
| 697 return Response::OK(); | 693 return Response::OK(); |
| 698 } | 694 } |
| 699 | 695 |
| 700 void V8RuntimeAgentImpl::reset() { | 696 void V8RuntimeAgentImpl::reset() { |
| 701 m_compiledScripts.clear(); | 697 m_compiledScripts.clear(); |
| 702 if (m_enabled) { | 698 if (m_enabled) { |
| 703 if (const V8InspectorImpl::ContextByIdMap* contexts = | 699 m_inspector->forEachContext( |
| 704 m_inspector->contextGroup(m_session->contextGroupId())) { | 700 m_session->contextGroupId(), |
| 705 for (auto& idContext : *contexts) idContext.second->setReported(false); | 701 [](InspectedContext* context) { context->setReported(false); }); |
| 706 } | |
| 707 m_frontend.executionContextsCleared(); | 702 m_frontend.executionContextsCleared(); |
| 708 } | 703 } |
| 709 } | 704 } |
| 710 | 705 |
| 711 void V8RuntimeAgentImpl::reportExecutionContextCreated( | 706 void V8RuntimeAgentImpl::reportExecutionContextCreated( |
| 712 InspectedContext* context) { | 707 InspectedContext* context) { |
| 713 if (!m_enabled) return; | 708 if (!m_enabled) return; |
| 714 context->setReported(true); | 709 context->setReported(true); |
| 715 std::unique_ptr<protocol::Runtime::ExecutionContextDescription> description = | 710 std::unique_ptr<protocol::Runtime::ExecutionContextDescription> description = |
| 716 protocol::Runtime::ExecutionContextDescription::create() | 711 protocol::Runtime::ExecutionContextDescription::create() |
| (...skipping 27 matching lines...) Expand all Loading... |
| 744 } | 739 } |
| 745 | 740 |
| 746 bool V8RuntimeAgentImpl::reportMessage(V8ConsoleMessage* message, | 741 bool V8RuntimeAgentImpl::reportMessage(V8ConsoleMessage* message, |
| 747 bool generatePreview) { | 742 bool generatePreview) { |
| 748 message->reportToFrontend(&m_frontend, m_session, generatePreview); | 743 message->reportToFrontend(&m_frontend, m_session, generatePreview); |
| 749 m_frontend.flush(); | 744 m_frontend.flush(); |
| 750 return m_inspector->hasConsoleMessageStorage(m_session->contextGroupId()); | 745 return m_inspector->hasConsoleMessageStorage(m_session->contextGroupId()); |
| 751 } | 746 } |
| 752 | 747 |
| 753 } // namespace v8_inspector | 748 } // namespace v8_inspector |
| OLD | NEW |