forked from nodejs/node-addon-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsymbol.js
More file actions
70 lines (54 loc) · 2.56 KB
/
Copy pathsymbol.js
File metadata and controls
70 lines (54 loc) · 2.56 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
'use strict';
const buildType = process.config.target_defaults.default_configuration;
const assert = require('assert');
test(require(`./build/${buildType}/binding.node`));
test(require(`./build/${buildType}/binding_noexcept.node`));
async function test(binding)
{
const wellKnownSymbolFunctions = ['asyncIterator','hasInstance','isConcatSpreadable', 'iterator','match','matchAll','replace','search','split','species','toPrimitive','toStringTag','unscopables'];
function assertCanCreateSymbol(symbol)
{
assert(binding.symbol.createNewSymbolWithCppStr(symbol) !== null);
assert(binding.symbol.createNewSymbolWithCStr(symbol) !== null);
assert(binding.symbol.createNewSymbolWithNapi(symbol) !== null);
}
function assertSymbolAreUnique(symbol)
{
const symbolOne = binding.symbol.createNewSymbolWithCppStr(symbol);
const symbolTwo = binding.symbol.createNewSymbolWithCppStr(symbol);
assert(symbolOne !== symbolTwo);
}
function assertSymbolIsWellknown(symbol)
{
const symbOne = binding.symbol.getWellKnownSymbol(symbol);
const symbTwo = binding.symbol.getWellKnownSymbol(symbol);
assert(symbOne && symbTwo);
assert(symbOne === symbTwo);
}
function assertSymbolIsNotWellknown(symbol)
{
const symbolTest = binding.symbol.getWellKnownSymbol(symbol);
assert(symbolTest === undefined);
}
function assertCanCreateOrFetchGlobalSymbols(symbol, fetchFunction)
{
const symbOne = fetchFunction(symbol);
const symbTwo = fetchFunction(symbol);
assert(symbOne && symbTwo);
assert(symbOne === symbTwo);
}
assertCanCreateSymbol("testing");
assertSymbolAreUnique("symbol");
assertSymbolIsNotWellknown("testing");
for(const wellknownProperty of wellKnownSymbolFunctions)
{
assertSymbolIsWellknown(wellknownProperty);
}
assertCanCreateOrFetchGlobalSymbols("data", binding.symbol.getSymbolFromGlobalRegistry);
assertCanCreateOrFetchGlobalSymbols("CppKey", binding.symbol.getSymbolFromGlobalRegistryWithCppKey);
assertCanCreateOrFetchGlobalSymbols("CKey", binding.symbol.getSymbolFromGlobalRegistryWithCKey);
assert(binding.symbol.createNewSymbolWithNoArgs() === undefined);
assert(binding.symbol.testNullSymbolCanBeCreated() === binding.symbol.testNullSymbolCanBeCreated());
assert(binding.symbol.testUndefinedSymbolCanBeCreated() === binding.symbol.testUndefinedSymbolCanBeCreated());
assert(binding.symbol.testUndefinedSymbolCanBeCreated() !== binding.symbol.testNullSymbolCanBeCreated());
}