| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 handler->m_callback->sendSuccess(std::move(wrappedValue), | 154 handler->m_callback->sendSuccess(std::move(wrappedValue), |
| 155 std::move(exceptionDetails)); | 155 std::move(exceptionDetails)); |
| 156 } | 156 } |
| 157 | 157 |
| 158 ProtocolPromiseHandler(V8InspectorSessionImpl* session, | 158 ProtocolPromiseHandler(V8InspectorSessionImpl* session, |
| 159 int executionContextId, const String16& objectGroup, | 159 int executionContextId, const String16& objectGroup, |
| 160 bool returnByValue, bool generatePreview, | 160 bool returnByValue, bool generatePreview, |
| 161 std::unique_ptr<Callback> callback) | 161 std::unique_ptr<Callback> callback) |
| 162 : m_inspector(session->inspector()), | 162 : m_inspector(session->inspector()), |
| 163 m_sessionId(session->sessionId()), | 163 m_sessionId(session->sessionId()), |
| 164 m_contextGroupId(session->contextGroupId()), |
| 164 m_executionContextId(executionContextId), | 165 m_executionContextId(executionContextId), |
| 165 m_objectGroup(objectGroup), | 166 m_objectGroup(objectGroup), |
| 166 m_returnByValue(returnByValue), | 167 m_returnByValue(returnByValue), |
| 167 m_generatePreview(generatePreview), | 168 m_generatePreview(generatePreview), |
| 168 m_callback(std::move(callback)), | 169 m_callback(std::move(callback)), |
| 169 m_wrapper(m_inspector->isolate(), | 170 m_wrapper(m_inspector->isolate(), |
| 170 v8::External::New(m_inspector->isolate(), this)) { | 171 v8::External::New(m_inspector->isolate(), this)) { |
| 171 m_wrapper.SetWeak(this, cleanup, v8::WeakCallbackType::kParameter); | 172 m_wrapper.SetWeak(this, cleanup, v8::WeakCallbackType::kParameter); |
| 172 } | 173 } |
| 173 | 174 |
| 174 static void cleanup( | 175 static void cleanup( |
| 175 const v8::WeakCallbackInfo<ProtocolPromiseHandler<Callback>>& data) { | 176 const v8::WeakCallbackInfo<ProtocolPromiseHandler<Callback>>& data) { |
| 176 if (!data.GetParameter()->m_wrapper.IsEmpty()) { | 177 if (!data.GetParameter()->m_wrapper.IsEmpty()) { |
| 177 data.GetParameter()->m_wrapper.Reset(); | 178 data.GetParameter()->m_wrapper.Reset(); |
| 178 data.SetSecondPassCallback(cleanup); | 179 data.SetSecondPassCallback(cleanup); |
| 179 } else { | 180 } else { |
| 180 data.GetParameter()->m_callback->sendFailure( | 181 data.GetParameter()->m_callback->sendFailure( |
| 181 Response::Error("Promise was collected")); | 182 Response::Error("Promise was collected")); |
| 182 delete data.GetParameter(); | 183 delete data.GetParameter(); |
| 183 } | 184 } |
| 184 } | 185 } |
| 185 | 186 |
| 186 std::unique_ptr<protocol::Runtime::RemoteObject> wrapObject( | 187 std::unique_ptr<protocol::Runtime::RemoteObject> wrapObject( |
| 187 v8::Local<v8::Value> value) { | 188 v8::Local<v8::Value> value) { |
| 188 V8InspectorSessionImpl* session = m_inspector->sessionById(m_sessionId); | 189 V8InspectorSessionImpl* session = |
| 190 m_inspector->sessionById(m_contextGroupId, m_sessionId); |
| 189 if (!session) { | 191 if (!session) { |
| 190 m_callback->sendFailure(Response::Error("No session")); | 192 m_callback->sendFailure(Response::Error("No session")); |
| 191 return nullptr; | 193 return nullptr; |
| 192 } | 194 } |
| 193 InjectedScript::ContextScope scope(session, m_executionContextId); | 195 InjectedScript::ContextScope scope(session, m_executionContextId); |
| 194 Response response = scope.initialize(); | 196 Response response = scope.initialize(); |
| 195 if (!response.isSuccess()) { | 197 if (!response.isSuccess()) { |
| 196 m_callback->sendFailure(response); | 198 m_callback->sendFailure(response); |
| 197 return nullptr; | 199 return nullptr; |
| 198 } | 200 } |
| 199 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedValue; | 201 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedValue; |
| 200 response = scope.injectedScript()->wrapObject( | 202 response = scope.injectedScript()->wrapObject( |
| 201 value, m_objectGroup, m_returnByValue, m_generatePreview, | 203 value, m_objectGroup, m_returnByValue, m_generatePreview, |
| 202 &wrappedValue); | 204 &wrappedValue); |
| 203 if (!response.isSuccess()) { | 205 if (!response.isSuccess()) { |
| 204 m_callback->sendFailure(response); | 206 m_callback->sendFailure(response); |
| 205 return nullptr; | 207 return nullptr; |
| 206 } | 208 } |
| 207 return wrappedValue; | 209 return wrappedValue; |
| 208 } | 210 } |
| 209 | 211 |
| 210 V8InspectorImpl* m_inspector; | 212 V8InspectorImpl* m_inspector; |
| 211 int m_sessionId; | 213 int m_sessionId; |
| 214 int m_contextGroupId; |
| 212 int m_executionContextId; | 215 int m_executionContextId; |
| 213 String16 m_objectGroup; | 216 String16 m_objectGroup; |
| 214 bool m_returnByValue; | 217 bool m_returnByValue; |
| 215 bool m_generatePreview; | 218 bool m_generatePreview; |
| 216 std::unique_ptr<Callback> m_callback; | 219 std::unique_ptr<Callback> m_callback; |
| 217 v8::Global<v8::External> m_wrapper; | 220 v8::Global<v8::External> m_wrapper; |
| 218 }; | 221 }; |
| 219 | 222 |
| 220 template <typename Callback> | 223 template <typename Callback> |
| 221 bool wrapEvaluateResultAsync(InjectedScript* injectedScript, | 224 bool wrapEvaluateResultAsync(InjectedScript* injectedScript, |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 m_session->setCustomObjectFormatterEnabled(false); | 692 m_session->setCustomObjectFormatterEnabled(false); |
| 690 reset(); | 693 reset(); |
| 691 m_inspector->client()->endEnsureAllContextsInGroup( | 694 m_inspector->client()->endEnsureAllContextsInGroup( |
| 692 m_session->contextGroupId()); | 695 m_session->contextGroupId()); |
| 693 return Response::OK(); | 696 return Response::OK(); |
| 694 } | 697 } |
| 695 | 698 |
| 696 void V8RuntimeAgentImpl::reset() { | 699 void V8RuntimeAgentImpl::reset() { |
| 697 m_compiledScripts.clear(); | 700 m_compiledScripts.clear(); |
| 698 if (m_enabled) { | 701 if (m_enabled) { |
| 699 m_inspector->forEachContext( | 702 int sessionId = m_session->sessionId(); |
| 700 m_session->contextGroupId(), | 703 m_inspector->forEachContext(m_session->contextGroupId(), |
| 701 [](InspectedContext* context) { context->setReported(false); }); | 704 [&sessionId](InspectedContext* context) { |
| 705 context->setReported(sessionId, false); |
| 706 }); |
| 702 m_frontend.executionContextsCleared(); | 707 m_frontend.executionContextsCleared(); |
| 703 } | 708 } |
| 704 } | 709 } |
| 705 | 710 |
| 706 void V8RuntimeAgentImpl::reportExecutionContextCreated( | 711 void V8RuntimeAgentImpl::reportExecutionContextCreated( |
| 707 InspectedContext* context) { | 712 InspectedContext* context) { |
| 708 if (!m_enabled) return; | 713 if (!m_enabled) return; |
| 709 context->setReported(true); | 714 context->setReported(m_session->sessionId(), true); |
| 710 std::unique_ptr<protocol::Runtime::ExecutionContextDescription> description = | 715 std::unique_ptr<protocol::Runtime::ExecutionContextDescription> description = |
| 711 protocol::Runtime::ExecutionContextDescription::create() | 716 protocol::Runtime::ExecutionContextDescription::create() |
| 712 .setId(context->contextId()) | 717 .setId(context->contextId()) |
| 713 .setName(context->humanReadableName()) | 718 .setName(context->humanReadableName()) |
| 714 .setOrigin(context->origin()) | 719 .setOrigin(context->origin()) |
| 715 .build(); | 720 .build(); |
| 716 if (!context->auxData().isEmpty()) | 721 if (!context->auxData().isEmpty()) |
| 717 description->setAuxData(protocol::DictionaryValue::cast( | 722 description->setAuxData(protocol::DictionaryValue::cast( |
| 718 protocol::StringUtil::parseJSON(context->auxData()))); | 723 protocol::StringUtil::parseJSON(context->auxData()))); |
| 719 m_frontend.executionContextCreated(std::move(description)); | 724 m_frontend.executionContextCreated(std::move(description)); |
| 720 } | 725 } |
| 721 | 726 |
| 722 void V8RuntimeAgentImpl::reportExecutionContextDestroyed( | 727 void V8RuntimeAgentImpl::reportExecutionContextDestroyed( |
| 723 InspectedContext* context) { | 728 InspectedContext* context) { |
| 724 if (m_enabled && context->isReported()) { | 729 if (m_enabled && context->isReported(m_session->sessionId())) { |
| 725 context->setReported(false); | 730 context->setReported(m_session->sessionId(), false); |
| 726 m_frontend.executionContextDestroyed(context->contextId()); | 731 m_frontend.executionContextDestroyed(context->contextId()); |
| 727 } | 732 } |
| 728 } | 733 } |
| 729 | 734 |
| 730 void V8RuntimeAgentImpl::inspect( | 735 void V8RuntimeAgentImpl::inspect( |
| 731 std::unique_ptr<protocol::Runtime::RemoteObject> objectToInspect, | 736 std::unique_ptr<protocol::Runtime::RemoteObject> objectToInspect, |
| 732 std::unique_ptr<protocol::DictionaryValue> hints) { | 737 std::unique_ptr<protocol::DictionaryValue> hints) { |
| 733 if (m_enabled) | 738 if (m_enabled) |
| 734 m_frontend.inspectRequested(std::move(objectToInspect), std::move(hints)); | 739 m_frontend.inspectRequested(std::move(objectToInspect), std::move(hints)); |
| 735 } | 740 } |
| 736 | 741 |
| 737 void V8RuntimeAgentImpl::messageAdded(V8ConsoleMessage* message) { | 742 void V8RuntimeAgentImpl::messageAdded(V8ConsoleMessage* message) { |
| 738 if (m_enabled) reportMessage(message, true); | 743 if (m_enabled) reportMessage(message, true); |
| 739 } | 744 } |
| 740 | 745 |
| 741 bool V8RuntimeAgentImpl::reportMessage(V8ConsoleMessage* message, | 746 bool V8RuntimeAgentImpl::reportMessage(V8ConsoleMessage* message, |
| 742 bool generatePreview) { | 747 bool generatePreview) { |
| 743 message->reportToFrontend(&m_frontend, m_session, generatePreview); | 748 message->reportToFrontend(&m_frontend, m_session, generatePreview); |
| 744 m_frontend.flush(); | 749 m_frontend.flush(); |
| 745 return m_inspector->hasConsoleMessageStorage(m_session->contextGroupId()); | 750 return m_inspector->hasConsoleMessageStorage(m_session->contextGroupId()); |
| 746 } | 751 } |
| 747 | 752 |
| 748 } // namespace v8_inspector | 753 } // namespace v8_inspector |
| OLD | NEW |