@@ -1399,6 +1399,35 @@ properties. Such objects are created either by Node.js internals or native
1399
1399
addons. In JavaScript, they are [ frozen] [ `Object.freeze()` ] objects with a
1400
1400
` null ` prototype.
1401
1401
1402
+ ``` c++
1403
+ #include < js_native_api.h>
1404
+ #include < string.h>
1405
+ napi_value result;
1406
+ static napi_value MyNapi (napi_env env, napi_callback_info info) {
1407
+ int* raw = (int* ) malloc(1024);
1408
+ napi_status status = napi_create_external(env, (void* ) raw, NULL, NULL, &result);
1409
+ if (status != napi_ok) {
1410
+ napi_throw_error(env, NULL, "napi_create_external failed");
1411
+ return NULL;
1412
+ }
1413
+ return result;
1414
+ }
1415
+ ...
1416
+ DECLARE_NAPI_PROPERTY("myNapi", MyNapi)
1417
+ ...
1418
+ ```
1419
+
1420
+ ```js
1421
+ const native = require('napi_addon.node');
1422
+ const data = native.myNapi();
1423
+ util.types.isExternal(data); // returns true
1424
+ util.types.isExternal(0); // returns false
1425
+ util.types.isExternal(new String('foo')); // returns false
1426
+ ```
1427
+
1428
+ For further information on ` napi_create_external ` , refer to
1429
+ [ ` napi_create_external() ` ] [ ] .
1430
+
1402
1431
### ` util.types.isFloat32Array(value) `
1403
1432
<!-- YAML
1404
1433
added: v10.0.0
@@ -2358,5 +2387,6 @@ util.log('Timestamped message.');
2358
2387
[ default sort ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
2359
2388
[ global symbol registry ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for
2360
2389
[ list of deprecated APIS ] : deprecations.html#deprecations_list_of_deprecated_apis
2390
+ [ `napi_create_external()` ] : n-api.html#n_api_napi_create_external
2361
2391
[ semantically incompatible ] : https://github.com/nodejs/node/issues/4179
2362
2392
[ util.inspect.custom ] : #util_util_inspect_custom
0 commit comments