-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#Callback | ||
`Callback` makes it easier to use `v8::Function` handles as callbacks. | ||
|
||
##Callback | ||
A class that wraps a `v8::Function` handle, protecting it from garbage collection. | ||
```c++ | ||
class Callback { | ||
public: | ||
Callback(); | ||
|
||
explicit Callback(const v8::Handle<v8::Function> &fn); | ||
|
||
~Callback(); | ||
|
||
bool operator==(const Callback &other) const; | ||
|
||
bool operator!=(const Callback &other) const; | ||
|
||
NAN_INLINE | ||
v8::Local<v8::Function> operator*() const; | ||
|
||
v8::Local<v8::Value> operator()( | ||
v8::Handle<v8::Object> target | ||
, int argc = 0 | ||
, v8::Handle<v8::Value> argv[] = 0) const; | ||
|
||
v8::Local<v8::Value> operator()( | ||
int argc = 0 | ||
, v8::Handle<v8::Value> argv[] = 0) const; | ||
|
||
void SetFunction(const v8::Handle<v8::Function> &fn); | ||
|
||
v8::Local<v8::Function> GetFunction() const; | ||
|
||
bool IsEmpty() const; | ||
|
||
v8::Local<v8::Value> | ||
Call(v8::Handle<v8::Object> target | ||
, int argc | ||
, v8::Handle<v8::Value> argv[]) const; | ||
|
||
v8::Local<v8::Value> | ||
Call(int argc, v8::Handle<v8::Value> argv[]) const; | ||
}; | ||
``` | ||
###Example | ||
```c++ | ||
v8::Local<v8::Function> function; | ||
Callback callback(function); | ||
callback->Call(0, 0); | ||
``` |