Skip to content

Commit c82a3af

Browse files
committed
Deprecate legacy Callback::Call
1 parent ae82fb2 commit c82a3af

9 files changed

+25
-17
lines changed

doc/callback.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Callback {
4949
v8::Local<v8::Value> argv[],
5050
AsyncResource* async_resource) const;
5151

52-
// Legacy versions. Use the versions that accept an async_resource instead
52+
// Deprecated versions. Use the versions that accept an async_resource instead
5353
// as they run the callback in the correct async context as specified by the
5454
// resource.
5555
v8::Local<v8::Value> operator()(v8::Local<v8::Object> target,

nan.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,17 +1479,19 @@ class Callback {
14791479
return !operator==(other);
14801480
}
14811481

1482+
// TODO(ofrobots): This is dangerous as it allows a call without async
1483+
// context. In a semver-major consider disallowing this.
14821484
inline
14831485
v8::Local<v8::Function> operator*() const { return GetFunction(); }
14841486

1485-
inline v8::Local<v8::Value> operator()(
1487+
NAN_DEPRECATED inline v8::Local<v8::Value> operator()(
14861488
v8::Local<v8::Object> target
14871489
, int argc = 0
14881490
, v8::Local<v8::Value> argv[] = 0) const {
14891491
return this->Call(target, argc, argv);
14901492
}
14911493

1492-
inline v8::Local<v8::Value> operator()(
1494+
NAN_DEPRECATED inline v8::Local<v8::Value> operator()(
14931495
int argc = 0
14941496
, v8::Local<v8::Value> argv[] = 0) const {
14951497
return this->Call(argc, argv);
@@ -1523,6 +1525,8 @@ class Callback {
15231525
handle_.Reset();
15241526
}
15251527

1528+
// TODO(ofrobots): This is dangerous as it allows a call without async
1529+
// context. In a semver-major consider disallowing this.
15261530
inline v8::Local<v8::Function> GetFunction() const {
15271531
return New(handle_);
15281532
}
@@ -1531,7 +1535,7 @@ class Callback {
15311535
return handle_.IsEmpty();
15321536
}
15331537

1534-
inline v8::Local<v8::Value>
1538+
NAN_DEPRECATED inline v8::Local<v8::Value>
15351539
Call(v8::Local<v8::Object> target
15361540
, int argc
15371541
, v8::Local<v8::Value> argv[]) const {
@@ -1543,7 +1547,7 @@ class Callback {
15431547
#endif
15441548
}
15451549

1546-
inline v8::Local<v8::Value>
1550+
NAN_DEPRECATED inline v8::Local<v8::Value>
15471551
Call(int argc, v8::Local<v8::Value> argv[]) const {
15481552
#if NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION
15491553
v8::Isolate *isolate = v8::Isolate::GetCurrent();

test/cpp/asyncprogressqueueworker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ProgressQueueWorker : public AsyncProgressQueueWorker<char> {
3535
v8::Local<v8::Value> argv[] = {
3636
New<v8::Integer>(*reinterpret_cast<int*>(const_cast<char*>(data)))
3737
};
38-
progress->Call(1, argv);
38+
progress->Call(1, argv, async_resource);
3939
}
4040

4141
private:

test/cpp/asyncprogressqueueworkerstream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ProgressQueueWorker : public AsyncProgressQueueWorker<T> {
5454
New<v8::Integer>(data->data));
5555

5656
v8::Local<v8::Value> argv[] = { obj };
57-
progress->Call(1, argv);
57+
progress->Call(1, argv, this->async_resource);
5858
}
5959

6060
private:

test/cpp/asyncprogressworker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ProgressWorker : public AsyncProgressWorker {
4141
v8::Local<v8::Value> argv[] = {
4242
New<v8::Integer>(*reinterpret_cast<int*>(const_cast<char*>(data)))
4343
};
44-
progress->Call(1, argv);
44+
progress->Call(1, argv, async_resource);
4545
}
4646

4747
private:

test/cpp/asyncprogressworkersignal.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ProgressWorker : public AsyncProgressWorker {
3939
HandleScope scope;
4040

4141
v8::Local<v8::Value> arg = New<v8::Boolean>(data == NULL && count == 0);
42-
progress->Call(1, &arg);
42+
progress->Call(1, &arg, async_resource);
4343
}
4444

4545
private:

test/cpp/asyncprogressworkerstream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class ProgressWorker : public AsyncProgressWorkerBase<T> {
6161
New<v8::Integer>(data->data));
6262

6363
v8::Local<v8::Value> argv[] = { obj };
64-
progress->Call(1, argv);
64+
progress->Call(1, argv, this->async_resource);
6565
}
6666

6767
private:

test/cpp/bufferworkerpersistent.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ class BufferWorker : public AsyncWorker {
3737
HandleScope scope;
3838

3939
v8::Local<v8::Value> handle = GetFromPersistent("buffer");
40-
callback->Call(1, &handle);
40+
callback->Call(1, &handle, async_resource);
4141

4242
handle = GetFromPersistent(New("puffer").ToLocalChecked());
43-
callback->Call(1, &handle);
43+
callback->Call(1, &handle, async_resource);
4444

4545
handle = GetFromPersistent(0u);
46-
callback->Call(1, &handle);
46+
callback->Call(1, &handle, async_resource);
4747
}
4848

4949
private:

test/cpp/nancallback.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,20 @@
1111
using namespace Nan; // NOLINT(build/namespaces)
1212

1313
NAN_METHOD(GlobalContext) {
14-
Callback(To<v8::Function>(info[0]).ToLocalChecked()).Call(0, NULL);
14+
AsyncResource resource("nan:test.nancallback");
15+
Callback(To<v8::Function>(info[0]).ToLocalChecked()).Call(0, NULL, &resource);
1516
}
1617

1718
NAN_METHOD(SpecificContext) {
19+
AsyncResource resource("nan:test.nancallback");
1820
Callback cb(To<v8::Function>(info[0]).ToLocalChecked());
19-
cb.Call(GetCurrentContext()->Global(), 0, NULL);
21+
cb.Call(GetCurrentContext()->Global(), 0, NULL, &resource);
2022
}
2123

2224
NAN_METHOD(CustomReceiver) {
25+
AsyncResource resource("nan:test.nancallback");
2326
Callback cb(To<v8::Function>(info[0]).ToLocalChecked());
24-
cb.Call(To<v8::Object>(info[1]).ToLocalChecked(), 0, NULL);
27+
cb.Call(To<v8::Object>(info[1]).ToLocalChecked(), 0, NULL, &resource);
2528
}
2629

2730
NAN_METHOD(CompareCallbacks) {
@@ -38,7 +41,8 @@ NAN_METHOD(CallDirect) {
3841
}
3942

4043
NAN_METHOD(CallAsFunction) {
41-
Callback(To<v8::Function>(info[0]).ToLocalChecked())();
44+
AsyncResource resource("nan:test.nancallback");
45+
Callback(To<v8::Function>(info[0]).ToLocalChecked())(&resource);
4246
}
4347

4448
NAN_METHOD(ResetUnset) {

0 commit comments

Comments
 (0)