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

[DevTools] Remove all calls to ::toJSONString from V8. (V8)

Instead, serialize to CBOR, then convert to JSON.
I plan to remove the JSON serialization support from
protocol::Value and from the generated types. We're
close - three files here, four files in Chromium.

Change-Id: I067dc896dad1bb7cd95914b3dcc86597f136251b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2008751
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Reviewed-by: 's avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65909}
parent a184598f
......@@ -4,6 +4,7 @@
#include "src/inspector/custom-preview.h"
#include "../../third_party/inspector_protocol/crdtp/json.h"
#include "src/debug/debug-interface.h"
#include "src/inspector/injected-script.h"
#include "src/inspector/inspected-context.h"
......@@ -119,8 +120,11 @@ bool substituteObjectTags(int sessionId, const String16& groupName,
reportError(context, tryCatch, "cannot wrap value");
return false;
}
std::vector<uint8_t> cbor = std::move(*wrapper).TakeSerialized();
std::vector<uint8_t> json;
v8_crdtp::json::ConvertCBORToJSON(v8_crdtp::SpanFrom(cbor), &json);
v8::Local<v8::Value> jsonWrapper;
String16 serialized = wrapper->toJSON();
v8_inspector::StringView serialized(json.data(), json.size());
if (!v8::JSON::Parse(context, toV8String(isolate, serialized))
.ToLocal(&jsonWrapper)) {
reportError(context, tryCatch, "cannot wrap value");
......
......@@ -33,6 +33,7 @@
#include <cmath>
#include <unordered_set>
#include "../../third_party/inspector_protocol/crdtp/json.h"
#include "src/inspector/custom-preview.h"
#include "src/inspector/inspected-context.h"
#include "src/inspector/protocol/Protocol.h"
......@@ -728,7 +729,14 @@ Response InjectedScript::resolveCallArgument(
if (callArgument->hasValue() || callArgument->hasUnserializableValue()) {
String16 value;
if (callArgument->hasValue()) {
value = "(" + callArgument->getValue(nullptr)->toJSONString() + ")";
std::vector<uint8_t> cbor =
std::move(*callArgument->getValue(nullptr)).TakeSerialized();
std::vector<uint8_t> json;
v8_crdtp::json::ConvertCBORToJSON(v8_crdtp::SpanFrom(cbor), &json);
value =
"(" +
String16(reinterpret_cast<const char*>(json.data()), json.size()) +
")";
} else {
String16 unserializableValue = callArgument->getUnserializableValue("");
// Protect against potential identifier resolution for NaN and Infinity.
......
......@@ -6,6 +6,7 @@
#include <algorithm>
#include "../../third_party/inspector_protocol/crdtp/json.h"
#include "src/inspector/v8-debugger.h"
#include "src/inspector/v8-inspector-impl.h"
......@@ -149,8 +150,12 @@ std::unique_ptr<StringBuffer> V8StackTraceId::ToString() {
dict->setString(kId, String16::fromInteger64(id));
dict->setString(kDebuggerId, V8DebuggerId(debugger_id).toString());
dict->setBoolean(kShouldPause, should_pause);
String16 json = dict->toJSONString();
return StringBufferImpl::adopt(json);
std::vector<uint8_t> json;
std::vector<uint8_t> cbor = std::move(*dict).TakeSerialized();
v8_crdtp::json::ConvertCBORToJSON(v8_crdtp::SpanFrom(cbor), &json);
// |json| is 7 bit ASCII (with \uXXXX JSON escapes).
// BinaryStringBuffer keeps the JSON and exposes an 8 bit StringView.
return std::make_unique<BinaryStringBuffer>(std::move(json));
}
StackFrame::StackFrame(v8::Isolate* isolate, v8::Local<v8::StackFrame> v8Frame)
......
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