From f464ac3c74ca2b2411c578b4dcb52838f569e9fa Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Wed, 29 Aug 2018 16:12:36 +0200 Subject: [PATCH] src: remove calls to deprecated v8 functions (IntegerValue) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove all calls to deprecated v8 functions (here: Value::IntegerValue) inside the code (src directory only). Co-authored-by: Michaƫl Zasso PR-URL: https://github.com/nodejs/node/pull/22129 Reviewed-By: Anna Henningsen --- src/node.cc | 11 +++++------ src/node_buffer.cc | 9 +++++---- src/node_crypto.cc | 9 +++++---- src/node_http_parser.cc | 8 ++++++-- src/process_wrap.cc | 5 +++-- src/tcp_wrap.cc | 5 ++++- src/udp_wrap.cc | 3 ++- 7 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/node.cc b/src/node.cc index da9ad93b8d658b..d1ce0ce1af3870 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2395,11 +2395,10 @@ void DebugProcess(const FunctionCallbackInfo& args) { return env->ThrowError("Invalid number of arguments."); } - pid_t pid; - int r; + CHECK(args[0]->IsNumber()); + pid_t pid = args[0].As()->Value(); + int r = kill(pid, SIGUSR1); - pid = args[0]->IntegerValue(); - r = kill(pid, SIGUSR1); if (r != 0) { return env->ThrowErrnoException(errno, "kill"); } @@ -2417,7 +2416,6 @@ static int GetDebugSignalHandlerMappingName(DWORD pid, wchar_t* buf, static void DebugProcess(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); Isolate* isolate = args.GetIsolate(); - DWORD pid; HANDLE process = nullptr; HANDLE thread = nullptr; HANDLE mapping = nullptr; @@ -2429,7 +2427,8 @@ static void DebugProcess(const FunctionCallbackInfo& args) { goto out; } - pid = (DWORD) args[0]->IntegerValue(); + CHECK(args[0]->IsNumber()); + DWORD pid = args[0].As()->Value(); process = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 7c4c0d9f657b24..465c42047911b0 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -173,7 +173,8 @@ inline MUST_USE_RESULT bool ParseArrayIndex(Local arg, return true; } - int64_t tmp_i = arg->IntegerValue(); + CHECK(arg->IsNumber()); + int64_t tmp_i = arg.As()->Value(); if (tmp_i < 0) return false; @@ -769,7 +770,7 @@ void IndexOfString(const FunctionCallbackInfo& args) { SPREAD_BUFFER_ARG(args[0], ts_obj); Local needle = args[1].As(); - int64_t offset_i64 = args[2]->IntegerValue(); + int64_t offset_i64 = args[2].As()->Value(); bool is_forward = args[4]->IsTrue(); const char* haystack = ts_obj_data; @@ -885,7 +886,7 @@ void IndexOfBuffer(const FunctionCallbackInfo& args) { THROW_AND_RETURN_UNLESS_BUFFER(Environment::GetCurrent(args), args[1]); SPREAD_BUFFER_ARG(args[0], ts_obj); SPREAD_BUFFER_ARG(args[1], buf); - int64_t offset_i64 = args[2]->IntegerValue(); + int64_t offset_i64 = args[2].As()->Value(); bool is_forward = args[4]->IsTrue(); const char* haystack = ts_obj_data; @@ -955,7 +956,7 @@ void IndexOfNumber(const FunctionCallbackInfo& args) { SPREAD_BUFFER_ARG(args[0], ts_obj); uint32_t needle = args[1].As()->Value(); - int64_t offset_i64 = args[2]->IntegerValue(); + int64_t offset_i64 = args[2].As()->Value(); bool is_forward = args[3]->IsTrue(); int64_t opt_offset = IndexOfOffset(ts_obj_length, offset_i64, 1, is_forward); diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 7b0bb6c1637dab..0ebebec5d2437a 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -985,15 +985,16 @@ void SecureContext::SetDHParam(const FunctionCallbackInfo& args) { void SecureContext::SetOptions(const FunctionCallbackInfo& args) { SecureContext* sc; ASSIGN_OR_RETURN_UNWRAP(&sc, args.Holder()); + int64_t val; - if (args.Length() != 1 || !args[0]->IntegerValue()) { + if (args.Length() != 1 || + !args[0]->IntegerValue(args.GetIsolate()->GetCurrentContext()).To(&val)) { return THROW_ERR_INVALID_ARG_TYPE( sc->env(), "Options must be an integer value"); } - SSL_CTX_set_options( - sc->ctx_.get(), - static_cast(args[0]->IntegerValue())); // NOLINT(runtime/int) + SSL_CTX_set_options(sc->ctx_.get(), + static_cast(val)); // NOLINT(runtime/int) } diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index f2ec2c0bbde4f2..07dd800b256abb 100644 --- a/src/node_http_parser.cc +++ b/src/node_http_parser.cc @@ -289,12 +289,16 @@ class Parser : public AsyncWrap, public StreamListener { MaybeLocal head_response = MakeCallback(cb.As(), arraysize(argv), argv); - if (head_response.IsEmpty()) { + int64_t val; + + if (head_response.IsEmpty() || !head_response.ToLocalChecked() + ->IntegerValue(env()->context()) + .To(&val)) { got_exception_ = true; return -1; } - return head_response.ToLocalChecked()->IntegerValue(); + return val; } diff --git a/src/process_wrap.cc b/src/process_wrap.cc index 70f656ae5e67d3..2841595c1f186b 100644 --- a/src/process_wrap.cc +++ b/src/process_wrap.cc @@ -132,8 +132,9 @@ class ProcessWrap : public HandleWrap { options->stdio[i].data.stream = stream; } else { Local fd_key = env->fd_string(); - int fd = static_cast( - stdio->Get(context, fd_key).ToLocalChecked()->IntegerValue()); + Local fd_value = stdio->Get(context, fd_key).ToLocalChecked(); + CHECK(fd_value->IsNumber()); + int fd = static_cast(fd_value.As()->Value()); options->stdio[i].flags = UV_INHERIT_FD; options->stdio[i].data.fd = fd; } diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index dd507e6ebde6f4..d8080319aa904c 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -207,7 +207,10 @@ void TCPWrap::Open(const FunctionCallbackInfo& args) { ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder(), args.GetReturnValue().Set(UV_EBADF)); - int fd = static_cast(args[0]->IntegerValue()); + int64_t val; + if (!args[0]->IntegerValue(args.GetIsolate()->GetCurrentContext()).To(&val)) + return; + int fd = static_cast(val); int err = uv_tcp_open(&wrap->handle_, fd); if (err == 0) diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index c7ca7fc44d67de..8005eeb9ff76e2 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -215,7 +215,8 @@ void UDPWrap::Open(const FunctionCallbackInfo& args) { ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder(), args.GetReturnValue().Set(UV_EBADF)); - int fd = static_cast(args[0]->IntegerValue()); + CHECK(args[0]->IsNumber()); + int fd = static_cast(args[0].As()->Value()); int err = uv_udp_open(&wrap->handle_, fd); args.GetReturnValue().Set(err);