@@ -801,7 +801,7 @@ napiVersion: 1
801
801
802
802
Function pointer type for add-on provided functions that allow the user to be
803
803
notified 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
805
805
must provide a function satisfying the following signature which would get
806
806
called upon the object's collection. Currently, `napi_finalize` can be used for
807
807
finding 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
819
819
where it cannot execute JavaScript code, some Node-API calls may return
820
820
`napi_pending_exception` even when there is no exception pending.
821
821
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
+
822
827
Change History:
823
828
824
829
* experimental (`NAPI_EXPERIMENTAL` is defined):
@@ -2886,6 +2891,56 @@ string. The native string is copied.
2886
2891
The JavaScript `string` type is described in
2887
2892
[Section 6.1.4][] of the ECMAScript Language Specification.
2888
2893
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
+
2889
2944
#### `napi_create_string_utf16`
2890
2945
2891
2946
<!-- YAML
@@ -2914,6 +2969,56 @@ The native string is copied.
2914
2969
The JavaScript `string` type is described in
2915
2970
[Section 6.1.4][] of the ECMAScript Language Specification.
2916
2971
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
+
2917
3022
#### `napi_create_string_utf8`
2918
3023
2919
3024
<!-- YAML
@@ -6476,6 +6581,8 @@ the add-on's file name during loading.
6476
6581
[`napi_wrap`]: #napi_wrap
6477
6582
[`node-addon-api`]: https://github.com/nodejs/node-addon-api
6478
6583
[`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
6479
6586
[`node_api_create_syntax_error`]: #node_api_create_syntax_error
6480
6587
[`node_api_throw_syntax_error`]: #node_api_throw_syntax_error
6481
6588
[`process.release`]: process.md#processrelease
0 commit comments