Subversion Repositories php-qbpwcf

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
14 liveuser 1
## Nan::Callback
2
 
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.
4
 
5
 - <a href="#api_nan_callback"><b><code>Nan::Callback</code></b></a>
6
 
7
<a name="api_nan_callback"></a>
8
### Nan::Callback
9
 
10
```c++
11
class Callback {
12
 public:
13
  Callback();
14
 
15
  explicit Callback(const v8::Local<v8::Function> &fn);
16
 
17
  ~Callback();
18
 
19
  bool operator==(const Callback &other) const;
20
 
21
  bool operator!=(const Callback &other) const;
22
 
23
  v8::Local<v8::Function> operator*() const;
24
 
25
  v8::Local<v8::Value> operator()(v8::Local<v8::Object> target,
26
                                  int argc = 0,
27
                                  v8::Local<v8::Value> argv[] = 0) const;
28
 
29
  v8::Local<v8::Value> operator()(int argc = 0,
30
                                  v8::Local<v8::Value> argv[] = 0) const;
31
 
32
  void SetFunction(const v8::Local<v8::Function> &fn);
33
 
34
  v8::Local<v8::Function> GetFunction() const;
35
 
36
  bool IsEmpty() const;
37
 
38
  void Reset(const v8::Local<v8::Function> &fn);
39
 
40
  void Reset();
41
 
42
  v8::Local<v8::Value> Call(v8::Local<v8::Object> target,
43
                            int argc,
44
                            v8::Local<v8::Value> argv[]) const;
45
 
46
  v8::Local<v8::Value> Call(int argc, v8::Local<v8::Value> argv[]) const;
47
};
48
```
49
 
50
Example usage:
51
 
52
```c++
53
v8::Local<v8::Function> function;
54
Nan::Callback callback(function);
55
callback.Call(0, 0);
56
```