@@ -1485,40 +1485,6 @@ structure, in most cases using a `TypedArray` will suffice. |
1485 | 1485 |
|
1486 | 1486 | For Node.js >=4 `Buffers` are `Uint8Array`s. |
1487 | 1487 |
|
1488 | | -#### napi_create_function |
1489 | | -<!-- YAML |
1490 | | -added: v8.0.0 |
1491 | | -napiVersion: 1 |
1492 | | ---> |
1493 | | -```C |
1494 | | -napi_status napi_create_function(napi_env env, |
1495 | | - const char* utf8name, |
1496 | | - size_t length, |
1497 | | - napi_callback cb, |
1498 | | - void* data, |
1499 | | - napi_value* result) |
1500 | | -``` |
1501 | | - |
1502 | | -- `[in] env`: The environment that the API is invoked under. |
1503 | | -- `[in] utf8name`: A string representing the name of the function encoded as |
1504 | | -UTF8. |
1505 | | -- `[in] length`: The length of the `utf8name` in bytes, or |
1506 | | -`NAPI_AUTO_LENGTH` if it is null-terminated. |
1507 | | -- `[in] cb`: A function pointer to the native function to be invoked when the |
1508 | | -created function is invoked from JavaScript. |
1509 | | -- `[in] data`: Optional arbitrary context data to be passed into the native |
1510 | | -function when it is invoked. |
1511 | | -- `[out] result`: A `napi_value` representing a JavaScript function. |
1512 | | - |
1513 | | -Returns `napi_ok` if the API succeeded. |
1514 | | - |
1515 | | -This API returns an N-API value corresponding to a JavaScript `Function` object. |
1516 | | -It's used to wrap native functions so that they can be invoked from JavaScript. |
1517 | | - |
1518 | | -JavaScript `Function`s are described in |
1519 | | -[Section 19.2](https://tc39.github.io/ecma262/#sec-function-objects) |
1520 | | -of the ECMAScript Language Specification. |
1521 | | - |
1522 | 1488 | #### napi_create_object |
1523 | 1489 | <!-- YAML |
1524 | 1490 | added: v8.0.0 |
@@ -3153,6 +3119,7 @@ napiVersion: 1 |
3153 | 3119 | ```C |
3154 | 3120 | napi_status napi_create_function(napi_env env, |
3155 | 3121 | const char* utf8name, |
| 3122 | + size_t length, |
3156 | 3123 | napi_callback cb, |
3157 | 3124 | void* data, |
3158 | 3125 | napi_value* result); |
@@ -3161,6 +3128,8 @@ napi_status napi_create_function(napi_env env, |
3161 | 3128 | - `[in] env`: The environment that the API is invoked under. |
3162 | 3129 | - `[in] utf8Name`: The name of the function encoded as UTF8. This is visible |
3163 | 3130 | within JavaScript as the new function object's `name` property. |
| 3131 | +- `[in] length`: The length of the `utf8name` in bytes, or |
| 3132 | +`NAPI_AUTO_LENGTH` if it is null-terminated. |
3164 | 3133 | - `[in] cb`: The native function which should be called when this function |
3165 | 3134 | object is invoked. |
3166 | 3135 | - `[in] data`: User-provided data context. This will be passed back into the |
@@ -3209,10 +3178,13 @@ const myaddon = require('./addon'); |
3209 | 3178 | myaddon.sayHello(); |
3210 | 3179 | ``` |
3211 | 3180 |
|
3212 | | -The string passed to require is not necessarily the name passed into |
3213 | | -`NAPI_MODULE` in the earlier snippet but the name of the target in `binding.gyp` |
| 3181 | +The string passed to `require()` is the name of the target in `binding.gyp` |
3214 | 3182 | responsible for creating the `.node` file. |
3215 | 3183 |
|
| 3184 | +JavaScript `Function`s are described in |
| 3185 | +[Section 19.2](https://tc39.github.io/ecma262/#sec-function-objects) |
| 3186 | +of the ECMAScript Language Specification. |
| 3187 | + |
3216 | 3188 | ### napi_get_cb_info |
3217 | 3189 | <!-- YAML |
3218 | 3190 | added: v8.0.0 |
|