Skip to content

Commit c637d41

Browse files
ryzokukentargos
authored andcommitted
src: remove calls to deprecated v8 functions (IntegerValue)
Remove all calls to deprecated v8 functions (here: Value::IntegerValue) inside the code (src directory only). Co-authored-by: Michaël Zasso <[email protected]> PR-URL: #22129 Reviewed-By: Anna Henningsen <[email protected]>
1 parent be86ddb commit c637d41

6 files changed

+28
-19
lines changed

src/node.cc

+5-6
Original file line numberDiff line numberDiff line change
@@ -2394,11 +2394,10 @@ void DebugProcess(const FunctionCallbackInfo<Value>& args) {
23942394
return env->ThrowError("Invalid number of arguments.");
23952395
}
23962396

2397-
pid_t pid;
2398-
int r;
2397+
CHECK(args[0]->IsNumber());
2398+
pid_t pid = args[0].As<Integer>()->Value();
2399+
int r = kill(pid, SIGUSR1);
23992400

2400-
pid = args[0]->IntegerValue();
2401-
r = kill(pid, SIGUSR1);
24022401
if (r != 0) {
24032402
return env->ThrowErrnoException(errno, "kill");
24042403
}
@@ -2416,7 +2415,6 @@ static int GetDebugSignalHandlerMappingName(DWORD pid, wchar_t* buf,
24162415
static void DebugProcess(const FunctionCallbackInfo<Value>& args) {
24172416
Environment* env = Environment::GetCurrent(args);
24182417
Isolate* isolate = args.GetIsolate();
2419-
DWORD pid;
24202418
HANDLE process = nullptr;
24212419
HANDLE thread = nullptr;
24222420
HANDLE mapping = nullptr;
@@ -2428,7 +2426,8 @@ static void DebugProcess(const FunctionCallbackInfo<Value>& args) {
24282426
goto out;
24292427
}
24302428

2431-
pid = (DWORD) args[0]->IntegerValue();
2429+
CHECK(args[0]->IsNumber());
2430+
DWORD pid = args[0].As<Integer>()->Value();
24322431

24332432
process = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION |
24342433
PROCESS_VM_OPERATION | PROCESS_VM_WRITE |

src/node_buffer.cc

+5-4
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ inline MUST_USE_RESULT bool ParseArrayIndex(Local<Value> arg,
173173
return true;
174174
}
175175

176-
int64_t tmp_i = arg->IntegerValue();
176+
CHECK(arg->IsNumber());
177+
int64_t tmp_i = arg.As<Integer>()->Value();
177178

178179
if (tmp_i < 0)
179180
return false;
@@ -769,7 +770,7 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) {
769770
SPREAD_BUFFER_ARG(args[0], ts_obj);
770771

771772
Local<String> needle = args[1].As<String>();
772-
int64_t offset_i64 = args[2]->IntegerValue();
773+
int64_t offset_i64 = args[2].As<Integer>()->Value();
773774
bool is_forward = args[4]->IsTrue();
774775

775776
const char* haystack = ts_obj_data;
@@ -885,7 +886,7 @@ void IndexOfBuffer(const FunctionCallbackInfo<Value>& args) {
885886
THROW_AND_RETURN_UNLESS_BUFFER(Environment::GetCurrent(args), args[1]);
886887
SPREAD_BUFFER_ARG(args[0], ts_obj);
887888
SPREAD_BUFFER_ARG(args[1], buf);
888-
int64_t offset_i64 = args[2]->IntegerValue();
889+
int64_t offset_i64 = args[2].As<Integer>()->Value();
889890
bool is_forward = args[4]->IsTrue();
890891

891892
const char* haystack = ts_obj_data;
@@ -955,7 +956,7 @@ void IndexOfNumber(const FunctionCallbackInfo<Value>& args) {
955956
SPREAD_BUFFER_ARG(args[0], ts_obj);
956957

957958
uint32_t needle = args[1].As<Uint32>()->Value();
958-
int64_t offset_i64 = args[2]->IntegerValue();
959+
int64_t offset_i64 = args[2].As<Integer>()->Value();
959960
bool is_forward = args[3]->IsTrue();
960961

961962
int64_t opt_offset = IndexOfOffset(ts_obj_length, offset_i64, 1, is_forward);

src/node_crypto.cc

+5-4
Original file line numberDiff line numberDiff line change
@@ -979,15 +979,16 @@ void SecureContext::SetDHParam(const FunctionCallbackInfo<Value>& args) {
979979
void SecureContext::SetOptions(const FunctionCallbackInfo<Value>& args) {
980980
SecureContext* sc;
981981
ASSIGN_OR_RETURN_UNWRAP(&sc, args.Holder());
982+
int64_t val;
982983

983-
if (args.Length() != 1 || !args[0]->IntegerValue()) {
984+
if (args.Length() != 1 ||
985+
!args[0]->IntegerValue(args.GetIsolate()->GetCurrentContext()).To(&val)) {
984986
return THROW_ERR_INVALID_ARG_TYPE(
985987
sc->env(), "Options must be an integer value");
986988
}
987989

988-
SSL_CTX_set_options(
989-
sc->ctx_.get(),
990-
static_cast<long>(args[0]->IntegerValue())); // NOLINT(runtime/int)
990+
SSL_CTX_set_options(sc->ctx_.get(),
991+
static_cast<long>(val)); // NOLINT(runtime/int)
991992
}
992993

993994

src/node_http_parser.cc

+6-2
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,16 @@ class Parser : public AsyncWrap, public StreamListener {
289289
MaybeLocal<Value> head_response =
290290
MakeCallback(cb.As<Function>(), arraysize(argv), argv);
291291

292-
if (head_response.IsEmpty()) {
292+
int64_t val;
293+
294+
if (head_response.IsEmpty() || !head_response.ToLocalChecked()
295+
->IntegerValue(env()->context())
296+
.To(&val)) {
293297
got_exception_ = true;
294298
return -1;
295299
}
296300

297-
return head_response.ToLocalChecked()->IntegerValue();
301+
return val;
298302
}
299303

300304

src/process_wrap.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ class ProcessWrap : public HandleWrap {
132132
options->stdio[i].data.stream = stream;
133133
} else {
134134
Local<String> fd_key = env->fd_string();
135-
int fd = static_cast<int>(
136-
stdio->Get(context, fd_key).ToLocalChecked()->IntegerValue());
135+
Local<Value> fd_value = stdio->Get(context, fd_key).ToLocalChecked();
136+
CHECK(fd_value->IsNumber());
137+
int fd = static_cast<int>(fd_value.As<Integer>()->Value());
137138
options->stdio[i].flags = UV_INHERIT_FD;
138139
options->stdio[i].data.fd = fd;
139140
}

src/tcp_wrap.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,10 @@ void TCPWrap::Open(const FunctionCallbackInfo<Value>& args) {
207207
ASSIGN_OR_RETURN_UNWRAP(&wrap,
208208
args.Holder(),
209209
args.GetReturnValue().Set(UV_EBADF));
210-
int fd = static_cast<int>(args[0]->IntegerValue());
210+
int64_t val;
211+
if (!args[0]->IntegerValue(args.GetIsolate()->GetCurrentContext()).To(&val))
212+
return;
213+
int fd = static_cast<int>(val);
211214
int err = uv_tcp_open(&wrap->handle_, fd);
212215

213216
if (err == 0)

0 commit comments

Comments
 (0)