-
-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathsymbol.cc
More file actions
79 lines (67 loc) · 2.86 KB
/
symbol.cc
File metadata and controls
79 lines (67 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <napi.h>
#include "test_helper.h"
using namespace Napi;
Symbol CreateNewSymbolWithNoArgs(const Napi::CallbackInfo&) {
return Napi::Symbol();
}
Symbol CreateNewSymbolWithCppStrDesc(const Napi::CallbackInfo& info) {
String cppStrKey = info[0].As<String>();
return Napi::Symbol::New(info.Env(), cppStrKey.Utf8Value());
}
Symbol CreateNewSymbolWithCStrDesc(const Napi::CallbackInfo& info) {
String cStrKey = info[0].As<String>();
return Napi::Symbol::New(info.Env(), cStrKey.Utf8Value().c_str());
}
Symbol CreateNewSymbolWithNapiString(const Napi::CallbackInfo& info) {
String strKey = info[0].As<String>();
return Napi::Symbol::New(info.Env(), strKey);
}
Symbol GetWellknownSymbol(const Napi::CallbackInfo& info) {
String registrySymbol = info[0].As<String>();
return MaybeUnwrap(
Napi::Symbol::WellKnown(info.Env(), registrySymbol.Utf8Value().c_str()));
}
Symbol FetchSymbolFromGlobalRegistry(const Napi::CallbackInfo& info) {
String registrySymbol = info[0].As<String>();
return MaybeUnwrap(Napi::Symbol::For(info.Env(), registrySymbol));
}
Symbol FetchSymbolFromGlobalRegistryWithCppKey(const Napi::CallbackInfo& info) {
String cppStringKey = info[0].As<String>();
return MaybeUnwrap(Napi::Symbol::For(info.Env(), cppStringKey.Utf8Value()));
}
Symbol FetchSymbolFromGlobalRegistryWithCKey(const Napi::CallbackInfo& info) {
String cppStringKey = info[0].As<String>();
return MaybeUnwrap(
Napi::Symbol::For(info.Env(), cppStringKey.Utf8Value().c_str()));
}
Symbol TestUndefinedSymbolsCanBeCreated(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
return MaybeUnwrap(Napi::Symbol::For(env, env.Undefined()));
}
Symbol TestNullSymbolsCanBeCreated(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
return MaybeUnwrap(Napi::Symbol::For(env, env.Null()));
}
Object InitSymbol(Env env) {
Object exports = Object::New(env);
exports["createNewSymbolWithNoArgs"] =
Function::New(env, CreateNewSymbolWithNoArgs);
exports["createNewSymbolWithCppStr"] =
Function::New(env, CreateNewSymbolWithCppStrDesc);
exports["createNewSymbolWithCStr"] =
Function::New(env, CreateNewSymbolWithCStrDesc);
exports["createNewSymbolWithNapi"] =
Function::New(env, CreateNewSymbolWithNapiString);
exports["getWellKnownSymbol"] = Function::New(env, GetWellknownSymbol);
exports["getSymbolFromGlobalRegistry"] =
Function::New(env, FetchSymbolFromGlobalRegistry);
exports["getSymbolFromGlobalRegistryWithCKey"] =
Function::New(env, FetchSymbolFromGlobalRegistryWithCKey);
exports["getSymbolFromGlobalRegistryWithCppKey"] =
Function::New(env, FetchSymbolFromGlobalRegistryWithCppKey);
exports["testUndefinedSymbolCanBeCreated"] =
Function::New(env, TestUndefinedSymbolsCanBeCreated);
exports["testNullSymbolCanBeCreated"] =
Function::New(env, TestNullSymbolsCanBeCreated);
return exports;
}