2016-10-10 03:43:44 +02:00
|
|
|
'use strict';
|
|
|
|
// ECMAScript 6 symbols shim
|
2017-05-27 17:36:13 +02:00
|
|
|
var global = require('./_global')
|
|
|
|
, has = require('./_has')
|
|
|
|
, DESCRIPTORS = require('./_descriptors')
|
|
|
|
, $export = require('./_export')
|
|
|
|
, redefine = require('./_redefine')
|
|
|
|
, META = require('./_meta').KEY
|
|
|
|
, $fails = require('./_fails')
|
|
|
|
, shared = require('./_shared')
|
|
|
|
, setToStringTag = require('./_set-to-string-tag')
|
|
|
|
, uid = require('./_uid')
|
|
|
|
, wks = require('./_wks')
|
|
|
|
, wksExt = require('./_wks-ext')
|
|
|
|
, wksDefine = require('./_wks-define')
|
|
|
|
, keyOf = require('./_keyof')
|
|
|
|
, enumKeys = require('./_enum-keys')
|
|
|
|
, isArray = require('./_is-array')
|
|
|
|
, anObject = require('./_an-object')
|
|
|
|
, toIObject = require('./_to-iobject')
|
|
|
|
, toPrimitive = require('./_to-primitive')
|
|
|
|
, createDesc = require('./_property-desc')
|
|
|
|
, _create = require('./_object-create')
|
|
|
|
, gOPNExt = require('./_object-gopn-ext')
|
|
|
|
, $GOPD = require('./_object-gopd')
|
|
|
|
, $DP = require('./_object-dp')
|
|
|
|
, $keys = require('./_object-keys')
|
|
|
|
, gOPD = $GOPD.f
|
|
|
|
, dP = $DP.f
|
|
|
|
, gOPN = gOPNExt.f
|
2016-10-10 03:43:44 +02:00
|
|
|
, $Symbol = global.Symbol
|
|
|
|
, $JSON = global.JSON
|
|
|
|
, _stringify = $JSON && $JSON.stringify
|
2017-05-27 17:36:13 +02:00
|
|
|
, PROTOTYPE = 'prototype'
|
2016-10-10 03:43:44 +02:00
|
|
|
, HIDDEN = wks('_hidden')
|
2017-05-27 17:36:13 +02:00
|
|
|
, TO_PRIMITIVE = wks('toPrimitive')
|
|
|
|
, isEnum = {}.propertyIsEnumerable
|
2016-10-10 03:43:44 +02:00
|
|
|
, SymbolRegistry = shared('symbol-registry')
|
|
|
|
, AllSymbols = shared('symbols')
|
2017-05-27 17:36:13 +02:00
|
|
|
, OPSymbols = shared('op-symbols')
|
|
|
|
, ObjectProto = Object[PROTOTYPE]
|
|
|
|
, USE_NATIVE = typeof $Symbol == 'function'
|
|
|
|
, QObject = global.QObject;
|
|
|
|
// Don't use setters in Qt Script, https://github.com/zloirock/core-js/issues/173
|
|
|
|
var setter = !QObject || !QObject[PROTOTYPE] || !QObject[PROTOTYPE].findChild;
|
2016-10-10 03:43:44 +02:00
|
|
|
|
|
|
|
// fallback for old Android, https://code.google.com/p/v8/issues/detail?id=687
|
|
|
|
var setSymbolDesc = DESCRIPTORS && $fails(function(){
|
2017-05-27 17:36:13 +02:00
|
|
|
return _create(dP({}, 'a', {
|
|
|
|
get: function(){ return dP(this, 'a', {value: 7}).a; }
|
2016-10-10 03:43:44 +02:00
|
|
|
})).a != 7;
|
|
|
|
}) ? function(it, key, D){
|
2017-05-27 17:36:13 +02:00
|
|
|
var protoDesc = gOPD(ObjectProto, key);
|
2016-10-10 03:43:44 +02:00
|
|
|
if(protoDesc)delete ObjectProto[key];
|
2017-05-27 17:36:13 +02:00
|
|
|
dP(it, key, D);
|
|
|
|
if(protoDesc && it !== ObjectProto)dP(ObjectProto, key, protoDesc);
|
|
|
|
} : dP;
|
2016-10-10 03:43:44 +02:00
|
|
|
|
|
|
|
var wrap = function(tag){
|
2017-05-27 17:36:13 +02:00
|
|
|
var sym = AllSymbols[tag] = _create($Symbol[PROTOTYPE]);
|
2016-10-10 03:43:44 +02:00
|
|
|
sym._k = tag;
|
|
|
|
return sym;
|
|
|
|
};
|
|
|
|
|
2017-05-27 17:36:13 +02:00
|
|
|
var isSymbol = USE_NATIVE && typeof $Symbol.iterator == 'symbol' ? function(it){
|
2016-10-10 03:43:44 +02:00
|
|
|
return typeof it == 'symbol';
|
2017-05-27 17:36:13 +02:00
|
|
|
} : function(it){
|
|
|
|
return it instanceof $Symbol;
|
2016-10-10 03:43:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var $defineProperty = function defineProperty(it, key, D){
|
2017-05-27 17:36:13 +02:00
|
|
|
if(it === ObjectProto)$defineProperty(OPSymbols, key, D);
|
|
|
|
anObject(it);
|
|
|
|
key = toPrimitive(key, true);
|
|
|
|
anObject(D);
|
|
|
|
if(has(AllSymbols, key)){
|
2016-10-10 03:43:44 +02:00
|
|
|
if(!D.enumerable){
|
2017-05-27 17:36:13 +02:00
|
|
|
if(!has(it, HIDDEN))dP(it, HIDDEN, createDesc(1, {}));
|
2016-10-10 03:43:44 +02:00
|
|
|
it[HIDDEN][key] = true;
|
|
|
|
} else {
|
|
|
|
if(has(it, HIDDEN) && it[HIDDEN][key])it[HIDDEN][key] = false;
|
|
|
|
D = _create(D, {enumerable: createDesc(0, false)});
|
|
|
|
} return setSymbolDesc(it, key, D);
|
2017-05-27 17:36:13 +02:00
|
|
|
} return dP(it, key, D);
|
2016-10-10 03:43:44 +02:00
|
|
|
};
|
|
|
|
var $defineProperties = function defineProperties(it, P){
|
|
|
|
anObject(it);
|
|
|
|
var keys = enumKeys(P = toIObject(P))
|
|
|
|
, i = 0
|
|
|
|
, l = keys.length
|
|
|
|
, key;
|
|
|
|
while(l > i)$defineProperty(it, key = keys[i++], P[key]);
|
|
|
|
return it;
|
|
|
|
};
|
|
|
|
var $create = function create(it, P){
|
|
|
|
return P === undefined ? _create(it) : $defineProperties(_create(it), P);
|
|
|
|
};
|
|
|
|
var $propertyIsEnumerable = function propertyIsEnumerable(key){
|
2017-05-27 17:36:13 +02:00
|
|
|
var E = isEnum.call(this, key = toPrimitive(key, true));
|
|
|
|
if(this === ObjectProto && has(AllSymbols, key) && !has(OPSymbols, key))return false;
|
|
|
|
return E || !has(this, key) || !has(AllSymbols, key) || has(this, HIDDEN) && this[HIDDEN][key] ? E : true;
|
2016-10-10 03:43:44 +02:00
|
|
|
};
|
|
|
|
var $getOwnPropertyDescriptor = function getOwnPropertyDescriptor(it, key){
|
2017-05-27 17:36:13 +02:00
|
|
|
it = toIObject(it);
|
|
|
|
key = toPrimitive(key, true);
|
|
|
|
if(it === ObjectProto && has(AllSymbols, key) && !has(OPSymbols, key))return;
|
|
|
|
var D = gOPD(it, key);
|
2016-10-10 03:43:44 +02:00
|
|
|
if(D && has(AllSymbols, key) && !(has(it, HIDDEN) && it[HIDDEN][key]))D.enumerable = true;
|
|
|
|
return D;
|
|
|
|
};
|
|
|
|
var $getOwnPropertyNames = function getOwnPropertyNames(it){
|
2017-05-27 17:36:13 +02:00
|
|
|
var names = gOPN(toIObject(it))
|
2016-10-10 03:43:44 +02:00
|
|
|
, result = []
|
|
|
|
, i = 0
|
|
|
|
, key;
|
2017-05-27 17:36:13 +02:00
|
|
|
while(names.length > i){
|
|
|
|
if(!has(AllSymbols, key = names[i++]) && key != HIDDEN && key != META)result.push(key);
|
|
|
|
} return result;
|
2016-10-10 03:43:44 +02:00
|
|
|
};
|
|
|
|
var $getOwnPropertySymbols = function getOwnPropertySymbols(it){
|
2017-05-27 17:36:13 +02:00
|
|
|
var IS_OP = it === ObjectProto
|
|
|
|
, names = gOPN(IS_OP ? OPSymbols : toIObject(it))
|
2016-10-10 03:43:44 +02:00
|
|
|
, result = []
|
|
|
|
, i = 0
|
|
|
|
, key;
|
2017-05-27 17:36:13 +02:00
|
|
|
while(names.length > i){
|
|
|
|
if(has(AllSymbols, key = names[i++]) && (IS_OP ? has(ObjectProto, key) : true))result.push(AllSymbols[key]);
|
|
|
|
} return result;
|
2016-10-10 03:43:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// 19.4.1.1 Symbol([description])
|
2017-05-27 17:36:13 +02:00
|
|
|
if(!USE_NATIVE){
|
2016-10-10 03:43:44 +02:00
|
|
|
$Symbol = function Symbol(){
|
2017-05-27 17:36:13 +02:00
|
|
|
if(this instanceof $Symbol)throw TypeError('Symbol is not a constructor!');
|
|
|
|
var tag = uid(arguments.length > 0 ? arguments[0] : undefined);
|
|
|
|
var $set = function(value){
|
|
|
|
if(this === ObjectProto)$set.call(OPSymbols, value);
|
|
|
|
if(has(this, HIDDEN) && has(this[HIDDEN], tag))this[HIDDEN][tag] = false;
|
|
|
|
setSymbolDesc(this, tag, createDesc(1, value));
|
|
|
|
};
|
|
|
|
if(DESCRIPTORS && setter)setSymbolDesc(ObjectProto, tag, {configurable: true, set: $set});
|
|
|
|
return wrap(tag);
|
2016-10-10 03:43:44 +02:00
|
|
|
};
|
2017-05-27 17:36:13 +02:00
|
|
|
redefine($Symbol[PROTOTYPE], 'toString', function toString(){
|
2016-10-10 03:43:44 +02:00
|
|
|
return this._k;
|
|
|
|
});
|
|
|
|
|
2017-05-27 17:36:13 +02:00
|
|
|
$GOPD.f = $getOwnPropertyDescriptor;
|
|
|
|
$DP.f = $defineProperty;
|
|
|
|
require('./_object-gopn').f = gOPNExt.f = $getOwnPropertyNames;
|
|
|
|
require('./_object-pie').f = $propertyIsEnumerable;
|
|
|
|
require('./_object-gops').f = $getOwnPropertySymbols;
|
2016-10-10 03:43:44 +02:00
|
|
|
|
2017-05-27 17:36:13 +02:00
|
|
|
if(DESCRIPTORS && !require('./_library')){
|
2017-04-20 03:09:25 +02:00
|
|
|
redefine(ObjectProto, 'propertyIsEnumerable', $propertyIsEnumerable, true);
|
2016-10-10 03:43:44 +02:00
|
|
|
}
|
2017-05-27 17:36:13 +02:00
|
|
|
|
|
|
|
wksExt.f = function(name){
|
|
|
|
return wrap(wks(name));
|
|
|
|
}
|
2016-10-10 03:43:44 +02:00
|
|
|
}
|
|
|
|
|
2017-05-27 17:36:13 +02:00
|
|
|
$export($export.G + $export.W + $export.F * !USE_NATIVE, {Symbol: $Symbol});
|
|
|
|
|
|
|
|
for(var symbols = (
|
|
|
|
// 19.4.2.2, 19.4.2.3, 19.4.2.4, 19.4.2.6, 19.4.2.8, 19.4.2.9, 19.4.2.10, 19.4.2.11, 19.4.2.12, 19.4.2.13, 19.4.2.14
|
|
|
|
'hasInstance,isConcatSpreadable,iterator,match,replace,search,species,split,toPrimitive,toStringTag,unscopables'
|
|
|
|
).split(','), i = 0; symbols.length > i; )wks(symbols[i++]);
|
|
|
|
|
|
|
|
for(var symbols = $keys(wks.store), i = 0; symbols.length > i; )wksDefine(symbols[i++]);
|
|
|
|
|
|
|
|
$export($export.S + $export.F * !USE_NATIVE, 'Symbol', {
|
2016-10-10 03:43:44 +02:00
|
|
|
// 19.4.2.1 Symbol.for(key)
|
|
|
|
'for': function(key){
|
|
|
|
return has(SymbolRegistry, key += '')
|
|
|
|
? SymbolRegistry[key]
|
|
|
|
: SymbolRegistry[key] = $Symbol(key);
|
|
|
|
},
|
|
|
|
// 19.4.2.5 Symbol.keyFor(sym)
|
|
|
|
keyFor: function keyFor(key){
|
2017-05-27 17:36:13 +02:00
|
|
|
if(isSymbol(key))return keyOf(SymbolRegistry, key);
|
|
|
|
throw TypeError(key + ' is not a symbol!');
|
2016-10-10 03:43:44 +02:00
|
|
|
},
|
|
|
|
useSetter: function(){ setter = true; },
|
|
|
|
useSimple: function(){ setter = false; }
|
|
|
|
});
|
|
|
|
|
2017-05-27 17:36:13 +02:00
|
|
|
$export($export.S + $export.F * !USE_NATIVE, 'Object', {
|
2016-10-10 03:43:44 +02:00
|
|
|
// 19.1.2.2 Object.create(O [, Properties])
|
|
|
|
create: $create,
|
|
|
|
// 19.1.2.4 Object.defineProperty(O, P, Attributes)
|
|
|
|
defineProperty: $defineProperty,
|
|
|
|
// 19.1.2.3 Object.defineProperties(O, Properties)
|
|
|
|
defineProperties: $defineProperties,
|
|
|
|
// 19.1.2.6 Object.getOwnPropertyDescriptor(O, P)
|
|
|
|
getOwnPropertyDescriptor: $getOwnPropertyDescriptor,
|
|
|
|
// 19.1.2.7 Object.getOwnPropertyNames(O)
|
|
|
|
getOwnPropertyNames: $getOwnPropertyNames,
|
|
|
|
// 19.1.2.8 Object.getOwnPropertySymbols(O)
|
|
|
|
getOwnPropertySymbols: $getOwnPropertySymbols
|
|
|
|
});
|
|
|
|
|
|
|
|
// 24.3.2 JSON.stringify(value [, replacer [, space]])
|
2017-05-27 17:36:13 +02:00
|
|
|
$JSON && $export($export.S + $export.F * (!USE_NATIVE || $fails(function(){
|
|
|
|
var S = $Symbol();
|
|
|
|
// MS Edge converts symbol values to JSON as {}
|
|
|
|
// WebKit converts symbol values to JSON as null
|
|
|
|
// V8 throws on boxed symbols
|
|
|
|
return _stringify([S]) != '[null]' || _stringify({a: S}) != '{}' || _stringify(Object(S)) != '{}';
|
|
|
|
})), 'JSON', {
|
|
|
|
stringify: function stringify(it){
|
|
|
|
if(it === undefined || isSymbol(it))return; // IE8 returns string on undefined
|
|
|
|
var args = [it]
|
|
|
|
, i = 1
|
|
|
|
, replacer, $replacer;
|
|
|
|
while(arguments.length > i)args.push(arguments[i++]);
|
|
|
|
replacer = args[1];
|
|
|
|
if(typeof replacer == 'function')$replacer = replacer;
|
|
|
|
if($replacer || !isArray(replacer))replacer = function(key, value){
|
|
|
|
if($replacer)value = $replacer.call(this, key, value);
|
|
|
|
if(!isSymbol(value))return value;
|
|
|
|
};
|
|
|
|
args[1] = replacer;
|
|
|
|
return _stringify.apply($JSON, args);
|
|
|
|
}
|
|
|
|
});
|
2016-10-10 03:43:44 +02:00
|
|
|
|
2017-05-27 17:36:13 +02:00
|
|
|
// 19.4.3.4 Symbol.prototype[@@toPrimitive](hint)
|
|
|
|
$Symbol[PROTOTYPE][TO_PRIMITIVE] || require('./_hide')($Symbol[PROTOTYPE], TO_PRIMITIVE, $Symbol[PROTOTYPE].valueOf);
|
2016-10-10 03:43:44 +02:00
|
|
|
// 19.4.3.5 Symbol.prototype[@@toStringTag]
|
|
|
|
setToStringTag($Symbol, 'Symbol');
|
|
|
|
// 20.2.1.9 Math[@@toStringTag]
|
|
|
|
setToStringTag(Math, 'Math', true);
|
|
|
|
// 24.3.3 JSON[@@toStringTag]
|
|
|
|
setToStringTag(global.JSON, 'JSON', true);
|