| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7644c7e commit 9f1fa19
86 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -53,12 +53,12 @@ void NetworkAgent::Wire(UberDispatcher* dispatcher) { | |||
| 53 | 53 | ||
| 54 | 54 | DispatchResponse NetworkAgent::enable() { | |
| 55 | 55 | inspector_->Enable(); | |
| 56 | - return DispatchResponse::OK(); | ||
| 56 | + return DispatchResponse::Success(); | ||
| 57 | 57 | } | |
| 58 | 58 | ||
| 59 | 59 | DispatchResponse NetworkAgent::disable() { | |
| 60 | 60 | inspector_->Disable(); | |
| 61 | - return DispatchResponse::OK(); | ||
| 61 | + return DispatchResponse::Success(); | ||
| 62 | 62 | } | |
| 63 | 63 | ||
| 64 | 64 | void NetworkAgent::requestWillBeSent( | |
@@ -76,9 +76,11 @@ void NetworkAgent::requestWillBeSent( | |||
| 76 | 76 | request->getString("method", &method); | |
| 77 | 77 | ||
| 78 | 78 | ErrorSupport errors; | |
| 79 | + errors.Push(); | ||
| 80 | + errors.SetName("headers"); | ||
| 79 | 81 | auto headers = | |
| 80 | 82 | Network::Headers::fromValue(request->getObject("headers"), &errors); | |
| 81 | - if (errors.hasErrors()) { | ||
| 83 | + if (!errors.Errors().empty()) { | ||
| 82 | 84 | headers = std::make_unique<Network::Headers>(DictionaryValue::create()); | |
| 83 | 85 | } | |
| 84 | 86 | ||
@@ -105,9 +107,11 @@ void NetworkAgent::responseReceived( | |||
| 105 | 107 | response->getString("statusText", &statusText); | |
| 106 | 108 | ||
| 107 | 109 | ErrorSupport errors; | |
| 110 | + errors.Push(); | ||
| 111 | + errors.SetName("headers"); | ||
| 108 | 112 | auto headers = | |
| 109 | 113 | Network::Headers::fromValue(response->getObject("headers"), &errors); | |
| 110 | - if (errors.hasErrors()) { | ||
| 114 | + if (!errors.Errors().empty()) { | ||
| 111 | 115 | headers = std::make_unique<Network::Headers>(DictionaryValue::create()); | |
| 112 | 116 | } | |
| 113 | 117 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,6 +15,8 @@ | |||
| 15 | 15 | 'src/inspector_socket_server.h', | |
| 16 | 16 | 'src/inspector/main_thread_interface.cc', | |
| 17 | 17 | 'src/inspector/main_thread_interface.h', | |
| 18 | + 'src/inspector/node_json.cc', | ||
| 19 | + 'src/inspector/node_json.h', | ||
| 18 | 20 | 'src/inspector/node_string.cc', | |
| 19 | 21 | 'src/inspector/node_string.h', | |
| 20 | 22 | 'src/inspector/runtime_agent.cc', | |
@@ -29,6 +31,30 @@ | |||
| 29 | 31 | 'src/inspector/network_agent.h', | |
| 30 | 32 | 'src/inspector/worker_inspector.cc', | |
| 31 | 33 | 'src/inspector/worker_inspector.h', | |
| 34 | + | ||
| 35 | + '<(protocol_tool_path)/crdtp/cbor.cc', | ||
| 36 | + '<(protocol_tool_path)/crdtp/cbor.h', | ||
| 37 | + '<(protocol_tool_path)/crdtp/dispatch.cc', | ||
| 38 | + '<(protocol_tool_path)/crdtp/dispatch.h', | ||
| 39 | + '<(protocol_tool_path)/crdtp/error_support.cc', | ||
| 40 | + '<(protocol_tool_path)/crdtp/error_support.h', | ||
| 41 | + '<(protocol_tool_path)/crdtp/export.h', | ||
| 42 | + '<(protocol_tool_path)/crdtp/find_by_first.h', | ||
| 43 | + '<(protocol_tool_path)/crdtp/frontend_channel.h', | ||
| 44 | + '<(protocol_tool_path)/crdtp/json.cc', | ||
| 45 | + '<(protocol_tool_path)/crdtp/json.h', | ||
| 46 | + '<(protocol_tool_path)/crdtp/json_platform.cc', | ||
| 47 | + '<(protocol_tool_path)/crdtp/json_platform.h', | ||
| 48 | + '<(protocol_tool_path)/crdtp/maybe.h', | ||
| 49 | + '<(protocol_tool_path)/crdtp/parser_handler.h', | ||
| 50 | + '<(protocol_tool_path)/crdtp/protocol_core.cc', | ||
| 51 | + '<(protocol_tool_path)/crdtp/protocol_core.h', | ||
| 52 | + '<(protocol_tool_path)/crdtp/serializable.cc', | ||
| 53 | + '<(protocol_tool_path)/crdtp/serializable.h', | ||
| 54 | + '<(protocol_tool_path)/crdtp/span.cc', | ||
| 55 | + '<(protocol_tool_path)/crdtp/span.h', | ||
| 56 | + '<(protocol_tool_path)/crdtp/status.cc', | ||
| 57 | + '<(protocol_tool_path)/crdtp/status.h', | ||
| 32 | 58 | ], | |
| 33 | 59 | 'node_inspector_generated_sources': [ | |
| 34 | 60 | '<(SHARED_INTERMEDIATE_DIR)/src/node/inspector/protocol/Forward.h', | |
@@ -44,23 +70,11 @@ | |||
| 44 | 70 | '<(SHARED_INTERMEDIATE_DIR)/src/node/inspector/protocol/Network.h', | |
| 45 | 71 | ], | |
| 46 | 72 | 'node_protocol_files': [ | |
| 47 | - '<(protocol_tool_path)/lib/Allocator_h.template', | ||
| 48 | - '<(protocol_tool_path)/lib/base_string_adapter_cc.template', | ||
| 49 | - '<(protocol_tool_path)/lib/base_string_adapter_h.template', | ||
| 50 | - '<(protocol_tool_path)/lib/DispatcherBase_cpp.template', | ||
| 51 | - '<(protocol_tool_path)/lib/DispatcherBase_h.template', | ||
| 52 | - '<(protocol_tool_path)/lib/encoding_cpp.template', | ||
| 53 | - '<(protocol_tool_path)/lib/encoding_h.template', | ||
| 54 | - '<(protocol_tool_path)/lib/ErrorSupport_cpp.template', | ||
| 55 | - '<(protocol_tool_path)/lib/ErrorSupport_h.template', | ||
| 56 | 73 | '<(protocol_tool_path)/lib/Forward_h.template', | |
| 57 | - '<(protocol_tool_path)/lib/FrontendChannel_h.template', | ||
| 58 | - '<(protocol_tool_path)/lib/Maybe_h.template', | ||
| 59 | 74 | '<(protocol_tool_path)/lib/Object_cpp.template', | |
| 60 | 75 | '<(protocol_tool_path)/lib/Object_h.template', | |
| 61 | - '<(protocol_tool_path)/lib/Parser_cpp.template', | ||
| 62 | - '<(protocol_tool_path)/lib/Parser_h.template', | ||
| 63 | 76 | '<(protocol_tool_path)/lib/Protocol_cpp.template', | |
| 77 | + '<(protocol_tool_path)/lib/ValueConversions_cpp.template', | ||
| 64 | 78 | '<(protocol_tool_path)/lib/ValueConversions_h.template', | |
| 65 | 79 | '<(protocol_tool_path)/lib/Values_cpp.template', | |
| 66 | 80 | '<(protocol_tool_path)/lib/Values_h.template', | |
@@ -77,6 +91,7 @@ | |||
| 77 | 91 | '<@(node_inspector_sources)', | |
| 78 | 92 | ], | |
| 79 | 93 | 'include_dirs': [ | |
| 94 | + '<(protocol_tool_path)', | ||
| 80 | 95 | '<(SHARED_INTERMEDIATE_DIR)/include', # for inspector | |
| 81 | 96 | '<(SHARED_INTERMEDIATE_DIR)', | |
| 82 | 97 | '<(SHARED_INTERMEDIATE_DIR)/src', # for inspector | |
@@ -112,6 +127,7 @@ | |||
| 112 | 127 | 'action': [ | |
| 113 | 128 | '<(python)', | |
| 114 | 129 | 'tools/inspector_protocol/code_generator.py', | |
| 130 | + '--inspector_protocol_dir', 'tools/inspector_protocol/', | ||
| 115 | 131 | '--jinja_dir', '<@(protocol_tool_path)', | |
| 116 | 132 | '--output_base', '<(SHARED_INTERMEDIATE_DIR)/src/', | |
| 117 | 133 | '--config', 'src/inspector/node_protocol_config.json', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,190 @@ | |||
| 1 | + #include "node_json.h" | ||
| 2 | + | ||
| 3 | + #include "crdtp/json.h" | ||
| 4 | + | ||
| 5 | + namespace node { | ||
| 6 | + namespace inspector { | ||
| 7 | + | ||
| 8 | + using crdtp::ParserHandler; | ||
| 9 | + using crdtp::span; | ||
| 10 | + using crdtp::Status; | ||
| 11 | + using protocol::Binary; | ||
| 12 | + using protocol::BinaryValue; | ||
| 13 | + using protocol::DictionaryValue; | ||
| 14 | + using protocol::FundamentalValue; | ||
| 15 | + using protocol::ListValue; | ||
| 16 | + using protocol::String; | ||
| 17 | + using protocol::StringUtil; | ||
| 18 | + using protocol::StringValue; | ||
| 19 | + using protocol::Value; | ||
| 20 | + | ||
| 21 | + namespace { | ||
| 22 | + | ||
| 23 | + // Uses the parsing events received from driver of `ParserHandler` | ||
| 24 | + // (e.g. crdtp::json::ParseJSON) into a protocol::Value instance. | ||
| 25 | + class ValueParserHandler : public ParserHandler { | ||
| 26 | + public: | ||
| 27 | + // Provides the parsed protocol::Value. | ||
| 28 | + std::unique_ptr<Value> ReleaseRoot() { return std::move(root_); } | ||
| 29 | + | ||
| 30 | + // The first parsing error encountered; `status().ok()` is the default. | ||
| 31 | + Status status() const { return status_; } | ||
| 32 | + | ||
| 33 | + private: | ||
| 34 | + // Implementation of `ParserHandler`. | ||
| 35 | + void HandleMapBegin() override { | ||
| 36 | + if (!status_.ok()) return; | ||
| 37 | + std::unique_ptr<DictionaryValue> dict = DictionaryValue::create(); | ||
| 38 | + DictionaryValue* dict_ptr = dict.get(); | ||
| 39 | + AddValueToParent(std::move(dict)); | ||
| 40 | + stack_.emplace_back(dict_ptr); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + void HandleMapEnd() override { | ||
| 44 | + if (!status_.ok()) return; | ||
| 45 | + DCHECK(!stack_.empty()); | ||
| 46 | + DCHECK(stack_.back().is_dict); | ||
| 47 | + stack_.pop_back(); | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + void HandleArrayBegin() override { | ||
| 51 | + if (!status_.ok()) return; | ||
| 52 | + std::unique_ptr<ListValue> list = ListValue::create(); | ||
| 53 | + ListValue* list_ptr = list.get(); | ||
| 54 | + AddValueToParent(std::move(list)); | ||
| 55 | + stack_.emplace_back(list_ptr); | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + void HandleArrayEnd() override { | ||
| 59 | + if (!status_.ok()) return; | ||
| 60 | + DCHECK(!stack_.empty()); | ||
| 61 | + DCHECK(!stack_.back().is_dict); | ||
| 62 | + stack_.pop_back(); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + void HandleString8(span<uint8_t> chars) override { | ||
| 66 | + AddStringToParent(StringUtil::fromUTF8(chars.data(), chars.size())); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + void HandleString16(span<uint16_t> chars) override { | ||
| 70 | + AddStringToParent(StringUtil::fromUTF16(chars.data(), chars.size())); | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + void HandleBinary(span<uint8_t> bytes) override { | ||
| 74 | + AddValueToParent( | ||
| 75 | + BinaryValue::create(Binary::fromSpan(bytes.data(), bytes.size()))); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + void HandleDouble(double value) override { | ||
| 79 | + AddValueToParent(FundamentalValue::create(value)); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + void HandleInt32(int32_t value) override { | ||
| 83 | + AddValueToParent(FundamentalValue::create(value)); | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + void HandleBool(bool value) override { | ||
| 87 | + AddValueToParent(FundamentalValue::create(value)); | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + void HandleNull() override { AddValueToParent(Value::null()); } | ||
| 91 | + | ||
| 92 | + void HandleError(Status error) override { status_ = error; } | ||
| 93 | + | ||
| 94 | + // Adding strings and values to the parent value. | ||
| 95 | + // Strings are handled separately because they can be keys for | ||
| 96 | + // dictionary values. | ||
| 97 | + void AddStringToParent(String str) { | ||
| 98 | + if (!status_.ok()) return; | ||
| 99 | + if (!root_) { | ||
| 100 | + DCHECK(!key_is_pending_); | ||
| 101 | + root_ = StringValue::create(str); | ||
| 102 | + } else if (stack_.back().is_dict) { | ||
| 103 | + // If we already have a pending key, then this is the value of the | ||
| 104 | + // key/value pair. Otherwise, it's the new pending key. | ||
| 105 | + if (key_is_pending_) { | ||
| 106 | + stack_.back().dict->setString(pending_key_, str); | ||
| 107 | + key_is_pending_ = false; | ||
| 108 | + } else { | ||
| 109 | + pending_key_ = std::move(str); | ||
| 110 | + key_is_pending_ = true; | ||
| 111 | + } | ||
| 112 | + } else { // Top of the stack is a list. | ||
| 113 | + DCHECK(!key_is_pending_); | ||
| 114 | + stack_.back().list->pushValue(StringValue::create(str)); | ||
| 115 | + } | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + void AddValueToParent(std::unique_ptr<Value> value) { | ||
| 119 | + if (!status_.ok()) return; | ||
| 120 | + if (!root_) { | ||
| 121 | + DCHECK(!key_is_pending_); | ||
| 122 | + root_ = std::move(value); | ||
| 123 | + } else if (stack_.back().is_dict) { | ||
| 124 | + DCHECK(key_is_pending_); | ||
| 125 | + stack_.back().dict->setValue(pending_key_, std::move(value)); | ||
| 126 | + key_is_pending_ = false; | ||
| 127 | + } else { // Top of the stack is a list. | ||
| 128 | + DCHECK(!key_is_pending_); | ||
| 129 | + stack_.back().list->pushValue(std::move(value)); | ||
| 130 | + } | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + // `status_.ok()` is the default; if we receive an error event | ||
| 134 | + // we keep the first one and stop modifying any other state. | ||
| 135 | + Status status_; | ||
| 136 | + | ||
| 137 | + // The root of the parsed protocol::Value tree. | ||
| 138 | + std::unique_ptr<Value> root_; | ||
| 139 | + | ||
| 140 | + // If root_ is a list or a dictionary, this stack keeps track of | ||
| 141 | + // the container we're currently parsing as well as its ancestors. | ||
| 142 | + struct ContainerState { | ||
| 143 | + explicit ContainerState(DictionaryValue* dict) | ||
| 144 | + : is_dict(true), dict(dict) {} | ||
| 145 | + explicit ContainerState(ListValue* list) : is_dict(false), list(list) {} | ||
| 146 | + | ||
| 147 | + bool is_dict; | ||
| 148 | + union { | ||
| 149 | + DictionaryValue* dict; | ||
| 150 | + ListValue* list; | ||
| 151 | + }; | ||
| 152 | + }; | ||
| 153 | + std::vector<ContainerState> stack_; | ||
| 154 | + | ||
| 155 | + // For maps, keys and values are alternating events, so we keep the | ||
| 156 | + // key around and process it when the value arrives. | ||
| 157 | + bool key_is_pending_ = false; | ||
| 158 | + String pending_key_; | ||
| 159 | + }; | ||
| 160 | + } // anonymous namespace | ||
| 161 | + | ||
| 162 | + std::unique_ptr<Value> JsonUtil::ParseJSON(const uint8_t* chars, size_t size) { | ||
| 163 | + ValueParserHandler handler; | ||
| 164 | + crdtp::json::ParseJSON(span<uint8_t>(chars, size), &handler); | ||
| 165 | + if (handler.status().ok()) return handler.ReleaseRoot(); | ||
| 166 | + return nullptr; | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + std::unique_ptr<Value> JsonUtil::ParseJSON(const uint16_t* chars, size_t size) { | ||
| 170 | + ValueParserHandler handler; | ||
| 171 | + crdtp::json::ParseJSON(span<uint16_t>(chars, size), &handler); | ||
| 172 | + if (handler.status().ok()) return handler.ReleaseRoot(); | ||
| 173 | + return nullptr; | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + std::unique_ptr<Value> JsonUtil::parseJSON(const std::string_view string) { | ||
| 177 | + if (string.empty()) return nullptr; | ||
| 178 | + | ||
| 179 | + return ParseJSON(reinterpret_cast<const uint8_t*>(string.data()), | ||
| 180 | + string.size()); | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + std::unique_ptr<Value> JsonUtil::parseJSON(v8_inspector::StringView string) { | ||
| 184 | + if (string.length() == 0) return nullptr; | ||
| 185 | + if (string.is8Bit()) return ParseJSON(string.characters8(), string.length()); | ||
| 186 | + return ParseJSON(string.characters16(), string.length()); | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + } // namespace inspector | ||
| 190 | + } // namespace node | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,24 @@ | |||
| 1 | + #ifndef SRC_INSPECTOR_NODE_JSON_H_ | ||
| 2 | + #define SRC_INSPECTOR_NODE_JSON_H_ | ||
| 3 | + | ||
| 4 | + #include "node/inspector/protocol/Protocol.h" | ||
| 5 | + | ||
| 6 | + namespace node { | ||
| 7 | + namespace inspector { | ||
| 8 | + | ||
| 9 | + struct JsonUtil { | ||
| 10 | + // Parse s JSON string into protocol::Value. | ||
| 11 | + static std::unique_ptr<protocol::Value> ParseJSON(const uint8_t* chars, | ||
| 12 | + size_t size); | ||
| 13 | + static std::unique_ptr<protocol::Value> ParseJSON(const uint16_t* chars, | ||
| 14 | + size_t size); | ||
| 15 | + | ||
| 16 | + static std::unique_ptr<protocol::Value> parseJSON(const std::string_view); | ||
| 17 | + static std::unique_ptr<protocol::Value> parseJSON( | ||
| 18 | + v8_inspector::StringView view); | ||
| 19 | + }; | ||
| 20 | + | ||
| 21 | + } // namespace inspector | ||
| 22 | + } // namespace node | ||
| 23 | + | ||
| 24 | + #endif // SRC_INSPECTOR_NODE_JSON_H_ | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | { | |
| 2 | 2 | "protocol": { | |
| 3 | - "path": "node_protocol.json", | ||
| 3 | + "path": "node_protocol.pdl", | ||
| 4 | 4 | "package": "src/node/inspector/protocol", | |
| 5 | 5 | "output": "node/inspector/protocol", | |
| 6 | 6 | "namespace": ["node", "inspector", "protocol"] | |
@@ -18,5 +18,8 @@ | |||
| 18 | 18 | "package": "src/node/inspector/protocol", | |
| 19 | 19 | "output": "node/inspector/protocol", | |
| 20 | 20 | "string_header": "inspector/node_string.h" | |
| 21 | + }, | ||
| 22 | + "crdtp": { | ||
| 23 | + "dir": "crdtp" | ||
| 21 | 24 | } | |
| 22 | 25 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments