source: trip-planner-front/node_modules/core-js/modules/es.symbol.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 12.6 KB
Line 
1'use strict';
2var $ = require('../internals/export');
3var global = require('../internals/global');
4var getBuiltIn = require('../internals/get-built-in');
5var IS_PURE = require('../internals/is-pure');
6var DESCRIPTORS = require('../internals/descriptors');
7var NATIVE_SYMBOL = require('../internals/native-symbol');
8var fails = require('../internals/fails');
9var has = require('../internals/has');
10var isArray = require('../internals/is-array');
11var isObject = require('../internals/is-object');
12var isSymbol = require('../internals/is-symbol');
13var anObject = require('../internals/an-object');
14var toObject = require('../internals/to-object');
15var toIndexedObject = require('../internals/to-indexed-object');
16var toPropertyKey = require('../internals/to-property-key');
17var $toString = require('../internals/to-string');
18var createPropertyDescriptor = require('../internals/create-property-descriptor');
19var nativeObjectCreate = require('../internals/object-create');
20var objectKeys = require('../internals/object-keys');
21var getOwnPropertyNamesModule = require('../internals/object-get-own-property-names');
22var getOwnPropertyNamesExternal = require('../internals/object-get-own-property-names-external');
23var getOwnPropertySymbolsModule = require('../internals/object-get-own-property-symbols');
24var getOwnPropertyDescriptorModule = require('../internals/object-get-own-property-descriptor');
25var definePropertyModule = require('../internals/object-define-property');
26var propertyIsEnumerableModule = require('../internals/object-property-is-enumerable');
27var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
28var redefine = require('../internals/redefine');
29var shared = require('../internals/shared');
30var sharedKey = require('../internals/shared-key');
31var hiddenKeys = require('../internals/hidden-keys');
32var uid = require('../internals/uid');
33var wellKnownSymbol = require('../internals/well-known-symbol');
34var wrappedWellKnownSymbolModule = require('../internals/well-known-symbol-wrapped');
35var defineWellKnownSymbol = require('../internals/define-well-known-symbol');
36var setToStringTag = require('../internals/set-to-string-tag');
37var InternalStateModule = require('../internals/internal-state');
38var $forEach = require('../internals/array-iteration').forEach;
39
40var HIDDEN = sharedKey('hidden');
41var SYMBOL = 'Symbol';
42var PROTOTYPE = 'prototype';
43var TO_PRIMITIVE = wellKnownSymbol('toPrimitive');
44var setInternalState = InternalStateModule.set;
45var getInternalState = InternalStateModule.getterFor(SYMBOL);
46var ObjectPrototype = Object[PROTOTYPE];
47var $Symbol = global.Symbol;
48var $stringify = getBuiltIn('JSON', 'stringify');
49var nativeGetOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f;
50var nativeDefineProperty = definePropertyModule.f;
51var nativeGetOwnPropertyNames = getOwnPropertyNamesExternal.f;
52var nativePropertyIsEnumerable = propertyIsEnumerableModule.f;
53var AllSymbols = shared('symbols');
54var ObjectPrototypeSymbols = shared('op-symbols');
55var StringToSymbolRegistry = shared('string-to-symbol-registry');
56var SymbolToStringRegistry = shared('symbol-to-string-registry');
57var WellKnownSymbolsStore = shared('wks');
58var QObject = global.QObject;
59// Don't use setters in Qt Script, https://github.com/zloirock/core-js/issues/173
60var USE_SETTER = !QObject || !QObject[PROTOTYPE] || !QObject[PROTOTYPE].findChild;
61
62// fallback for old Android, https://code.google.com/p/v8/issues/detail?id=687
63var setSymbolDescriptor = DESCRIPTORS && fails(function () {
64 return nativeObjectCreate(nativeDefineProperty({}, 'a', {
65 get: function () { return nativeDefineProperty(this, 'a', { value: 7 }).a; }
66 })).a != 7;
67}) ? function (O, P, Attributes) {
68 var ObjectPrototypeDescriptor = nativeGetOwnPropertyDescriptor(ObjectPrototype, P);
69 if (ObjectPrototypeDescriptor) delete ObjectPrototype[P];
70 nativeDefineProperty(O, P, Attributes);
71 if (ObjectPrototypeDescriptor && O !== ObjectPrototype) {
72 nativeDefineProperty(ObjectPrototype, P, ObjectPrototypeDescriptor);
73 }
74} : nativeDefineProperty;
75
76var wrap = function (tag, description) {
77 var symbol = AllSymbols[tag] = nativeObjectCreate($Symbol[PROTOTYPE]);
78 setInternalState(symbol, {
79 type: SYMBOL,
80 tag: tag,
81 description: description
82 });
83 if (!DESCRIPTORS) symbol.description = description;
84 return symbol;
85};
86
87var $defineProperty = function defineProperty(O, P, Attributes) {
88 if (O === ObjectPrototype) $defineProperty(ObjectPrototypeSymbols, P, Attributes);
89 anObject(O);
90 var key = toPropertyKey(P);
91 anObject(Attributes);
92 if (has(AllSymbols, key)) {
93 if (!Attributes.enumerable) {
94 if (!has(O, HIDDEN)) nativeDefineProperty(O, HIDDEN, createPropertyDescriptor(1, {}));
95 O[HIDDEN][key] = true;
96 } else {
97 if (has(O, HIDDEN) && O[HIDDEN][key]) O[HIDDEN][key] = false;
98 Attributes = nativeObjectCreate(Attributes, { enumerable: createPropertyDescriptor(0, false) });
99 } return setSymbolDescriptor(O, key, Attributes);
100 } return nativeDefineProperty(O, key, Attributes);
101};
102
103var $defineProperties = function defineProperties(O, Properties) {
104 anObject(O);
105 var properties = toIndexedObject(Properties);
106 var keys = objectKeys(properties).concat($getOwnPropertySymbols(properties));
107 $forEach(keys, function (key) {
108 if (!DESCRIPTORS || $propertyIsEnumerable.call(properties, key)) $defineProperty(O, key, properties[key]);
109 });
110 return O;
111};
112
113var $create = function create(O, Properties) {
114 return Properties === undefined ? nativeObjectCreate(O) : $defineProperties(nativeObjectCreate(O), Properties);
115};
116
117var $propertyIsEnumerable = function propertyIsEnumerable(V) {
118 var P = toPropertyKey(V);
119 var enumerable = nativePropertyIsEnumerable.call(this, P);
120 if (this === ObjectPrototype && has(AllSymbols, P) && !has(ObjectPrototypeSymbols, P)) return false;
121 return enumerable || !has(this, P) || !has(AllSymbols, P) || has(this, HIDDEN) && this[HIDDEN][P] ? enumerable : true;
122};
123
124var $getOwnPropertyDescriptor = function getOwnPropertyDescriptor(O, P) {
125 var it = toIndexedObject(O);
126 var key = toPropertyKey(P);
127 if (it === ObjectPrototype && has(AllSymbols, key) && !has(ObjectPrototypeSymbols, key)) return;
128 var descriptor = nativeGetOwnPropertyDescriptor(it, key);
129 if (descriptor && has(AllSymbols, key) && !(has(it, HIDDEN) && it[HIDDEN][key])) {
130 descriptor.enumerable = true;
131 }
132 return descriptor;
133};
134
135var $getOwnPropertyNames = function getOwnPropertyNames(O) {
136 var names = nativeGetOwnPropertyNames(toIndexedObject(O));
137 var result = [];
138 $forEach(names, function (key) {
139 if (!has(AllSymbols, key) && !has(hiddenKeys, key)) result.push(key);
140 });
141 return result;
142};
143
144var $getOwnPropertySymbols = function getOwnPropertySymbols(O) {
145 var IS_OBJECT_PROTOTYPE = O === ObjectPrototype;
146 var names = nativeGetOwnPropertyNames(IS_OBJECT_PROTOTYPE ? ObjectPrototypeSymbols : toIndexedObject(O));
147 var result = [];
148 $forEach(names, function (key) {
149 if (has(AllSymbols, key) && (!IS_OBJECT_PROTOTYPE || has(ObjectPrototype, key))) {
150 result.push(AllSymbols[key]);
151 }
152 });
153 return result;
154};
155
156// `Symbol` constructor
157// https://tc39.es/ecma262/#sec-symbol-constructor
158if (!NATIVE_SYMBOL) {
159 $Symbol = function Symbol() {
160 if (this instanceof $Symbol) throw TypeError('Symbol is not a constructor');
161 var description = !arguments.length || arguments[0] === undefined ? undefined : $toString(arguments[0]);
162 var tag = uid(description);
163 var setter = function (value) {
164 if (this === ObjectPrototype) setter.call(ObjectPrototypeSymbols, value);
165 if (has(this, HIDDEN) && has(this[HIDDEN], tag)) this[HIDDEN][tag] = false;
166 setSymbolDescriptor(this, tag, createPropertyDescriptor(1, value));
167 };
168 if (DESCRIPTORS && USE_SETTER) setSymbolDescriptor(ObjectPrototype, tag, { configurable: true, set: setter });
169 return wrap(tag, description);
170 };
171
172 redefine($Symbol[PROTOTYPE], 'toString', function toString() {
173 return getInternalState(this).tag;
174 });
175
176 redefine($Symbol, 'withoutSetter', function (description) {
177 return wrap(uid(description), description);
178 });
179
180 propertyIsEnumerableModule.f = $propertyIsEnumerable;
181 definePropertyModule.f = $defineProperty;
182 getOwnPropertyDescriptorModule.f = $getOwnPropertyDescriptor;
183 getOwnPropertyNamesModule.f = getOwnPropertyNamesExternal.f = $getOwnPropertyNames;
184 getOwnPropertySymbolsModule.f = $getOwnPropertySymbols;
185
186 wrappedWellKnownSymbolModule.f = function (name) {
187 return wrap(wellKnownSymbol(name), name);
188 };
189
190 if (DESCRIPTORS) {
191 // https://github.com/tc39/proposal-Symbol-description
192 nativeDefineProperty($Symbol[PROTOTYPE], 'description', {
193 configurable: true,
194 get: function description() {
195 return getInternalState(this).description;
196 }
197 });
198 if (!IS_PURE) {
199 redefine(ObjectPrototype, 'propertyIsEnumerable', $propertyIsEnumerable, { unsafe: true });
200 }
201 }
202}
203
204$({ global: true, wrap: true, forced: !NATIVE_SYMBOL, sham: !NATIVE_SYMBOL }, {
205 Symbol: $Symbol
206});
207
208$forEach(objectKeys(WellKnownSymbolsStore), function (name) {
209 defineWellKnownSymbol(name);
210});
211
212$({ target: SYMBOL, stat: true, forced: !NATIVE_SYMBOL }, {
213 // `Symbol.for` method
214 // https://tc39.es/ecma262/#sec-symbol.for
215 'for': function (key) {
216 var string = $toString(key);
217 if (has(StringToSymbolRegistry, string)) return StringToSymbolRegistry[string];
218 var symbol = $Symbol(string);
219 StringToSymbolRegistry[string] = symbol;
220 SymbolToStringRegistry[symbol] = string;
221 return symbol;
222 },
223 // `Symbol.keyFor` method
224 // https://tc39.es/ecma262/#sec-symbol.keyfor
225 keyFor: function keyFor(sym) {
226 if (!isSymbol(sym)) throw TypeError(sym + ' is not a symbol');
227 if (has(SymbolToStringRegistry, sym)) return SymbolToStringRegistry[sym];
228 },
229 useSetter: function () { USE_SETTER = true; },
230 useSimple: function () { USE_SETTER = false; }
231});
232
233$({ target: 'Object', stat: true, forced: !NATIVE_SYMBOL, sham: !DESCRIPTORS }, {
234 // `Object.create` method
235 // https://tc39.es/ecma262/#sec-object.create
236 create: $create,
237 // `Object.defineProperty` method
238 // https://tc39.es/ecma262/#sec-object.defineproperty
239 defineProperty: $defineProperty,
240 // `Object.defineProperties` method
241 // https://tc39.es/ecma262/#sec-object.defineproperties
242 defineProperties: $defineProperties,
243 // `Object.getOwnPropertyDescriptor` method
244 // https://tc39.es/ecma262/#sec-object.getownpropertydescriptors
245 getOwnPropertyDescriptor: $getOwnPropertyDescriptor
246});
247
248$({ target: 'Object', stat: true, forced: !NATIVE_SYMBOL }, {
249 // `Object.getOwnPropertyNames` method
250 // https://tc39.es/ecma262/#sec-object.getownpropertynames
251 getOwnPropertyNames: $getOwnPropertyNames,
252 // `Object.getOwnPropertySymbols` method
253 // https://tc39.es/ecma262/#sec-object.getownpropertysymbols
254 getOwnPropertySymbols: $getOwnPropertySymbols
255});
256
257// Chrome 38 and 39 `Object.getOwnPropertySymbols` fails on primitives
258// https://bugs.chromium.org/p/v8/issues/detail?id=3443
259$({ target: 'Object', stat: true, forced: fails(function () { getOwnPropertySymbolsModule.f(1); }) }, {
260 getOwnPropertySymbols: function getOwnPropertySymbols(it) {
261 return getOwnPropertySymbolsModule.f(toObject(it));
262 }
263});
264
265// `JSON.stringify` method behavior with symbols
266// https://tc39.es/ecma262/#sec-json.stringify
267if ($stringify) {
268 var FORCED_JSON_STRINGIFY = !NATIVE_SYMBOL || fails(function () {
269 var symbol = $Symbol();
270 // MS Edge converts symbol values to JSON as {}
271 return $stringify([symbol]) != '[null]'
272 // WebKit converts symbol values to JSON as null
273 || $stringify({ a: symbol }) != '{}'
274 // V8 throws on boxed symbols
275 || $stringify(Object(symbol)) != '{}';
276 });
277
278 $({ target: 'JSON', stat: true, forced: FORCED_JSON_STRINGIFY }, {
279 // eslint-disable-next-line no-unused-vars -- required for `.length`
280 stringify: function stringify(it, replacer, space) {
281 var args = [it];
282 var index = 1;
283 var $replacer;
284 while (arguments.length > index) args.push(arguments[index++]);
285 $replacer = replacer;
286 if (!isObject(replacer) && it === undefined || isSymbol(it)) return; // IE8 returns string on undefined
287 if (!isArray(replacer)) replacer = function (key, value) {
288 if (typeof $replacer == 'function') value = $replacer.call(this, key, value);
289 if (!isSymbol(value)) return value;
290 };
291 args[1] = replacer;
292 return $stringify.apply(null, args);
293 }
294 });
295}
296
297// `Symbol.prototype[@@toPrimitive]` method
298// https://tc39.es/ecma262/#sec-symbol.prototype-@@toprimitive
299if (!$Symbol[PROTOTYPE][TO_PRIMITIVE]) {
300 createNonEnumerableProperty($Symbol[PROTOTYPE], TO_PRIMITIVE, $Symbol[PROTOTYPE].valueOf);
301}
302// `Symbol.prototype[@@toStringTag]` property
303// https://tc39.es/ecma262/#sec-symbol.prototype-@@tostringtag
304setToStringTag($Symbol, SYMBOL);
305
306hiddenKeys[HIDDEN] = true;
Note: See TracBrowser for help on using the repository browser.