Skip to content

Commit

Permalink
docs: added initial methods & gc in methods.md
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Jul 25, 2015
1 parent ef954b9 commit fa84621
Show file tree
Hide file tree
Showing 2 changed files with 362 additions and 140 deletions.
142 changes: 2 additions & 140 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,21 +254,7 @@ NAN_METHOD(CalculateAsync) {
<a name="api"></a>
## API
* <a href="#api_nan_method"><b><code>NAN_METHOD</code></b></a>
* <a href="#api_nan_getter"><b><code>NAN_GETTER</code></b></a>
* <a href="#api_nan_setter"><b><code>NAN_SETTER</code></b></a>
* <a href="#api_nan_property_getter"><b><code>NAN_PROPERTY_GETTER</code></b></a>
* <a href="#api_nan_property_setter"><b><code>NAN_PROPERTY_SETTER</code></b></a>
* <a href="#api_nan_property_enumerator"><b><code>NAN_PROPERTY_ENUMERATOR</code></b></a>
* <a href="#api_nan_property_deleter"><b><code>NAN_PROPERTY_DELETER</code></b></a>
* <a href="#api_nan_property_query"><b><code>NAN_PROPERTY_QUERY</code></b></a>
* <a href="#api_nan_index_getter"><b><code>NAN_INDEX_GETTER</code></b></a>
* <a href="#api_nan_index_setter"><b><code>NAN_INDEX_SETTER</code></b></a>
* <a href="#api_nan_index_enumerator"><b><code>NAN_INDEX_ENUMERATOR</code></b></a>
* <a href="#api_nan_index_deleter"><b><code>NAN_INDEX_DELETER</code></b></a>
* <a href="#api_nan_index_query"><b><code>NAN_INDEX_QUERY</code></b></a>
* <a href="#api_nan_gc_callback"><b><code>NAN_GC_CALLBACK</code></b></a>
* <a href="#api_nan_weak_callback"><b><code>NAN_WEAK_CALLBACK</code></b></a>
* <a href="#api_nan_weak_callback"><b><code>NAN_WEAK_CALLBACK(callbackname)</code></b></a>
* <a href="#api_nan_deprecated"><b><code>NAN_DEPRECATED</code></b></a>
* <a href="#api_nan_inline"><b><code>NAN_INLINE</code></b></a>
* <a href="#api_nan_new"><b><code>NanNew</code></b></a>
Expand Down Expand Up @@ -337,132 +323,8 @@ NAN_METHOD(CalculateAsync) {
* <a href="#api_nan_async_worker"><b><code>NanAsyncWorker</code></b></a>
* <a href="#api_nan_async_queue_worker"><b><code>NanAsyncQueueWorker</code></b></a>
<a name="api_nan_method"></a>
### NAN_METHOD(methodname)
Use `NAN_METHOD` to define your V8 accessible methods:
```c++
// .h:
class Foo : public node::ObjectWrap {
...
static NAN_METHOD(Bar);
static NAN_METHOD(Baz);
}
// .cc:
NAN_METHOD(Foo::Bar) {
...
}
NAN_METHOD(Foo::Baz) {
...
}
```

The reason for this macro is because of the method signature change in 0.11:

```c++
// 0.10 and below:
Handle<Value> name(const Arguments& args)

// 0.11 and above
void name(const FunctionCallbackInfo<Value>& args)
```
The introduction of `FunctionCallbackInfo` brings additional complications:
<a name="api_nan_getter"></a>
### NAN_GETTER(methodname)
Use `NAN_GETTER` to declare your V8 accessible getters. You get a `Local<String>` `property` and an appropriately typed `args` object that can act like the `args` argument to a `NAN_METHOD` call.
You can use `NanReturnNull()`, `NanReturnEmptyString()`, `NanReturnUndefined()` and `NanReturnValue()` in a `NAN_GETTER`.
<a name="api_nan_setter"></a>
### NAN_SETTER(methodname)
Use `NAN_SETTER` to declare your V8 accessible setters. Same as `NAN_GETTER` but you also get a `Local<Value>` `value` object to work with.
<a name="api_nan_property_getter"></a>
### NAN_PROPERTY_GETTER(cbname)
Use `NAN_PROPERTY_GETTER` to declare your V8 accessible property getters. You get a `Local<String>` `property` and an appropriately typed `args` object that can act similar to the `args` argument to a `NAN_METHOD` call.
You can use `NanReturnNull()`, `NanReturnEmptyString()`, `NanReturnUndefined()` and `NanReturnValue()` in a `NAN_PROPERTY_GETTER`.
<a name="api_nan_property_setter"></a>
### NAN_PROPERTY_SETTER(cbname)
Use `NAN_PROPERTY_SETTER` to declare your V8 accessible property setters. Same as `NAN_PROPERTY_GETTER` but you also get a `Local<Value>` `value` object to work with.
<a name="api_nan_property_enumerator"></a>
### NAN_PROPERTY_ENUMERATOR(cbname)
Use `NAN_PROPERTY_ENUMERATOR` to declare your V8 accessible property enumerators. You get an appropriately typed `args` object like the `args` argument to a `NAN_PROPERTY_GETTER` call.
You can use `NanReturnNull()`, `NanReturnEmptyString()`, `NanReturnUndefined()` and `NanReturnValue()` in a `NAN_PROPERTY_ENUMERATOR`.
<a name="api_nan_property_deleter"></a>
### NAN_PROPERTY_DELETER(cbname)
Use `NAN_PROPERTY_DELETER` to declare your V8 accessible property deleters. Same as `NAN_PROPERTY_GETTER`.
You can use `NanReturnNull()`, `NanReturnEmptyString()`, `NanReturnUndefined()` and `NanReturnValue()` in a `NAN_PROPERTY_DELETER`.
<a name="api_nan_property_query"></a>
### NAN_PROPERTY_QUERY(cbname)
Use `NAN_PROPERTY_QUERY` to declare your V8 accessible property queries. Same as `NAN_PROPERTY_GETTER`.
You can use `NanReturnNull()`, `NanReturnEmptyString()`, `NanReturnUndefined()` and `NanReturnValue()` in a `NAN_PROPERTY_QUERY`.
<a name="api_nan_index_getter"></a>
### NAN_INDEX_GETTER(cbname)
Use `NAN_INDEX_GETTER` to declare your V8 accessible index getters. You get a `uint32_t` `index` and an appropriately typed `args` object that can act similar to the `args` argument to a `NAN_METHOD` call.
You can use `NanReturnNull()`, `NanReturnEmptyString()`, `NanReturnUndefined()` and `NanReturnValue()` in a `NAN_INDEX_GETTER`.
<a name="api_nan_index_setter"></a>
### NAN_INDEX_SETTER(cbname)
Use `NAN_INDEX_SETTER` to declare your V8 accessible index setters. Same as `NAN_INDEX_GETTER` but you also get a `Local<Value>` `value` object to work with.
<a name="api_nan_index_enumerator"></a>
### NAN_INDEX_ENUMERATOR(cbname)
Use `NAN_INDEX_ENUMERATOR` to declare your V8 accessible index enumerators. You get an appropriately typed `args` object like the `args` argument to a `NAN_INDEX_GETTER` call.
You can use `NanReturnNull()`, `NanReturnEmptyString()`, `NanReturnUndefined()` and `NanReturnValue()` in a `NAN_INDEX_ENUMERATOR`.
<a name="api_nan_index_deleter"></a>
### NAN_INDEX_DELETER(cbname)
Use `NAN_INDEX_DELETER` to declare your V8 accessible index deleters. Same as `NAN_INDEX_GETTER`.
You can use `NanReturnNull()`, `NanReturnEmptyString()`, `NanReturnUndefined()` and `NanReturnValue()` in a `NAN_INDEX_DELETER`.
<a name="api_nan_index_query"></a>
### NAN_INDEX_QUERY(cbname)
Use `NAN_INDEX_QUERY` to declare your V8 accessible index queries. Same as `NAN_INDEX_GETTER`.
You can use `NanReturnNull()`, `NanReturnEmptyString()`, `NanReturnUndefined()` and `NanReturnValue()` in a `NAN_INDEX_QUERY`.
<a name="api_nan_gc_callback"></a>
### NAN_GC_CALLBACK(cbname)
Use `NAN_GC_CALLBACK` to declare your callbacks for `NanAddGCEpilogueCallback` and `NanAddGCPrologueCallback`. You get arguments `GCType type` and `GCCallbackFlags flags`.
```c++
static Persistent<Function> callback;
NAN_GC_CALLBACK(gcPrologueCallback) {
Local<Value> argv[] = {NanNew("prologue")};
NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(callback), 1, argv);
}
NAN_METHOD(Hook) {
NanAssignPersistent(callback, args[0].As<Function>());
NanAddGCPrologueCallback(gcPrologueCallback);
NanReturnValue(args.Holder());
}
```

<a name="api_nan_weak_callback"></a>
### NAN_WEAK_CALLBACK(cbname)
### NAN_WEAK_CALLBACK(callbackname)
Use `NAN_WEAK_CALLBACK` to define your V8 WeakReference callbacks. There is an argument object `const _NanWeakCallbackData<T, P> &data` allowing access to the weak object and the supplied parameter through its `GetValue` and `GetParameter` methods. You can even access the weak callback info object through the `GetCallbackInfo()`method, but you probably should not. `Revive()` keeps the weak object alive until the next GC round.
Expand Down
Loading

0 comments on commit fa84621

Please sign in to comment.