From 11ec3345e7a722fa73918e2aaf43aaaf9e726541 Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Sun, 26 Dec 2021 17:30:56 +0530 Subject: [PATCH] node-api: add node_api_symbol_for() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: https://github.com/nodejs/node/issues/41294 Signed-off-by: Darshan Sen PR-URL: https://github.com/nodejs/node/pull/41329 Reviewed-By: Anna Henningsen Reviewed-By: Michael Dawson Reviewed-By: Tobias Nießen Reviewed-By: James M Snell --- doc/api/n-api.md | 32 +++++++++++++++ src/js_native_api.h | 6 +++ src/js_native_api_v8.cc | 21 ++++++++++ test/js-native-api/test_properties/test.js | 11 +++--- .../test_properties/test_properties.c | 13 +++++++ test/js-native-api/test_reference/test.js | 19 +++++++++ .../test_reference/test_reference.c | 39 +++++++++++++++++++ 7 files changed, 135 insertions(+), 6 deletions(-) diff --git a/doc/api/n-api.md b/doc/api/n-api.md index 9aab850b8b7ce0..58ee65a1d222ff 100644 --- a/doc/api/n-api.md +++ b/doc/api/n-api.md @@ -2492,6 +2492,38 @@ This API creates a JavaScript `symbol` value from a UTF8-encoded C string. The JavaScript `symbol` type is described in [Section 19.4][] of the ECMAScript Language Specification. +#### `node_api_symbol_for` + + + +> Stability: 1 - Experimental + +```c +napi_status node_api_symbol_for(napi_env env, + const char* utf8description, + size_t length, + napi_value* result) +``` + +* `[in] env`: The environment that the API is invoked under. +* `[in] utf8description`: UTF-8 C string representing the text to be used as the + description for the symbol. +* `[in] length`: The length of the description string in bytes, or + `NAPI_AUTO_LENGTH` if it is null-terminated. +* `[out] result`: A `napi_value` representing a JavaScript `symbol`. + +Returns `napi_ok` if the API succeeded. + +This API searches in the global registry for an existing symbol with the given +description. If the symbol already exists it will be returned, otherwise a new +symbol will be created in the registry. + +The JavaScript `symbol` type is described in [Section 19.4][] of the ECMAScript +Language Specification. + #### `napi_create_typedarray`