src: remove calls to deprecated v8 functions (Uint32Value)

Remove all calls to deprecated v8 functions (here:
Value::Uint32Value) inside the code (src directory only).

PR-URL: https://github.com/nodejs/node/pull/22143
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
This commit is contained in:
Ujjwal Sharma 2018-08-29 16:46:36 +02:00 committed by Michaël Zasso
parent 5da155398e
commit 37cd10a116
No known key found for this signature in database
GPG Key ID: 770F7A9A5AE15600
9 changed files with 70 additions and 45 deletions

View File

@ -772,7 +772,7 @@ function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
} else if (isUint8Array(val)) { } else if (isUint8Array(val)) {
return indexOfBuffer(buffer, val, byteOffset, encoding, dir); return indexOfBuffer(buffer, val, byteOffset, encoding, dir);
} else if (typeof val === 'number') { } else if (typeof val === 'number') {
return indexOfNumber(buffer, val, byteOffset, dir); return indexOfNumber(buffer, val >>> 0, byteOffset, dir);
} }
throw new ERR_INVALID_ARG_TYPE( throw new ERR_INVALID_ARG_TYPE(

View File

@ -21,6 +21,7 @@ using v8::MaybeLocal;
using v8::NewStringType; using v8::NewStringType;
using v8::Object; using v8::Object;
using v8::String; using v8::String;
using v8::Uint32;
using v8::Value; using v8::Value;
using v8_inspector::StringBuffer; using v8_inspector::StringBuffer;
@ -241,7 +242,7 @@ void Open(const FunctionCallbackInfo<Value>& args) {
bool wait_for_connect = false; bool wait_for_connect = false;
if (args.Length() > 0 && args[0]->IsUint32()) { if (args.Length() > 0 && args[0]->IsUint32()) {
uint32_t port = args[0]->Uint32Value(); uint32_t port = args[0].As<Uint32>()->Value();
agent->options()->host_port.port = port; agent->options()->host_port.port = port;
} }

View File

@ -83,6 +83,7 @@ using v8::Maybe;
using v8::MaybeLocal; using v8::MaybeLocal;
using v8::Object; using v8::Object;
using v8::String; using v8::String;
using v8::Uint32;
using v8::Uint32Array; using v8::Uint32Array;
using v8::Uint8Array; using v8::Uint8Array;
using v8::Value; using v8::Value;
@ -565,12 +566,15 @@ void Copy(const FunctionCallbackInfo<Value> &args) {
void Fill(const FunctionCallbackInfo<Value>& args) { void Fill(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args); Environment* env = Environment::GetCurrent(args);
Local<Context> ctx = env->context();
THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]); THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]);
SPREAD_BUFFER_ARG(args[0], ts_obj); SPREAD_BUFFER_ARG(args[0], ts_obj);
size_t start = args[2]->Uint32Value(); uint32_t start;
size_t end = args[3]->Uint32Value(); if (!args[2]->Uint32Value(ctx).To(&start)) return;
uint32_t end;
if (!args[3]->Uint32Value(ctx).To(&end)) return;
size_t fill_length = end - start; size_t fill_length = end - start;
Local<String> str_obj; Local<String> str_obj;
size_t str_length; size_t str_length;
@ -590,7 +594,9 @@ void Fill(const FunctionCallbackInfo<Value>& args) {
// Then coerce everything that's not a string. // Then coerce everything that's not a string.
if (!args[1]->IsString()) { if (!args[1]->IsString()) {
int value = args[1]->Uint32Value() & 255; uint32_t val;
if (!args[1]->Uint32Value(ctx).To(&val)) return;
int value = val & 255;
memset(ts_obj_data + start, value, fill_length); memset(ts_obj_data + start, value, fill_length);
return; return;
} }
@ -1000,14 +1006,14 @@ void IndexOfBuffer(const FunctionCallbackInfo<Value>& args) {
} }
void IndexOfNumber(const FunctionCallbackInfo<Value>& args) { void IndexOfNumber(const FunctionCallbackInfo<Value>& args) {
CHECK(args[1]->IsNumber()); CHECK(args[1]->IsUint32());
CHECK(args[2]->IsNumber()); CHECK(args[2]->IsNumber());
CHECK(args[3]->IsBoolean()); CHECK(args[3]->IsBoolean());
THROW_AND_RETURN_UNLESS_BUFFER(Environment::GetCurrent(args), args[0]); THROW_AND_RETURN_UNLESS_BUFFER(Environment::GetCurrent(args), args[0]);
SPREAD_BUFFER_ARG(args[0], ts_obj); SPREAD_BUFFER_ARG(args[0], ts_obj);
uint32_t needle = args[1]->Uint32Value(); uint32_t needle = args[1].As<Uint32>()->Value();
int64_t offset_i64 = args[2]->IntegerValue(); int64_t offset_i64 = args[2]->IntegerValue();
bool is_forward = args[3]->IsTrue(); bool is_forward = args[3]->IsTrue();

View File

@ -3882,7 +3882,8 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) {
char* buf = Buffer::Data(args[1]); char* buf = Buffer::Data(args[1]);
ssize_t len = Buffer::Length(args[1]); ssize_t len = Buffer::Length(args[1]);
int padding = args[2]->Uint32Value(); uint32_t padding;
if (!args[2]->Uint32Value(env->context()).To(&padding)) return;
String::Utf8Value passphrase(args.GetIsolate(), args[3]); String::Utf8Value passphrase(args.GetIsolate(), args[3]);
@ -4447,8 +4448,9 @@ void ECDH::GetPublicKey(const FunctionCallbackInfo<Value>& args) {
return env->ThrowError("Failed to get ECDH public key"); return env->ThrowError("Failed to get ECDH public key");
int size; int size;
point_conversion_form_t form = CHECK(args[0]->IsUint32());
static_cast<point_conversion_form_t>(args[0]->Uint32Value()); uint32_t val = args[0].As<Uint32>()->Value();
point_conversion_form_t form = static_cast<point_conversion_form_t>(val);
size = EC_POINT_point2oct(ecdh->group_, pub, form, nullptr, 0, nullptr); size = EC_POINT_point2oct(ecdh->group_, pub, form, nullptr, 0, nullptr);
if (size == 0) if (size == 0)
@ -5063,8 +5065,9 @@ void ConvertKey(const FunctionCallbackInfo<Value>& args) {
if (pub == nullptr) if (pub == nullptr)
return env->ThrowError("Failed to convert Buffer to EC_POINT"); return env->ThrowError("Failed to convert Buffer to EC_POINT");
point_conversion_form_t form = CHECK(args[2]->IsUint32());
static_cast<point_conversion_form_t>(args[2]->Uint32Value()); uint32_t val = args[2].As<Uint32>()->Value();
point_conversion_form_t form = static_cast<point_conversion_form_t>(val);
int size = EC_POINT_point2oct( int size = EC_POINT_point2oct(
group.get(), pub.get(), form, nullptr, 0, nullptr); group.get(), pub.get(), form, nullptr, 0, nullptr);
@ -5163,7 +5166,8 @@ void InitCryptoOnce() {
void SetEngine(const FunctionCallbackInfo<Value>& args) { void SetEngine(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args); Environment* env = Environment::GetCurrent(args);
CHECK(args.Length() >= 2 && args[0]->IsString()); CHECK(args.Length() >= 2 && args[0]->IsString());
unsigned int flags = args[1]->Uint32Value(); uint32_t flags;
if (!args[1]->Uint32Value(env->context()).To(&flags)) return;
ClearErrorOnReturn clear_error_on_return; ClearErrorOnReturn clear_error_on_return;

View File

@ -819,9 +819,9 @@ static void GetStringWidth(const FunctionCallbackInfo<Value>& args) {
bool expand_emoji_sequence = args[2]->IsTrue(); bool expand_emoji_sequence = args[2]->IsTrue();
if (args[0]->IsNumber()) { if (args[0]->IsNumber()) {
args.GetReturnValue().Set( uint32_t val;
GetColumnWidth(args[0]->Uint32Value(), if (!args[0]->Uint32Value(env->context()).To(&val)) return;
ambiguous_as_full_width)); args.GetReturnValue().Set(GetColumnWidth(val, ambiguous_as_full_width));
return; return;
} }

View File

@ -335,7 +335,7 @@ static const char* name_by_gid(gid_t gid) {
static uid_t uid_by_name(Isolate* isolate, Local<Value> value) { static uid_t uid_by_name(Isolate* isolate, Local<Value> value) {
if (value->IsUint32()) { if (value->IsUint32()) {
return static_cast<uid_t>(value->Uint32Value()); return static_cast<uid_t>(value.As<Uint32>()->Value());
} else { } else {
Utf8Value name(isolate, value); Utf8Value name(isolate, value);
return uid_by_name(*name); return uid_by_name(*name);
@ -345,7 +345,7 @@ static uid_t uid_by_name(Isolate* isolate, Local<Value> value) {
static gid_t gid_by_name(Isolate* isolate, Local<Value> value) { static gid_t gid_by_name(Isolate* isolate, Local<Value> value) {
if (value->IsUint32()) { if (value->IsUint32()) {
return static_cast<gid_t>(value->Uint32Value()); return static_cast<gid_t>(value.As<Uint32>()->Value());
} else { } else {
Utf8Value name(isolate, value); Utf8Value name(isolate, value);
return gid_by_name(*name); return gid_by_name(*name);
@ -538,7 +538,7 @@ void InitGroups(const FunctionCallbackInfo<Value>& args) {
char* user; char* user;
if (args[0]->IsUint32()) { if (args[0]->IsUint32()) {
user = name_by_uid(args[0]->Uint32Value()); user = name_by_uid(args[0].As<Uint32>()->Value());
must_free = true; must_free = true;
} else { } else {
user = *arg0; user = *arg0;

View File

@ -49,6 +49,7 @@ using v8::Local;
using v8::Number; using v8::Number;
using v8::Object; using v8::Object;
using v8::String; using v8::String;
using v8::Uint32;
using v8::Uint32Array; using v8::Uint32Array;
using v8::Value; using v8::Value;
@ -155,7 +156,11 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
CHECK_EQ(false, args[0]->IsUndefined() && "must provide flush value"); CHECK_EQ(false, args[0]->IsUndefined() && "must provide flush value");
unsigned int flush = args[0]->Uint32Value(); Environment* env = ctx->env();
Local<Context> context = env->context();
unsigned int flush;
if (!args[0]->Uint32Value(context).To(&flush)) return;
if (flush != Z_NO_FLUSH && if (flush != Z_NO_FLUSH &&
flush != Z_PARTIAL_FLUSH && flush != Z_PARTIAL_FLUSH &&
@ -170,8 +175,7 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
Bytef* in; Bytef* in;
Bytef* out; Bytef* out;
size_t in_off, in_len, out_off, out_len; uint32_t in_off, in_len, out_off, out_len;
Environment* env = ctx->env();
if (args[1]->IsNull()) { if (args[1]->IsNull()) {
// just a flush // just a flush
@ -181,18 +185,18 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
} else { } else {
CHECK(Buffer::HasInstance(args[1])); CHECK(Buffer::HasInstance(args[1]));
Local<Object> in_buf; Local<Object> in_buf;
in_buf = args[1]->ToObject(env->context()).ToLocalChecked(); in_buf = args[1]->ToObject(context).ToLocalChecked();
in_off = args[2]->Uint32Value(); if (!args[2]->Uint32Value(context).To(&in_off)) return;
in_len = args[3]->Uint32Value(); if (!args[3]->Uint32Value(context).To(&in_len)) return;
CHECK(Buffer::IsWithinBounds(in_off, in_len, Buffer::Length(in_buf))); CHECK(Buffer::IsWithinBounds(in_off, in_len, Buffer::Length(in_buf)));
in = reinterpret_cast<Bytef *>(Buffer::Data(in_buf) + in_off); in = reinterpret_cast<Bytef *>(Buffer::Data(in_buf) + in_off);
} }
CHECK(Buffer::HasInstance(args[4])); CHECK(Buffer::HasInstance(args[4]));
Local<Object> out_buf = args[4]->ToObject(env->context()).ToLocalChecked(); Local<Object> out_buf = args[4]->ToObject(context).ToLocalChecked();
out_off = args[5]->Uint32Value(); if (!args[5]->Uint32Value(context).To(&out_off)) return;
out_len = args[6]->Uint32Value(); if (!args[6]->Uint32Value(context).To(&out_len)) return;
CHECK(Buffer::IsWithinBounds(out_off, out_len, Buffer::Length(out_buf))); CHECK(Buffer::IsWithinBounds(out_off, out_len, Buffer::Length(out_buf)));
out = reinterpret_cast<Bytef *>(Buffer::Data(out_buf) + out_off); out = reinterpret_cast<Bytef *>(Buffer::Data(out_buf) + out_off);
@ -438,32 +442,38 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
ZCtx* ctx; ZCtx* ctx;
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Holder()); ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Holder());
Local<Context> context = args.GetIsolate()->GetCurrentContext();
// windowBits is special. On the compression side, 0 is an invalid value. // windowBits is special. On the compression side, 0 is an invalid value.
// But on the decompression side, a value of 0 for windowBits tells zlib // But on the decompression side, a value of 0 for windowBits tells zlib
// to use the window size in the zlib header of the compressed stream. // to use the window size in the zlib header of the compressed stream.
int windowBits = args[0]->Uint32Value(); uint32_t windowBits;
if (!args[0]->Uint32Value(context).To(&windowBits)) return;
if (!((windowBits == 0) && if (!((windowBits == 0) &&
(ctx->mode_ == INFLATE || (ctx->mode_ == INFLATE ||
ctx->mode_ == GUNZIP || ctx->mode_ == GUNZIP ||
ctx->mode_ == UNZIP))) { ctx->mode_ == UNZIP))) {
CHECK((windowBits >= Z_MIN_WINDOWBITS && CHECK(
windowBits <= Z_MAX_WINDOWBITS) && "invalid windowBits"); (windowBits >= Z_MIN_WINDOWBITS && windowBits <= Z_MAX_WINDOWBITS) &&
"invalid windowBits");
} }
int level = args[1]->Int32Value(); int level = args[1]->Int32Value();
CHECK((level >= Z_MIN_LEVEL && level <= Z_MAX_LEVEL) && CHECK((level >= Z_MIN_LEVEL && level <= Z_MAX_LEVEL) &&
"invalid compression level"); "invalid compression level");
int memLevel = args[2]->Uint32Value(); uint32_t memLevel;
if (!args[2]->Uint32Value(context).To(&memLevel)) return;
CHECK((memLevel >= Z_MIN_MEMLEVEL && memLevel <= Z_MAX_MEMLEVEL) && CHECK((memLevel >= Z_MIN_MEMLEVEL && memLevel <= Z_MAX_MEMLEVEL) &&
"invalid memlevel"); "invalid memlevel");
int strategy = args[3]->Uint32Value(); uint32_t strategy;
CHECK((strategy == Z_FILTERED || if (!args[3]->Uint32Value(context).To(&strategy)) return;
strategy == Z_HUFFMAN_ONLY || CHECK((strategy == Z_FILTERED || strategy == Z_HUFFMAN_ONLY ||
strategy == Z_RLE || strategy == Z_RLE || strategy == Z_FIXED ||
strategy == Z_FIXED || strategy == Z_DEFAULT_STRATEGY) &&
strategy == Z_DEFAULT_STRATEGY) && "invalid strategy"); "invalid strategy");
CHECK(args[4]->IsUint32Array()); CHECK(args[4]->IsUint32Array());
Local<Uint32Array> array = args[4].As<Uint32Array>(); Local<Uint32Array> array = args[4].As<Uint32Array>();

View File

@ -48,6 +48,7 @@ using v8::Integer;
using v8::Local; using v8::Local;
using v8::Object; using v8::Object;
using v8::String; using v8::String;
using v8::Uint32;
using v8::Value; using v8::Value;
using AsyncHooks = Environment::AsyncHooks; using AsyncHooks = Environment::AsyncHooks;
@ -180,7 +181,7 @@ void TCPWrap::SetKeepAlive(const FunctionCallbackInfo<Value>& args) {
args.Holder(), args.Holder(),
args.GetReturnValue().Set(UV_EBADF)); args.GetReturnValue().Set(UV_EBADF));
int enable = args[0]->Int32Value(); int enable = args[0]->Int32Value();
unsigned int delay = args[1]->Uint32Value(); unsigned int delay = args[1].As<Uint32>()->Value();
int err = uv_tcp_keepalive(&wrap->handle_, enable, delay); int err = uv_tcp_keepalive(&wrap->handle_, enable, delay);
args.GetReturnValue().Set(err); args.GetReturnValue().Set(err);
} }
@ -277,7 +278,7 @@ void TCPWrap::Connect(const FunctionCallbackInfo<Value>& args) {
Local<Object> req_wrap_obj = args[0].As<Object>(); Local<Object> req_wrap_obj = args[0].As<Object>();
node::Utf8Value ip_address(env->isolate(), args[1]); node::Utf8Value ip_address(env->isolate(), args[1]);
int port = args[2]->Uint32Value(); int port = args[2].As<Uint32>()->Value();
sockaddr_in addr; sockaddr_in addr;
int err = uv_ip4_addr(*ip_address, port, &addr); int err = uv_ip4_addr(*ip_address, port, &addr);

View File

@ -180,8 +180,11 @@ void UDPWrap::DoBind(const FunctionCallbackInfo<Value>& args, int family) {
CHECK_EQ(args.Length(), 3); CHECK_EQ(args.Length(), 3);
node::Utf8Value address(args.GetIsolate(), args[0]); node::Utf8Value address(args.GetIsolate(), args[0]);
const int port = args[1]->Uint32Value(); Local<Context> ctx = args.GetIsolate()->GetCurrentContext();
const int flags = args[2]->Uint32Value(); uint32_t port, flags;
if (!args[1]->Uint32Value(ctx).To(&port) ||
!args[2]->Uint32Value(ctx).To(&flags))
return;
char addr[sizeof(sockaddr_in6)]; char addr[sizeof(sockaddr_in6)];
int err; int err;
@ -353,8 +356,8 @@ void UDPWrap::DoSend(const FunctionCallbackInfo<Value>& args, int family) {
Local<Array> chunks = args[1].As<Array>(); Local<Array> chunks = args[1].As<Array>();
// it is faster to fetch the length of the // it is faster to fetch the length of the
// array in js-land // array in js-land
size_t count = args[2]->Uint32Value(); size_t count = args[2].As<Uint32>()->Value();
const unsigned short port = args[3]->Uint32Value(); const unsigned short port = args[3].As<Uint32>()->Value();
node::Utf8Value address(env->isolate(), args[4]); node::Utf8Value address(env->isolate(), args[4]);
const bool have_callback = args[5]->IsTrue(); const bool have_callback = args[5]->IsTrue();