Skip to content

Commit

Permalink
First draft of docs for weak callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoopa committed May 31, 2015
1 parent 3d7b97f commit c54eb6e
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions doc/weak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#Weak Callbacks

## NanWeakCallbackInfo
Argument to weak callbacks.
You may need to free any external resources attached to the object.
```c++
template<typename T>
class NanWeakCallbackInfo {
public:
typedef void (*Callback)(const NanWeakCallbackInfo<T>& data);

v8::Isolate *GetIsolate() const;

/**
* Get the parameter that was associated with the weak handle.
*/
T *GetParameter() const;

/**
* Get pointer from internal field, index can be 0 or 1.
*/
void *GetInternalField(int index) const;
};
```
### Example
```c++
void weakCallback(const NanWeakCallbackInfo<int> &data) {
int *parameter = data.GetParameter();
delete parameter;
}
NanPersistent<v8::Object> obj;
int *data = new int(0);
obj.SetWeak(data, callback, NanWeakCallbackType::kParameter);
```

0 comments on commit c54eb6e

Please sign in to comment.