@@ -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):
@@ -2882,6 +2887,56 @@ string. The native string is copied.
2882
2887
The JavaScript `string` type is described in
2883
2888
[Section 6.1.4][] of the ECMAScript Language Specification.
2884
2889
2890
+ #### `node_api_create_external_string_latin1`
2891
+
2892
+ <!-- YAML
2893
+ added: REPLACEME
2894
+ -->
2895
+
2896
+ > Stability: 1 - Experimental
2897
+
2898
+ ```c
2899
+ napi_status
2900
+ node_api_create_external_string_latin1(napi_env env,
2901
+ char* str,
2902
+ size_t length,
2903
+ napi_finalize finalize_callback,
2904
+ void* finalize_hint,
2905
+ napi_value* result,
2906
+ bool* copied);
2907
+ ```
2908
+
2909
+ * `[in] env`: The environment that the API is invoked under.
2910
+ * `[in] str`: Character buffer representing an ISO-8859-1-encoded string.
2911
+ * `[in] length`: The length of the string in bytes, or `NAPI_AUTO_LENGTH` if it
2912
+ is null-terminated.
2913
+ * `[in] finalize_callback`: The function to call when the string is being
2914
+ collected. The function will be called with the following parameters:
2915
+ * `[in] env`: The environment in which the add-on is running. This value
2916
+ may be null if the string is being collected as part of the termination
2917
+ of the worker or the main Node.js instance.
2918
+ * `[in] data`: This is the value `str` as a `void*` pointer.
2919
+ * `[in] finalize_hint`: This is the value `finalize_hint` that was given
2920
+ to the API.
2921
+ [`napi_finalize`][] provides more details.
2922
+ This parameter is optional. Passing a null value means that the add-on
2923
+ doesn't need to be notified when the corresponding JavaScript string is
2924
+ collected.
2925
+ * `[in] finalize_hint`: Optional hint to pass to the finalize callback during
2926
+ collection.
2927
+ * `[out] result`: A `napi_value` representing a JavaScript `string`.
2928
+ * `[out] copied`: Whether the string was copied. If it was, the finalizer will
2929
+ already have been invoked to destroy `str`.
2930
+
2931
+ Returns `napi_ok` if the API succeeded.
2932
+
2933
+ This API creates a JavaScript `string` value from an ISO-8859-1-encoded C
2934
+ string. The native string may not be copied and must thus exist for the entire
2935
+ life cycle of the JavaScript value.
2936
+
2937
+ The JavaScript `string` type is described in
2938
+ [Section 6.1.4][] of the ECMAScript Language Specification.
2939
+
2885
2940
#### `napi_create_string_utf16`
2886
2941
2887
2942
<!-- YAML
@@ -2910,6 +2965,56 @@ The native string is copied.
2910
2965
The JavaScript `string` type is described in
2911
2966
[Section 6.1.4][] of the ECMAScript Language Specification.
2912
2967
2968
+ #### `node_api_create_external_string_utf16`
2969
+
2970
+ <!-- YAML
2971
+ added: REPLACEME
2972
+ -->
2973
+
2974
+ > Stability: 1 - Experimental
2975
+
2976
+ ```c
2977
+ napi_status
2978
+ node_api_create_external_string_utf16(napi_env env,
2979
+ char16_t* str,
2980
+ size_t length,
2981
+ napi_finalize finalize_callback,
2982
+ void* finalize_hint,
2983
+ napi_value* result,
2984
+ bool* copied);
2985
+ ```
2986
+
2987
+ * `[in] env`: The environment that the API is invoked under.
2988
+ * `[in] str`: Character buffer representing a UTF16-LE-encoded string.
2989
+ * `[in] length`: The length of the string in two-byte code units, or
2990
+ `NAPI_AUTO_LENGTH` if it is null-terminated.
2991
+ * `[in] finalize_callback`: The function to call when the string is being
2992
+ collected. The function will be called with the following parameters:
2993
+ * `[in] env`: The environment in which the add-on is running. This value
2994
+ may be null if the string is being collected as part of the termination
2995
+ of the worker or the main Node.js instance.
2996
+ * `[in] data`: This is the value `str` as a `void*` pointer.
2997
+ * `[in] finalize_hint`: This is the value `finalize_hint` that was given
2998
+ to the API.
2999
+ [`napi_finalize`][] provides more details.
3000
+ This parameter is optional. Passing a null value means that the add-on
3001
+ doesn't need to be notified when the corresponding JavaScript string is
3002
+ collected.
3003
+ * `[in] finalize_hint`: Optional hint to pass to the finalize callback during
3004
+ collection.
3005
+ * `[out] result`: A `napi_value` representing a JavaScript `string`.
3006
+ * `[out] copied`: Whether the string was copied. If it was, the finalizer will
3007
+ already have been invoked to destroy `str`.
3008
+
3009
+ Returns `napi_ok` if the API succeeded.
3010
+
3011
+ This API creates a JavaScript `string` value from a UTF16-LE-encoded C string.
3012
+ The native string may not be copied and must thus exist for the entire life
3013
+ cycle of the JavaScript value.
3014
+
3015
+ The JavaScript `string` type is described in
3016
+ [Section 6.1.4][] of the ECMAScript Language Specification.
3017
+
2913
3018
#### `napi_create_string_utf8`
2914
3019
2915
3020
<!-- YAML
@@ -6472,6 +6577,8 @@ the add-on's file name during loading.
6472
6577
[`napi_wrap`]: #napi_wrap
6473
6578
[`node-addon-api`]: https://github.com/nodejs/node-addon-api
6474
6579
[`node_api.h`]: https://github.com/nodejs/node/blob/HEAD/src/node_api.h
6580
+ [`node_api_create_external_string_latin1`]: #node_api_create_external_string_latin1
6581
+ [`node_api_create_external_string_utf16`]: #node_api_create_external_string_utf16
6475
6582
[`node_api_create_syntax_error`]: #node_api_create_syntax_error
6476
6583
[`node_api_throw_syntax_error`]: #node_api_throw_syntax_error
6477
6584
[`process.release`]: process.md#processrelease
0 commit comments