Skip to content

Commit b1e5491

Browse files
committed
src: remove calls to deprecated V8 functions (Int32Value)
Remove all calls to deprecated V8 functions (here: Value::Int32Value) inside the code. PR-URL: #22662 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ujjwal Sharma <[email protected]>
1 parent 4cdecc5 commit b1e5491

19 files changed

+118
-81
lines changed

src/cares_wrap.cc

+14-13
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

+3-1
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

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

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

src/node_crypto.cc

+10-19
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ void SecureContext::SetSessionTimeout(const FunctionCallbackInfo<Value>& args) {
10391039
sc->env(), "Session timeout must be a 32-bit integer");
10401040
}
10411041

1042-
int32_t sessionTimeout = args[0]->Int32Value();
1042+
int32_t sessionTimeout = args[0].As<Int32>()->Value();
10431043
SSL_CTX_set_timeout(sc->ctx_.get(), sessionTimeout);
10441044
}
10451045

@@ -1261,7 +1261,8 @@ int SecureContext::TicketKeyCallback(SSL* ssl,
12611261
{0, 0}).ToLocalChecked();
12621262
Local<Array> arr = ret.As<Array>();
12631263

1264-
int r = arr->Get(kTicketKeyReturnIndex)->Int32Value();
1264+
int r =
1265+
arr->Get(kTicketKeyReturnIndex)->Int32Value(env->context()).FromJust();
12651266
if (r < 0)
12661267
return r;
12671268

