Commit 18d189dd authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

[DevTools] Switch compilation cache to protocol::Binary.

This moves base64 encoding / decoding into the protocol layer.
It takes advantage of these recently landed changes:

Supporting binary in .pdl files:
https://chromium-review.googlesource.com/c/deps/inspector_protocol/+/1285695
Rolled into Chromium / v8.

Add protocol::Binary to v8_inspector_string:
https://chromium-review.googlesource.com/c/chromium/src/+/1280210

Bug: chromium:891377
Change-Id: I6a2712ad9556da5961565da95452aee47838e10a
Reviewed-on: https://chromium-review.googlesource.com/c/1298247Reviewed-by: default avatarPaul Irish <paulirish@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602539}
parent 6cb3a11b
......@@ -5316,7 +5316,7 @@ domain Page
parameters
string url
# Base64-encoded data
string data
binary data
# Clears seeded compilation cache.
experimental command clearCompilationCache
......@@ -5484,7 +5484,7 @@ domain Page
parameters
string url
# Base64-encoded data
string data
binary data
domain Performance
......
......@@ -1286,10 +1286,9 @@ void InspectorPageAgent::ConsumeCompilationCache(
auto it = compilation_cache_.find(source.Url().GetString());
if (it == compilation_cache_.end())
return;
const Vector<char>& data = it->value;
const protocol::Binary& data = it->value;
*cached_data = new v8::ScriptCompiler::CachedData(
reinterpret_cast<const uint8_t*>(data.data()), data.size(),
v8::ScriptCompiler::CachedData::BufferNotOwned);
data.data(), data.size(), v8::ScriptCompiler::CachedData::BufferNotOwned);
}
void InspectorPageAgent::ProduceCompilationCache(const ScriptSourceCode& source,
......@@ -1313,9 +1312,11 @@ void InspectorPageAgent::ProduceCompilationCache(const ScriptSourceCode& source,
std::unique_ptr<v8::ScriptCompiler::CachedData> cached_data(
v8::ScriptCompiler::CreateCodeCache(script->GetUnboundScript()));
if (cached_data) {
String base64data = Base64Encode(
reinterpret_cast<const char*>(cached_data->data), cached_data->length);
GetFrontend()->compilationCacheProduced(url_string, base64data);
// CachedData produced by CreateCodeCache always owns its buffer.
CHECK_EQ(cached_data->buffer_policy,
v8::ScriptCompiler::CachedData::BufferOwned);
GetFrontend()->compilationCacheProduced(
url_string, protocol::Binary::fromCachedData(std::move(cached_data)));
}
}
......@@ -1325,11 +1326,8 @@ Response InspectorPageAgent::setProduceCompilationCache(bool enabled) {
}
Response InspectorPageAgent::addCompilationCache(const String& url,
const String& base64data) {
Vector<char> data;
if (!Base64Decode(base64data, data))
return Response::Error("data should be base64-encoded");
compilation_cache_.Set(url, std::move(data));
const protocol::Binary& data) {
compilation_cache_.Set(url, data);
return Response::OK();
}
......
......@@ -164,7 +164,7 @@ class CORE_EXPORT InspectorPageAgent final
protocol::Response setProduceCompilationCache(bool enabled) override;
protocol::Response addCompilationCache(const String& url,
const String& data) override;
const protocol::Binary& data) override;
protocol::Response clearCompilationCache() override;
// InspectorInstrumentation API
......@@ -236,7 +236,7 @@ class CORE_EXPORT InspectorPageAgent final
std::unique_ptr<protocol::Page::FrameResourceTree> BuildObjectForResourceTree(
LocalFrame*);
Member<InspectedFrames> inspected_frames_;
HashMap<String, Vector<char>> compilation_cache_;
HashMap<String, protocol::Binary> compilation_cache_;
v8_inspector::V8InspectorSession* v8_session_;
Client* client_;
String pending_script_to_evaluate_on_load_once_;
......
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