Skip to content

Commit fa3aa2e

Browse files
tniessenaddaleax
authored andcommitted
src: return MaybeLocal in AsyncWrap::MakeCallback
PR-URL: #14549 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 51c1afa commit fa3aa2e

5 files changed

+44
-35
lines changed

src/async-wrap-inl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ inline double AsyncWrap::get_trigger_id() const {
5151
}
5252

5353

54-
inline v8::Local<v8::Value> AsyncWrap::MakeCallback(
54+
inline v8::MaybeLocal<v8::Value> AsyncWrap::MakeCallback(
5555
const v8::Local<v8::String> symbol,
5656
int argc,
5757
v8::Local<v8::Value>* argv) {
@@ -61,7 +61,7 @@ inline v8::Local<v8::Value> AsyncWrap::MakeCallback(
6161
}
6262

6363

64-
inline v8::Local<v8::Value> AsyncWrap::MakeCallback(
64+
inline v8::MaybeLocal<v8::Value> AsyncWrap::MakeCallback(
6565
uint32_t index,
6666
int argc,
6767
v8::Local<v8::Value>* argv) {

src/async-wrap.cc

+9-10
Original file line numberDiff line numberDiff line change
@@ -674,9 +674,9 @@ void AsyncWrap::EmitAsyncInit(Environment* env,
674674
}
675675

676676

677-
Local<Value> AsyncWrap::MakeCallback(const Local<Function> cb,
678-
int argc,
679-
Local<Value>* argv) {
677+
MaybeLocal<Value> AsyncWrap::MakeCallback(const Local<Function> cb,
678+
int argc,
679+
Local<Value>* argv) {
680680
CHECK(env()->context() == env()->isolate()->GetCurrentContext());
681681

682682
Environment::AsyncCallbackScope callback_scope(env());
@@ -686,15 +686,14 @@ Local<Value> AsyncWrap::MakeCallback(const Local<Function> cb,
686686
get_trigger_id());
687687

688688
if (!PreCallbackExecution(this, true)) {
689-
return Local<Value>();
689+
return MaybeLocal<Value>();
690690
}
691691

692692
// Finally... Get to running the user's callback.
693693
MaybeLocal<Value> ret = cb->Call(env()->context(), object(), argc, argv);
694694

695-
Local<Value> ret_v;
696-
if (!ret.ToLocal(&ret_v)) {
697-
return Local<Value>();
695+
if (ret.IsEmpty()) {
696+
return ret;
698697
}
699698

700699
if (!PostCallbackExecution(this, true)) {
@@ -704,7 +703,7 @@ Local<Value> AsyncWrap::MakeCallback(const Local<Function> cb,
704703
exec_scope.Dispose();
705704

706705
if (callback_scope.in_makecallback()) {
707-
return ret_v;
706+
return ret;
708707
}
709708

710709
Environment::TickInfo* tick_info = env()->tick_info();
@@ -722,7 +721,7 @@ Local<Value> AsyncWrap::MakeCallback(const Local<Function> cb,
722721

723722
if (tick_info->length() == 0) {
724723
tick_info->set_index(0);
725-
return ret_v;
724+
return ret;
726725
}
727726

728727
MaybeLocal<Value> rcheck =
@@ -735,7 +734,7 @@ Local<Value> AsyncWrap::MakeCallback(const Local<Function> cb,
735734
CHECK_EQ(env()->current_async_id(), 0);
736735
CHECK_EQ(env()->trigger_id(), 0);
737736

738-
return rcheck.IsEmpty() ? Local<Value>() : ret_v;
737+
return rcheck.IsEmpty() ? MaybeLocal<Value>() : ret;
739738
}
740739

741740

src/async-wrap.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,16 @@ class AsyncWrap : public BaseObject {
122122
void AsyncReset(bool silent = false);
123123

124124
// Only call these within a valid HandleScope.
125-
// TODO(trevnorris): These should return a MaybeLocal.
126-
v8::Local<v8::Value> MakeCallback(const v8::Local<v8::Function> cb,
127-
int argc,
128-
v8::Local<v8::Value>* argv);
129-
inline v8::Local<v8::Value> MakeCallback(const v8::Local<v8::String> symbol,
130-
int argc,
131-
v8::Local<v8::Value>* argv);
132-
inline v8::Local<v8::Value> MakeCallback(uint32_t index,
133-
int argc,
134-
v8::Local<v8::Value>* argv);
125+
v8::MaybeLocal<v8::Value> MakeCallback(const v8::Local<v8::Function> cb,
126+
int argc,
127+
v8::Local<v8::Value>* argv);
128+
inline v8::MaybeLocal<v8::Value> MakeCallback(
129+
const v8::Local<v8::String> symbol,
130+
int argc,
131+
v8::Local<v8::Value>* argv);
132+
inline v8::MaybeLocal<v8::Value> MakeCallback(uint32_t index,
133+
int argc,
134+
v8::Local<v8::Value>* argv);
135135

136136
virtual size_t self_size() const = 0;
137137

src/js_stream.cc

+13-8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ using v8::FunctionCallbackInfo;
1616
using v8::FunctionTemplate;
1717
using v8::HandleScope;
1818
using v8::Local;
19+
using v8::MaybeLocal;
1920
using v8::Object;
2021
using v8::Value;
2122

@@ -46,22 +47,26 @@ bool JSStream::IsAlive() {
4647
v8::Local<v8::Value> fn = object()->Get(env()->isalive_string());
4748
if (!fn->IsFunction())
4849
return false;
49-
return MakeCallback(fn.As<v8::Function>(), 0, nullptr)->IsTrue();
50+
return MakeCallback(fn.As<v8::Function>(), 0, nullptr)
51+
.ToLocalChecked()->IsTrue();
5052
}
5153

5254

5355
bool JSStream::IsClosing() {
54-
return MakeCallback(env()->isclosing_string(), 0, nullptr)->IsTrue();
56+
return MakeCallback(env()->isclosing_string(), 0, nullptr)
57+
.ToLocalChecked()->IsTrue();
5558
}
5659

5760

5861
int JSStream::ReadStart() {
59-
return MakeCallback(env()->onreadstart_string(), 0, nullptr)->Int32Value();
62+
return MakeCallback(env()->onreadstart_string(), 0, nullptr)
63+
.ToLocalChecked()->Int32Value();
6064
}
6165

6266

6367
int JSStream::ReadStop() {
64-
return MakeCallback(env()->onreadstop_string(), 0, nullptr)->Int32Value();
68+
return MakeCallback(env()->onreadstop_string(), 0, nullptr)
69+
.ToLocalChecked()->Int32Value();
6570
}
6671

6772

@@ -73,10 +78,10 @@ int JSStream::DoShutdown(ShutdownWrap* req_wrap) {
7378
};
7479

7580
req_wrap->Dispatched();
76-
Local<Value> res =
81+
MaybeLocal<Value> res =
7782
MakeCallback(env()->onshutdown_string(), arraysize(argv), argv);
7883

79-
return res->Int32Value();
84+
return res.ToLocalChecked()->Int32Value();
8085
}
8186

8287

@@ -101,10 +106,10 @@ int JSStream::DoWrite(WriteWrap* w,
101106
};
102107

103108
w->Dispatched();
104-
Local<Value> res =
109+
MaybeLocal<Value> res =
105110
MakeCallback(env()->onwrite_string(), arraysize(argv), argv);
106111

107-
return res->Int32Value();
112+
return res.ToLocalChecked()->Int32Value();
108113
}
109114

110115

src/node_http_parser.cc

+10-5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ using v8::FunctionTemplate;
6262
using v8::HandleScope;
6363
using v8::Integer;
6464
using v8::Local;
65+
using v8::MaybeLocal;
6566
using v8::Object;
6667
using v8::String;
6768
using v8::Uint32;
@@ -308,15 +309,15 @@ class Parser : public AsyncWrap {
308309

309310
Environment::AsyncCallbackScope callback_scope(env());
310311

311-
Local<Value> head_response =
312+
MaybeLocal<Value> head_response =
312313
MakeCallback(cb.As<Function>(), arraysize(argv), argv);
313314

314315
if (head_response.IsEmpty()) {
315316
got_exception_ = true;
316317
return -1;
317318
}
318319

319-
return head_response->IntegerValue();
320+
return head_response.ToLocalChecked()->IntegerValue();
320321
}
321322

322323

@@ -344,7 +345,9 @@ class Parser : public AsyncWrap {
344345
Integer::NewFromUnsigned(env()->isolate(), length)
345346
};
346347

347-
Local<Value> r = MakeCallback(cb.As<Function>(), arraysize(argv), argv);
348+
MaybeLocal<Value> r = MakeCallback(cb.As<Function>(),
349+
arraysize(argv),
350+
argv);
348351

349352
if (r.IsEmpty()) {
350353
got_exception_ = true;
@@ -369,7 +372,7 @@ class Parser : public AsyncWrap {
369372

370373
Environment::AsyncCallbackScope callback_scope(env());
371374

372-
Local<Value> r = MakeCallback(cb.As<Function>(), 0, nullptr);
375+
MaybeLocal<Value> r = MakeCallback(cb.As<Function>(), 0, nullptr);
373376

374377
if (r.IsEmpty()) {
375378
got_exception_ = true;
@@ -702,7 +705,9 @@ class Parser : public AsyncWrap {
702705
url_.ToString(env())
703706
};
704707

705-
Local<Value> r = MakeCallback(cb.As<Function>(), arraysize(argv), argv);
708+
MaybeLocal<Value> r = MakeCallback(cb.As<Function>(),
709+
arraysize(argv),
710+
argv);
706711

707712
if (r.IsEmpty())
708713
got_exception_ = true;

0 commit comments

Comments
 (0)