Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: roll inspector_protocol to f67ec5 #26303

Merged
merged 1 commit into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/inspector/node_inspector.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
'<(protocol_tool_path)/templates/Imported_h.template',
'<(protocol_tool_path)/templates/TypeBuilder_cpp.template',
'<(protocol_tool_path)/templates/TypeBuilder_h.template',
'<(protocol_tool_path)/CodeGenerator.py',
'<(protocol_tool_path)/code_generator.py',
]
},
'defines': [
Expand Down Expand Up @@ -87,7 +87,7 @@
],
'action': [
'python',
'tools/inspector_protocol/ConvertProtocolToJSON.py',
'tools/inspector_protocol/convert_protocol_to_json.py',
'<@(_inputs)',
'<@(_outputs)',
],
Expand All @@ -105,7 +105,7 @@
'process_outputs_as_sources': 1,
'action': [
'python',
'tools/inspector_protocol/CodeGenerator.py',
'tools/inspector_protocol/code_generator.py',
'--jinja_dir', '<@(protocol_tool_path)/..',
'--output_base', '<(SHARED_INTERMEDIATE_DIR)/src/',
'--config', '<(SHARED_INTERMEDIATE_DIR)/node_protocol_config.json',
Expand All @@ -123,7 +123,7 @@
],
'action': [
'python',
'tools/inspector_protocol/ConcatenateProtocols.py',
'tools/inspector_protocol/concatenate_protocols.py',
'<@(_inputs)',
'<@(_outputs)',
],
Expand Down
22 changes: 22 additions & 0 deletions src/inspector/node_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,28 @@ double toDouble(const char* buffer, size_t length, bool* ok) {
return d;
}

std::unique_ptr<Value> parseMessage(const std::string& message, bool binary) {
if (binary) {
return Value::parseBinary(
reinterpret_cast<const uint8_t*>(message.data()),
message.length());
}
return parseJSON(message);
}

ProtocolMessage jsonToMessage(String message) {
return message;
}

ProtocolMessage binaryToMessage(std::vector<uint8_t> message) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be

Suggested change
ProtocolMessage binaryToMessage(std::vector<uint8_t> message) {
ProtocolMessage binaryToMessage(const std::vector<uint8_t>& message) {

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, we are std::move-ing binary messages around. It is likely that we switch to using std::unique_ptr<std::vector> for clarity at some point.

return std::string(reinterpret_cast<const char*>(message.data()),
message.size());
}

String fromUTF8(const uint8_t* data, size_t length) {
return std::string(reinterpret_cast<const char*>(data), length);
}

} // namespace StringUtil
} // namespace protocol
} // namespace inspector
Expand Down
32 changes: 32 additions & 0 deletions src/inspector/node_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ class Value;

using String = std::string;
using StringBuilder = std::ostringstream;
using ProtocolMessage = std::string;

class StringUTF8Adapter {
public:
explicit StringUTF8Adapter(const std::string& string) : string_(string) { }
const char* Data() const { return string_.data(); }
size_t length() const { return string_.length(); }

private:
const std::string& string_;
};

namespace StringUtil {
// NOLINTNEXTLINE(runtime/references) This is V8 API...
Expand Down Expand Up @@ -67,8 +78,29 @@ void builderAppendQuotedString(StringBuilder& builder, const String&);
std::unique_ptr<Value> parseJSON(const String&);
std::unique_ptr<Value> parseJSON(v8_inspector::StringView view);

std::unique_ptr<Value> parseMessage(const std::string& message, bool binary);
ProtocolMessage jsonToMessage(String message);
ProtocolMessage binaryToMessage(std::vector<uint8_t> message);
String fromUTF8(const uint8_t* data, size_t length);

extern size_t kNotFound;
} // namespace StringUtil

// A read-only sequence of uninterpreted bytes with reference-counted storage.
// Though the templates for generating the protocol bindings reference
// this type, js_protocol.pdl doesn't have a field of type 'binary', so
// therefore it's unnecessary to provide an implementation here.
class Binary {
public:
const uint8_t* data() const { UNREACHABLE(); }
size_t size() const { UNREACHABLE(); }
String toBase64() const { UNREACHABLE(); }
static Binary fromBase64(const String& base64, bool* success) {
UNREACHABLE();
}
static Binary fromSpan(const uint8_t* data, size_t size) { UNREACHABLE(); }
};

} // namespace protocol
} // namespace inspector
} // namespace node
Expand Down
22 changes: 16 additions & 6 deletions src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,19 @@ class ChannelImpl final : public v8_inspector::V8Inspector::Channel,
}

