Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

methods.md 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. ## JavaScript-accessible methods
  2. 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://github.com/v8/v8/wiki/Embedder%27s-Guide#templates) for further information.
  3. 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.
  4. * **Method argument types**
  5. - <a href="#api_nan_function_callback_info"><b><code>Nan::FunctionCallbackInfo</code></b></a>
  6. - <a href="#api_nan_property_callback_info"><b><code>Nan::PropertyCallbackInfo</code></b></a>
  7. - <a href="#api_nan_return_value"><b><code>Nan::ReturnValue</code></b></a>
  8. * **Method declarations**
  9. - <a href="#api_nan_method"><b>Method declaration</b></a>
  10. - <a href="#api_nan_getter"><b>Getter declaration</b></a>
  11. - <a href="#api_nan_setter"><b>Setter declaration</b></a>
  12. - <a href="#api_nan_property_getter"><b>Property getter declaration</b></a>
  13. - <a href="#api_nan_property_setter"><b>Property setter declaration</b></a>
  14. - <a href="#api_nan_property_enumerator"><b>Property enumerator declaration</b></a>
  15. - <a href="#api_nan_property_deleter"><b>Property deleter declaration</b></a>
  16. - <a href="#api_nan_property_query"><b>Property query declaration</b></a>
  17. - <a href="#api_nan_index_getter"><b>Index getter declaration</b></a>
  18. - <a href="#api_nan_index_setter"><b>Index setter declaration</b></a>
  19. - <a href="#api_nan_index_enumerator"><b>Index enumerator declaration</b></a>
  20. - <a href="#api_nan_index_deleter"><b>Index deleter declaration</b></a>
  21. - <a href="#api_nan_index_query"><b>Index query declaration</b></a>
  22. * Method and template helpers
  23. - <a href="#api_nan_set_method"><b><code>Nan::SetMethod()</code></b></a>
  24. - <a href="#api_nan_set_prototype_method"><b><code>Nan::SetPrototypeMethod()</code></b></a>
  25. - <a href="#api_nan_set_accessor"><b><code>Nan::SetAccessor()</code></b></a>
  26. - <a href="#api_nan_set_named_property_handler"><b><code>Nan::SetNamedPropertyHandler()</code></b></a>
  27. - <a href="#api_nan_set_indexed_property_handler"><b><code>Nan::SetIndexedPropertyHandler()</code></b></a>
  28. - <a href="#api_nan_set_template"><b><code>Nan::SetTemplate()</code></b></a>
  29. - <a href="#api_nan_set_prototype_template"><b><code>Nan::SetPrototypeTemplate()</code></b></a>
  30. - <a href="#api_nan_set_instance_template"><b><code>Nan::SetInstanceTemplate()</code></b></a>
  31. - <a href="#api_nan_set_call_handler"><b><code>Nan::SetCallHandler()</code></b></a>
  32. - <a href="#api_nan_set_call_as_function_handler"><b><code>Nan::SetCallAsFunctionHandler()</code></b></a>
  33. <a name="api_nan_function_callback_info"></a>
  34. ### Nan::FunctionCallbackInfo
  35. `Nan::FunctionCallbackInfo` should be used in place of [`v8::FunctionCallbackInfo`](https://v8docs.nodesource.com/node-8.11/dd/d0d/classv8_1_1_function_callback_info.html), even with older versions of Node where `v8::FunctionCallbackInfo` does not exist.
  36. Definition:
  37. ```c++
  38. template<typename T> class FunctionCallbackInfo {
  39. public:
  40. ReturnValue<T> GetReturnValue() const;
  41. v8::Local<v8::Function> Callee(); // NOTE: Not available in NodeJS >= 10.0.0
  42. v8::Local<v8::Value> Data();
  43. v8::Local<v8::Object> Holder();
  44. bool IsConstructCall();
  45. int Length() const;
  46. v8::Local<v8::Value> operator[](int i) const;
  47. v8::Local<v8::Object> This() const;
  48. v8::Isolate *GetIsolate() const;
  49. };
  50. ```
  51. See the [`v8::FunctionCallbackInfo`](https://v8docs.nodesource.com/node-8.11/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.
  52. **Note:** `FunctionCallbackInfo::Callee` is removed in Node.js after `10.0.0` because it is was deprecated in V8. Consider using `info.Data()` to pass any information you need.
  53. <a name="api_nan_property_callback_info"></a>
  54. ### Nan::PropertyCallbackInfo
  55. `Nan::PropertyCallbackInfo` should be used in place of [`v8::PropertyCallbackInfo`](https://v8docs.nodesource.com/node-8.11/d7/dc5/classv8_1_1_property_callback_info.html), even with older versions of Node where `v8::PropertyCallbackInfo` does not exist.
  56. Definition:
  57. ```c++
  58. template<typename T> class PropertyCallbackInfo : public PropertyCallbackInfoBase<T> {
  59. public:
  60. ReturnValue<T> GetReturnValue() const;
  61. v8::Isolate* GetIsolate() const;
  62. v8::Local<v8::Value> Data() const;
  63. v8::Local<v8::Object> This() const;
  64. v8::Local<v8::Object> Holder() const;
  65. };
  66. ```
  67. See the [`v8::PropertyCallbackInfo`](https://v8docs.nodesource.com/node-8.11/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.
  68. <a name="api_nan_return_value"></a>
  69. ### Nan::ReturnValue
  70. `Nan::ReturnValue` is used in place of [`v8::ReturnValue`](https://v8docs.nodesource.com/node-8.11/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()`.
  71. Example usage:
  72. ```c++
  73. void EmptyArray(const Nan::FunctionCallbackInfo<v8::Value>& info) {
  74. info.GetReturnValue().Set(Nan::New<v8::Array>());
  75. }
  76. ```
  77. Definition:
  78. ```c++
  79. template<typename T> class ReturnValue {
  80. public:
  81. // Handle setters
  82. template <typename S> void Set(const v8::Local<S> &handle);
  83. template <typename S> void Set(const Nan::Global<S> &handle);
  84. // Fast primitive setters
  85. void Set(bool value);
  86. void Set(double i);
  87. void Set(int32_t i);
  88. void Set(uint32_t i);
  89. // Fast JS primitive setters
  90. void SetNull();
  91. void SetUndefined();
  92. void SetEmptyString();
  93. // Convenience getter for isolate
  94. v8::Isolate *GetIsolate() const;
  95. };
  96. ```
  97. See the documentation on [`v8::ReturnValue`](https://v8docs.nodesource.com/node-8.11/da/da7/classv8_1_1_return_value.html) for further information on this.
  98. <a name="api_nan_method"></a>
  99. ### Method declaration
  100. JavaScript-accessible methods should be declared with the following signature to form a `Nan::FunctionCallback`:
  101. ```c++
  102. typedef void(*FunctionCallback)(const FunctionCallbackInfo<v8::Value>&);
  103. ```
  104. Example:
  105. ```c++
  106. void MethodName(const Nan::FunctionCallbackInfo<v8::Value>& info) {
  107. ...
  108. }
  109. ```
  110. You do not need to declare a new `HandleScope` within a method as one is implicitly created for you.
  111. **Example usage**
  112. ```c++
  113. // .h:
  114. class Foo : public Nan::ObjectWrap {
  115. ...
  116. static void Bar(const Nan::FunctionCallbackInfo<v8::Value>& info);
  117. static void Baz(const Nan::FunctionCallbackInfo<v8::Value>& info);
  118. }
  119. // .cc:
  120. void Foo::Bar(const Nan::FunctionCallbackInfo<v8::Value>& info) {
  121. ...
  122. }
  123. void Foo::Baz(const Nan::FunctionCallbackInfo<v8::Value>& info) {
  124. ...
  125. }
  126. ```
  127. A helper macro `NAN_METHOD(methodname)` exists, compatible with NAN v1 method declarations.
  128. **Example usage with `NAN_METHOD(methodname)`**
  129. ```c++
  130. // .h:
  131. class Foo : public Nan::ObjectWrap {
  132. ...
  133. static NAN_METHOD(Bar);
  134. static NAN_METHOD(Baz);
  135. }
  136. // .cc:
  137. NAN_METHOD(Foo::Bar) {
  138. ...
  139. }
  140. NAN_METHOD(Foo::Baz) {
  141. ...
  142. }
  143. ```
  144. 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.
  145. <a name="api_nan_getter"></a>
  146. ### Getter declaration
  147. JavaScript-accessible getters should be declared with the following signature to form a `Nan::GetterCallback`:
  148. ```c++
  149. typedef void(*GetterCallback)(v8::Local<v8::String>,
  150. const PropertyCallbackInfo<v8::Value>&);
  151. ```
  152. Example:
  153. ```c++
  154. void GetterName(v8::Local<v8::String> property,
  155. const Nan::PropertyCallbackInfo<v8::Value>& info) {
  156. ...
  157. }
  158. ```
  159. You do not need to declare a new `HandleScope` within a getter as one is implicitly created for you.
  160. A helper macro `NAN_GETTER(methodname)` exists, compatible with NAN v1 method declarations.
  161. Also see the V8 Embedders Guide documentation on [Accessors](https://developers.google.com/v8/embed#accesssors).
  162. <a name="api_nan_setter"></a>
  163. ### Setter declaration
  164. JavaScript-accessible setters should be declared with the following signature to form a <b><code>Nan::SetterCallback</code></b>:
  165. ```c++
  166. typedef void(*SetterCallback)(v8::Local<v8::String>,
  167. v8::Local<v8::Value>,
  168. const PropertyCallbackInfo<void>&);
  169. ```
  170. Example:
  171. ```c++
  172. void SetterName(v8::Local<v8::String> property,
  173. v8::Local<v8::Value> value,
  174. const Nan::PropertyCallbackInfo<void>& info) {
  175. ...
  176. }
  177. ```
  178. You do not need to declare a new `HandleScope` within a setter as one is implicitly created for you.
  179. A helper macro `NAN_SETTER(methodname)` exists, compatible with NAN v1 method declarations.
  180. Also see the V8 Embedders Guide documentation on [Accessors](https://developers.google.com/v8/embed#accesssors).
  181. <a name="api_nan_property_getter"></a>
  182. ### Property getter declaration
  183. JavaScript-accessible property getters should be declared with the following signature to form a <b><code>Nan::PropertyGetterCallback</code></b>:
  184. ```c++
  185. typedef void(*PropertyGetterCallback)(v8::Local<v8::String>,
  186. const PropertyCallbackInfo<v8::Value>&);
  187. ```
  188. Example:
  189. ```c++
  190. void PropertyGetterName(v8::Local<v8::String> property,
  191. const Nan::PropertyCallbackInfo<v8::Value>& info) {
  192. ...
  193. }
  194. ```
  195. You do not need to declare a new `HandleScope` within a property getter as one is implicitly created for you.
  196. A helper macro `NAN_PROPERTY_GETTER(methodname)` exists, compatible with NAN v1 method declarations.
  197. Also see the V8 Embedders Guide documentation on named property [Interceptors](https://developers.google.com/v8/embed#interceptors).
  198. <a name="api_nan_property_setter"></a>
  199. ### Property setter declaration
  200. JavaScript-accessible property setters should be declared with the following signature to form a <b><code>Nan::PropertySetterCallback</code></b>:
  201. ```c++
  202. typedef void(*PropertySetterCallback)(v8::Local<v8::String>,
  203. v8::Local<v8::Value>,
  204. const PropertyCallbackInfo<v8::Value>&);
  205. ```
  206. Example:
  207. ```c++
  208. void PropertySetterName(v8::Local<v8::String> property,
  209. v8::Local<v8::Value> value,
  210. const Nan::PropertyCallbackInfo<v8::Value>& info);
  211. ```
  212. You do not need to declare a new `HandleScope` within a property setter as one is implicitly created for you.
  213. A helper macro `NAN_PROPERTY_SETTER(methodname)` exists, compatible with NAN v1 method declarations.
  214. Also see the V8 Embedders Guide documentation on named property [Interceptors](https://developers.google.com/v8/embed#interceptors).
  215. <a name="api_nan_property_enumerator"></a>
  216. ### Property enumerator declaration
  217. JavaScript-accessible property enumerators should be declared with the following signature to form a <b><code>Nan::PropertyEnumeratorCallback</code></b>:
  218. ```c++
  219. typedef void(*PropertyEnumeratorCallback)(const PropertyCallbackInfo<v8::Array>&);
  220. ```
  221. Example:
  222. ```c++
  223. void PropertyEnumeratorName(const Nan::PropertyCallbackInfo<v8::Array>& info);
  224. ```
  225. You do not need to declare a new `HandleScope` within a property enumerator as one is implicitly created for you.
  226. A helper macro `NAN_PROPERTY_ENUMERATOR(methodname)` exists, compatible with NAN v1 method declarations.
  227. Also see the V8 Embedders Guide documentation on named property [Interceptors](https://developers.google.com/v8/embed#interceptors).
  228. <a name="api_nan_property_deleter"></a>
  229. ### Property deleter declaration
  230. JavaScript-accessible property deleters should be declared with the following signature to form a <b><code>Nan::PropertyDeleterCallback</code></b>:
  231. ```c++
  232. typedef void(*PropertyDeleterCallback)(v8::Local<v8::String>,
  233. const PropertyCallbackInfo<v8::Boolean>&);
  234. ```
  235. Example:
  236. ```c++
  237. void PropertyDeleterName(v8::Local<v8::String> property,
  238. const Nan::PropertyCallbackInfo<v8::Boolean>& info);
  239. ```
  240. You do not need to declare a new `HandleScope` within a property deleter as one is implicitly created for you.
  241. A helper macro `NAN_PROPERTY_DELETER(methodname)` exists, compatible with NAN v1 method declarations.
  242. Also see the V8 Embedders Guide documentation on named property [Interceptors](https://developers.google.com/v8/embed#interceptors).
  243. <a name="api_nan_property_query"></a>
  244. ### Property query declaration
  245. JavaScript-accessible property query methods should be declared with the following signature to form a <b><code>Nan::PropertyQueryCallback</code></b>:
  246. ```c++
  247. typedef void(*PropertyQueryCallback)(v8::Local<v8::String>,
  248. const PropertyCallbackInfo<v8::Integer>&);
  249. ```
  250. Example:
  251. ```c++
  252. void PropertyQueryName(v8::Local<v8::String> property,
  253. const Nan::PropertyCallbackInfo<v8::Integer>& info);
  254. ```
  255. You do not need to declare a new `HandleScope` within a property query method as one is implicitly created for you.
  256. A helper macro `NAN_PROPERTY_QUERY(methodname)` exists, compatible with NAN v1 method declarations.
  257. Also see the V8 Embedders Guide documentation on named property [Interceptors](https://developers.google.com/v8/embed#interceptors).
  258. <a name="api_nan_index_getter"></a>
  259. ### Index getter declaration
  260. JavaScript-accessible index getter methods should be declared with the following signature to form a <b><code>Nan::IndexGetterCallback</code></b>:
  261. ```c++
  262. typedef void(*IndexGetterCallback)(uint32_t,
  263. const PropertyCallbackInfo<v8::Value>&);
  264. ```
  265. Example:
  266. ```c++
  267. void IndexGetterName(uint32_t index, const PropertyCallbackInfo<v8::Value>& info);
  268. ```
  269. You do not need to declare a new `HandleScope` within a index getter as one is implicitly created for you.
  270. A helper macro `NAN_INDEX_GETTER(methodname)` exists, compatible with NAN v1 method declarations.
  271. Also see the V8 Embedders Guide documentation on indexed property [Interceptors](https://developers.google.com/v8/embed#interceptors).
  272. <a name="api_nan_index_setter"></a>
  273. ### Index setter declaration
  274. JavaScript-accessible index setter methods should be declared with the following signature to form a <b><code>Nan::IndexSetterCallback</code></b>:
  275. ```c++
  276. typedef void(*IndexSetterCallback)(uint32_t,
  277. v8::Local<v8::Value>,
  278. const PropertyCallbackInfo<v8::Value>&);
  279. ```
  280. Example:
  281. ```c++
  282. void IndexSetterName(uint32_t index,
  283. v8::Local<v8::Value> value,
  284. const PropertyCallbackInfo<v8::Value>& info);
  285. ```
  286. You do not need to declare a new `HandleScope` within a index setter as one is implicitly created for you.
  287. A helper macro `NAN_INDEX_SETTER(methodname)` exists, compatible with NAN v1 method declarations.
  288. Also see the V8 Embedders Guide documentation on indexed property [Interceptors](https://developers.google.com/v8/embed#interceptors).
  289. <a name="api_nan_index_enumerator"></a>
  290. ### Index enumerator declaration
  291. JavaScript-accessible index enumerator methods should be declared with the following signature to form a <b><code>Nan::IndexEnumeratorCallback</code></b>:
  292. ```c++
  293. typedef void(*IndexEnumeratorCallback)(const PropertyCallbackInfo<v8::Array>&);
  294. ```
  295. Example:
  296. ```c++
  297. void IndexEnumeratorName(const PropertyCallbackInfo<v8::Array>& info);
  298. ```
  299. You do not need to declare a new `HandleScope` within a index enumerator as one is implicitly created for you.
  300. A helper macro `NAN_INDEX_ENUMERATOR(methodname)` exists, compatible with NAN v1 method declarations.
  301. Also see the V8 Embedders Guide documentation on indexed property [Interceptors](https://developers.google.com/v8/embed#interceptors).
  302. <a name="api_nan_index_deleter"></a>
  303. ### Index deleter declaration
  304. JavaScript-accessible index deleter methods should be declared with the following signature to form a <b><code>Nan::IndexDeleterCallback</code></b>:
  305. ```c++
  306. typedef void(*IndexDeleterCallback)(uint32_t,
  307. const PropertyCallbackInfo<v8::Boolean>&);
  308. ```
  309. Example:
  310. ```c++
  311. void IndexDeleterName(uint32_t index, const PropertyCallbackInfo<v8::Boolean>& info);
  312. ```
  313. You do not need to declare a new `HandleScope` within a index deleter as one is implicitly created for you.
  314. A helper macro `NAN_INDEX_DELETER(methodname)` exists, compatible with NAN v1 method declarations.
  315. Also see the V8 Embedders Guide documentation on indexed property [Interceptors](https://developers.google.com/v8/embed#interceptors).
  316. <a name="api_nan_index_query"></a>
  317. ### Index query declaration
  318. JavaScript-accessible index query methods should be declared with the following signature to form a <b><code>Nan::IndexQueryCallback</code></b>:
  319. ```c++
  320. typedef void(*IndexQueryCallback)(uint32_t,
  321. const PropertyCallbackInfo<v8::Integer>&);
  322. ```
  323. Example:
  324. ```c++
  325. void IndexQueryName(uint32_t index, const PropertyCallbackInfo<v8::Integer>& info);
  326. ```
  327. You do not need to declare a new `HandleScope` within a index query method as one is implicitly created for you.
  328. A helper macro `NAN_INDEX_QUERY(methodname)` exists, compatible with NAN v1 method declarations.
  329. Also see the V8 Embedders Guide documentation on indexed property [Interceptors](https://developers.google.com/v8/embed#interceptors).
  330. <a name="api_nan_set_method"></a>
  331. ### Nan::SetMethod()
  332. 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>).
  333. Signature:
  334. ```c++
  335. void Nan::SetMethod(v8::Local<v8::Object> recv,
  336. const char *name,
  337. Nan::FunctionCallback callback)
  338. void Nan::SetMethod(v8::Local<v8::Template> templ,
  339. const char *name,
  340. Nan::FunctionCallback callback)
  341. ```
  342. <a name="api_nan_set_prototype_method"></a>
  343. ### Nan::SetPrototypeMethod()
  344. 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>).
  345. Signature:
  346. ```c++
  347. void Nan::SetPrototypeMethod(v8::Local<v8::FunctionTemplate> recv,
  348. const char* name,
  349. Nan::FunctionCallback callback)
  350. ```
  351. <a name="api_nan_set_accessor"></a>
  352. ### Nan::SetAccessor()
  353. 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>).
  354. Signature:
  355. ```c++
  356. void SetAccessor(v8::Local<v8::ObjectTemplate> tpl,
  357. v8::Local<v8::String> name,
  358. Nan::GetterCallback getter,
  359. Nan::SetterCallback setter = 0,
  360. v8::Local<v8::Value> data = v8::Local<v8::Value>(),
  361. v8::AccessControl settings = v8::DEFAULT,
  362. v8::PropertyAttribute attribute = v8::None,
  363. imp::Sig signature = imp::Sig());
  364. bool SetAccessor(v8::Local<v8::Object> obj,
  365. v8::Local<v8::String> name,
  366. Nan::GetterCallback getter,
  367. Nan::SetterCallback setter = 0,
  368. v8::Local<v8::Value> data = v8::Local<v8::Value>(),
  369. v8::AccessControl settings = v8::DEFAULT,
  370. v8::PropertyAttribute attribute = v8::None)
  371. ```
  372. See the V8 [`ObjectTemplate#SetAccessor()`](https://v8docs.nodesource.com/node-8.11/db/d5f/classv8_1_1_object_template.html#aca0ed196f8a9adb1f68b1aadb6c9cd77) and [`Object#SetAccessor()`](https://v8docs.nodesource.com/node-8.11/db/d85/classv8_1_1_object.html#ae91b3b56b357f285288c89fbddc46d1b) for further information about how to use `Nan::SetAccessor()`.
  373. <a name="api_nan_set_named_property_handler"></a>
  374. ### Nan::SetNamedPropertyHandler()
  375. Sets named property getters, setters, query, deleter and enumerator methods on an `ObjectTemplate`. Accepts:
  376. * Property getters with the `Nan::PropertyGetterCallback` signature (see <a href="#api_nan_property_getter">Property getter declaration</a>)
  377. * Property setters with the `Nan::PropertySetterCallback` signature (see <a href="#api_nan_property_setter">Property setter declaration</a>)
  378. * Property query methods with the `Nan::PropertyQueryCallback` signature (see <a href="#api_nan_property_query">Property query declaration</a>)
  379. * Property deleters with the `Nan::PropertyDeleterCallback` signature (see <a href="#api_nan_property_deleter">Property deleter declaration</a>)
  380. * Property enumerators with the `Nan::PropertyEnumeratorCallback` signature (see <a href="#api_nan_property_enumerator">Property enumerator declaration</a>)
  381. Signature:
  382. ```c++
  383. void SetNamedPropertyHandler(v8::Local<v8::ObjectTemplate> tpl,
  384. Nan::PropertyGetterCallback getter,
  385. Nan::PropertySetterCallback setter = 0,
  386. Nan::PropertyQueryCallback query = 0,
  387. Nan::PropertyDeleterCallback deleter = 0,
  388. Nan::PropertyEnumeratorCallback enumerator = 0,
  389. v8::Local<v8::Value> data = v8::Local<v8::Value>())
  390. ```
  391. See the V8 [`ObjectTemplate#SetNamedPropertyHandler()`](https://v8docs.nodesource.com/node-8.11/db/d5f/classv8_1_1_object_template.html#a33b3ebd7de641f6cc6414b7de01fc1c7) for further information about how to use `Nan::SetNamedPropertyHandler()`.
  392. <a name="api_nan_set_indexed_property_handler"></a>
  393. ### Nan::SetIndexedPropertyHandler()
  394. Sets indexed property getters, setters, query, deleter and enumerator methods on an `ObjectTemplate`. Accepts:
  395. * Indexed property getters with the `Nan::IndexGetterCallback` signature (see <a href="#api_nan_index_getter">Index getter declaration</a>)
  396. * Indexed property setters with the `Nan::IndexSetterCallback` signature (see <a href="#api_nan_index_setter">Index setter declaration</a>)
  397. * Indexed property query methods with the `Nan::IndexQueryCallback` signature (see <a href="#api_nan_index_query">Index query declaration</a>)
  398. * Indexed property deleters with the `Nan::IndexDeleterCallback` signature (see <a href="#api_nan_index_deleter">Index deleter declaration</a>)
  399. * Indexed property enumerators with the `Nan::IndexEnumeratorCallback` signature (see <a href="#api_nan_index_enumerator">Index enumerator declaration</a>)
  400. Signature:
  401. ```c++
  402. void SetIndexedPropertyHandler(v8::Local<v8::ObjectTemplate> tpl,
  403. Nan::IndexGetterCallback getter,
  404. Nan::IndexSetterCallback setter = 0,
  405. Nan::IndexQueryCallback query = 0,
  406. Nan::IndexDeleterCallback deleter = 0,
  407. Nan::IndexEnumeratorCallback enumerator = 0,
  408. v8::Local<v8::Value> data = v8::Local<v8::Value>())
  409. ```
  410. See the V8 [`ObjectTemplate#SetIndexedPropertyHandler()`](https://v8docs.nodesource.com/node-8.11/db/d5f/classv8_1_1_object_template.html#ac89f06d634add0e890452033f7d17ff1) for further information about how to use `Nan::SetIndexedPropertyHandler()`.
  411. <a name="api_nan_set_template"></a>
  412. ### Nan::SetTemplate()
  413. Adds properties on an `Object`'s or `Function`'s template.
  414. Signature:
  415. ```c++
  416. void Nan::SetTemplate(v8::Local<v8::Template> templ,
  417. const char *name,
  418. v8::Local<v8::Data> value);
  419. void Nan::SetTemplate(v8::Local<v8::Template> templ,
  420. v8::Local<v8::String> name,
  421. v8::Local<v8::Data> value,
  422. v8::PropertyAttribute attributes)
  423. ```
  424. Calls the `Template`'s [`Set()`](https://v8docs.nodesource.com/node-8.11/db/df7/classv8_1_1_template.html#ae3fbaff137557aa6a0233bc7e52214ac).
  425. <a name="api_nan_set_prototype_template"></a>
  426. ### Nan::SetPrototypeTemplate()
  427. Adds properties on an `Object`'s or `Function`'s prototype template.
  428. Signature:
  429. ```c++
  430. void Nan::SetPrototypeTemplate(v8::Local<v8::FunctionTemplate> templ,
  431. const char *name,
  432. v8::Local<v8::Data> value);
  433. void Nan::SetPrototypeTemplate(v8::Local<v8::FunctionTemplate> templ,
  434. v8::Local<v8::String> name,
  435. v8::Local<v8::Data> value,
  436. v8::PropertyAttribute attributes)
  437. ```
  438. Calls the `FunctionTemplate`'s _PrototypeTemplate's_ [`Set()`](https://v8docs.nodesource.com/node-8.11/db/df7/classv8_1_1_template.html#a2db6a56597bf23c59659c0659e564ddf).
  439. <a name="api_nan_set_instance_template"></a>
  440. ### Nan::SetInstanceTemplate()
  441. Use to add instance properties on `FunctionTemplate`'s.
  442. Signature:
  443. ```c++
  444. void Nan::SetInstanceTemplate(v8::Local<v8::FunctionTemplate> templ,
  445. const char *name,
  446. v8::Local<v8::Data> value);
  447. void Nan::SetInstanceTemplate(v8::Local<v8::FunctionTemplate> templ,
  448. v8::Local<v8::String> name,
  449. v8::Local<v8::Data> value,
  450. v8::PropertyAttribute attributes)
  451. ```
  452. Calls the `FunctionTemplate`'s _InstanceTemplate's_ [`Set()`](https://v8docs.nodesource.com/node-8.11/db/df7/classv8_1_1_template.html#a2db6a56597bf23c59659c0659e564ddf).
  453. <a name="api_nan_set_call_handler"></a>
  454. ### Nan::SetCallHandler()
  455. Set the call-handler callback for a `v8::FunctionTemplate`.
  456. This callback is called whenever the function created from this FunctionTemplate is called.
  457. Signature:
  458. ```c++
  459. void Nan::SetCallHandler(v8::Local<v8::FunctionTemplate> templ, Nan::FunctionCallback callback, v8::Local<v8::Value> data = v8::Local<v8::Value>())
  460. ```
  461. Calls the `FunctionTemplate`'s [`SetCallHandler()`](https://v8docs.nodesource.com/node-8.11/d8/d83/classv8_1_1_function_template.html#ab7574b298db3c27fbc2ed465c08ea2f8).
  462. <a name="api_nan_set_call_as_function_handler"></a>
  463. ### Nan::SetCallAsFunctionHandler()
  464. Sets the callback to be used when calling instances created from the `v8::ObjectTemplate` as a function.
  465. If no callback is set, instances behave like normal JavaScript objects that cannot be called as a function.
  466. Signature:
  467. ```c++
  468. void Nan::SetCallAsFunctionHandler(v8::Local<v8::ObjectTemplate> templ, Nan::FunctionCallback callback, v8::Local<v8::Value> data = v8::Local<v8::Value>())
  469. ```
  470. Calls the `ObjectTemplate`'s [`SetCallAsFunctionHandler()`](https://v8docs.nodesource.com/node-8.11/db/d5f/classv8_1_1_object_template.html#a5e9612fc80bf6db8f2da199b9b0bd04e).