3 `Nan::Callback` makes it easier to use `v8::Function` handles as callbacks. A class that wraps a `v8::Function` handle, protecting it from garbage collection and making it particularly useful for storage and use across asynchronous execution.
5 - <a href="#api_nan_callback"><b><code>Nan::Callback</code></b></a>
7 <a name="api_nan_callback"></a>
15 explicit Callback(const v8::Local<v8::Function> &fn);
19 bool operator==(const Callback &other) const;
21 bool operator!=(const Callback &other) const;
23 v8::Local<v8::Function> operator*() const;
25 MaybeLocal<v8::Value> operator()(AsyncResource* async_resource,
26 v8::Local<v8::Object> target,
28 v8::Local<v8::Value> argv[] = 0) const;
30 MaybeLocal<v8::Value> operator()(AsyncResource* async_resource,
32 v8::Local<v8::Value> argv[] = 0) const;
34 void SetFunction(const v8::Local<v8::Function> &fn);
36 v8::Local<v8::Function> GetFunction() const;
40 void Reset(const v8::Local<v8::Function> &fn);
44 MaybeLocal<v8::Value> Call(v8::Local<v8::Object> target,
46 v8::Local<v8::Value> argv[],
47 AsyncResource* async_resource) const;
48 MaybeLocal<v8::Value> Call(int argc,
49 v8::Local<v8::Value> argv[],
50 AsyncResource* async_resource) const;
52 // Deprecated versions. Use the versions that accept an async_resource instead
53 // as they run the callback in the correct async context as specified by the
54 // resource. If you want to call a synchronous JS function (i.e. on a
55 // non-empty JS stack), you can use Nan::Call instead.
56 v8::Local<v8::Value> operator()(v8::Local<v8::Object> target,
58 v8::Local<v8::Value> argv[] = 0) const;
60 v8::Local<v8::Value> operator()(int argc = 0,
61 v8::Local<v8::Value> argv[] = 0) const;
62 v8::Local<v8::Value> Call(v8::Local<v8::Object> target,
64 v8::Local<v8::Value> argv[]) const;
66 v8::Local<v8::Value> Call(int argc, v8::Local<v8::Value> argv[]) const;
73 v8::Local<v8::Function> function;
74 Nan::Callback callback(function);