@@ -801,7 +801,7 @@ napiVersion: 1
801801
802802Function pointer type for add-on provided functions that allow the user to be
803803notified when externally-owned data is ready to be cleaned up because the
804- object with which it was associated with, has been garbage-collected. The user
804+ object with which it was associated with has been garbage-collected. The user
805805must provide a function satisfying the following signature which would get
806806called upon the object's collection. Currently, `napi_finalize` can be used for
807807finding out when objects that have external data are collected.
@@ -819,6 +819,11 @@ Since these functions may be called while the JavaScript engine is in a state
819819where it cannot execute JavaScript code, some Node-API calls may return
820820`napi_pending_exception` even when there is no exception pending.
821821
822+ In the case of [`node_api_create_external_string_latin1`][] and
823+ [`node_api_create_external_string_utf16`][] the `env` parameter may be null,
824+ because external strings can be collected during the latter part of environment
825+ shutdown.
826+
822827Change History:
823828
824829* experimental (`NAPI_EXPERIMENTAL` is defined):
@@ -2886,6 +2891,56 @@ string. The native string is copied.
28862891The JavaScript `string` type is described in
28872892[Section 6.1.4][] of the ECMAScript Language Specification.
28882893
2894+ #### `node_api_create_external_string_latin1`
2895+
2896+ <!-- YAML
2897+ added: REPLACEME
2898+ -->
2899+
2900+ > Stability: 1 - Experimental
2901+
2902+ ```c
2903+ napi_status
2904+ node_api_create_external_string_latin1(napi_env env,
2905+ char* str,
2906+ size_t length,
2907+ napi_finalize finalize_callback,
2908+ void* finalize_hint,
2909+ napi_value* result,
2910+ bool* copied);
2911+ ```
2912+
2913+ * `[in] env`: The environment that the API is invoked under.
2914+ * `[in] str`: Character buffer representing an ISO-8859-1-encoded string.
2915+ * `[in] length`: The length of the string in bytes, or `NAPI_AUTO_LENGTH` if it
2916+ is null-terminated.
2917+ * `[in] finalize_callback`: The function to call when the string is being
2918+ collected. The function will be called with the following parameters:
2919+ * `[in] env`: The environment in which the add-on is running. This value
2920+ may be null if the string is being collected as part of the termination
2921+ of the worker or the main Node.js instance.
2922+ * `[in] data`: This is the value `str` as a `void*` pointer.
2923+ * `[in] finalize_hint`: This is the value `finalize_hint` that was given
2924+ to the API.
2925+ [`napi_finalize`][] provides more details.
2926+ This parameter is optional. Passing a null value means that the add-on
2927+ doesn't need to be notified when the corresponding JavaScript string is
2928+ collected.
2929+ * `[in] finalize_hint`: Optional hint to pass to the finalize callback during
2930+ collection.
2931+ * `[out] result`: A `napi_value` representing a JavaScript `string`.
2932+ * `[out] copied`: Whether the string was copied. If it was, the finalizer will
2933+ already have been invoked to destroy `str`.
2934+
2935+ Returns `napi_ok` if the API succeeded.
2936+
2937+ This API creates a JavaScript `string` value from an ISO-8859-1-encoded C
2938+ string. The native string may not be copied and must thus exist for the entire
2939+ life cycle of the JavaScript value.
2940+
2941+ The JavaScript `string` type is described in
2942+ [Section 6.1.4][] of the ECMAScript Language Specification.
2943+
28892944#### `napi_create_string_utf16`
28902945
28912946<!-- YAML
@@ -2914,6 +2969,56 @@ The native string is copied.
29142969The JavaScript `string` type is described in
29152970[Section 6.1.4][] of the ECMAScript Language Specification.
29162971
2972+ #### `node_api_create_external_string_utf16`
2973+
2974+ <!-- YAML
2975+ added: REPLACEME
2976+ -->
2977+
2978+ > Stability: 1 - Experimental
2979+
2980+ ```c
2981+ napi_status
2982+ node_api_create_external_string_utf16(napi_env env,
2983+ char16_t* str,
2984+ size_t length,
2985+ napi_finalize finalize_callback,
2986+ void* finalize_hint,
2987+ napi_value* result,
2988+ bool* copied);
2989+ ```
2990+
2991+ * `[in] env`: The environment that the API is invoked under.
2992+ * `[in] str`: Character buffer representing a UTF16-LE-encoded string.
2993+ * `[in] length`: The length of the string in two-byte code units, or
2994+ `NAPI_AUTO_LENGTH` if it is null-terminated.
2995+ * `[in] finalize_callback`: The function to call when the string is being
2996+ collected. The function will be called with the following parameters:
2997+ * `[in] env`: The environment in which the add-on is running. This value
2998+ may be null if the string is being collected as part of the termination
2999+ of the worker or the main Node.js instance.
3000+ * `[in] data`: This is the value `str` as a `void*` pointer.
3001+ * `[in] finalize_hint`: This is the value `finalize_hint` that was given
3002+ to the API.
3003+ [`napi_finalize`][] provides more details.
3004+ This parameter is optional. Passing a null value means that the add-on
3005+ doesn't need to be notified when the corresponding JavaScript string is
3006+ collected.
3007+ * `[in] finalize_hint`: Optional hint to pass to the finalize callback during
3008+ collection.
3009+ * `[out] result`: A `napi_value` representing a JavaScript `string`.
3010+ * `[out] copied`: Whether the string was copied. If it was, the finalizer will
3011+ already have been invoked to destroy `str`.
3012+
3013+ Returns `napi_ok` if the API succeeded.
3014+
3015+ This API creates a JavaScript `string` value from a UTF16-LE-encoded C string.
3016+ The native string may not be copied and must thus exist for the entire life
3017+ cycle of the JavaScript value.
3018+
3019+ The JavaScript `string` type is described in
3020+ [Section 6.1.4][] of the ECMAScript Language Specification.
3021+
29173022#### `napi_create_string_utf8`
29183023
29193024<!-- YAML
@@ -6476,6 +6581,8 @@ the add-on's file name during loading.
64766581[`napi_wrap`]: #napi_wrap
64776582[`node-addon-api`]: https://github.com/nodejs/node-addon-api
64786583[`node_api.h`]: https://github.com/nodejs/node/blob/HEAD/src/node_api.h
6584+ [`node_api_create_external_string_latin1`]: #node_api_create_external_string_latin1
6585+ [`node_api_create_external_string_utf16`]: #node_api_create_external_string_utf16
64796586[`node_api_create_syntax_error`]: #node_api_create_syntax_error
64806587[`node_api_throw_syntax_error`]: #node_api_throw_syntax_error
64816588[`process.release`]: process.md#processrelease
0 commit comments