Commit 2021d4ef authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

[DevTools] Switch inspector-test.cc to use the CBOR encoded inspector state.

The main change here is that in isolate-data.h, I'm switching from stateJSON to state.
This routine returns a CBOR encoded state cookie, which is also what we already
use in Chromium (blink).

In inspector-test.cc, I then put this byte vector into a V8 String,
and to make this roundtrip, change the extraction routine to get the
bytes. It's a little weird to store arbitrary bytes inside a v8 string,
but it appears to work fine because these bytes end up in the 8 bit portion,
much like isolatin characters would.

Change-Id: I72a0bdefd85a290f4e91db79be67d86952831685
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1610478Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarAlexei Filippov <alph@chromium.org>
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61544}
parent 0607f8ae
......@@ -130,7 +130,10 @@ class V8_EXPORT V8InspectorSession {
// Dispatching protocol messages.
static bool canDispatchMethod(const StringView& method);
virtual void dispatchProtocolMessage(const StringView& message) = 0;
virtual std::unique_ptr<StringBuffer> stateJSON() = 0;
virtual V8_DEPRECATED("Use state() instead",
std::unique_ptr<StringBuffer> stateJSON()) {
return nullptr;
}
virtual std::vector<uint8_t> state() = 0;
virtual std::vector<std::unique_ptr<protocol::Schema::API::Domain>>
supportedDomains() = 0;
......
......@@ -56,11 +56,25 @@ std::vector<uint16_t> ToVector(v8::Isolate* isolate,
return buffer;
}
std::vector<uint8_t> ToBytes(v8::Isolate* isolate, v8::Local<v8::String> str) {
std::vector<uint8_t> buffer(str->Length());
str->WriteOneByte(isolate, buffer.data(), 0, str->Length());
return buffer;
}
v8::Local<v8::String> ToV8String(v8::Isolate* isolate, const char* str) {
return v8::String::NewFromUtf8(isolate, str, v8::NewStringType::kNormal)
.ToLocalChecked();
}
v8::Local<v8::String> ToV8String(v8::Isolate* isolate,
const std::vector<uint8_t>& bytes) {
return v8::String::NewFromOneByte(isolate, bytes.data(),
v8::NewStringType::kNormal,
static_cast<int>(bytes.size()))
.ToLocalChecked();
}
v8::Local<v8::String> ToV8String(v8::Isolate* isolate,
const std::string& buffer) {
int length = static_cast<int>(buffer.size());
......@@ -564,8 +578,8 @@ class UtilsExtension : public IsolateData::SetupGlobalTask {
IsolateData::FromContext(context)->GetContextGroupId(context),
args.GetIsolate(), args[2].As<v8::Function>());
std::vector<uint16_t> state =
ToVector(args.GetIsolate(), args[1].As<v8::String>());
std::vector<uint8_t> state =
ToBytes(args.GetIsolate(), args[1].As<v8::String>());
int context_group_id = args[0].As<v8::Int32>()->Value();
int session_id = 0;
RunSyncTask(backend_runner_, [&context_group_id, &session_id, &channel,
......@@ -587,9 +601,9 @@ class UtilsExtension : public IsolateData::SetupGlobalTask {
Exit();
}
int session_id = args[0].As<v8::Int32>()->Value();
std::vector<uint16_t> state;
std::vector<uint8_t> state;
RunSyncTask(backend_runner_, [&session_id, &state](IsolateData* data) {
state = ToVector(data->DisconnectSession(session_id)->string());
state = data->DisconnectSession(session_id);
});
channels_.erase(session_id);
args.GetReturnValue().Set(ToV8String(args.GetIsolate(), state));
......
......@@ -157,13 +157,12 @@ int IsolateData::ConnectSession(int context_group_id,
return session_id;
}
std::unique_ptr<v8_inspector::StringBuffer> IsolateData::DisconnectSession(
int session_id) {
std::vector<uint8_t> IsolateData::DisconnectSession(int session_id) {
v8::SealHandleScope seal_handle_scope(isolate());
auto it = sessions_.find(session_id);
CHECK(it != sessions_.end());
context_group_by_session_.erase(it->second.get());
std::unique_ptr<v8_inspector::StringBuffer> result = it->second->stateJSON();
std::vector<uint8_t> result = it->second->state();
sessions_.erase(it);
return result;
}
......
......@@ -46,7 +46,7 @@ class IsolateData : public v8_inspector::V8InspectorClient {
int ConnectSession(int context_group_id,
const v8_inspector::StringView& state,
v8_inspector::V8Inspector::Channel* channel);
std::unique_ptr<v8_inspector::StringBuffer> DisconnectSession(int session_id);
std::vector<uint8_t> DisconnectSession(int session_id);
void SendMessage(int session_id, const v8_inspector::StringView& message);
void BreakProgram(int context_group_id,
const v8_inspector::StringView& reason,
......
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