(binding)
| 5 | module.exports = require('./common').runTest(test); |
| 6 | |
| 7 | function test (binding) { |
| 8 | const majorNodeVersion = process.versions.node.split('.')[0]; |
| 9 | |
| 10 | const wellKnownSymbolFunctions = ['asyncIterator', 'hasInstance', 'isConcatSpreadable', 'iterator', 'match', 'replace', 'search', 'split', 'species', 'toPrimitive', 'toStringTag', 'unscopables']; |
| 11 | if (majorNodeVersion >= 12) { |
| 12 | wellKnownSymbolFunctions.push('matchAll'); |
| 13 | } |
| 14 | |
| 15 | function assertCanCreateSymbol (symbol) { |
| 16 | assert(binding.symbol.createNewSymbolWithCppStr(symbol) !== null); |
| 17 | assert(binding.symbol.createNewSymbolWithCStr(symbol) !== null); |
| 18 | assert(binding.symbol.createNewSymbolWithNapi(symbol) !== null); |
| 19 | } |
| 20 | |
| 21 | function assertSymbolAreUnique (symbol) { |
| 22 | const symbolOne = binding.symbol.createNewSymbolWithCppStr(symbol); |
| 23 | const symbolTwo = binding.symbol.createNewSymbolWithCppStr(symbol); |
| 24 | |
| 25 | assert(symbolOne !== symbolTwo); |
| 26 | } |
| 27 | |
| 28 | function assertSymbolIsWellknown (symbol) { |
| 29 | const symbOne = binding.symbol.getWellKnownSymbol(symbol); |
| 30 | const symbTwo = binding.symbol.getWellKnownSymbol(symbol); |
| 31 | assert(symbOne && symbTwo); |
| 32 | assert(symbOne === symbTwo); |
| 33 | } |
| 34 | |
| 35 | function assertSymbolIsNotWellknown (symbol) { |
| 36 | const symbolTest = binding.symbol.getWellKnownSymbol(symbol); |
| 37 | assert(symbolTest === undefined); |
| 38 | } |
| 39 | |
| 40 | function assertCanCreateOrFetchGlobalSymbols (symbol, fetchFunction) { |
| 41 | const symbOne = fetchFunction(symbol); |
| 42 | const symbTwo = fetchFunction(symbol); |
| 43 | assert(symbOne && symbTwo); |
| 44 | assert(symbOne === symbTwo); |
| 45 | } |
| 46 | |
| 47 | assertCanCreateSymbol('testing'); |
| 48 | assertSymbolAreUnique('symbol'); |
| 49 | assertSymbolIsNotWellknown('testing'); |
| 50 | |
| 51 | for (const wellknownProperty of wellKnownSymbolFunctions) { |
| 52 | assertSymbolIsWellknown(wellknownProperty); |
| 53 | } |
| 54 | |
| 55 | assertCanCreateOrFetchGlobalSymbols('data', binding.symbol.getSymbolFromGlobalRegistry); |
| 56 | assertCanCreateOrFetchGlobalSymbols('CppKey', binding.symbol.getSymbolFromGlobalRegistryWithCppKey); |
| 57 | assertCanCreateOrFetchGlobalSymbols('StringViewKey', binding.symbol.getSymbolFromGlobalRegistryWithStringViewKey); |
| 58 | assertCanCreateOrFetchGlobalSymbols('CKey', binding.symbol.getSymbolFromGlobalRegistryWithCKey); |
| 59 | |
| 60 | assert(binding.symbol.createNewSymbolWithNoArgs() === undefined); |
| 61 | |
| 62 | // eslint-disable-next-line no-self-compare |
| 63 | assert(binding.symbol.testNullSymbolCanBeCreated() === binding.symbol.testNullSymbolCanBeCreated()); |
| 64 | // eslint-disable-next-line no-self-compare |
nothing calls this directly
no test coverage detected