Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9565029

Browse files
ryzokukentargos
authored andcommittedSep 3, 2018
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: #22143 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Denys Otrishko <[email protected]>
1 parent c32d557 commit 9565029

9 files changed

+71
-46
lines changed
 

‎lib/buffer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
771771
} else if (isUint8Array(val)) {
772772
return indexOfBuffer(buffer, val, byteOffset, encoding, dir);
773773
} else if (typeof val === 'number') {
774-
return indexOfNumber(buffer, val, byteOffset, dir);
774+
return indexOfNumber(buffer, val >>> 0, byteOffset, dir);
775775
}
776776

777777
throw new ERR_INVALID_ARG_TYPE(

‎src/inspector_js_api.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ using v8::MaybeLocal;
2121
using v8::NewStringType;
2222
using v8::Object;
2323
using v8::String;
24+
using v8::Uint32;
2425
using v8::Value;
2526

2627
using v8_inspector::StringBuffer;
@@ -241,7 +242,7 @@ void Open(const FunctionCallbackInfo<Value>& args) {
241242
bool wait_for_connect = false;
242243

243244
if (args.Length() > 0 && args[0]->IsUint32()) {
244-
uint32_t port = args[0]->Uint32Value();
245+
uint32_t port = args[0].As<Uint32>()->Value();
245246
agent->options()->host_port.port = port;
246247
}
247248

‎src/node_buffer.cc

+11-5
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ using v8::Maybe;
8383
using v8::MaybeLocal;
8484
using v8::Object;
8585
using v8::String;
86+
using v8::Uint32;
8687
using v8::Uint32Array;
8788
using v8::Uint8Array;
8889
using v8::Value;
@@ -565,12 +566,15 @@ void Copy(const FunctionCallbackInfo<Value> &args) {
565566

566567
void Fill(const FunctionCallbackInfo<Value>& args) {
567568
Environment* env = Environment::GetCurrent(args);
569+
Local<Context> ctx = env->context();
568570

569571
THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]);
570572
SPREAD_BUFFER_ARG(args[0], ts_obj);
571573

572-
size_t start = args[2]->Uint32Value();
573-
size_t end = args[3]->Uint32Value();
574+
uint32_t start;
575+
if (!args[2]->Uint32Value(ctx).To(&start)) return;
576+
uint32_t end;
577+
if (!args[3]->Uint32Value(ctx).To(&end)) return;
574578
size_t fill_length = end - start;
575579
Local<String> str_obj;
576580
size_t str_length;
@@ -590,7 +594,9 @@ void Fill(const FunctionCallbackInfo<Value>& args) {
590594

591595
// Then coerce everything that's not a string.
592596
if (!args[1]->IsString()) {
593-
int value = args[1]->Uint32Value() & 255;
597+
uint32_t val;
598+
if (!args[1]->Uint32Value(ctx).To(&val)) return;
599+
int value = val & 255;
594600
memset(ts_obj_data + start, value, fill_length);
595601
return;
596602
}
@@ -1000,14 +1006,14 @@ void IndexOfBuffer(const FunctionCallbackInfo<Value>& args) {
10001006
}
10011007

10021008
void IndexOfNumber(const FunctionCallbackInfo<Value>& args) {
1003-
CHECK(args[1]->IsNumber());
1009+
CHECK(args[1]->IsUint32());
10041010
CHECK(args[2]->IsNumber());
10051011
CHECK(args[3]->IsBoolean());
10061012

10071013
THROW_AND_RETURN_UNLESS_BUFFER(Environment::GetCurrent(args), args[0]);
10081014
SPREAD_BUFFER_ARG(args[0], ts_obj);
10091015

1010-
uint32_t needle = args[1]->Uint32Value();
1016+
uint32_t needle = args[1].As<Uint32>()->Value();
10111017
int64_t offset_i64 = args[2]->IntegerValue();
10121018
bool is_forward = args[3]->IsTrue();
10131019

‎src/node_crypto.cc

+10-6
Original file line numberDiff line numberDiff line change
@@ -3885,7 +3885,8 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) {
38853885
char* buf = Buffer::Data(args[1]);
38863886
ssize_t len = Buffer::Length(args[1]);
38873887

3888-
int padding = args[2]->Uint32Value();
3888+
uint32_t padding;
3889+
if (!args[2]->Uint32Value(env->context()).To(&padding)) return;
38893890

38903891
String::Utf8Value passphrase(args.GetIsolate(), args[3]);
38913892

@@ -4450,8 +4451,9 @@ void ECDH::GetPublicKey(const FunctionCallbackInfo<Value>& args) {
44504451
return env->ThrowError("Failed to get ECDH public key");
44514452

44524453
int size;
4453-
point_conversion_form_t form =
4454-
static_cast<point_conversion_form_t>(args[0]->Uint32Value());
4454+
CHECK(args[0]->IsUint32());
4455+
uint32_t val = args[0].As<Uint32>()->Value();
4456+
point_conversion_form_t form = static_cast<point_conversion_form_t>(val);
44554457

44564458
size = EC_POINT_point2oct(ecdh->group_, pub, form, nullptr, 0, nullptr);
44574459
if (size == 0)
@@ -5066,8 +5068,9 @@ void ConvertKey(const FunctionCallbackInfo<Value>& args) {
50665068
if (pub == nullptr)
50675069
return env->ThrowError("Failed to convert Buffer to EC_POINT");
50685070

5069-
point_conversion_form_t form =
5070-
static_cast<point_conversion_form_t>(args[2]->Uint32Value());
5071+
CHECK(args[2]->IsUint32());
5072+
uint32_t val = args[2].As<Uint32>()->Value();
5073+
point_conversion_form_t form = static_cast<point_conversion_form_t>(val);
50715074

50725075
int size = EC_POINT_point2oct(
50735076
group.get(), pub.get(), form, nullptr, 0, nullptr);
@@ -5166,7 +5169,8 @@ void InitCryptoOnce() {
51665169
void SetEngine(const FunctionCallbackInfo<Value>& args) {
51675170
Environment* env = Environment::GetCurrent(args);
51685171
CHECK(args.Length() >= 2 && args[0]->IsString());
5169-
unsigned int flags = args[1]->Uint32Value();
5172+
uint32_t flags;
5173+
if (!args[1]->Uint32Value(env->context()).To(&flags)) return;
51705174

51715175
ClearErrorOnReturn clear_error_on_return;
51725176

‎src/node_i18n.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -819,9 +819,9 @@ static void GetStringWidth(const FunctionCallbackInfo<Value>& args) {
819819
bool expand_emoji_sequence = args[2]->IsTrue();
820820

821821
if (args[0]->IsNumber()) {
822-
args.GetReturnValue().Set(
823-
GetColumnWidth(args[0]->Uint32Value(),
824-
ambiguous_as_full_width));
822+
uint32_t val;
823+
if (!args[0]->Uint32Value(env->context()).To(&val)) return;
824+
args.GetReturnValue().Set(GetColumnWidth(val, ambiguous_as_full_width));
825825
return;
826826
}
827827

‎src/node_process.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ static const char* name_by_gid(gid_t gid) {
345345

346346
static uid_t uid_by_name(Isolate* isolate, Local<Value> value) {
347347
if (value->IsUint32()) {
348-
return static_cast<uid_t>(value->Uint32Value());
348+
return static_cast<uid_t>(value.As<Uint32>()->Value());
349349
} else {
350350
Utf8Value name(isolate, value);
351351
return uid_by_name(*name);
@@ -355,7 +355,7 @@ static uid_t uid_by_name(Isolate* isolate, Local<Value> value) {
355355

356356
static gid_t gid_by_name(Isolate* isolate, Local<Value> value) {
357357
if (value->IsUint32()) {
358-
return static_cast<gid_t>(value->Uint32Value());
358+
return static_cast<gid_t>(value.As<Uint32>()->Value());
359359
} else {
360360
Utf8Value name(isolate, value);
361361
return gid_by_name(*name);
@@ -534,7 +534,7 @@ void InitGroups(const FunctionCallbackInfo<Value>& args) {
534534
char* user;
535535

536536
if (args[0]->IsUint32()) {
537-
user = name_by_uid(args[0]->Uint32Value());
537+
user = name_by_uid(args[0].As<Uint32>()->Value());
538538
must_free = true;
539539
} else {
540540
user = *arg0;

‎src/node_zlib.cc

+31-21
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ using v8::Local;
4949
using v8::Number;
5050
using v8::Object;
5151
using v8::String;
52+
using v8::Uint32;
5253
using v8::Uint32Array;
5354
using v8::Value;
5455

@@ -155,7 +156,11 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
155156

156157
CHECK_EQ(false, args[0]->IsUndefined() && "must provide flush value");
157158

158-
unsigned int flush = args[0]->Uint32Value();
159+
Environment* env = ctx->env();
160+
Local<Context> context = env->context();
161+
162+
unsigned int flush;
163+
if (!args[0]->Uint32Value(context).To(&flush)) return;
159164

160165
if (flush != Z_NO_FLUSH &&
161166
flush != Z_PARTIAL_FLUSH &&
@@ -170,8 +175,7 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
170175

171176
Bytef* in;
172177
Bytef* out;
173-
size_t in_off, in_len, out_off, out_len;
174-
Environment* env = ctx->env();
178+
uint32_t in_off, in_len, out_off, out_len;
175179

176180
if (args[1]->IsNull()) {
177181
// just a flush
@@ -181,18 +185,18 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
181185
} else {
182186
CHECK(Buffer::HasInstance(args[1]));
183187
Local<Object> in_buf;
184-
in_buf = args[1]->ToObject(env->context()).ToLocalChecked();
185-
in_off = args[2]->Uint32Value();
186-
in_len = args[3]->Uint32Value();
188+
in_buf = args[1]->ToObject(context).ToLocalChecked();
189+
if (!args[2]->Uint32Value(context).To(&in_off)) return;
190+
if (!args[3]->Uint32Value(context).To(&in_len)) return;
187191

188192
CHECK(Buffer::IsWithinBounds(in_off, in_len, Buffer::Length(in_buf)));
189193
in = reinterpret_cast<Bytef *>(Buffer::Data(in_buf) + in_off);
190194
}
191195

192196
CHECK(Buffer::HasInstance(args[4]));
193-
Local<Object> out_buf = args[4]->ToObject(env->context()).ToLocalChecked();
194-
out_off = args[5]->Uint32Value();
195-
out_len = args[6]->Uint32Value();
197+
Local<Object> out_buf = args[4]->ToObject(context).ToLocalChecked();
198+
if (!args[5]->Uint32Value(context).To(&out_off)) return;
199+
if (!args[6]->Uint32Value(context).To(&out_len)) return;
196200
CHECK(Buffer::IsWithinBounds(out_off, out_len, Buffer::Length(out_buf)));
197201
out = reinterpret_cast<Bytef *>(Buffer::Data(out_buf) + out_off);
198202

@@ -438,32 +442,38 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
438442
ZCtx* ctx;
439443
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Holder());
440444

445+
Local<Context> context = args.GetIsolate()->GetCurrentContext();
446+
441447
// windowBits is special. On the compression side, 0 is an invalid value.
442448
// But on the decompression side, a value of 0 for windowBits tells zlib
443449
// to use the window size in the zlib header of the compressed stream.
444-
int windowBits = args[0]->Uint32Value();
450+
uint32_t windowBits;
451+
if (!args[0]->Uint32Value(context).To(&windowBits)) return;
452+
445453
if (!((windowBits == 0) &&
446454
(ctx->mode_ == INFLATE ||
447455
ctx->mode_ == GUNZIP ||
448456
ctx->mode_ == UNZIP))) {
449-
CHECK((windowBits >= Z_MIN_WINDOWBITS &&
450-
windowBits <= Z_MAX_WINDOWBITS) && "invalid windowBits");
457+
CHECK(
458+
(windowBits >= Z_MIN_WINDOWBITS && windowBits <= Z_MAX_WINDOWBITS) &&
459+
"invalid windowBits");
451460
}
452461

453462
int level = args[1]->Int32Value();
454463
CHECK((level >= Z_MIN_LEVEL && level <= Z_MAX_LEVEL) &&
455464
"invalid compression level");
456465

457-
int memLevel = args[2]->Uint32Value();
466+
uint32_t memLevel;
467+
if (!args[2]->Uint32Value(context).To(&memLevel)) return;
458468
CHECK((memLevel >= Z_MIN_MEMLEVEL && memLevel <= Z_MAX_MEMLEVEL) &&
459-
"invalid memlevel");
460-
461-
int strategy = args[3]->Uint32Value();
462-
CHECK((strategy == Z_FILTERED ||
463-
strategy == Z_HUFFMAN_ONLY ||
464-
strategy == Z_RLE ||
465-
strategy == Z_FIXED ||
466-
strategy == Z_DEFAULT_STRATEGY) && "invalid strategy");
469+
"invalid memlevel");
470+
471+
uint32_t strategy;
472+
if (!args[3]->Uint32Value(context).To(&strategy)) return;
473+
CHECK((strategy == Z_FILTERED || strategy == Z_HUFFMAN_ONLY ||
474+
strategy == Z_RLE || strategy == Z_FIXED ||
475+
strategy == Z_DEFAULT_STRATEGY) &&
476+
"invalid strategy");
467477

468478
CHECK(args[4]->IsUint32Array());
469479
Local<Uint32Array> array = args[4].As<Uint32Array>();

‎src/tcp_wrap.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ using v8::Integer;
4848
using v8::Local;
4949
using v8::Object;
5050
using v8::String;
51+
using v8::Uint32;
5152
using v8::Value;
5253

5354
using AsyncHooks = Environment::AsyncHooks;
@@ -180,7 +181,7 @@ void TCPWrap::SetKeepAlive(const FunctionCallbackInfo<Value>& args) {
180181
args.Holder(),
181182
args.GetReturnValue().Set(UV_EBADF));
182183
int enable = args[0]->Int32Value();
183-
unsigned int delay = args[1]->Uint32Value();
184+
unsigned int delay = args[1].As<Uint32>()->Value();
184185
int err = uv_tcp_keepalive(&wrap->handle_, enable, delay);
185186
args.GetReturnValue().Set(err);
186187
}
@@ -277,7 +278,7 @@ void TCPWrap::Connect(const FunctionCallbackInfo<Value>& args) {
277278

278279
Local<Object> req_wrap_obj = args[0].As<Object>();
279280
node::Utf8Value ip_address(env->isolate(), args[1]);
280-
int port = args[2]->Uint32Value();
281+
int port = args[2].As<Uint32>()->Value();
281282

282283
sockaddr_in addr;
283284
int err = uv_ip4_addr(*ip_address, port, &addr);

‎src/udp_wrap.cc

+7-4
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,11 @@ void UDPWrap::DoBind(const FunctionCallbackInfo<Value>& args, int family) {
179179
CHECK_EQ(args.Length(), 3);
180180

181181
node::Utf8Value address(args.GetIsolate(), args[0]);
182-
const int port = args[1]->Uint32Value();
183-
const int flags = args[2]->Uint32Value();
182+
Local<Context> ctx = args.GetIsolate()->GetCurrentContext();
183+
uint32_t port, flags;
184+
if (!args[1]->Uint32Value(ctx).To(&port) ||
185+
!args[2]->Uint32Value(ctx).To(&flags))
186+
return;
184187
char addr[sizeof(sockaddr_in6)];
185188
int err;
186189

@@ -340,8 +343,8 @@ void UDPWrap::DoSend(const FunctionCallbackInfo<Value>& args, int family) {
340343
Local<Array> chunks = args[1].As<Array>();
341344
// it is faster to fetch the length of the
342345
// array in js-land
343-
size_t count = args[2]->Uint32Value();
344-
const unsigned short port = args[3]->Uint32Value();
346+
size_t count = args[2].As<Uint32>()->Value();
347+
const unsigned short port = args[3].As<Uint32>()->Value();
345348
node::Utf8Value address(env->isolate(), args[4]);
346349
const bool have_callback = args[5]->IsTrue();
347350

0 commit comments

Comments
 (0)
Please sign in to comment.