node_api_create_external_string_utf16
napi_status
node_api_create_external_string_utf16(napi_env env,
char16_t* str,
size_t length,
napi_finalize finalize_callback,
void* finalize_hint,
napi_value* result,
bool* copied);
-
[in] env
:调用 API 的环境。¥
[in] env
: The environment that the API is invoked under. -
[in] str
:表示 UTF16-LE 编码字符串的字符缓冲区。¥
[in] str
: Character buffer representing a UTF16-LE-encoded string. -
[in] length
:以两字节代码单元表示的字符串长度,如果它以 null 终止,则为NAPI_AUTO_LENGTH
。¥
[in] length
: The length of the string in two-byte code units, orNAPI_AUTO_LENGTH
if it is null-terminated. -
[in] finalize_callback
:收集字符串时调用的函数。该函数将使用以下参数调用:¥
[in] finalize_callback
: The function to call when the string is being collected. The function will be called with the following parameters:-
[in] env
:加载项运行的环境。如果字符串是作为工作线程或主 Node.js 实例终止的一部分而被收集的,则该值可能为 null。¥
[in] env
: The environment in which the add-on is running. This value may be null if the string is being collected as part of the termination of the worker or the main Node.js instance. -
[in] data
:这是作为void*
指针的值str
。¥
[in] data
: This is the valuestr
as avoid*
pointer. -
[in] finalize_hint
:这是赋予 API 的值finalize_hint
。napi_finalize
提供了更多详细信息。该参数是可选的。传递 null 值意味着在收集相应的 JavaScript 字符串时不需要通知加载项。¥
[in] finalize_hint
: This is the valuefinalize_hint
that was given to the API.napi_finalize
provides more details. This parameter is optional. Passing a null value means that the add-on doesn't need to be notified when the corresponding JavaScript string is collected.
-
-
[in] finalize_hint
:在收集期间传递给最终回调的可选提示。¥
[in] finalize_hint
: Optional hint to pass to the finalize callback during collection. -
[out] result
:代表 JavaScriptstring
的napi_value
。¥
[out] result
: Anapi_value
representing a JavaScriptstring
. -
[out] copied
:字符串是否被复制。如果是,则终结器将已被调用来销毁str
。¥
[out] copied
: Whether the string was copied. If it was, the finalizer will already have been invoked to destroystr
.
如果 API 成功,则返回 napi_ok
。
¥Returns napi_ok
if the API succeeded.
此 API 从 UTF16-LE 编码的 C 字符串创建 JavaScript string
值。原生字符串不能被复制,因此必须在 JavaScript 值的整个生命周期中存在。
¥This API creates a JavaScript string
value from a UTF16-LE-encoded C string.
The native string may not be copied and must thus exist for the entire life
cycle of the JavaScript value.
JavaScript string
类型在 ECMAScript 语言规范的 第 6.1.4 节 中进行了描述。
¥The JavaScript string
type is described in
Section 6.1.4 of the ECMAScript Language Specification.