From c6c00ce20c9ccdd1291c043e8393acbb407bc04f Mon Sep 17 00:00:00 2001 From: pluris Date: Mon, 25 Sep 2023 11:06:42 +0900 Subject: [PATCH] src: modify int to uint16_t fori `HostPort` --- src/inspector_io.cc | 2 +- src/inspector_js_api.cc | 2 +- src/node_options.h | 10 ++++------ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/inspector_io.cc b/src/inspector_io.cc index b7b8f21e3ff16a..9b1f2b7f3b0a76 100644 --- a/src/inspector_io.cc +++ b/src/inspector_io.cc @@ -293,7 +293,7 @@ void InspectorIo::ThreadMain() { new InspectorIoDelegate(queue, main_thread_, id_, script_path, script_name_)); std::string host; - int port; + uint16_t port; { ExclusiveAccess::Scoped host_port(host_port_); host = host_port->host(); diff --git a/src/inspector_js_api.cc b/src/inspector_js_api.cc index 5c66757afd1a7a..2b5f884341082c 100644 --- a/src/inspector_js_api.cc +++ b/src/inspector_js_api.cc @@ -286,7 +286,7 @@ void Open(const FunctionCallbackInfo& args) { uint32_t port = args[0].As()->Value(); CHECK_LE(port, std::numeric_limits::max()); ExclusiveAccess::Scoped host_port(agent->host_port()); - host_port->set_port(static_cast(port)); + host_port->set_port(static_cast(port)); } if (args.Length() > 1 && args[1]->IsString()) { diff --git a/src/node_options.h b/src/node_options.h index bc18a45e681a3c..0c816ce6b947f1 100644 --- a/src/node_options.h +++ b/src/node_options.h @@ -28,24 +28,22 @@ class HostPort { void set_host(const std::string& host) { host_name_ = host; } - void set_port(int port) { port_ = port; } + void set_port(uint16_t port) { port_ = port; } const std::string& host() const { return host_name_; } - int port() const { - // TODO(joyeecheung): make port a uint16_t - CHECK_GE(port_, 0); + uint16_t port() const { return port_; } void Update(const HostPort& other) { if (!other.host_name_.empty()) host_name_ = other.host_name_; - if (other.port_ >= 0) port_ = other.port_; + port_ = other.port_; } private: std::string host_name_; - int port_; + uint16_t port_; }; class Options {