Commit edaec0cb authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

[DevTools] Roll inspector_protocol (V8)

"Remove the JSON parser and revamp Value::parseBinary."
Upstream review: https://chromium-review.googlesource.com/c/deps/inspector_protocol/+/2026351

In addition to the upstream changes, this PR includes the necessary
tweaks to the V8 inspector (now taking the detour via
CBOR to parse Javascript).

New Revision: 0e0a1995497511008864546c094e885f3f1e13a3

Change-Id: I5ccfea5a3e1bab3e183b45c87726747d17d06944
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2020518Reviewed-by: 's avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66116}
parent 5ae7258c
...@@ -521,8 +521,12 @@ Response InjectedScript::getInternalAndPrivateProperties( ...@@ -521,8 +521,12 @@ Response InjectedScript::getInternalAndPrivateProperties(
} }
void InjectedScript::releaseObject(const String16& objectId) { void InjectedScript::releaseObject(const String16& objectId) {
std::vector<uint8_t> cbor;
v8_crdtp::json::ConvertJSONToCBOR(
v8_crdtp::span<uint16_t>(objectId.characters16(), objectId.length()),
&cbor);
std::unique_ptr<protocol::Value> parsedObjectId = std::unique_ptr<protocol::Value> parsedObjectId =
protocol::StringUtil::parseJSON(objectId); protocol::Value::parseBinary(cbor.data(), cbor.size());
if (!parsedObjectId) return; if (!parsedObjectId) return;
protocol::DictionaryValue* object = protocol::DictionaryValue* object =
protocol::DictionaryValue::cast(parsedObjectId.get()); protocol::DictionaryValue::cast(parsedObjectId.get());
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "src/inspector/remote-object-id.h" #include "src/inspector/remote-object-id.h"
#include "../../third_party/inspector_protocol/crdtp/json.h"
#include "src/inspector/protocol/Protocol.h" #include "src/inspector/protocol/Protocol.h"
#include "src/inspector/string-util.h" #include "src/inspector/string-util.h"
...@@ -13,8 +14,12 @@ RemoteObjectIdBase::RemoteObjectIdBase() : m_injectedScriptId(0) {} ...@@ -13,8 +14,12 @@ RemoteObjectIdBase::RemoteObjectIdBase() : m_injectedScriptId(0) {}
std::unique_ptr<protocol::DictionaryValue> std::unique_ptr<protocol::DictionaryValue>
RemoteObjectIdBase::parseInjectedScriptId(const String16& objectId) { RemoteObjectIdBase::parseInjectedScriptId(const String16& objectId) {
std::vector<uint8_t> cbor;
v8_crdtp::json::ConvertJSONToCBOR(
v8_crdtp::span<uint16_t>(objectId.characters16(), objectId.length()),
&cbor);
std::unique_ptr<protocol::Value> parsedValue = std::unique_ptr<protocol::Value> parsedValue =
protocol::StringUtil::parseJSON(objectId); protocol::Value::parseBinary(cbor.data(), cbor.size());
if (!parsedValue || parsedValue->type() != protocol::Value::TypeObject) if (!parsedValue || parsedValue->type() != protocol::Value::TypeObject)
return nullptr; return nullptr;
......
...@@ -105,23 +105,6 @@ double StringUtil::toDouble(const char* s, size_t len, bool* isOk) { ...@@ -105,23 +105,6 @@ double StringUtil::toDouble(const char* s, size_t len, bool* isOk) {
*isOk = !std::isnan(result); *isOk = !std::isnan(result);
return result; return result;
} }
std::unique_ptr<protocol::Value> StringUtil::parseJSON(
const StringView& string) {
if (!string.length()) return nullptr;
if (string.is8Bit()) {
return parseJSONCharacters(string.characters8(),
static_cast<int>(string.length()));
}
return parseJSONCharacters(string.characters16(),
static_cast<int>(string.length()));
}
std::unique_ptr<protocol::Value> StringUtil::parseJSON(const String16& string) {
if (!string.length()) return nullptr;
return parseJSONCharacters(string.characters16(),
static_cast<int>(string.length()));
}
} // namespace protocol } // namespace protocol
namespace { namespace {
......
...@@ -65,8 +65,6 @@ class StringUtil { ...@@ -65,8 +65,6 @@ class StringUtil {
StringBuilder& builder) { // NOLINT(runtime/references) StringBuilder& builder) { // NOLINT(runtime/references)
return builder.toString(); return builder.toString();
} }
static std::unique_ptr<protocol::Value> parseJSON(const String16& json);
static std::unique_ptr<protocol::Value> parseJSON(const StringView& json);
static String fromUTF8(const uint8_t* data, size_t length) { static String fromUTF8(const uint8_t* data, size_t length) {
return String16::fromUTF8(reinterpret_cast<const char*>(data), length); return String16::fromUTF8(reinterpret_cast<const char*>(data), length);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <algorithm> #include <algorithm>
#include "../../third_party/inspector_protocol/crdtp/json.h"
#include "src/base/safe_conversions.h" #include "src/base/safe_conversions.h"
#include "src/debug/debug-interface.h" #include "src/debug/debug-interface.h"
#include "src/inspector/injected-script.h" #include "src/inspector/injected-script.h"
...@@ -1418,8 +1419,12 @@ void V8DebuggerAgentImpl::didParseSource( ...@@ -1418,8 +1419,12 @@ void V8DebuggerAgentImpl::didParseSource(
if (inspected) { if (inspected) {
// Script reused between different groups/sessions can have a stale // Script reused between different groups/sessions can have a stale
// execution context id. // execution context id.
const String16& aux = inspected->auxData();
std::vector<uint8_t> cbor;
v8_crdtp::json::ConvertJSONToCBOR(
v8_crdtp::span<uint16_t>(aux.characters16(), aux.length()), &cbor);
executionContextAuxData = protocol::DictionaryValue::cast( executionContextAuxData = protocol::DictionaryValue::cast(
protocol::StringUtil::parseJSON(inspected->auxData())); protocol::Value::parseBinary(cbor.data(), cbor.size()));
} }
bool isLiveEdit = script->isLiveEdit(); bool isLiveEdit = script->isLiveEdit();
bool hasSourceURLComment = script->hasSourceURLComment(); bool hasSourceURLComment = script->hasSourceURLComment();
......
...@@ -347,16 +347,9 @@ void V8InspectorSessionImpl::dispatchProtocolMessage( ...@@ -347,16 +347,9 @@ void V8InspectorSessionImpl::dispatchProtocolMessage(
m_state->setBoolean("use_binary_protocol", true); m_state->setBoolean("use_binary_protocol", true);
cbor = span<uint8_t>(message.characters8(), message.length()); cbor = span<uint8_t>(message.characters8(), message.length());
} else { } else {
if (message.is8Bit()) { // We're ignoring the return value of the conversion function
// We're ignoring the return value of these conversion functions // intentionally. It means the |parsed_message| below will be nullptr.
// intentionally. It means the |parsed_message| below will be nullptr. ConvertToCBOR(message, &converted_cbor);
ConvertJSONToCBOR(span<uint8_t>(message.characters8(), message.length()),
&converted_cbor);
} else {
ConvertJSONToCBOR(
span<uint16_t>(message.characters16(), message.length()),
&converted_cbor);
}
cbor = SpanFrom(converted_cbor); cbor = SpanFrom(converted_cbor);
} }
int callId; int callId;
...@@ -426,10 +419,12 @@ V8InspectorSession::Inspectable* V8InspectorSessionImpl::inspectedObject( ...@@ -426,10 +419,12 @@ V8InspectorSession::Inspectable* V8InspectorSessionImpl::inspectedObject(
void V8InspectorSessionImpl::schedulePauseOnNextStatement( void V8InspectorSessionImpl::schedulePauseOnNextStatement(
const StringView& breakReason, const StringView& breakDetails) { const StringView& breakReason, const StringView& breakDetails) {
std::vector<uint8_t> cbor;
ConvertToCBOR(breakDetails, &cbor);
m_debuggerAgent->schedulePauseOnNextStatement( m_debuggerAgent->schedulePauseOnNextStatement(
toString16(breakReason), toString16(breakReason),
protocol::DictionaryValue::cast( protocol::DictionaryValue::cast(
protocol::StringUtil::parseJSON(breakDetails))); protocol::Value::parseBinary(cbor.data(), cbor.size())));
} }
void V8InspectorSessionImpl::cancelPauseOnNextStatement() { void V8InspectorSessionImpl::cancelPauseOnNextStatement() {
...@@ -438,10 +433,12 @@ void V8InspectorSessionImpl::cancelPauseOnNextStatement() { ...@@ -438,10 +433,12 @@ void V8InspectorSessionImpl::cancelPauseOnNextStatement() {
void V8InspectorSessionImpl::breakProgram(const StringView& breakReason, void V8InspectorSessionImpl::breakProgram(const StringView& breakReason,
const StringView& breakDetails) { const StringView& breakDetails) {
std::vector<uint8_t> cbor;
ConvertToCBOR(breakDetails, &cbor);
m_debuggerAgent->breakProgram( m_debuggerAgent->breakProgram(
toString16(breakReason), toString16(breakReason),
protocol::DictionaryValue::cast( protocol::DictionaryValue::cast(
protocol::StringUtil::parseJSON(breakDetails))); protocol::Value::parseBinary(cbor.data(), cbor.size())));
} }
void V8InspectorSessionImpl::setSkipAllPauses(bool skip) { void V8InspectorSessionImpl::setSkipAllPauses(bool skip) {
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <inttypes.h> #include <inttypes.h>
#include "../../third_party/inspector_protocol/crdtp/json.h"
#include "src/debug/debug-interface.h" #include "src/debug/debug-interface.h"
#include "src/inspector/injected-script.h" #include "src/inspector/injected-script.h"
#include "src/inspector/inspected-context.h" #include "src/inspector/inspected-context.h"
...@@ -823,9 +824,14 @@ void V8RuntimeAgentImpl::reportExecutionContextCreated( ...@@ -823,9 +824,14 @@ void V8RuntimeAgentImpl::reportExecutionContextCreated(
.setName(context->humanReadableName()) .setName(context->humanReadableName())
.setOrigin(context->origin()) .setOrigin(context->origin())
.build(); .build();
if (!context->auxData().isEmpty()) const String16& aux = context->auxData();
if (!aux.isEmpty()) {
std::vector<uint8_t> cbor;
v8_crdtp::json::ConvertJSONToCBOR(
v8_crdtp::span<uint16_t>(aux.characters16(), aux.length()), &cbor);
description->setAuxData(protocol::DictionaryValue::cast( description->setAuxData(protocol::DictionaryValue::cast(
protocol::StringUtil::parseJSON(context->auxData()))); protocol::Value::parseBinary(cbor.data(), cbor.size())));
}
m_frontend.executionContextCreated(std::move(description)); m_frontend.executionContextCreated(std::move(description));
} }
......
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
#include "src/inspector/v8-debugger.h" #include "src/inspector/v8-debugger.h"
#include "src/inspector/v8-inspector-impl.h" #include "src/inspector/v8-inspector-impl.h"
using v8_crdtp::SpanFrom;
using v8_crdtp::json::ConvertCBORToJSON;
using v8_crdtp::json::ConvertJSONToCBOR;
namespace v8_inspector { namespace v8_inspector {
int V8StackTraceImpl::maxCallStackSizeToCapture = 200; int V8StackTraceImpl::maxCallStackSizeToCapture = 200;
...@@ -126,8 +130,17 @@ V8StackTraceId::V8StackTraceId(uintptr_t id, ...@@ -126,8 +130,17 @@ V8StackTraceId::V8StackTraceId(uintptr_t id,
V8StackTraceId::V8StackTraceId(const StringView& json) V8StackTraceId::V8StackTraceId(const StringView& json)
: id(0), debugger_id(V8DebuggerId().pair()) { : id(0), debugger_id(V8DebuggerId().pair()) {
auto dict = if (json.length() == 0) return;
protocol::DictionaryValue::cast(protocol::StringUtil::parseJSON(json)); std::vector<uint8_t> cbor;
if (json.is8Bit()) {
ConvertJSONToCBOR(
v8_crdtp::span<uint8_t>(json.characters8(), json.length()), &cbor);
} else {
ConvertJSONToCBOR(
v8_crdtp::span<uint16_t>(json.characters16(), json.length()), &cbor);
}
auto dict = protocol::DictionaryValue::cast(
protocol::Value::parseBinary(cbor.data(), cbor.size()));
if (!dict) return; if (!dict) return;
String16 s; String16 s;
if (!dict->getString(kId, &s)) return; if (!dict->getString(kId, &s)) return;
...@@ -152,7 +165,7 @@ std::unique_ptr<StringBuffer> V8StackTraceId::ToString() { ...@@ -152,7 +165,7 @@ std::unique_ptr<StringBuffer> V8StackTraceId::ToString() {
dict->setBoolean(kShouldPause, should_pause); dict->setBoolean(kShouldPause, should_pause);
std::vector<uint8_t> json; std::vector<uint8_t> json;
std::vector<uint8_t> cbor = std::move(*dict).TakeSerialized(); std::vector<uint8_t> cbor = std::move(*dict).TakeSerialized();
v8_crdtp::json::ConvertCBORToJSON(v8_crdtp::SpanFrom(cbor), &json); ConvertCBORToJSON(SpanFrom(cbor), &json);
return StringBufferFrom(std::move(json)); return StringBufferFrom(std::move(json));
} }
......
...@@ -2,7 +2,7 @@ Name: inspector protocol ...@@ -2,7 +2,7 @@ Name: inspector protocol
Short Name: inspector_protocol Short Name: inspector_protocol
URL: https://chromium.googlesource.com/deps/inspector_protocol/ URL: https://chromium.googlesource.com/deps/inspector_protocol/
Version: 0 Version: 0
Revision: 0213a8545f6362cd1cd5091cedf29747736552e8 Revision: 0e0a1995497511008864546c094e885f3f1e13a3
License: BSD License: BSD
License File: LICENSE License File: LICENSE
Security Critical: no Security Critical: no
......
...@@ -4,21 +4,4 @@ ...@@ -4,21 +4,4 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef {{"_".join(config.protocol.namespace)}}_Parser_h // TODO(johannes): Remove Parser_h.template.
#define {{"_".join(config.protocol.namespace)}}_Parser_h
//#include "Forward.h"
//#include "Values.h"
{% for namespace in config.protocol.namespace %}
namespace {{namespace}} {
{% endfor %}
{{config.lib.export_macro}} std::unique_ptr<Value> parseJSONCharacters(const uint8_t*, unsigned);
{{config.lib.export_macro}} std::unique_ptr<Value> parseJSONCharacters(const uint16_t*, unsigned);
{% for namespace in config.protocol.namespace %}
} // namespace {{namespace}}
{% endfor %}
#endif // !defined({{"_".join(config.protocol.namespace)}}_Parser_h)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment