Skip to content

Commit 0366264

Browse files
committed
Update PR based on comments received
1 parent f49c894 commit 0366264

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

doc/symbol.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ If an error occurs, a `Napi::Error` will get thrown. If C++ exceptions are not
3434
being used, callers should check the result of `Napi::Env::IsExceptionPending` before
3535
attempting to use the returned value.
3636
37-
### Wellkown
37+
### WellKnown
3838
```cpp
3939
static Napi::Symbol Napi::Symbol::WellKnown(napi_env env, const std::string& name);
4040
```
@@ -47,12 +47,15 @@ Returns a `Napi::Symbol` representing a well-known `Symbol` from the
4747

4848
### For
4949
```cpp
50-
static Napi::Symbol Napi::Symbol::WellKnown(napi_env env, const std::string& name);
50+
static Napi::Symbol Napi::Symbol::For(napi_env env, const std::string& description);
51+
static Napi::Symbol Napi::Symbol::For(napi_env env, const char* description = nullptr);
52+
static Napi::Symbol Napi::Symbol::For(napi_env env, String description);
53+
static Napi::Symbol Napi::Symbol::For(napi_env env, napi_value description);
5154
```
5255
5356
- `[in] env`: The `napi_env` environment in which to construct the `Napi::Symbol` object.
54-
- `[in] name`: The C++ string representing the `Napi::Symbol` to retrieve.
57+
- `[in] description`: The C++ string representing the `Napi::Symbol` in the global registry to retrieve.
5558
56-
Register `Napi::Symbol` in the global registry. If symbol already exist retrieve said symbol. Equivalent to `Symbol.for("symb")` called from JS.
59+
Searches in the global registry for existing symbol with the given name. If the symbol already exist it will be returned, otherwise a new symbol will be created in the registry. It's equivalent to Symbol.for() called from JavaScript.
5760
58-
[`Napi::Name`]: ./name.md
61+
[`Napi::Name`]: ./name.md

napi-inl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,8 +1011,7 @@ inline Symbol Symbol::For(napi_env env, const char* description) {
10111011
}
10121012

10131013
inline Symbol Symbol::For(napi_env env, String description) {
1014-
napi_value descriptionValue = description;
1015-
return Symbol::For(env, descriptionValue);
1014+
return Symbol::For(env, static_cast<napi_value>(description));
10161015
}
10171016

10181017
inline Symbol Symbol::For(napi_env env, napi_value description) {

napi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ namespace Napi {
539539
static Symbol WellKnown(napi_env, const std::string& name);
540540

541541
// Create a symbol in the global registry, UTF-8 Encoded cpp string
542-
static Symbol For(napi_env env, const std::string& name);
542+
static Symbol For(napi_env env, const std::string& description);
543543

544544
// Create a symbol in the global registry, C style string (null terminated)
545545
static Symbol For(napi_env env, const char* description = nullptr);

test/symbol.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ async function test(binding)
5353
assertSymbolAreUnique("symbol");
5454
assertSymbolIsNotWellknown("testing");
5555

56-
for(const wellknownProperty of wellKnownSymbolFunctions)
57-
{
58-
assertSymbolIsWellknown(wellknownProperty);
59-
}
56+
for(const wellknownProperty of wellKnownSymbolFunctions)
57+
{
58+
assertSymbolIsWellknown(wellknownProperty);
59+
}
6060

61-
assertCanCreateOrFetchGlobalSymbols("data", binding.symbol.getSymbolFromGlobalRegistry);
62-
assertCanCreateOrFetchGlobalSymbols("CppKey", binding.symbol.getSymbolFromGlobalRegistryWithCppKey);
63-
assertCanCreateOrFetchGlobalSymbols("CKey", binding.symbol.getSymbolFromGlobalRegistryWithCKey);
61+
assertCanCreateOrFetchGlobalSymbols("data", binding.symbol.getSymbolFromGlobalRegistry);
62+
assertCanCreateOrFetchGlobalSymbols("CppKey", binding.symbol.getSymbolFromGlobalRegistryWithCppKey);
63+
assertCanCreateOrFetchGlobalSymbols("CKey", binding.symbol.getSymbolFromGlobalRegistryWithCKey);
6464

6565
assert(binding.symbol.createNewSymbolWithNoArgs() === undefined);
66-
}
66+
}

0 commit comments

Comments
 (0)