std::string dispatchProtocolMessage(const StringView& message) {
std::unique_ptr<protocol::DictionaryValue> parsed;
std::string raw_message = protocol::StringUtil::StringViewToUtf8(message);
std::unique_ptr<protocol::DictionaryValue> value =
protocol::DictionaryValue::cast(protocol::StringUtil::parseMessage(
raw_message, false));
int call_id;
std::string method;
node_dispatcher_->getCommandName(
protocol::StringUtil::StringViewToUtf8(message), &method, &parsed);
node_dispatcher_->parseCommand(value.get(), &call_id, &method);
if (v8_inspector::V8InspectorSession::canDispatchMethod(
Utf8ToStringView(method)->string())) {
session_->dispatchProtocolMessage(message);
} else {
node_dispatcher_->dispatch(std::move(parsed));
node_dispatcher_->dispatch(call_id, method, std::move(value),
raw_message);
}
return method;
}
Expand Down Expand Up @@ -284,11 +288,17 @@ class ChannelImpl final : public v8_inspector::V8Inspector::Channel,

void sendProtocolResponse(int callId,
std::unique_ptr<Serializable> message) override {
sendMessageToFrontend(message->serialize());
sendMessageToFrontend(message->serializeToJSON());
}
void sendProtocolNotification(
std::unique_ptr<Serializable> message) override {
sendMessageToFrontend(message->serialize());
sendMessageToFrontend(message->serializeToJSON());
}

void fallThrough(int callId,
const std::string& method,
const std::string& message) override {
DCHECK(false);
}

std::unique_ptr<protocol::TracingAgent> tracing_agent_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Name: inspector protocol
Short Name: inspector_protocol
URL: https://chromium.googlesource.com/deps/inspector_protocol/
Version: 0
Revision: 752d4abd13119010cf30e454e8ef9b5fb7ef43a3
Revision: f67ec5180f476830e839226b5ca948e43070fdab
License: BSD
License File: LICENSE
Security Critical: no
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@
#
# Adding --show_changes to the command line prints out a list of valid public API changes.

from __future__ import print_function
import copy
import os.path
import optparse
import sys

import pdl

try:
import json
except ImportError:
Expand Down Expand Up @@ -166,6 +169,11 @@ def compare_types(context, kind, type_1, type_2, types_map_1, types_map_2, depth
base_type_1 = type_1["type"]
base_type_2 = type_2["type"]

# Binary and string have the same wire representation in JSON.
if ((base_type_1 == "string" and base_type_2 == "binary") or
(base_type_2 == "string" and base_type_1 == "binary")):
return

if base_type_1 != base_type_2:
errors.append("%s: %s base type mismatch, '%s' vs '%s'" % (context, kind, base_type_1, base_type_2))
elif base_type_1 == "object":
Expand Down Expand Up @@ -228,8 +236,8 @@ def load_schema(file_name, domains):
if not os.path.isfile(file_name):
return
input_file = open(file_name, "r")
json_string = input_file.read()
parsed_json = json.loads(json_string)
parsed_json = pdl.loads(input_file.read(), file_name)
input_file.close()
domains += parsed_json["domains"]
return parsed_json["version"]

Expand Down Expand Up @@ -422,6 +430,7 @@ def load_domains_and_baselines(file_name, domains, baseline_domains):
version = load_schema(os.path.normpath(file_name), domains)
suffix = "-%s.%s.json" % (version["major"], version["minor"])
baseline_file = file_name.replace(".json", suffix)
baseline_file = file_name.replace(".pdl", suffix)
load_schema(os.path.normpath(baseline_file), baseline_domains)
return version

Expand Down Expand Up @@ -467,9 +476,9 @@ def main():
if arg_options.show_changes:
changes = compare_schemas(domains, baseline_domains, True)
if len(changes) > 0:
print " Public changes since %s:" % version
print(" Public changes since %s:" % version)
for change in changes:
print " %s" % change
print(" %s" % change)

if arg_options.stamp:
with open(arg_options.stamp, 'a') as _:
Expand Down
Loading