@@ -3632,14 +3633,10 @@ void Sign::SignFinal(const FunctionCallbackInfo<Value>& args) {
36323633
char* buf = Buffer::Data(args[0]);
36333634

36343635
CHECK(args[2]->IsInt32());
3635-
Maybe<int32_t> maybe_padding = args[2]->Int32Value(env->context());
3636-
CHECK(maybe_padding.IsJust());
3637-
int padding = maybe_padding.ToChecked();
3636+
int padding = args[2].As<Int32>()->Value();
36383637

36393638
CHECK(args[3]->IsInt32());
3640-
Maybe<int32_t> maybe_salt_len = args[3]->Int32Value(env->context());
3641-
CHECK(maybe_salt_len.IsJust());
3642-
int salt_len = maybe_salt_len.ToChecked();
3639+
int salt_len = args[3].As<Int32>()->Value();
36433640

36443641
ClearErrorOnReturn clear_error_on_return;
36453642
unsigned char md_value[8192];
@@ -3786,8 +3783,6 @@ SignBase::Error Verify::VerifyFinal(const char* key_pem,
37863783

37873784

37883785
void Verify::VerifyFinal(const FunctionCallbackInfo<Value>& args) {
3789-
Environment* env = Environment::GetCurrent(args);
3790-
37913786
ClearErrorOnReturn clear_error_on_return;
37923787

37933788
Verify* verify;
@@ -3800,14 +3795,10 @@ void Verify::VerifyFinal(const FunctionCallbackInfo<Value>& args) {
38003795
ssize_t hlen = Buffer::Length(args[1]);
38013796

38023797
CHECK(args[2]->IsInt32());
3803-
Maybe<int32_t> maybe_padding = args[2]->Int32Value(env->context());
3804-
CHECK(maybe_padding.IsJust());
3805-
int padding = maybe_padding.ToChecked();
3798+
int padding = args[2].As<Int32>()->Value();
38063799

38073800
CHECK(args[3]->IsInt32());
3808-
Maybe<int32_t> maybe_salt_len = args[3]->Int32Value(env->context());
3809-
CHECK(maybe_salt_len.IsJust());
3810-
int salt_len = maybe_salt_len.ToChecked();
3801+
int salt_len = args[3].As<Int32>()->Value();
38113802

38123803
bool verify_result;
38133804
Error err = verify->VerifyFinal(kbuf, klen, hbuf, hlen, padding, salt_len,
@@ -4079,14 +4070,14 @@ void DiffieHellman::New(const FunctionCallbackInfo<Value>& args) {
40794070
if (args.Length() == 2) {
40804071
if (args[0]->IsInt32()) {
40814072
if (args[1]->IsInt32()) {
4082-
initialized = diffieHellman->Init(args[0]->Int32Value(),
4083-
args[1]->Int32Value());
4073+
initialized = diffieHellman->Init(args[0].As<Int32>()->Value(),
4074+
args[1].As<Int32>()->Value());
40844075
}
40854076
} else {
40864077
if (args[1]->IsInt32()) {
40874078
initialized = diffieHellman->Init(Buffer::Data(args[0]),
40884079
Buffer::Length(args[0]),
4089-
args[1]->Int32Value());
4080+
args[1].As<Int32>()->Value());
40904081
} else {
40914082
initialized = diffieHellman->Init(Buffer::Data(args[0]),
40924083
Buffer::Length(args[0]),

src/node_dtrace.cc

+9-7
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

+5-2
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

+3-1
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

+5-2
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,15 @@ void HrtimeBigInt(const FunctionCallbackInfo<Value>& args) {
159159

160160
void Kill(const FunctionCallbackInfo<Value>& args) {
161161
Environment* env = Environment::GetCurrent(args);
162+
Local<Context> context = env->context();
162163

163164
if (args.Length() != 2)
164165
return env->ThrowError("Bad argument.");
165166

166-
int pid = args[0]->Int32Value();
167-
int sig = args[1]->Int32Value();
167+
int pid;
168+
if (!args[0]->Int32Value(context).To(&pid)) return;
169+
int sig;
170+
if (!args[1]->Int32Value(context).To(&sig)) return;
168171
int err = uv_kill(pid, sig);
169172
args.GetReturnValue().Set(err);
170173
}

src/node_zlib.cc

+11-3
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

+7-3
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);

src/process_wrap.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ using v8::Context;
3636
using v8::FunctionCallbackInfo;
3737
using v8::FunctionTemplate;
3838
using v8::HandleScope;
39+
using v8::Int32;
3940
using v8::Integer;
4041
using v8::Local;
4142
using v8::Number;
@@ -158,7 +159,7 @@ class ProcessWrap : public HandleWrap {
158159
js_options->Get(context, env->uid_string()).ToLocalChecked();
159160
if (!uid_v->IsUndefined() && !uid_v->IsNull()) {
160161
CHECK(uid_v->IsInt32());
161-
const int32_t uid = uid_v->Int32Value(context).FromJust();
162+
const int32_t uid = uid_v.As<Int32>()->Value();
162163
options.flags |= UV_PROCESS_SETUID;
163164
options.uid = static_cast<uv_uid_t>(uid);
164165
}
@@ -168,7 +169,7 @@ class ProcessWrap : public HandleWrap {
168169
js_options->Get(context, env->gid_string()).ToLocalChecked();
169170
if (!gid_v->IsUndefined() && !gid_v->IsNull()) {
170171
CHECK(gid_v->IsInt32());
171-
const int32_t gid = gid_v->Int32Value(context).FromJust();
172+
const int32_t gid = gid_v.As<Int32>()->Value();
172173
options.flags |= UV_PROCESS_SETGID;
173174
options.gid = static_cast<uv_gid_t>(gid);
174175
}

src/signal_wrap.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ class SignalWrap : public HandleWrap {
8888
static void Start(const FunctionCallbackInfo<Value>& args) {
8989
SignalWrap* wrap;
9090
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
91-
int signum = args[0]->Int32Value();
91+
Environment* env = wrap->env();
92+
int signum;
93+
if (!args[0]->Int32Value(env->context()).To(&signum)) return;
9294
#if defined(__POSIX__) && HAVE_INSPECTOR
9395
if (signum == SIGPROF) {
9496
Environment* env = Environment::GetCurrent(args);

src/spawn_sync.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ using v8::Context;
3535
using v8::EscapableHandleScope;
3636
using v8::FunctionCallbackInfo;
3737
using v8::HandleScope;
38+
using v8::Int32;
3839
using v8::Integer;
3940
using v8::Isolate;
4041
using v8::Just;
@@ -783,7 +784,7 @@ Maybe<int> SyncProcessRunner::ParseOptions(Local<Value> js_value) {
783784
js_options->Get(context, env()->uid_string()).ToLocalChecked();
784785
if (IsSet(js_uid)) {
785786
CHECK(js_uid->IsInt32());
786-
const int32_t uid = js_uid->Int32Value(context).FromJust();
787+
const int32_t uid = js_uid.As<Int32>()->Value();
787788
uv_process_options_.uid = static_cast<uv_uid_t>(uid);
788789
uv_process_options_.flags |= UV_PROCESS_SETUID;
789790
}
@@ -792,7 +793,7 @@ Maybe<int> SyncProcessRunner::ParseOptions(Local<Value> js_value) {
792793
js_options->Get(context, env()->gid_string()).ToLocalChecked();
793794
if (IsSet(js_gid)) {
794795
CHECK(js_gid->IsInt32());
795-
const int32_t gid = js_gid->Int32Value(context).FromJust();
796+
const int32_t gid = js_gid.As<Int32>()->Value();
796797
uv_process_options_.gid = static_cast<uv_gid_t>(gid);
797798
uv_process_options_.flags |= UV_PROCESS_SETGID;
798799
}
@@ -833,7 +834,7 @@ Maybe<int> SyncProcessRunner::ParseOptions(Local<Value> js_value) {
833834
js_options->Get(context, env()->kill_signal_string()).ToLocalChecked();
834835
if (IsSet(js_kill_signal)) {
835836
CHECK(js_kill_signal->IsInt32());
836-
kill_signal_ = js_kill_signal->Int32Value(context).FromJust();
837+
kill_signal_ = js_kill_signal.As<Int32>()->Value();
837838
}
838839

839840
Local<Value> js_stdio =

0 commit comments

Comments
 (0)