You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
919 B
24 lines
919 B
4 weeks ago
|
'use strict';
|
||
|
var $ = require('../internals/export');
|
||
|
var getBuiltIn = require('../internals/get-built-in');
|
||
|
var hasOwn = require('../internals/has-own-property');
|
||
|
var toString = require('../internals/to-string');
|
||
|
var shared = require('../internals/shared');
|
||
|
var NATIVE_SYMBOL_REGISTRY = require('../internals/symbol-registry-detection');
|
||
|
|
||
|
var StringToSymbolRegistry = shared('string-to-symbol-registry');
|
||
|
var SymbolToStringRegistry = shared('symbol-to-string-registry');
|
||
|
|
||
|
// `Symbol.for` method
|
||
|
// https://tc39.es/ecma262/#sec-symbol.for
|
||
|
$({ target: 'Symbol', stat: true, forced: !NATIVE_SYMBOL_REGISTRY }, {
|
||
|
'for': function (key) {
|
||
|
var string = toString(key);
|
||
|
if (hasOwn(StringToSymbolRegistry, string)) return StringToSymbolRegistry[string];
|
||
|
var symbol = getBuiltIn('Symbol')(string);
|
||
|
StringToSymbolRegistry[string] = symbol;
|
||
|
SymbolToStringRegistry[symbol] = string;
|
||
|
return symbol;
|
||
|
}
|
||
|
});
|