Skip to content

Commit 76e79b1

Browse files
ryzokukentargos
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]>
1 parent 0d3da39 commit 76e79b1

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
@@ -2384,11 +2384,10 @@ void DebugProcess(const FunctionCallbackInfo<Value>& args) {
23842384
return env->ThrowError("Invalid number of arguments.");
23852385
}
23862386

2387-
pid_t pid;
2388-
int r;
2387+
CHECK(args[0]->IsNumber());
2388+
pid_t pid = args[0].As<Integer>()->Value();
2389+
int r = kill(pid, SIGUSR1);
23892390

2390-
pid = args[0]->IntegerValue();
2391-
r = kill(pid, SIGUSR1);
23922391
if (r != 0) {
23932392
return env->ThrowErrnoException(errno, "kill");
23942393
}
@@ -2406,7 +2405,6 @@ static int GetDebugSignalHandlerMappingName(DWORD pid, wchar_t* buf,
24062405
static void DebugProcess(const FunctionCallbackInfo<Value>& args) {
24072406
Environment* env = Environment::GetCurrent(args);
24082407
Isolate* isolate = args.GetIsolate();
2409-
DWORD pid;
24102408
HANDLE process = nullptr;
24112409
HANDLE thread = nullptr;
24122410
HANDLE mapping = nullptr;
@@ -2418,7 +2416,8 @@ static void DebugProcess(const FunctionCallbackInfo<Value>& args) {
24182416
goto out;
24192417
}
24202418

2421-
pid = (DWORD) args[0]->IntegerValue();
2419+
CHECK(args[0]->IsNumber());
2420+
DWORD pid = args[0].As<Integer>()->Value();
24222421

24232422
process = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION |
24242423
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
@@ -288,12 +288,16 @@ class Parser : public AsyncWrap, public StreamListener {
288288
MaybeLocal<Value> head_response =
289289
MakeCallback(cb.As<Function>(), arraysize(argv), argv);
290290

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

296-
return head_response.ToLocalChecked()->IntegerValue();
300+
return val;
297301
}
298302

299303

src/process_wrap.cc

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

src/tcp_wrap.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,10 @@ void TCPWrap::Open(const FunctionCallbackInfo<Value>& args) {
205205
ASSIGN_OR_RETURN_UNWRAP(&wrap,
206206
args.Holder(),
207207
args.GetReturnValue().Set(UV_EBADF));
208-
int fd = static_cast<int>(args[0]->IntegerValue());
208+
int64_t val;
209+
if (!args[0]->IntegerValue(args.GetIsolate()->GetCurrentContext()).To(&val))
210+
return;
211+
int fd = static_cast<int>(val);
209212
int err = uv_tcp_open(&wrap->handle_, fd);
210213

211214
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)