Skip to content

Commit 8899246

Browse files
committed
Migrate deprecated v8 functions to use MaybeLocal pattern
1 parent e355b7c commit 8899246

File tree

1 file changed

+13
-10
lines changed
  • src/wrap_js/makewrappers/templates

1 file changed

+13
-10
lines changed

src/wrap_js/makewrappers/templates/nan.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
if (!node::Buffer::HasInstance(obj))
4949
ret = WALLY_EINVAL;
5050
else {
51-
mBuffer = obj->ToObject();
51+
mBuffer = obj->ToObject(Nan::GetCurrentContext()).ToLocalChecked();
5252
if (IsValid(mBuffer)) {
5353
mData = (unsigned char*) node::Buffer::Data(mBuffer);
5454
mLength = node::Buffer::Length(mBuffer);
@@ -62,7 +62,7 @@
6262
{
6363
if (ret != WALLY_OK)
6464
return; // Do nothing, caller will already throw
65-
const v8::MaybeLocal<v8::Object> local = Nan::NewBuffer(len);
65+
const Nan::MaybeLocal<v8::Object> local = Nan::NewBuffer(len);
6666
if (local.ToLocal(&mBuffer)) {
6767
mData = (unsigned char*) node::Buffer::Data(mBuffer);
6868
mLength = len;
@@ -86,7 +86,7 @@
8686
if (!IsValid(obj) || !obj->IsArray())
8787
ret = WALLY_EINVAL;
8888
else {
89-
mArray = obj->ToObject();
89+
mArray = obj->ToObject(Nan::GetCurrentContext()).ToLocalChecked();
9090
if (!IsValid(mArray))
9191
ret = WALLY_EINVAL;
9292
}
@@ -269,7 +269,7 @@ def _generate_nan(funcname, f):
269269
' const size_t len = arr%s.get().Length();' % i,
270270
' be64array%s.reserve(len);' % i,
271271
' for (size_t i = 0; i < len && ret == WALLY_OK; ++i)',
272-
' be64array%s.push_back(LocalUInt64(arr%s.get().Get(i), ret).mValue);' % (i, i),
272+
' be64array%s.push_back(LocalUInt64(arr%s.get().Get(Nan::GetCurrentContext(), i).ToLocalChecked(), ret).mValue);' % (i, i),
273273
'}',
274274
])
275275
postprocessing.extend([
@@ -287,7 +287,7 @@ def _generate_nan(funcname, f):
287287
postprocessing.extend([
288288
'v8::Local<v8::String> str_res;',
289289
'if (ret == WALLY_OK) {',
290-
' str_res = v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), result_ptr);',
290+
' str_res = v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), result_ptr, v8::NewStringType::kNormal).ToLocalChecked();',
291291
' wally_free_string(result_ptr);',
292292
' if (!IsValid(str_res))',
293293
' ret = WALLY_ENOMEM;',
@@ -317,7 +317,8 @@ def _generate_nan(funcname, f):
317317
if num_outs > 1:
318318
postprocessing.extend([
319319
'if (ret == WALLY_OK)',
320-
' res->Set(%s, res%s);' % (cur_out, i),
320+
' if (!res->Set(Nan::GetCurrentContext(), %s, res%s).FromMaybe(false))' % (cur_out, i),
321+
' ret = WALLY_ERROR;',
321322
])
322323
cur_out += 1
323324
else:
@@ -333,16 +334,18 @@ def _generate_nan(funcname, f):
333334
postprocessing.extend([
334335
'if (ret == WALLY_OK) {',
335336
' *be64%s = cpu_to_be64(*be64%s);' % (i, i),
336-
' res->Set(%s, res%s);' % (cur_out, i),
337+
' if (!res->Set(Nan::GetCurrentContext(), %s, res%s).FromMaybe(false)) ' % (cur_out, i),
338+
' ret = WALLY_ERROR;',
337339
'}',
338340
])
339341
cur_out += 1
340342
elif arg == 'bip32_in':
341343
input_args.append((
342344
'ext_key* inkey;'
343-
'unsigned char* inbuf = (unsigned char*) node::Buffer::Data(info[%s]->ToObject());'
344-
'bip32_key_unserialize_alloc(inbuf, node::Buffer::Length(info[%s]->ToObject()), &inkey);'
345-
) % (i, i))
345+
'const LocalObject buf = info[%s]->ToObject(Nan::GetCurrentContext()).ToLocalChecked();'
346+
'unsigned char* inbuf = (unsigned char*) node::Buffer::Data(buf);'
347+
'bip32_key_unserialize_alloc(inbuf, node::Buffer::Length(buf), &inkey);'
348+
) % (i))
346349
args.append('inkey')
347350
postprocessing.append('bip32_key_free(inkey);')
348351
elif arg in ['bip32_pub_out', 'bip32_priv_out']:

0 commit comments

Comments
 (0)