Skip to content

Commit 594a84d

Browse files
targosdanbev
authored andcommitted
src: remove calls to deprecated V8 functions (Int32Value)
Remove all calls to deprecated V8 functions (here: Value::Int32Value) inside the code. PR-URL: nodejs#22662 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com>
1 parent d6a4343 commit 594a84d

19 files changed

+118
-81
lines changed

src/cares_wrap.cc

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ using v8::EscapableHandleScope;
6161
using v8::FunctionCallbackInfo;
6262
using v8::FunctionTemplate;
6363
using v8::HandleScope;
64+
using v8::Int32;
6465
using v8::Integer;
6566
using v8::Local;
6667
using v8::Null;
@@ -1987,23 +1988,23 @@ void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
19871988

19881989
int32_t flags = 0;
19891990
if (args[3]->IsInt32()) {
1990-
flags = args[3]->Int32Value(env->context()).FromJust();
1991+
flags = args[3].As<Int32>()->Value();
19911992
}
19921993

19931994
int family;
19941995

1995-
switch (args[2]->Int32Value(env->context()).FromJust()) {
1996-
case 0:
1997-
family = AF_UNSPEC;
1998-
break;
1999-
case 4:
2000-
family = AF_INET;
2001-
break;
2002-
case 6:
2003-
family = AF_INET6;
2004-
break;
2005-
default:
2006-
CHECK(0 && "bad address family");
1996+
switch (args[2].As<Int32>()->Value()) {
1997+
case 0:
1998+
family = AF_UNSPEC;
1999+
break;
2000+
case 4:
2001+
family = AF_INET;
2002+
break;
2003+
case 6:
2004+
family = AF_INET6;
2005+
break;
2006+
default:
2007+
CHECK(0 && "bad address family");
20072008
}
20082009

20092010
auto req_wrap = new GetAddrInfoReqWrap(env, req_wrap_obj, args[4]->IsTrue());

src/js_stream.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ using v8::Context;
1414
using v8::FunctionCallbackInfo;
1515
using v8::FunctionTemplate;
1616
using v8::HandleScope;
17+
using v8::Int32;
1718
using v8::Local;
1819
using v8::Object;
1920
using v8::String;
@@ -154,7 +155,8 @@ void JSStream::Finish(const FunctionCallbackInfo<Value>& args) {
154155
CHECK(args[0]->IsObject());
155156
Wrap* w = static_cast<Wrap*>(StreamReq::FromObject(args[0].As<Object>()));
156157

157-
w->Done(args[1]->Int32Value());
158+
CHECK(args[1]->IsInt32());
159+
w->Done(args[1].As<Int32>()->Value());
158160
}
159161

160162

src/node.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,8 @@ static void Exit(const FunctionCallbackInfo<Value>& args) {
11981198
Environment* env = Environment::GetCurrent(args);
11991199
WaitForInspectorDisconnect(env);
12001200
v8_platform.StopTracingAgent();
1201-
env->Exit(args[0]->Int32Value());
1201+
int code = args[0]->Int32Value(env->context()).FromMaybe(0);
1202+
env->Exit(code);
12021203
}
12031204

12041205
extern "C" void node_module_register(void* m) {

src/node_crypto.cc

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ void SecureContext::SetSessionTimeout(const FunctionCallbackInfo<Value>& args) {
10451045
sc->env(), "Session timeout must be a 32-bit integer");
10461046
}
10471047

1048-
int32_t sessionTimeout = args[0]->Int32Value();
1048+
int32_t sessionTimeout = args[0].As<Int32>()->Value();
10491049
SSL_CTX_set_timeout(sc->ctx_.get(), sessionTimeout);
10501050
}
10511051

@@ -1267,7 +1267,8 @@ int SecureContext::TicketKeyCallback(SSL* ssl,
12671267
{0, 0}).ToLocalChecked();
12681268
Local<Array> arr = ret.As<Array>();
12691269

1270-
int r = arr->Get(kTicketKeyReturnIndex)->Int32Value();
1270+
int r =
1271+
arr->Get(kTicketKeyReturnIndex)->Int32Value(env->context()).FromJust();
12711272
if (r < 0)
12721273
return r;
12731274

