diff options
Diffstat (limited to 'src/inspector/v8-inspector-session-impl.cc')
-rw-r--r-- | src/inspector/v8-inspector-session-impl.cc | 74 |
1 files changed, 55 insertions, 19 deletions
diff --git a/src/inspector/v8-inspector-session-impl.cc b/src/inspector/v8-inspector-session-impl.cc index e4155753..2674fc2f 100644 --- a/src/inspector/v8-inspector-session-impl.cc +++ b/src/inspector/v8-inspector-session-impl.cc @@ -37,10 +37,15 @@ bool V8InspectorSession::canDispatchMethod(const StringView& method) { protocol::Schema::Metainfo::commandPrefix); } +// static +int V8ContextInfo::executionContextId(v8::Local<v8::Context> context) { + return InspectedContext::contextId(context); +} + std::unique_ptr<V8InspectorSessionImpl> V8InspectorSessionImpl::create( V8InspectorImpl* inspector, int contextGroupId, V8Inspector::Channel* channel, const StringView& state) { - return wrapUnique( + return std::unique_ptr<V8InspectorSessionImpl>( new V8InspectorSessionImpl(inspector, contextGroupId, channel, state)); } @@ -62,35 +67,35 @@ V8InspectorSessionImpl::V8InspectorSessionImpl(V8InspectorImpl* inspector, m_schemaAgent(nullptr) { if (savedState.length()) { std::unique_ptr<protocol::Value> state = - protocol::parseJSON(toString16(savedState)); + protocol::StringUtil::parseJSON(toString16(savedState)); if (state) m_state = protocol::DictionaryValue::cast(std::move(state)); if (!m_state) m_state = protocol::DictionaryValue::create(); } else { m_state = protocol::DictionaryValue::create(); } - m_runtimeAgent = wrapUnique(new V8RuntimeAgentImpl( + m_runtimeAgent.reset(new V8RuntimeAgentImpl( this, this, agentState(protocol::Runtime::Metainfo::domainName))); protocol::Runtime::Dispatcher::wire(&m_dispatcher, m_runtimeAgent.get()); - m_debuggerAgent = wrapUnique(new V8DebuggerAgentImpl( + m_debuggerAgent.reset(new V8DebuggerAgentImpl( this, this, agentState(protocol::Debugger::Metainfo::domainName))); protocol::Debugger::Dispatcher::wire(&m_dispatcher, m_debuggerAgent.get()); - m_profilerAgent = wrapUnique(new V8ProfilerAgentImpl( + m_profilerAgent.reset(new V8ProfilerAgentImpl( this, this, agentState(protocol::Profiler::Metainfo::domainName))); protocol::Profiler::Dispatcher::wire(&m_dispatcher, m_profilerAgent.get()); - m_heapProfilerAgent = wrapUnique(new V8HeapProfilerAgentImpl( + m_heapProfilerAgent.reset(new V8HeapProfilerAgentImpl( this, this, agentState(protocol::HeapProfiler::Metainfo::domainName))); protocol::HeapProfiler::Dispatcher::wire(&m_dispatcher, m_heapProfilerAgent.get()); - m_consoleAgent = wrapUnique(new V8ConsoleAgentImpl( + m_consoleAgent.reset(new V8ConsoleAgentImpl( this, this, agentState(protocol::Console::Metainfo::domainName))); protocol::Console::Dispatcher::wire(&m_dispatcher, m_consoleAgent.get()); - m_schemaAgent = wrapUnique(new V8SchemaAgentImpl( + m_schemaAgent.reset(new V8SchemaAgentImpl( this, this, agentState(protocol::Schema::Metainfo::domainName))); protocol::Schema::Dispatcher::wire(&m_dispatcher, m_schemaAgent.get()); @@ -126,13 +131,42 @@ protocol::DictionaryValue* V8InspectorSessionImpl::agentState( return state; } -void V8InspectorSessionImpl::sendProtocolResponse(int callId, - const String16& message) { - m_channel->sendProtocolResponse(callId, toStringView(message)); +namespace { + +class MessageBuffer : public StringBuffer { + public: + static std::unique_ptr<MessageBuffer> create( + std::unique_ptr<protocol::Serializable> message) { + return std::unique_ptr<MessageBuffer>( + new MessageBuffer(std::move(message))); + } + + const StringView& string() override { + if (!m_serialized) { + m_serialized = StringBuffer::create(toStringView(m_message->serialize())); + m_message.reset(nullptr); + } + return m_serialized->string(); + } + + private: + explicit MessageBuffer(std::unique_ptr<protocol::Serializable> message) + : m_message(std::move(message)) {} + + std::unique_ptr<protocol::Serializable> m_message; + std::unique_ptr<StringBuffer> m_serialized; +}; + +} // namespace + +void V8InspectorSessionImpl::sendProtocolResponse( + int callId, std::unique_ptr<protocol::Serializable> message) { + m_channel->sendResponse(callId, MessageBuffer::create(std::move(message))); } -void V8InspectorSessionImpl::sendProtocolNotification(const String16& message) { - m_channel->sendProtocolNotification(toStringView(message)); +void V8InspectorSessionImpl::sendProtocolNotification( + std::unique_ptr<protocol::Serializable> message) { + m_channel->sendNotification(MessageBuffer::create(std::move(message))); } void V8InspectorSessionImpl::flushProtocolNotifications() { @@ -266,7 +300,7 @@ V8InspectorSessionImpl::wrapObject(v8::Local<v8::Context> context, const String16& groupName, bool generatePreview) { InjectedScript* injectedScript = nullptr; - findInjectedScript(V8Debugger::contextId(context), injectedScript); + findInjectedScript(InspectedContext::contextId(context), injectedScript); if (!injectedScript) return nullptr; std::unique_ptr<protocol::Runtime::RemoteObject> result; injectedScript->wrapObject(value, groupName, false, generatePreview, &result); @@ -278,7 +312,7 @@ V8InspectorSessionImpl::wrapTable(v8::Local<v8::Context> context, v8::Local<v8::Value> table, v8::Local<v8::Value> columns) { InjectedScript* injectedScript = nullptr; - findInjectedScript(V8Debugger::contextId(context), injectedScript); + findInjectedScript(InspectedContext::contextId(context), injectedScript); if (!injectedScript) return nullptr; return injectedScript->wrapTable(table, columns); } @@ -305,11 +339,11 @@ void V8InspectorSessionImpl::reportAllContexts(V8RuntimeAgentImpl* agent) { void V8InspectorSessionImpl::dispatchProtocolMessage( const StringView& message) { - m_dispatcher.dispatch(protocol::parseJSON(message)); + m_dispatcher.dispatch(protocol::StringUtil::parseJSON(message)); } std::unique_ptr<StringBuffer> V8InspectorSessionImpl::stateJSON() { - String16 json = m_state->toJSONString(); + String16 json = m_state->serialize(); return StringBufferImpl::adopt(json); } @@ -366,7 +400,8 @@ void V8InspectorSessionImpl::schedulePauseOnNextStatement( const StringView& breakReason, const StringView& breakDetails) { m_debuggerAgent->schedulePauseOnNextStatement( toString16(breakReason), - protocol::DictionaryValue::cast(protocol::parseJSON(breakDetails))); + protocol::DictionaryValue::cast( + protocol::StringUtil::parseJSON(breakDetails))); } void V8InspectorSessionImpl::cancelPauseOnNextStatement() { @@ -377,7 +412,8 @@ void V8InspectorSessionImpl::breakProgram(const StringView& breakReason, const StringView& breakDetails) { m_debuggerAgent->breakProgram( toString16(breakReason), - protocol::DictionaryValue::cast(protocol::parseJSON(breakDetails))); + protocol::DictionaryValue::cast( + protocol::StringUtil::parseJSON(breakDetails))); } void V8InspectorSessionImpl::setSkipAllPauses(bool skip) { |