From 9d3dc30b7488563db1bff0ef8d3263de70a0a8b3 Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Sun, 26 Dec 2021 17:30:56 +0530 Subject: [PATCH] src: add napi_create_symbol_for() Fixes: https://github.com/nodejs/node/issues/41294 Signed-off-by: Darshan Sen --- doc/api/n-api.md | 27 +++++++++++++++++++ src/js_native_api.h | 3 +++ src/js_native_api_v8.cc | 22 +++++++++++++++ test/js-native-api/test_properties/test.js | 14 +++++----- .../test_properties/test_properties.c | 19 +++++++++++++ test/js-native-api/test_reference/test.js | 7 +++++ .../test_reference/test_reference.c | 15 +++++++++++ 7 files changed, 101 insertions(+), 6 deletions(-) diff --git a/doc/api/n-api.md b/doc/api/n-api.md index c146a6d661dddb..7ff884d93c8998 100644 --- a/doc/api/n-api.md +++ b/doc/api/n-api.md @@ -2492,6 +2492,33 @@ 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. +#### `napi_create_symbol_for` + + + +```c +napi_status napi_create_symbol_for(napi_env env, + napi_value description, + napi_value* result) +``` + +* `[in] env`: The environment that the API is invoked under. +* `[in] description`: Optional `napi_value` which refers to a JavaScript + `string` to be set 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`