Skip to content

Commit

Permalink
src: remove calls to deprecated V8 functions (Int32Value)
Browse files Browse the repository at this point in the history
Remove all calls to deprecated V8 functions (here: Value::Int32Value)
inside the code.

PR-URL: nodejs#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]>
  • Loading branch information
targos authored and danbev committed Sep 5, 2018
1 parent d6a4343 commit 594a84d
Show file tree
Hide file tree
Showing 19 changed files with 118 additions and 81 deletions.
27 changes: 14 additions & 13 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ using v8::EscapableHandleScope;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
using v8::HandleScope;
using v8::Int32;
using v8::Integer;
using v8::Local;
using v8::Null;
Expand Down Expand Up @@ -1987,23 +1988,23 @@ void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {

int32_t flags = 0;
if (args[3]->IsInt32()) {
flags = args[3]->Int32Value(env->context()).FromJust();
flags = args[3].As<Int32>()->Value();
}

int family;

switch (args[2]->Int32Value(env->context()).FromJust()) {
case 0:
family = AF_UNSPEC;
break;
case 4:
family = AF_INET;
break;
case 6:
family = AF_INET6;
break;
default:
CHECK(0 && "bad address family");
switch (args[2].As<Int32>()->Value()) {
case 0:
family = AF_UNSPEC;
break;
case 4:
family = AF_INET;
break;
case 6:
family = AF_INET6;
break;
default:
CHECK(0 && "bad address family");
}

auto req_wrap = new GetAddrInfoReqWrap(env, req_wrap_obj, args[4]->IsTrue());
Expand Down
4 changes: 3 additions & 1 deletion src/js_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ using v8::Context;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
using v8::HandleScope;
using v8::Int32;
using v8::Local;
using v8::Object;
using v8::String;
Expand Down Expand Up @@ -154,7 +155,8 @@ void JSStream::Finish(const FunctionCallbackInfo<Value>& args) {
CHECK(args[0]->IsObject());
Wrap* w = static_cast<Wrap*>(StreamReq::FromObject(args[0].As<Object>()));

w->Done(args[1]->Int32Value());
CHECK(args[1]->IsInt32());
w->Done(args[1].As<Int32>()->Value());
}


Expand Down
3 changes: 2 additions & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,8 @@ static void Exit(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
WaitForInspectorDisconnect(env);
v8_platform.StopTracingAgent();
env->Exit(args[0]->Int32Value());
int code = args[0]->Int32Value(env->context()).FromMaybe(0);
env->Exit(code);
}

extern "C" void node_module_register(void* m) {
Expand Down
29 changes: 10 additions & 19 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ void SecureContext::SetSessionTimeout(const FunctionCallbackInfo<Value>& args) {
sc->env(), "Session timeout must be a 32-bit integer");
}

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

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

int r = arr->Get(kTicketKeyReturnIndex)->Int32Value();
int r =
arr->Get(kTicketKeyReturnIndex)->Int32Value(env->context()).FromJust();
if (r < 0)
return r;

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

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

CHECK(args[3]->IsInt32());
Maybe<int32_t> maybe_salt_len = args[3]->Int32Value(env->context());
CHECK(maybe_salt_len.IsJust());
int salt_len = maybe_salt_len.ToChecked();
int salt_len = args[3].As<Int32>()->Value();

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


void Verify::VerifyFinal(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

ClearErrorOnReturn clear_error_on_return;

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

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

CHECK(args[3]->IsInt32());
Maybe<int32_t> maybe_salt_len = args[3]->Int32Value(env->context());
CHECK(maybe_salt_len.IsJust());
int salt_len = maybe_salt_len.ToChecked();
int salt_len = args[3].As<Int32>()->Value();

bool verify_result;
Error err = verify->VerifyFinal(kbuf, klen, hbuf, hlen, padding, salt_len,
Expand Down Expand Up @@ -4076,14 +4067,14 @@ void DiffieHellman::New(const FunctionCallbackInfo<Value>& args) {
if (args.Length() == 2) {
if (args[0]->IsInt32()) {
if (args[1]->IsInt32()) {
initialized = diffieHellman->Init(args[0]->Int32Value(),
args[1]->Int32Value());
initialized = diffieHellman->Init(args[0].As<Int32>()->Value(),
args[1].As<Int32>()->Value());
}
} else {
if (args[1]->IsInt32()) {
initialized = diffieHellman->Init(Buffer::Data(args[0]),
Buffer::Length(args[0]),
args[1]->Int32Value());
args[1].As<Int32>()->Value());
} else {
initialized = diffieHellman->Init(Buffer::Data(args[0]),
Buffer::Length(args[0]),
Expand Down
16 changes: 9 additions & 7 deletions src/node_dtrace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ using v8::Value;
if ((*(const char **)valp = *_##member) == nullptr) \
*(const char **)valp = "<unknown>";

#define SLURP_INT(obj, member, valp) \
if (!(obj)->IsObject()) { \
return node::THROW_ERR_INVALID_ARG_TYPE(env, \
"expected object for " #obj " to contain integer member " #member);\
} \
*valp = obj->Get(OneByteString(env->isolate(), #member)) \
->Int32Value();
#define SLURP_INT(obj, member, valp) \
if (!(obj)->IsObject()) { \
return node::THROW_ERR_INVALID_ARG_TYPE( \
env, \
"expected object for " #obj " to contain integer member " #member); \
} \
*valp = obj->Get(OneByteString(env->isolate(), #member)) \
->Int32Value(env->context()) \
.FromJust();

#define SLURP_OBJECT(obj, member, valp) \
if (!(obj)->IsObject()) { \
Expand Down
7 changes: 5 additions & 2 deletions src/node_http_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ using v8::Function;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
using v8::HandleScope;
using v8::Int32;
using v8::Integer;
using v8::Local;
using v8::MaybeLocal;
Expand Down Expand Up @@ -361,8 +362,9 @@ class Parser : public AsyncWrap, public StreamListener {

static void New(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
CHECK(args[0]->IsInt32());
http_parser_type type =
static_cast<http_parser_type>(args[0]->Int32Value());
static_cast<http_parser_type>(args[0].As<Int32>()->Value());
CHECK(type == HTTP_REQUEST || type == HTTP_RESPONSE);
new Parser(env, args.This(), type);
}
Expand Down Expand Up @@ -458,8 +460,9 @@ class Parser : public AsyncWrap, public StreamListener {
static void Reinitialize(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

CHECK(args[0]->IsInt32());
http_parser_type type =
static_cast<http_parser_type>(args[0]->Int32Value());
static_cast<http_parser_type>(args[0].As<Int32>()->Value());

CHECK(type == HTTP_REQUEST || type == HTTP_RESPONSE);
Parser* parser;
Expand Down
4 changes: 3 additions & 1 deletion src/node_i18n.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ namespace node {
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::HandleScope;
using v8::Int32;
using v8::Isolate;
using v8::Local;
using v8::MaybeLocal;
Expand Down Expand Up @@ -502,7 +503,8 @@ void Transcode(const FunctionCallbackInfo<Value>&args) {

void ICUErrorName(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
UErrorCode status = static_cast<UErrorCode>(args[0]->Int32Value());
CHECK(args[0]->IsInt32());
UErrorCode status = static_cast<UErrorCode>(args[0].As<Int32>()->Value());
args.GetReturnValue().Set(
String::NewFromUtf8(env->isolate(),
u_errorName(status),
Expand Down
7 changes: 5 additions & 2 deletions src/node_process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,15 @@ void HrtimeBigInt(const FunctionCallbackInfo<Value>& args) {

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

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

int pid = args[0]->Int32Value();
int sig = args[1]->Int32Value();
int pid;
if (!args[0]->Int32Value(context).To(&pid)) return;
int sig;
if (!args[1]->Int32Value(context).To(&sig)) return;
int err = uv_kill(pid, sig);
args.GetReturnValue().Set(err);
}
Expand Down
14 changes: 11 additions & 3 deletions src/node_zlib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ using v8::Function;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
using v8::HandleScope;
using v8::Int32;
using v8::Local;
using v8::Number;
using v8::Object;
Expand Down Expand Up @@ -419,7 +420,8 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
static void New(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
CHECK(args[0]->IsInt32());
node_zlib_mode mode = static_cast<node_zlib_mode>(args[0]->Int32Value());
node_zlib_mode mode =
static_cast<node_zlib_mode>(args[0].As<Int32>()->Value());
new ZCtx(env, args.This(), mode);
}

Expand Down Expand Up @@ -459,7 +461,8 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
"invalid windowBits");
}

int level = args[1]->Int32Value();
int level;
if (!args[1]->Int32Value(context).To(&level)) return;
CHECK((level >= Z_MIN_LEVEL && level <= Z_MAX_LEVEL) &&
"invalid compression level");

Expand Down Expand Up @@ -506,7 +509,12 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
CHECK(args.Length() == 2 && "params(level, strategy)");
ZCtx* ctx;
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Holder());
ctx->Params(args[0]->Int32Value(), args[1]->Int32Value());
Environment* env = ctx->env();
int level;
if (!args[0]->Int32Value(env->context()).To(&level)) return;
int strategy;
if (!args[1]->Int32Value(env->context()).To(&strategy)) return;
ctx->Params(level, strategy);
}

static void Reset(const FunctionCallbackInfo<Value> &args) {
Expand Down
10 changes: 7 additions & 3 deletions src/pipe_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ void PipeWrap::Bind(const FunctionCallbackInfo<Value>& args) {
void PipeWrap::SetPendingInstances(const FunctionCallbackInfo<Value>& args) {
PipeWrap* wrap;
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
int instances = args[0]->Int32Value();
CHECK(args[0]->IsInt32());
int instances = args[0].As<Int32>()->Value();
uv_pipe_pending_instances(&wrap->handle_, instances);
}
#endif
Expand All @@ -193,7 +194,9 @@ void PipeWrap::Fchmod(const v8::FunctionCallbackInfo<v8::Value>& args) {
void PipeWrap::Listen(const FunctionCallbackInfo<Value>& args) {
PipeWrap* wrap;
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
int backlog = args[0]->Int32Value();
Environment* env = wrap->env();
int backlog;
if (!args[0]->Int32Value(env->context()).To(&backlog)) return;
int err = uv_listen(reinterpret_cast<uv_stream_t*>(&wrap->handle_),
backlog,
OnConnection);
Expand All @@ -207,7 +210,8 @@ void PipeWrap::Open(const FunctionCallbackInfo<Value>& args) {
PipeWrap* wrap;
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());

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

int err = uv_pipe_open(&wrap->handle_, fd);
wrap->set_fd(fd);
Expand Down
5 changes: 3 additions & 2 deletions src/process_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ using v8::Context;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
using v8::HandleScope;
using v8::Int32;
using v8::Integer;
using v8::Local;
using v8::Number;
Expand Down Expand Up @@ -158,7 +159,7 @@ class ProcessWrap : public HandleWrap {
js_options->Get(context, env->uid_string()).ToLocalChecked();
if (!uid_v->IsUndefined() && !uid_v->IsNull()) {
CHECK(uid_v->IsInt32());
const int32_t uid = uid_v->Int32Value(context).FromJust();
const int32_t uid = uid_v.As<Int32>()->Value();
options.flags |= UV_PROCESS_SETUID;
options.uid = static_cast<uv_uid_t>(uid);
}
Expand All @@ -168,7 +169,7 @@ class ProcessWrap : public HandleWrap {
js_options->Get(context, env->gid_string()).ToLocalChecked();
if (!gid_v->IsUndefined() && !gid_v->IsNull()) {
CHECK(gid_v->IsInt32());
const int32_t gid = gid_v->Int32Value(context).FromJust();
const int32_t gid = gid_v.As<Int32>()->Value();
options.flags |= UV_PROCESS_SETGID;
options.gid = static_cast<uv_gid_t>(gid);
}
Expand Down
4 changes: 3 additions & 1 deletion src/signal_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ class SignalWrap : public HandleWrap {
static void Start(const FunctionCallbackInfo<Value>& args) {
SignalWrap* wrap;
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
int signum = args[0]->Int32Value();
Environment* env = wrap->env();
int signum;
if (!args[0]->Int32Value(env->context()).To(&signum)) return;
#if defined(__POSIX__) && HAVE_INSPECTOR
if (signum == SIGPROF) {
Environment* env = Environment::GetCurrent(args);
Expand Down
7 changes: 4 additions & 3 deletions src/spawn_sync.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ using v8::Context;
using v8::EscapableHandleScope;
using v8::FunctionCallbackInfo;
using v8::HandleScope;
using v8::Int32;
using v8::Integer;
using v8::Isolate;
using v8::Just;
Expand Down Expand Up @@ -783,7 +784,7 @@ Maybe<int> SyncProcessRunner::ParseOptions(Local<Value> js_value) {
js_options->Get(context, env()->uid_string()).ToLocalChecked();
if (IsSet(js_uid)) {
CHECK(js_uid->IsInt32());
const int32_t uid = js_uid->Int32Value(context).FromJust();
const int32_t uid = js_uid.As<Int32>()->Value();
uv_process_options_.uid = static_cast<uv_uid_t>(uid);
uv_process_options_.flags |= UV_PROCESS_SETUID;
}
Expand All @@ -792,7 +793,7 @@ Maybe<int> SyncProcessRunner::ParseOptions(Local<Value> js_value) {
js_options->Get(context, env()->gid_string()).ToLocalChecked();
if (IsSet(js_gid)) {
CHECK(js_gid->IsInt32());
const int32_t gid = js_gid->Int32Value(context).FromJust();
const int32_t gid = js_gid.As<Int32>()->Value();
uv_process_options_.gid = static_cast<uv_gid_t>(gid);
uv_process_options_.flags |= UV_PROCESS_SETGID;
}
Expand Down Expand Up @@ -833,7 +834,7 @@ Maybe<int> SyncProcessRunner::ParseOptions(Local<Value> js_value) {
js_options->Get(context, env()->kill_signal_string()).ToLocalChecked();
if (IsSet(js_kill_signal)) {
CHECK(js_kill_signal->IsInt32());
kill_signal_ = js_kill_signal->Int32Value(context).FromJust();
kill_signal_ = js_kill_signal.As<Int32>()->Value();
}

Local<Value> js_stdio =
Expand Down
Loading

0 comments on commit 594a84d

Please sign in to comment.