Skip to content

Commit f464ac3

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 31ca5dc commit f464ac3

File tree

7 files changed

+30
-20
lines changed

7 files changed

+30
-20
lines changed

src/node.cc

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

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

2401-
pid = args[0]->IntegerValue();
2402-
r = kill(pid, SIGUSR1);
24032402
if (r != 0) {
24042403
return env->ThrowErrnoException(errno, "kill");
24052404
}
@@ -2417,7 +2416,6 @@ static int GetDebugSignalHandlerMappingName(DWORD pid, wchar_t* buf,
24172416
static void DebugProcess(const FunctionCallbackInfo<Value>& args) {
24182417
Environment* env = Environment::GetCurrent(args);
24192418
Isolate* isolate = args.GetIsolate();
2420-
DWORD pid;
24212419
HANDLE process = nullptr;
24222420
HANDLE thread = nullptr;
24232421
HANDLE mapping = nullptr;
@@ -2429,7 +2427,8 @@ static void DebugProcess(const FunctionCallbackInfo<Value>& args) {
24292427
goto out;
24302428
}
24312429

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

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

src/node_buffer.cc

Lines changed: 5 additions & 4 deletions
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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -985,15 +985,16 @@ void SecureContext::SetDHParam(const FunctionCallbackInfo<Value>& args) {
985985
void SecureContext::SetOptions(const FunctionCallbackInfo<Value>& args) {
986986
SecureContext* sc;
987987
ASSIGN_OR_RETURN_UNWRAP(&sc, args.Holder());
988+
int64_t val;
988989

989-
if (args.Length() != 1 || !args[0]->IntegerValue()) {
990+
if (args.Length() != 1 ||
991+
!args[0]->IntegerValue(args.GetIsolate()->GetCurrentContext()).To(&val)) {
990992
return THROW_ERR_INVALID_ARG_TYPE(
991993
sc->env(), "Options must be an integer value");
992994
}
993995

994-
SSL_CTX_set_options(
995-
sc->ctx_.get(),
996-
static_cast<long>(args[0]->IntegerValue())); // NOLINT(runtime/int)
996+
SSL_CTX_set_options(sc->ctx_.get(),
997+
static_cast<long>(val)); // NOLINT(runtime/int)
997998
}
998999

9991000

src/node_http_parser.cc

Lines changed: 6 additions & 2 deletions
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 4 additions & 1 deletion
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)

src/udp_wrap.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ void UDPWrap::Open(const FunctionCallbackInfo<Value>& args) {
215215
ASSIGN_OR_RETURN_UNWRAP(&wrap,
216216
args.Holder(),
217217
args.GetReturnValue().Set(UV_EBADF));
218-
int fd = static_cast<int>(args[0]->IntegerValue());
218+
CHECK(args[0]->IsNumber());
219+
int fd = static_cast<int>(args[0].As<Integer>()->Value());
219220
int err = uv_udp_open(&wrap->handle_, fd);
220221

221222
args.GetReturnValue().Set(err);

0 commit comments

Comments
 (0)