@@ -3629,14 +3630,10 @@ void Sign::SignFinal(const FunctionCallbackInfo<Value>& args) {
36293630
char* buf = Buffer::Data(args[0]);
36303631

36313632
CHECK(args[2]->IsInt32());
3632-
Maybe<int32_t> maybe_padding = args[2]->Int32Value(env->context());
3633-
CHECK(maybe_padding.IsJust());
3634-
int padding = maybe_padding.ToChecked();
3633+
int padding = args[2].As<Int32>()->Value();
36353634

36363635
CHECK(args[3]->IsInt32());
3637-
Maybe<int32_t> maybe_salt_len = args[3]->Int32Value(env->context());
3638-
CHECK(maybe_salt_len.IsJust());
3639-
int salt_len = maybe_salt_len.ToChecked();
3636+
int salt_len = args[3].As<Int32>()->Value();
36403637

36413638
ClearErrorOnReturn clear_error_on_return;
36423639
unsigned char md_value[8192];
@@ -3783,8 +3780,6 @@ SignBase::Error Verify::VerifyFinal(const char* key_pem,
37833780

37843781

37853782
void Verify::VerifyFinal(const FunctionCallbackInfo<Value>& args) {
3786-
Environment* env = Environment::GetCurrent(args);
3787-
37883783
ClearErrorOnReturn clear_error_on_return;
37893784

37903785
Verify* verify;
@@ -3797,14 +3792,10 @@ void Verify::VerifyFinal(const FunctionCallbackInfo<Value>& args) {
37973792
ssize_t hlen = Buffer::Length(args[1]);
37983793

37993794
CHECK(args[2]->IsInt32());
3800-
Maybe<int32_t> maybe_padding = args[2]->Int32Value(env->context());
3801-
CHECK(maybe_padding.IsJust());
3802-
int padding = maybe_padding.ToChecked();
3795+
int padding = args[2].As<Int32>()->Value();
38033796

38043797
CHECK(args[3]->IsInt32());
3805-
Maybe<int32_t> maybe_salt_len = args[3]->Int32Value(env->context());
3806-
CHECK(maybe_salt_len.IsJust());
3807-
int salt_len = maybe_salt_len.ToChecked();
3798+
int salt_len = args[3].As<Int32>()->Value();
38083799

38093800
bool verify_result;
38103801
Error err = verify->VerifyFinal(kbuf, klen, hbuf, hlen, padding, salt_len,
@@ -4076,14 +4067,14 @@ void DiffieHellman::New(const FunctionCallbackInfo<Value>& args) {
40764067
if (args.Length() == 2) {
40774068
if (args[0]->IsInt32()) {
40784069
if (args[1]->IsInt32()) {
4079-
initialized = diffieHellman->Init(args[0]->Int32Value(),
4080-
args[1]->Int32Value());
4070+
initialized = diffieHellman->Init(args[0].As<Int32>()->Value(),
4071+
args[1].As<Int32>()->Value());
40814072
}
40824073
} else {
40834074
if (args[1]->IsInt32()) {
40844075
initialized = diffieHellman->Init(Buffer::Data(args[0]),
40854076
Buffer::Length(args[0]),
4086-
args[1]->Int32Value());
4077+
args[1].As<Int32>()->Value());
40874078
} else {
40884079
initialized = diffieHellman->Init(Buffer::Data(args[0]),
40894080
Buffer::Length(args[0]),

src/node_dtrace.cc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,15 @@ using v8::Value;
6969
if ((*(const char **)valp = *_##member) == nullptr) \
7070
*(const char **)valp = "<unknown>";
7171

72-
#define SLURP_INT(obj, member, valp) \
73-
if (!(obj)->IsObject()) { \
74-
return node::THROW_ERR_INVALID_ARG_TYPE(env, \
75-
"expected object for " #obj " to contain integer member " #member);\
76-
} \
77-
*valp = obj->Get(OneByteString(env->isolate(), #member)) \
78-
->Int32Value();
72+
#define SLURP_INT(obj, member, valp) \
73+
if (!(obj)->IsObject()) { \
74+
return node::THROW_ERR_INVALID_ARG_TYPE( \
75+
env, \
76+
"expected object for " #obj " to contain integer member " #member); \
77+
} \
78+
*valp = obj->Get(OneByteString(env->isolate(), #member)) \
79+
->Int32Value(env->context()) \
80+
.FromJust();
7981

8082
#define SLURP_OBJECT(obj, member, valp) \
8183
if (!(obj)->IsObject()) { \

src/node_http_parser.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ using v8::Function;
5757
using v8::FunctionCallbackInfo;
5858
using v8::FunctionTemplate;
5959
using v8::HandleScope;
60+
using v8::Int32;
6061
using v8::Integer;
6162
using v8::Local;
6263
using v8::MaybeLocal;
@@ -361,8 +362,9 @@ class Parser : public AsyncWrap, public StreamListener {
361362

362363
static void New(const FunctionCallbackInfo<Value>& args) {
363364
Environment* env = Environment::GetCurrent(args);
365+
CHECK(args[0]->IsInt32());
364366
http_parser_type type =
365-
static_cast<http_parser_type>(args[0]->Int32Value());
367+
static_cast<http_parser_type>(args[0].As<Int32>()->Value());
366368
CHECK(type == HTTP_REQUEST || type == HTTP_RESPONSE);
367369
new Parser(env, args.This(), type);
368370
}
@@ -458,8 +460,9 @@ class Parser : public AsyncWrap, public StreamListener {
458460
static void Reinitialize(const FunctionCallbackInfo<Value>& args) {
459461
Environment* env = Environment::GetCurrent(args);
460462

463+
CHECK(args[0]->IsInt32());
461464
http_parser_type type =
462-
static_cast<http_parser_type>(args[0]->Int32Value());
465+
static_cast<http_parser_type>(args[0].As<Int32>()->Value());
463466

464467
CHECK(type == HTTP_REQUEST || type == HTTP_RESPONSE);
465468
Parser* parser;

src/node_i18n.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ namespace node {
8787
using v8::Context;
8888
using v8::FunctionCallbackInfo;
8989
using v8::HandleScope;
90+
using v8::Int32;
9091
using v8::Isolate;
9192
using v8::Local;
9293
using v8::MaybeLocal;
@@ -502,7 +503,8 @@ void Transcode(const FunctionCallbackInfo<Value>&args) {
502503

503504
void ICUErrorName(const FunctionCallbackInfo<Value>& args) {
504505
Environment* env = Environment::GetCurrent(args);
505-
UErrorCode status = static_cast<UErrorCode>(args[0]->Int32Value());
506+
CHECK(args[0]->IsInt32());
507+
UErrorCode status = static_cast<UErrorCode>(args[0].As<Int32>()->Value());
506508
args.GetReturnValue().Set(
507509
String::NewFromUtf8(env->isolate(),
508510
u_errorName(status),

src/node_process.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,15 @@ void HrtimeBigInt(const FunctionCallbackInfo<Value>& args) {
165165

166166
void Kill(const FunctionCallbackInfo<Value>& args) {
167167
Environment* env = Environment::GetCurrent(args);
168+
Local<Context> context = env->context();
168169

169170
if (args.Length() != 2)
170171
return env->ThrowError("Bad argument.");
171172

172-
int pid = args[0]->Int32Value();
173-
int sig = args[1]->Int32Value();
173+
int pid;
174+
if (!args[0]->Int32Value(context).To(&pid)) return;
175+
int sig;
176+
if (!args[1]->Int32Value(context).To(&sig)) return;
174177
int err = uv_kill(pid, sig);
175178
args.GetReturnValue().Set(err);
176179
}

src/node_zlib.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ using v8::Function;
4545
using v8::FunctionCallbackInfo;
4646
using v8::FunctionTemplate;
4747
using v8::HandleScope;
48+
using v8::Int32;
4849
using v8::Local;
4950
using v8::Number;
5051
using v8::Object;
@@ -419,7 +420,8 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
419420
static void New(const FunctionCallbackInfo<Value>& args) {
420421
Environment* env = Environment::GetCurrent(args);
421422
CHECK(args[0]->IsInt32());
422-
node_zlib_mode mode = static_cast<node_zlib_mode>(args[0]->Int32Value());
423+
node_zlib_mode mode =
424+
static_cast<node_zlib_mode>(args[0].As<Int32>()->Value());
423425
new ZCtx(env, args.This(), mode);
424426
}
425427

@@ -459,7 +461,8 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
459461
"invalid windowBits");
460462
}
461463

462-
int level = args[1]->Int32Value();
464+
int level;
465+
if (!args[1]->Int32Value(context).To(&level)) return;
463466
CHECK((level >= Z_MIN_LEVEL && level <= Z_MAX_LEVEL) &&
464467
"invalid compression level");
465468

@@ -506,7 +509,12 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
506509
CHECK(args.Length() == 2 && "params(level, strategy)");
507510
ZCtx* ctx;
508511
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Holder());
509-
ctx->Params(args[0]->Int32Value(), args[1]->Int32Value());
512+
Environment* env = ctx->env();
513+
int level;
514+
if (!args[0]->Int32Value(env->context()).To(&level)) return;
515+
int strategy;
516+
if (!args[1]->Int32Value(env->context()).To(&strategy)) return;
517+
ctx->Params(level, strategy);
510518
}
511519

512520
static void Reset(const FunctionCallbackInfo<Value> &args) {

src/pipe_wrap.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ void PipeWrap::Bind(const FunctionCallbackInfo<Value>& args) {
173173
void PipeWrap::SetPendingInstances(const FunctionCallbackInfo<Value>& args) {
174174
PipeWrap* wrap;
175175
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
176-
int instances = args[0]->Int32Value();
176+
CHECK(args[0]->IsInt32());
177+
int instances = args[0].As<Int32>()->Value();
177178
uv_pipe_pending_instances(&wrap->handle_, instances);
178179
}
179180
#endif
@@ -193,7 +194,9 @@ void PipeWrap::Fchmod(const v8::FunctionCallbackInfo<v8::Value>& args) {
193194
void PipeWrap::Listen(const FunctionCallbackInfo<Value>& args) {
194195
PipeWrap* wrap;
195196
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
196-
int backlog = args[0]->Int32Value();
197+
Environment* env = wrap->env();
198+
int backlog;
199+
if (!args[0]->Int32Value(env->context()).To(&backlog)) return;
197200
int err = uv_listen(reinterpret_cast<uv_stream_t*>(&wrap->handle_),
198201
backlog,
199202
OnConnection);
@@ -207,7 +210,8 @@ void PipeWrap::Open(const FunctionCallbackInfo<Value>& args) {
207210
PipeWrap* wrap;
208211
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
209212

210-
int fd = args[0]->Int32Value();
213+
int fd;
214+
if (!args[0]->Int32Value(env->context()).To(&fd)) return;
211215

212216
int err = uv_pipe_open(&wrap->handle_, fd);
213217
wrap->set_fd(fd);

0 commit comments

Comments
 (0)