Initial commit
[yaffs-website] / node_modules / nan / doc / methods.md
1 ## JavaScript-accessible methods
2
3 A _template_ is a blueprint for JavaScript functions and objects in a context. You can use a template to wrap C++ functions and data structures within JavaScript objects so that they can be manipulated from JavaScript. See the V8 Embedders Guide section on [Templates](https://developers.google.com/v8/embed#templates) for further information.
4
5 In order to expose functionality to JavaScript via a template, you must provide it to V8 in a form that it understands. Across the versions of V8 supported by NAN, JavaScript-accessible method signatures vary widely, NAN fully abstracts method declaration and provides you with an interface that is similar to the most recent V8 API but is backward-compatible with older versions that still use the now-deceased `v8::Argument` type.
6
7 * **Method argument types**
8  - <a href="#api_nan_function_callback_info"><b><code>Nan::FunctionCallbackInfo</code></b></a>
9  - <a href="#api_nan_property_callback_info"><b><code>Nan::PropertyCallbackInfo</code></b></a>
10  - <a href="#api_nan_return_value"><b><code>Nan::ReturnValue</code></b></a>
11 * **Method declarations**
12  - <a href="#api_nan_method"><b>Method declaration</b></a>
13  - <a href="#api_nan_getter"><b>Getter declaration</b></a>
14  - <a href="#api_nan_setter"><b>Setter declaration</b></a>
15  - <a href="#api_nan_property_getter"><b>Property getter declaration</b></a>
16  - <a href="#api_nan_property_setter"><b>Property setter declaration</b></a>
17  - <a href="#api_nan_property_enumerator"><b>Property enumerator declaration</b></a>
18  - <a href="#api_nan_property_deleter"><b>Property deleter declaration</b></a>
19  - <a href="#api_nan_property_query"><b>Property query declaration</b></a>
20  - <a href="#api_nan_index_getter"><b>Index getter declaration</b></a>
21  - <a href="#api_nan_index_setter"><b>Index setter declaration</b></a>
22  - <a href="#api_nan_index_enumerator"><b>Index enumerator declaration</b></a>
23  - <a href="#api_nan_index_deleter"><b>Index deleter declaration</b></a>
24  - <a href="#api_nan_index_query"><b>Index query declaration</b></a>
25 * Method and template helpers
26  - <a href="#api_nan_set_method"><b><code>Nan::SetMethod()</code></b></a>
27  - <a href="#api_nan_set_prototype_method"><b><code>Nan::SetPrototypeMethod()</code></b></a>
28  - <a href="#api_nan_set_accessor"><b><code>Nan::SetAccessor()</code></b></a>
29  - <a href="#api_nan_set_named_property_handler"><b><code>Nan::SetNamedPropertyHandler()</code></b></a>
30  - <a href="#api_nan_set_indexed_property_handler"><b><code>Nan::SetIndexedPropertyHandler()</code></b></a>
31  - <a href="#api_nan_set_template"><b><code>Nan::SetTemplate()</code></b></a>
32  - <a href="#api_nan_set_prototype_template"><b><code>Nan::SetPrototypeTemplate()</code></b></a>
33  - <a href="#api_nan_set_instance_template"><b><code>Nan::SetInstanceTemplate()</code></b></a>
34  - <a href="#api_nan_set_call_handler"><b><code>Nan::SetCallHandler()</code></b></a>
35  - <a href="#api_nan_set_call_as_function_handler"><b><code>Nan::SetCallAsFunctionHandler()</code></b></a>
36
37 <a name="api_nan_function_callback_info"></a>
38 ### Nan::FunctionCallbackInfo
39
40 `Nan::FunctionCallbackInfo` should be used in place of [`v8::FunctionCallbackInfo`](https://v8docs.nodesource.com/io.js-3.0/dd/d0d/classv8_1_1_function_callback_info.html), even with older versions of Node where `v8::FunctionCallbackInfo` does not exist.
41
42 Definition:
43
44 ```c++
45 template<typename T> class FunctionCallbackInfo {
46  public:
47   ReturnValue<T> GetReturnValue() const;
48   v8::Local<v8::Function> Callee();
49   v8::Local<v8::Value> Data();
50   v8::Local<v8::Object> Holder();
51   bool IsConstructCall();
52   int Length() const;
53   v8::Local<v8::Value> operator[](int i) const;
54   v8::Local<v8::Object> This() const;
55   v8::Isolate *GetIsolate() const;
56 };
57 ```
58
59 See the [`v8::FunctionCallbackInfo`](https://v8docs.nodesource.com/io.js-3.0/dd/d0d/classv8_1_1_function_callback_info.html) documentation for usage details on these. See [`Nan::ReturnValue`](#api_nan_return_value) for further information on how to set a return value from methods.
60
61 <a name="api_nan_property_callback_info"></a>
62 ### Nan::PropertyCallbackInfo
63
64 `Nan::PropertyCallbackInfo` should be used in place of [`v8::PropertyCallbackInfo`](https://v8docs.nodesource.com/io.js-3.0/d7/dc5/classv8_1_1_property_callback_info.html), even with older versions of Node where `v8::PropertyCallbackInfo` does not exist.
65
66 Definition:
67
68 ```c++
69 template<typename T> class PropertyCallbackInfo : public PropertyCallbackInfoBase<T> {
70  public:
71   ReturnValue<T> GetReturnValue() const;
72   v8::Isolate* GetIsolate() const;
73   v8::Local<v8::Value> Data() const;
74   v8::Local<v8::Object> This() const;
75   v8::Local<v8::Object> Holder() const;
76 };
77 ```
78
79 See the [`v8::PropertyCallbackInfo`](https://v8docs.nodesource.com/io.js-3.0/d7/dc5/classv8_1_1_property_callback_info.html) documentation for usage details on these. See [`Nan::ReturnValue`](#api_nan_return_value) for further information on how to set a return value from property accessor methods.
80
81 <a name="api_nan_return_value"></a>
82 ### Nan::ReturnValue
83
84 `Nan::ReturnValue` is used in place of [`v8::ReturnValue`](https://v8docs.nodesource.com/io.js-3.0/da/da7/classv8_1_1_return_value.html) on both [`Nan::FunctionCallbackInfo`](#api_nan_function_callback_info) and [`Nan::PropertyCallbackInfo`](#api_nan_property_callback_info) as the return type of `GetReturnValue()`.
85
86 Example usage:
87
88 ```c++
89 void EmptyArray(const Nan::FunctionCallbackInfo<v8::Value>& info) {
90   info.GetReturnValue().Set(Nan::New<v8::Array>());
91 }
92 ```
93
94 Definition:
95
96 ```c++
97 template<typename T> class ReturnValue {
98  public:
99   // Handle setters
100   template <typename S> void Set(const v8::Local<S> &handle);
101   template <typename S> void Set(const Nan::Global<S> &handle);
102
103   // Fast primitive setters
104   void Set(bool value);
105   void Set(double i);
106   void Set(int32_t i);
107   void Set(uint32_t i);
108
109   // Fast JS primitive setters
110   void SetNull();
111   void SetUndefined();
112   void SetEmptyString();
113
114   // Convenience getter for isolate
115   v8::Isolate *GetIsolate() const;
116 };
117 ```
118
119 See the documentation on [`v8::ReturnValue`](https://v8docs.nodesource.com/io.js-3.0/da/da7/classv8_1_1_return_value.html) for further information on this.
120
121 <a name="api_nan_method"></a>
122 ### Method declaration
123
124 JavaScript-accessible methods should be declared with the following signature to form a `Nan::FunctionCallback`:
125
126 ```c++
127 typedef void(*FunctionCallback)(const FunctionCallbackInfo<v8::Value>&);
128 ```
129
130 Example:
131
132 ```c++
133 void MethodName(const Nan::FunctionCallbackInfo<v8::Value>& info) {
134   ...
135 }
136 ```
137
138 You do not need to declare a new `HandleScope` within a method as one is implicitly created for you.
139
140 **Example usage**
141
142 ```c++
143 // .h:
144 class Foo : public Nan::ObjectWrap {
145   ...
146
147   static void Bar(const Nan::FunctionCallbackInfo<v8::Value>& info);
148   static void Baz(const Nan::FunctionCallbackInfo<v8::Value>& info);
149 }
150
151
152 // .cc:
153 void Foo::Bar(const Nan::FunctionCallbackInfo<v8::Value>& info) {
154   ...
155 }
156
157 void Foo::Baz(const Nan::FunctionCallbackInfo<v8::Value>& info) {
158   ...
159 }
160 ```
161
162 A helper macro `NAN_METHOD(methodname)` exists, compatible with NAN v1 method declarations.
163
164 **Example usage with `NAN_METHOD(methodname)`**
165
166 ```c++
167 // .h:
168 class Foo : public Nan::ObjectWrap {
169   ...
170
171   static NAN_METHOD(Bar);
172   static NAN_METHOD(Baz);
173 }
174
175
176 // .cc:
177 NAN_METHOD(Foo::Bar) {
178   ...
179 }
180
181 NAN_METHOD(Foo::Baz) {
182   ...
183 }
184 ```
185
186 Use [`Nan::SetPrototypeMethod`](#api_nan_set_prototype_method) to attach a method to a JavaScript function prototype or [`Nan::SetMethod`](#api_nan_set_method) to attach a method directly on a JavaScript object.
187
188 <a name="api_nan_getter"></a>
189 ### Getter declaration
190
191 JavaScript-accessible getters should be declared with the following signature to form a `Nan::GetterCallback`:
192
193 ```c++
194 typedef void(*GetterCallback)(v8::Local<v8::String>,
195                               const PropertyCallbackInfo<v8::Value>&);
196 ```
197
198 Example:
199
200 ```c++
201 void GetterName(v8::Local<v8::String> property,
202                 const Nan::PropertyCallbackInfo<v8::Value>& info) {
203   ...
204 }
205 ```
206
207 You do not need to declare a new `HandleScope` within a getter as one is implicitly created for you.
208
209 A helper macro `NAN_GETTER(methodname)` exists, compatible with NAN v1 method declarations.
210
211 Also see the V8 Embedders Guide documentation on [Accessors](https://developers.google.com/v8/embed#accesssors).
212
213 <a name="api_nan_setter"></a>
214 ### Setter declaration
215
216 JavaScript-accessible setters should be declared with the following signature to form a <b><code>Nan::SetterCallback</code></b>:
217
218 ```c++
219 typedef void(*SetterCallback)(v8::Local<v8::String>,
220                               v8::Local<v8::Value>,
221                               const PropertyCallbackInfo<void>&);
222 ```
223
224 Example:
225
226 ```c++
227 void SetterName(v8::Local<v8::String> property,
228                 v8::Local<v8::Value> value,
229                 const Nan::PropertyCallbackInfo<void>& info) {
230   ...
231 }
232 ```
233
234 You do not need to declare a new `HandleScope` within a setter as one is implicitly created for you.
235
236 A helper macro `NAN_SETTER(methodname)` exists, compatible with NAN v1 method declarations.
237
238 Also see the V8 Embedders Guide documentation on [Accessors](https://developers.google.com/v8/embed#accesssors).
239
240 <a name="api_nan_property_getter"></a>
241 ### Property getter declaration
242
243 JavaScript-accessible property getters should be declared with the following signature to form a <b><code>Nan::PropertyGetterCallback</code></b>:
244
245 ```c++
246 typedef void(*PropertyGetterCallback)(v8::Local<v8::String>,
247                                       const PropertyCallbackInfo<v8::Value>&);
248 ```
249
250 Example:
251
252 ```c++
253 void PropertyGetterName(v8::Local<v8::String> property,
254                         const Nan::PropertyCallbackInfo<v8::Value>& info) {
255   ...
256 }
257 ```
258
259 You do not need to declare a new `HandleScope` within a property getter as one is implicitly created for you.
260
261 A helper macro `NAN_PROPERTY_GETTER(methodname)` exists, compatible with NAN v1 method declarations.
262
263 Also see the V8 Embedders Guide documentation on named property [Interceptors](https://developers.google.com/v8/embed#interceptors).
264
265 <a name="api_nan_property_setter"></a>
266 ### Property setter declaration
267
268 JavaScript-accessible property setters should be declared with the following signature to form a <b><code>Nan::PropertySetterCallback</code></b>:
269
270 ```c++
271 typedef void(*PropertySetterCallback)(v8::Local<v8::String>,
272                                       v8::Local<v8::Value>,
273                                       const PropertyCallbackInfo<v8::Value>&);
274 ```
275
276 Example:
277
278 ```c++
279 void PropertySetterName(v8::Local<v8::String> property,
280                         v8::Local<v8::Value> value,
281                         const Nan::PropertyCallbackInfo<v8::Value>& info);
282 ```
283
284 You do not need to declare a new `HandleScope` within a property setter as one is implicitly created for you.
285
286 A helper macro `NAN_PROPERTY_SETTER(methodname)` exists, compatible with NAN v1 method declarations.
287
288 Also see the V8 Embedders Guide documentation on named property [Interceptors](https://developers.google.com/v8/embed#interceptors).
289
290 <a name="api_nan_property_enumerator"></a>
291 ### Property enumerator declaration
292
293 JavaScript-accessible property enumerators should be declared with the following signature to form a <b><code>Nan::PropertyEnumeratorCallback</code></b>:
294
295 ```c++
296 typedef void(*PropertyEnumeratorCallback)(const PropertyCallbackInfo<v8::Array>&);
297 ```
298
299 Example:
300
301 ```c++
302 void PropertyEnumeratorName(const Nan::PropertyCallbackInfo<v8::Array>& info);
303 ```
304
305 You do not need to declare a new `HandleScope` within a property enumerator as one is implicitly created for you.
306
307 A helper macro `NAN_PROPERTY_ENUMERATOR(methodname)` exists, compatible with NAN v1 method declarations.
308
309 Also see the V8 Embedders Guide documentation on named property [Interceptors](https://developers.google.com/v8/embed#interceptors).
310
311 <a name="api_nan_property_deleter"></a>
312 ### Property deleter declaration
313
314 JavaScript-accessible property deleters should be declared with the following signature to form a <b><code>Nan::PropertyDeleterCallback</code></b>:
315
316 ```c++
317 typedef void(*PropertyDeleterCallback)(v8::Local<v8::String>,
318                                        const PropertyCallbackInfo<v8::Boolean>&);
319 ```
320
321 Example:
322
323 ```c++
324 void PropertyDeleterName(v8::Local<v8::String> property,
325                          const Nan::PropertyCallbackInfo<v8::Boolean>& info);
326 ```
327
328 You do not need to declare a new `HandleScope` within a property deleter as one is implicitly created for you.
329
330 A helper macro `NAN_PROPERTY_DELETER(methodname)` exists, compatible with NAN v1 method declarations.
331
332 Also see the V8 Embedders Guide documentation on named property [Interceptors](https://developers.google.com/v8/embed#interceptors).
333
334 <a name="api_nan_property_query"></a>
335 ### Property query declaration
336
337 JavaScript-accessible property query methods should be declared with the following signature to form a <b><code>Nan::PropertyQueryCallback</code></b>:
338
339 ```c++
340 typedef void(*PropertyQueryCallback)(v8::Local<v8::String>,
341                                      const PropertyCallbackInfo<v8::Integer>&);
342 ```
343
344 Example:
345
346 ```c++
347 void PropertyQueryName(v8::Local<v8::String> property,
348                        const Nan::PropertyCallbackInfo<v8::Integer>& info);
349 ```
350
351 You do not need to declare a new `HandleScope` within a property query method as one is implicitly created for you.
352
353 A helper macro `NAN_PROPERTY_QUERY(methodname)` exists, compatible with NAN v1 method declarations.
354
355 Also see the V8 Embedders Guide documentation on named property [Interceptors](https://developers.google.com/v8/embed#interceptors).
356
357 <a name="api_nan_index_getter"></a>
358 ### Index getter declaration
359
360 JavaScript-accessible index getter methods should be declared with the following signature to form a <b><code>Nan::IndexGetterCallback</code></b>:
361
362 ```c++
363 typedef void(*IndexGetterCallback)(uint32_t,
364                                    const PropertyCallbackInfo<v8::Value>&);
365 ```
366
367 Example:
368
369 ```c++
370 void IndexGetterName(uint32_t index, const PropertyCallbackInfo<v8::Value>& info);
371 ```
372
373 You do not need to declare a new `HandleScope` within a index getter as one is implicitly created for you.
374
375 A helper macro `NAN_INDEX_GETTER(methodname)` exists, compatible with NAN v1 method declarations.
376
377 Also see the V8 Embedders Guide documentation on indexed property [Interceptors](https://developers.google.com/v8/embed#interceptors).
378
379 <a name="api_nan_index_setter"></a>
380 ### Index setter declaration
381
382 JavaScript-accessible index setter methods should be declared with the following signature to form a <b><code>Nan::IndexSetterCallback</code></b>:
383
384 ```c++
385 typedef void(*IndexSetterCallback)(uint32_t,
386                                    v8::Local<v8::Value>,
387                                    const PropertyCallbackInfo<v8::Value>&);
388 ```
389
390 Example:
391
392 ```c++
393 void IndexSetterName(uint32_t index,
394                      v8::Local<v8::Value> value,
395                      const PropertyCallbackInfo<v8::Value>& info);
396 ```
397
398 You do not need to declare a new `HandleScope` within a index setter as one is implicitly created for you.
399
400 A helper macro `NAN_INDEX_SETTER(methodname)` exists, compatible with NAN v1 method declarations.
401
402 Also see the V8 Embedders Guide documentation on indexed property [Interceptors](https://developers.google.com/v8/embed#interceptors).
403
404 <a name="api_nan_index_enumerator"></a>
405 ### Index enumerator declaration
406
407 JavaScript-accessible index enumerator methods should be declared with the following signature to form a <b><code>Nan::IndexEnumeratorCallback</code></b>:
408
409 ```c++
410 typedef void(*IndexEnumeratorCallback)(const PropertyCallbackInfo<v8::Array>&);
411 ```
412
413 Example:
414
415 ```c++
416 void IndexEnumeratorName(const PropertyCallbackInfo<v8::Array>& info);
417 ```
418
419 You do not need to declare a new `HandleScope` within a index enumerator as one is implicitly created for you.
420
421 A helper macro `NAN_INDEX_ENUMERATOR(methodname)` exists, compatible with NAN v1 method declarations.
422
423 Also see the V8 Embedders Guide documentation on indexed property [Interceptors](https://developers.google.com/v8/embed#interceptors).
424
425 <a name="api_nan_index_deleter"></a>
426 ### Index deleter declaration
427
428 JavaScript-accessible index deleter methods should be declared with the following signature to form a <b><code>Nan::IndexDeleterCallback</code></b>:
429
430 ```c++
431 typedef void(*IndexDeleterCallback)(uint32_t,
432                                     const PropertyCallbackInfo<v8::Boolean>&);
433 ```
434
435 Example:
436
437 ```c++
438 void IndexDeleterName(uint32_t index, const PropertyCallbackInfo<v8::Boolean>& info);
439 ```
440
441 You do not need to declare a new `HandleScope` within a index deleter as one is implicitly created for you.
442
443 A helper macro `NAN_INDEX_DELETER(methodname)` exists, compatible with NAN v1 method declarations.
444
445 Also see the V8 Embedders Guide documentation on indexed property [Interceptors](https://developers.google.com/v8/embed#interceptors).
446
447 <a name="api_nan_index_query"></a>
448 ### Index query declaration
449
450 JavaScript-accessible index query methods should be declared with the following signature to form a <b><code>Nan::IndexQueryCallback</code></b>:
451
452 ```c++
453 typedef void(*IndexQueryCallback)(uint32_t,
454                                   const PropertyCallbackInfo<v8::Integer>&);
455 ```
456
457 Example:
458
459 ```c++
460 void IndexQueryName(uint32_t index, const PropertyCallbackInfo<v8::Integer>& info);
461 ```
462
463 You do not need to declare a new `HandleScope` within a index query method as one is implicitly created for you.
464
465 A helper macro `NAN_INDEX_QUERY(methodname)` exists, compatible with NAN v1 method declarations.
466
467 Also see the V8 Embedders Guide documentation on indexed property [Interceptors](https://developers.google.com/v8/embed#interceptors).
468
469 <a name="api_nan_set_method"></a>
470 ### Nan::SetMethod()
471
472 Sets a method with a given name directly on a JavaScript object where the method has the `Nan::FunctionCallback` signature (see <a href="#api_nan_method">Method declaration</a>).
473
474 Signature:
475
476 ```c++
477 void Nan::SetMethod(v8::Local<v8::Object> recv,
478                     const char *name,
479                     Nan::FunctionCallback callback)
480 void Nan::SetMethod(v8::Local<v8::Template> templ,
481                     const char *name,
482                     Nan::FunctionCallback callback)
483 ```
484
485 <a name="api_nan_set_prototype_method"></a>
486 ### Nan::SetPrototypeMethod()
487
488 Sets a method with a given name on a `FunctionTemplate`'s prototype where the method has the `Nan::FunctionCallback` signature (see <a href="#api_nan_method">Method declaration</a>).
489
490 Signature:
491
492 ```c++
493 void Nan::SetPrototypeMethod(v8::Local<v8::FunctionTemplate> recv,
494                              const char* name,
495                              Nan::FunctionCallback callback)
496 ```
497
498 <a name="api_nan_set_accessor"></a>
499 ### Nan::SetAccessor()
500
501 Sets getters and setters for a property with a given name on an `ObjectTemplate` or a plain `Object`. Accepts getters with the `Nan::GetterCallback` signature (see <a href="#api_nan_getter">Getter declaration</a>) and setters with the `Nan::SetterCallback` signature (see <a href="#api_nan_setter">Setter declaration</a>).
502
503 Signature:
504
505 ```c++
506 void SetAccessor(v8::Local<v8::ObjectTemplate> tpl,
507                  v8::Local<v8::String> name,
508                  Nan::GetterCallback getter,
509                  Nan::SetterCallback setter = 0,
510                  v8::Local<v8::Value> data = v8::Local<v8::Value>(),
511                  v8::AccessControl settings = v8::DEFAULT,
512                  v8::PropertyAttribute attribute = v8::None,
513                  imp::Sig signature = imp::Sig());
514 bool SetAccessor(v8::Local<v8::Object> obj,
515                  v8::Local<v8::String> name,
516                  Nan::GetterCallback getter,
517                  Nan::SetterCallback setter = 0,
518                  v8::Local<v8::Value> data = v8::Local<v8::Value>(),
519                  v8::AccessControl settings = v8::DEFAULT,
520                  v8::PropertyAttribute attribute = v8::None)
521 ```
522
523 See the V8 [`ObjectTemplate#SetAccessor()`](https://v8docs.nodesource.com/io.js-3.0/db/d5f/classv8_1_1_object_template.html#aa90691622f01269c6a11391d372ca0c5) and [`Object#SetAccessor()`](https://v8docs.nodesource.com/io.js-3.0/db/d85/classv8_1_1_object.html#a3f9dee085f5ec346465f1dc924325043) for further information about how to use `Nan::SetAccessor()`.
524
525 <a name="api_nan_set_named_property_handler"></a>
526 ### Nan::SetNamedPropertyHandler()
527
528 Sets named property getters, setters, query, deleter and enumerator methods on an `ObjectTemplate`. Accepts:
529
530 * Property getters with the `Nan::PropertyGetterCallback` signature (see <a href="#api_nan_property_getter">Property getter declaration</a>)
531 * Property setters with the `Nan::PropertySetterCallback` signature (see <a href="#api_nan_property_setter">Property setter declaration</a>)
532 * Property query methods with the `Nan::PropertyQueryCallback` signature (see <a href="#api_nan_property_query">Property query declaration</a>)
533 * Property deleters with the `Nan::PropertyDeleterCallback` signature (see <a href="#api_nan_property_deleter">Property deleter declaration</a>)
534 * Property enumerators with the `Nan::PropertyEnumeratorCallback` signature (see <a href="#api_nan_property_enumerator">Property enumerator declaration</a>)
535
536 Signature:
537
538 ```c++
539 void SetNamedPropertyHandler(v8::Local<v8::ObjectTemplate> tpl,
540                              Nan::PropertyGetterCallback getter,
541                              Nan::PropertySetterCallback setter = 0,
542                              Nan::PropertyQueryCallback query = 0,
543                              Nan::PropertyDeleterCallback deleter = 0,
544                              Nan::PropertyEnumeratorCallback enumerator = 0,
545                              v8::Local<v8::Value> data = v8::Local<v8::Value>())
546 ```
547
548 See the V8 [`ObjectTemplate#SetNamedPropertyHandler()`](https://v8docs.nodesource.com/io.js-3.0/db/d5f/classv8_1_1_object_template.html#a34d1cc45b642cd131706663801aadd76) for further information about how to use `Nan::SetNamedPropertyHandler()`.
549
550 <a name="api_nan_set_indexed_property_handler"></a>
551 ### Nan::SetIndexedPropertyHandler()
552
553 Sets indexed property getters, setters, query, deleter and enumerator methods on an `ObjectTemplate`. Accepts:
554
555 * Indexed property getters with the `Nan::IndexGetterCallback` signature (see <a href="#api_nan_index_getter">Index getter declaration</a>)
556 * Indexed property setters with the `Nan::IndexSetterCallback` signature (see <a href="#api_nan_index_setter">Index setter declaration</a>)
557 * Indexed property query methods with the `Nan::IndexQueryCallback` signature (see <a href="#api_nan_index_query">Index query declaration</a>)
558 * Indexed property deleters with the `Nan::IndexDeleterCallback` signature (see <a href="#api_nan_index_deleter">Index deleter declaration</a>)
559 * Indexed property enumerators with the `Nan::IndexEnumeratorCallback` signature (see <a href="#api_nan_index_enumerator">Index enumerator declaration</a>)
560
561 Signature:
562
563 ```c++
564 void SetIndexedPropertyHandler(v8::Local<v8::ObjectTemplate> tpl,
565                                Nan::IndexGetterCallback getter,
566                                Nan::IndexSetterCallback setter = 0,
567                                Nan::IndexQueryCallback query = 0,
568                                Nan::IndexDeleterCallback deleter = 0,
569                                Nan::IndexEnumeratorCallback enumerator = 0,
570                                v8::Local<v8::Value> data = v8::Local<v8::Value>())
571 ```
572
573 See the V8 [`ObjectTemplate#SetIndexedPropertyHandler()`](https://v8docs.nodesource.com/io.js-3.0/db/d5f/classv8_1_1_object_template.html#ac0234cbede45d51778bb5f6a32a9e125) for further information about how to use `Nan::SetIndexedPropertyHandler()`.
574
575 <a name="api_nan_set_template"></a>
576 ### Nan::SetTemplate()
577
578 Adds properties on an `Object`'s or `Function`'s template.
579
580 Signature:
581
582 ```c++
583 void Nan::SetTemplate(v8::Local<v8::Template> templ,
584                       const char *name,
585                       v8::Local<v8::Data> value);
586 void Nan::SetTemplate(v8::Local<v8::Template> templ,
587                       v8::Local<v8::String> name,
588                       v8::Local<v8::Data> value,
589                       v8::PropertyAttribute attributes)
590 ```
591
592 Calls the `Template`'s [`Set()`](https://v8docs.nodesource.com/io.js-3.0/db/df7/classv8_1_1_template.html#a2db6a56597bf23c59659c0659e564ddf).
593
594 <a name="api_nan_set_prototype_template"></a>
595 ### Nan::SetPrototypeTemplate()
596
597 Adds properties on an `Object`'s or `Function`'s prototype template.
598
599 Signature:
600
601 ```c++
602 void Nan::SetPrototypeTemplate(v8::Local<v8::FunctionTemplate> templ,
603                                const char *name,
604                                v8::Local<v8::Data> value);
605 void Nan::SetPrototypeTemplate(v8::Local<v8::FunctionTemplate> templ,
606                                v8::Local<v8::String> name,
607                                v8::Local<v8::Data> value,
608                                v8::PropertyAttribute attributes)
609 ```
610
611 Calls the `FunctionTemplate`'s _PrototypeTemplate's_ [`Set()`](https://v8docs.nodesource.com/io.js-3.0/db/df7/classv8_1_1_template.html#a2db6a56597bf23c59659c0659e564ddf).
612
613 <a name="api_nan_set_instance_template"></a>
614 ### Nan::SetInstanceTemplate()
615
616 Use to add instance properties on `FunctionTemplate`'s.
617
618 Signature:
619
620 ```c++
621 void Nan::SetInstanceTemplate(v8::Local<v8::FunctionTemplate> templ,
622                               const char *name,
623                               v8::Local<v8::Data> value);
624 void Nan::SetInstanceTemplate(v8::Local<v8::FunctionTemplate> templ,
625                               v8::Local<v8::String> name,
626                               v8::Local<v8::Data> value,
627                               v8::PropertyAttribute attributes)
628 ```
629
630 Calls the `FunctionTemplate`'s _InstanceTemplate's_ [`Set()`](https://v8docs.nodesource.com/io.js-3.0/db/df7/classv8_1_1_template.html#a2db6a56597bf23c59659c0659e564ddf).
631
632 <a name="api_nan_set_call_handler"></a>
633 ### Nan::SetCallHandler()
634
635 Set the call-handler callback for a `v8::FunctionTemplate`.
636 This callback is called whenever the function created from this FunctionTemplate is called.
637
638 Signature:
639
640 ```c++
641 void Nan::SetCallHandler(v8::Local<v8::FunctionTemplate> templ, Nan::FunctionCallback callback, v8::Local<v8::Value> data = v8::Local<v8::Value>())
642 ```
643
644 Calls the `FunctionTemplate`'s [`SetCallHandler()`](https://v8docs.nodesource.com/io.js-3.0/d8/d83/classv8_1_1_function_template.html#a26cf14e36aa1a47091b98536d08ea821).
645
646 <a name="api_nan_set_call_as_function_handler"></a>
647 ### Nan::SetCallAsFunctionHandler()
648
649 Sets the callback to be used when calling instances created from the `v8::ObjectTemplate` as a function.
650 If no callback is set, instances behave like normal JavaScript objects that cannot be called as a function.
651
652 Signature:
653
654 ```c++
655 void Nan::SetCallAsFunctionHandler(v8::Local<v8::ObjectTemplate> templ, Nan::FunctionCallback callback, v8::Local<v8::Value> data = v8::Local<v8::Value>())
656 ```
657
658 Calls the `ObjectTemplate`'s [`SetCallAsFunctionHandler()`](https://v8docs.nodesource.com/io.js-3.0/db/d5f/classv8_1_1_object_template.html#ae0a0e72fb0c5e5f32e255fe5bcc7316a).
659