From 4d2dc483de5e70abf5f2689bed9587e635b90f76 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() Fixes: https://github.com/nodejs/node/issues/41294 Signed-off-by: Darshan Sen --- doc/api/n-api.md | 29 +++++++++++++++++++ src/js_native_api.h | 5 ++++ src/js_native_api_v8.cc | 15 ++++++++++ test/js-native-api/test_properties/test.js | 11 ++++--- .../test_properties/test_properties.c | 11 +++++++ test/js-native-api/test_reference/test.js | 11 +++++++ .../test_reference/test_reference.c | 29 +++++++++++++++++++ 7 files changed, 105 insertions(+), 6 deletions(-) diff --git a/doc/api/n-api.md b/doc/api/n-api.md index c146a6d661dddb..be3a06e15c34a2 100644 --- a/doc/api/n-api.md +++ b/doc/api/n-api.md @@ -2492,6 +2492,35 @@ 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* description, + napi_value* result) +``` + +* `[in] env`: The environment that the API is invoked under. +* `[in] description`: C string representing the text to be used as the + description for the symbol. +* `[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`