source: trip-planner-front/node_modules/reflect-metadata/Reflect.js@ 76712b2

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

initial commit

  • Property mode set to 100644
File size: 50.0 KB
Line 
1/*! *****************************************************************************
2Copyright (C) Microsoft. All rights reserved.
3Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4this file except in compliance with the License. You may obtain a copy of the
5License at http://www.apache.org/licenses/LICENSE-2.0
6
7THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10MERCHANTABLITY OR NON-INFRINGEMENT.
11
12See the Apache Version 2.0 License for specific language governing permissions
13and limitations under the License.
14***************************************************************************** */
15var Reflect;
16(function (Reflect) {
17 // Metadata Proposal
18 // https://rbuckton.github.io/reflect-metadata/
19 (function (factory) {
20 var root = typeof global === "object" ? global :
21 typeof self === "object" ? self :
22 typeof this === "object" ? this :
23 Function("return this;")();
24 var exporter = makeExporter(Reflect);
25 if (typeof root.Reflect === "undefined") {
26 root.Reflect = Reflect;
27 }
28 else {
29 exporter = makeExporter(root.Reflect, exporter);
30 }
31 factory(exporter);
32 function makeExporter(target, previous) {
33 return function (key, value) {
34 if (typeof target[key] !== "function") {
35 Object.defineProperty(target, key, { configurable: true, writable: true, value: value });
36 }
37 if (previous)
38 previous(key, value);
39 };
40 }
41 })(function (exporter) {
42 var hasOwn = Object.prototype.hasOwnProperty;
43 // feature test for Symbol support
44 var supportsSymbol = typeof Symbol === "function";
45 var toPrimitiveSymbol = supportsSymbol && typeof Symbol.toPrimitive !== "undefined" ? Symbol.toPrimitive : "@@toPrimitive";
46 var iteratorSymbol = supportsSymbol && typeof Symbol.iterator !== "undefined" ? Symbol.iterator : "@@iterator";
47 var supportsCreate = typeof Object.create === "function"; // feature test for Object.create support
48 var supportsProto = { __proto__: [] } instanceof Array; // feature test for __proto__ support
49 var downLevel = !supportsCreate && !supportsProto;
50 var HashMap = {
51 // create an object in dictionary mode (a.k.a. "slow" mode in v8)
52 create: supportsCreate
53 ? function () { return MakeDictionary(Object.create(null)); }
54 : supportsProto
55 ? function () { return MakeDictionary({ __proto__: null }); }
56 : function () { return MakeDictionary({}); },
57 has: downLevel
58 ? function (map, key) { return hasOwn.call(map, key); }
59 : function (map, key) { return key in map; },
60 get: downLevel
61 ? function (map, key) { return hasOwn.call(map, key) ? map[key] : undefined; }
62 : function (map, key) { return map[key]; },
63 };
64 // Load global or shim versions of Map, Set, and WeakMap
65 var functionPrototype = Object.getPrototypeOf(Function);
66 var usePolyfill = typeof process === "object" && process.env && process.env["REFLECT_METADATA_USE_MAP_POLYFILL"] === "true";
67 var _Map = !usePolyfill && typeof Map === "function" && typeof Map.prototype.entries === "function" ? Map : CreateMapPolyfill();
68 var _Set = !usePolyfill && typeof Set === "function" && typeof Set.prototype.entries === "function" ? Set : CreateSetPolyfill();
69 var _WeakMap = !usePolyfill && typeof WeakMap === "function" ? WeakMap : CreateWeakMapPolyfill();
70 // [[Metadata]] internal slot
71 // https://rbuckton.github.io/reflect-metadata/#ordinary-object-internal-methods-and-internal-slots
72 var Metadata = new _WeakMap();
73 /**
74 * Applies a set of decorators to a property of a target object.
75 * @param decorators An array of decorators.
76 * @param target The target object.
77 * @param propertyKey (Optional) The property key to decorate.
78 * @param attributes (Optional) The property descriptor for the target key.
79 * @remarks Decorators are applied in reverse order.
80 * @example
81 *
82 * class Example {
83 * // property declarations are not part of ES6, though they are valid in TypeScript:
84 * // static staticProperty;
85 * // property;
86 *
87 * constructor(p) { }
88 * static staticMethod(p) { }
89 * method(p) { }
90 * }
91 *
92 * // constructor
93 * Example = Reflect.decorate(decoratorsArray, Example);
94 *
95 * // property (on constructor)
96 * Reflect.decorate(decoratorsArray, Example, "staticProperty");
97 *
98 * // property (on prototype)
99 * Reflect.decorate(decoratorsArray, Example.prototype, "property");
100 *
101 * // method (on constructor)
102 * Object.defineProperty(Example, "staticMethod",
103 * Reflect.decorate(decoratorsArray, Example, "staticMethod",
104 * Object.getOwnPropertyDescriptor(Example, "staticMethod")));
105 *
106 * // method (on prototype)
107 * Object.defineProperty(Example.prototype, "method",
108 * Reflect.decorate(decoratorsArray, Example.prototype, "method",
109 * Object.getOwnPropertyDescriptor(Example.prototype, "method")));
110 *
111 */
112 function decorate(decorators, target, propertyKey, attributes) {
113 if (!IsUndefined(propertyKey)) {
114 if (!IsArray(decorators))
115 throw new TypeError();
116 if (!IsObject(target))
117 throw new TypeError();
118 if (!IsObject(attributes) && !IsUndefined(attributes) && !IsNull(attributes))
119 throw new TypeError();
120 if (IsNull(attributes))
121 attributes = undefined;
122 propertyKey = ToPropertyKey(propertyKey);
123 return DecorateProperty(decorators, target, propertyKey, attributes);
124 }
125 else {
126 if (!IsArray(decorators))
127 throw new TypeError();
128 if (!IsConstructor(target))
129 throw new TypeError();
130 return DecorateConstructor(decorators, target);
131 }
132 }
133 exporter("decorate", decorate);
134 // 4.1.2 Reflect.metadata(metadataKey, metadataValue)
135 // https://rbuckton.github.io/reflect-metadata/#reflect.metadata
136 /**
137 * A default metadata decorator factory that can be used on a class, class member, or parameter.
138 * @param metadataKey The key for the metadata entry.
139 * @param metadataValue The value for the metadata entry.
140 * @returns A decorator function.
141 * @remarks
142 * If `metadataKey` is already defined for the target and target key, the
143 * metadataValue for that key will be overwritten.
144 * @example
145 *
146 * // constructor
147 * @Reflect.metadata(key, value)
148 * class Example {
149 * }
150 *
151 * // property (on constructor, TypeScript only)
152 * class Example {
153 * @Reflect.metadata(key, value)
154 * static staticProperty;
155 * }
156 *
157 * // property (on prototype, TypeScript only)
158 * class Example {
159 * @Reflect.metadata(key, value)
160 * property;
161 * }
162 *
163 * // method (on constructor)
164 * class Example {
165 * @Reflect.metadata(key, value)
166 * static staticMethod() { }
167 * }
168 *
169 * // method (on prototype)
170 * class Example {
171 * @Reflect.metadata(key, value)
172 * method() { }
173 * }
174 *
175 */
176 function metadata(metadataKey, metadataValue) {
177 function decorator(target, propertyKey) {
178 if (!IsObject(target))
179 throw new TypeError();
180 if (!IsUndefined(propertyKey) && !IsPropertyKey(propertyKey))
181 throw new TypeError();
182 OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey);
183 }
184 return decorator;
185 }
186 exporter("metadata", metadata);
187 /**
188 * Define a unique metadata entry on the target.
189 * @param metadataKey A key used to store and retrieve metadata.
190 * @param metadataValue A value that contains attached metadata.
191 * @param target The target object on which to define metadata.
192 * @param propertyKey (Optional) The property key for the target.
193 * @example
194 *
195 * class Example {
196 * // property declarations are not part of ES6, though they are valid in TypeScript:
197 * // static staticProperty;
198 * // property;
199 *
200 * constructor(p) { }
201 * static staticMethod(p) { }
202 * method(p) { }
203 * }
204 *
205 * // constructor
206 * Reflect.defineMetadata("custom:annotation", options, Example);
207 *
208 * // property (on constructor)
209 * Reflect.defineMetadata("custom:annotation", options, Example, "staticProperty");
210 *
211 * // property (on prototype)
212 * Reflect.defineMetadata("custom:annotation", options, Example.prototype, "property");
213 *
214 * // method (on constructor)
215 * Reflect.defineMetadata("custom:annotation", options, Example, "staticMethod");
216 *
217 * // method (on prototype)
218 * Reflect.defineMetadata("custom:annotation", options, Example.prototype, "method");
219 *
220 * // decorator factory as metadata-producing annotation.
221 * function MyAnnotation(options): Decorator {
222 * return (target, key?) => Reflect.defineMetadata("custom:annotation", options, target, key);
223 * }
224 *
225 */
226 function defineMetadata(metadataKey, metadataValue, target, propertyKey) {
227 if (!IsObject(target))
228 throw new TypeError();
229 if (!IsUndefined(propertyKey))
230 propertyKey = ToPropertyKey(propertyKey);
231 return OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey);
232 }
233 exporter("defineMetadata", defineMetadata);
234 /**
235 * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined.
236 * @param metadataKey A key used to store and retrieve metadata.
237 * @param target The target object on which the metadata is defined.
238 * @param propertyKey (Optional) The property key for the target.
239 * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`.
240 * @example
241 *
242 * class Example {
243 * // property declarations are not part of ES6, though they are valid in TypeScript:
244 * // static staticProperty;
245 * // property;
246 *
247 * constructor(p) { }
248 * static staticMethod(p) { }
249 * method(p) { }
250 * }
251 *
252 * // constructor
253 * result = Reflect.hasMetadata("custom:annotation", Example);
254 *
255 * // property (on constructor)
256 * result = Reflect.hasMetadata("custom:annotation", Example, "staticProperty");
257 *
258 * // property (on prototype)
259 * result = Reflect.hasMetadata("custom:annotation", Example.prototype, "property");
260 *
261 * // method (on constructor)
262 * result = Reflect.hasMetadata("custom:annotation", Example, "staticMethod");
263 *
264 * // method (on prototype)
265 * result = Reflect.hasMetadata("custom:annotation", Example.prototype, "method");
266 *
267 */
268 function hasMetadata(metadataKey, target, propertyKey) {
269 if (!IsObject(target))
270 throw new TypeError();
271 if (!IsUndefined(propertyKey))
272 propertyKey = ToPropertyKey(propertyKey);
273 return OrdinaryHasMetadata(metadataKey, target, propertyKey);
274 }
275 exporter("hasMetadata", hasMetadata);
276 /**
277 * Gets a value indicating whether the target object has the provided metadata key defined.
278 * @param metadataKey A key used to store and retrieve metadata.
279 * @param target The target object on which the metadata is defined.
280 * @param propertyKey (Optional) The property key for the target.
281 * @returns `true` if the metadata key was defined on the target object; otherwise, `false`.
282 * @example
283 *
284 * class Example {
285 * // property declarations are not part of ES6, though they are valid in TypeScript:
286 * // static staticProperty;
287 * // property;
288 *
289 * constructor(p) { }
290 * static staticMethod(p) { }
291 * method(p) { }
292 * }
293 *
294 * // constructor
295 * result = Reflect.hasOwnMetadata("custom:annotation", Example);
296 *
297 * // property (on constructor)
298 * result = Reflect.hasOwnMetadata("custom:annotation", Example, "staticProperty");
299 *
300 * // property (on prototype)
301 * result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "property");
302 *
303 * // method (on constructor)
304 * result = Reflect.hasOwnMetadata("custom:annotation", Example, "staticMethod");
305 *
306 * // method (on prototype)
307 * result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "method");
308 *
309 */
310 function hasOwnMetadata(metadataKey, target, propertyKey) {
311 if (!IsObject(target))
312 throw new TypeError();
313 if (!IsUndefined(propertyKey))
314 propertyKey = ToPropertyKey(propertyKey);
315 return OrdinaryHasOwnMetadata(metadataKey, target, propertyKey);
316 }
317 exporter("hasOwnMetadata", hasOwnMetadata);
318 /**
319 * Gets the metadata value for the provided metadata key on the target object or its prototype chain.
320 * @param metadataKey A key used to store and retrieve metadata.
321 * @param target The target object on which the metadata is defined.
322 * @param propertyKey (Optional) The property key for the target.
323 * @returns The metadata value for the metadata key if found; otherwise, `undefined`.
324 * @example
325 *
326 * class Example {
327 * // property declarations are not part of ES6, though they are valid in TypeScript:
328 * // static staticProperty;
329 * // property;
330 *
331 * constructor(p) { }
332 * static staticMethod(p) { }
333 * method(p) { }
334 * }
335 *
336 * // constructor
337 * result = Reflect.getMetadata("custom:annotation", Example);
338 *
339 * // property (on constructor)
340 * result = Reflect.getMetadata("custom:annotation", Example, "staticProperty");
341 *
342 * // property (on prototype)
343 * result = Reflect.getMetadata("custom:annotation", Example.prototype, "property");
344 *
345 * // method (on constructor)
346 * result = Reflect.getMetadata("custom:annotation", Example, "staticMethod");
347 *
348 * // method (on prototype)
349 * result = Reflect.getMetadata("custom:annotation", Example.prototype, "method");
350 *
351 */
352 function getMetadata(metadataKey, target, propertyKey) {
353 if (!IsObject(target))
354 throw new TypeError();
355 if (!IsUndefined(propertyKey))
356 propertyKey = ToPropertyKey(propertyKey);
357 return OrdinaryGetMetadata(metadataKey, target, propertyKey);
358 }
359 exporter("getMetadata", getMetadata);
360 /**
361 * Gets the metadata value for the provided metadata key on the target object.
362 * @param metadataKey A key used to store and retrieve metadata.
363 * @param target The target object on which the metadata is defined.
364 * @param propertyKey (Optional) The property key for the target.
365 * @returns The metadata value for the metadata key if found; otherwise, `undefined`.
366 * @example
367 *
368 * class Example {
369 * // property declarations are not part of ES6, though they are valid in TypeScript:
370 * // static staticProperty;
371 * // property;
372 *
373 * constructor(p) { }
374 * static staticMethod(p) { }
375 * method(p) { }
376 * }
377 *
378 * // constructor
379 * result = Reflect.getOwnMetadata("custom:annotation", Example);
380 *
381 * // property (on constructor)
382 * result = Reflect.getOwnMetadata("custom:annotation", Example, "staticProperty");
383 *
384 * // property (on prototype)
385 * result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "property");
386 *
387 * // method (on constructor)
388 * result = Reflect.getOwnMetadata("custom:annotation", Example, "staticMethod");
389 *
390 * // method (on prototype)
391 * result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "method");
392 *
393 */
394 function getOwnMetadata(metadataKey, target, propertyKey) {
395 if (!IsObject(target))
396 throw new TypeError();
397 if (!IsUndefined(propertyKey))
398 propertyKey = ToPropertyKey(propertyKey);
399 return OrdinaryGetOwnMetadata(metadataKey, target, propertyKey);
400 }
401 exporter("getOwnMetadata", getOwnMetadata);
402 /**
403 * Gets the metadata keys defined on the target object or its prototype chain.
404 * @param target The target object on which the metadata is defined.
405 * @param propertyKey (Optional) The property key for the target.
406 * @returns An array of unique metadata keys.
407 * @example
408 *
409 * class Example {
410 * // property declarations are not part of ES6, though they are valid in TypeScript:
411 * // static staticProperty;
412 * // property;
413 *
414 * constructor(p) { }
415 * static staticMethod(p) { }
416 * method(p) { }
417 * }
418 *
419 * // constructor
420 * result = Reflect.getMetadataKeys(Example);
421 *
422 * // property (on constructor)
423 * result = Reflect.getMetadataKeys(Example, "staticProperty");
424 *
425 * // property (on prototype)
426 * result = Reflect.getMetadataKeys(Example.prototype, "property");
427 *
428 * // method (on constructor)
429 * result = Reflect.getMetadataKeys(Example, "staticMethod");
430 *
431 * // method (on prototype)
432 * result = Reflect.getMetadataKeys(Example.prototype, "method");
433 *
434 */
435 function getMetadataKeys(target, propertyKey) {
436 if (!IsObject(target))
437 throw new TypeError();
438 if (!IsUndefined(propertyKey))
439 propertyKey = ToPropertyKey(propertyKey);
440 return OrdinaryMetadataKeys(target, propertyKey);
441 }
442 exporter("getMetadataKeys", getMetadataKeys);
443 /**
444 * Gets the unique metadata keys defined on the target object.
445 * @param target The target object on which the metadata is defined.
446 * @param propertyKey (Optional) The property key for the target.
447 * @returns An array of unique metadata keys.
448 * @example
449 *
450 * class Example {
451 * // property declarations are not part of ES6, though they are valid in TypeScript:
452 * // static staticProperty;
453 * // property;
454 *
455 * constructor(p) { }
456 * static staticMethod(p) { }
457 * method(p) { }
458 * }
459 *
460 * // constructor
461 * result = Reflect.getOwnMetadataKeys(Example);
462 *
463 * // property (on constructor)
464 * result = Reflect.getOwnMetadataKeys(Example, "staticProperty");
465 *
466 * // property (on prototype)
467 * result = Reflect.getOwnMetadataKeys(Example.prototype, "property");
468 *
469 * // method (on constructor)
470 * result = Reflect.getOwnMetadataKeys(Example, "staticMethod");
471 *
472 * // method (on prototype)
473 * result = Reflect.getOwnMetadataKeys(Example.prototype, "method");
474 *
475 */
476 function getOwnMetadataKeys(target, propertyKey) {
477 if (!IsObject(target))
478 throw new TypeError();
479 if (!IsUndefined(propertyKey))
480 propertyKey = ToPropertyKey(propertyKey);
481 return OrdinaryOwnMetadataKeys(target, propertyKey);
482 }
483 exporter("getOwnMetadataKeys", getOwnMetadataKeys);
484 /**
485 * Deletes the metadata entry from the target object with the provided key.
486 * @param metadataKey A key used to store and retrieve metadata.
487 * @param target The target object on which the metadata is defined.
488 * @param propertyKey (Optional) The property key for the target.
489 * @returns `true` if the metadata entry was found and deleted; otherwise, false.
490 * @example
491 *
492 * class Example {
493 * // property declarations are not part of ES6, though they are valid in TypeScript:
494 * // static staticProperty;
495 * // property;
496 *
497 * constructor(p) { }
498 * static staticMethod(p) { }
499 * method(p) { }
500 * }
501 *
502 * // constructor
503 * result = Reflect.deleteMetadata("custom:annotation", Example);
504 *
505 * // property (on constructor)
506 * result = Reflect.deleteMetadata("custom:annotation", Example, "staticProperty");
507 *
508 * // property (on prototype)
509 * result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "property");
510 *
511 * // method (on constructor)
512 * result = Reflect.deleteMetadata("custom:annotation", Example, "staticMethod");
513 *
514 * // method (on prototype)
515 * result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "method");
516 *
517 */
518 function deleteMetadata(metadataKey, target, propertyKey) {
519 if (!IsObject(target))
520 throw new TypeError();
521 if (!IsUndefined(propertyKey))
522 propertyKey = ToPropertyKey(propertyKey);
523 var metadataMap = GetOrCreateMetadataMap(target, propertyKey, /*Create*/ false);
524 if (IsUndefined(metadataMap))
525 return false;
526 if (!metadataMap.delete(metadataKey))
527 return false;
528 if (metadataMap.size > 0)
529 return true;
530 var targetMetadata = Metadata.get(target);
531 targetMetadata.delete(propertyKey);
532 if (targetMetadata.size > 0)
533 return true;
534 Metadata.delete(target);
535 return true;
536 }
537 exporter("deleteMetadata", deleteMetadata);
538 function DecorateConstructor(decorators, target) {
539 for (var i = decorators.length - 1; i >= 0; --i) {
540 var decorator = decorators[i];
541 var decorated = decorator(target);
542 if (!IsUndefined(decorated) && !IsNull(decorated)) {
543 if (!IsConstructor(decorated))
544 throw new TypeError();
545 target = decorated;
546 }
547 }
548 return target;
549 }
550 function DecorateProperty(decorators, target, propertyKey, descriptor) {
551 for (var i = decorators.length - 1; i >= 0; --i) {
552 var decorator = decorators[i];
553 var decorated = decorator(target, propertyKey, descriptor);
554 if (!IsUndefined(decorated) && !IsNull(decorated)) {
555 if (!IsObject(decorated))
556 throw new TypeError();
557 descriptor = decorated;
558 }
559 }
560 return descriptor;
561 }
562 function GetOrCreateMetadataMap(O, P, Create) {
563 var targetMetadata = Metadata.get(O);
564 if (IsUndefined(targetMetadata)) {
565 if (!Create)
566 return undefined;
567 targetMetadata = new _Map();
568 Metadata.set(O, targetMetadata);
569 }
570 var metadataMap = targetMetadata.get(P);
571 if (IsUndefined(metadataMap)) {
572 if (!Create)
573 return undefined;
574 metadataMap = new _Map();
575 targetMetadata.set(P, metadataMap);
576 }
577 return metadataMap;
578 }
579 // 3.1.1.1 OrdinaryHasMetadata(MetadataKey, O, P)
580 // https://rbuckton.github.io/reflect-metadata/#ordinaryhasmetadata
581 function OrdinaryHasMetadata(MetadataKey, O, P) {
582 var hasOwn = OrdinaryHasOwnMetadata(MetadataKey, O, P);
583 if (hasOwn)
584 return true;
585 var parent = OrdinaryGetPrototypeOf(O);
586 if (!IsNull(parent))
587 return OrdinaryHasMetadata(MetadataKey, parent, P);
588 return false;
589 }
590 // 3.1.2.1 OrdinaryHasOwnMetadata(MetadataKey, O, P)
591 // https://rbuckton.github.io/reflect-metadata/#ordinaryhasownmetadata
592 function OrdinaryHasOwnMetadata(MetadataKey, O, P) {
593 var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
594 if (IsUndefined(metadataMap))
595 return false;
596 return ToBoolean(metadataMap.has(MetadataKey));
597 }
598 // 3.1.3.1 OrdinaryGetMetadata(MetadataKey, O, P)
599 // https://rbuckton.github.io/reflect-metadata/#ordinarygetmetadata
600 function OrdinaryGetMetadata(MetadataKey, O, P) {
601 var hasOwn = OrdinaryHasOwnMetadata(MetadataKey, O, P);
602 if (hasOwn)
603 return OrdinaryGetOwnMetadata(MetadataKey, O, P);
604 var parent = OrdinaryGetPrototypeOf(O);
605 if (!IsNull(parent))
606 return OrdinaryGetMetadata(MetadataKey, parent, P);
607 return undefined;
608 }
609 // 3.1.4.1 OrdinaryGetOwnMetadata(MetadataKey, O, P)
610 // https://rbuckton.github.io/reflect-metadata/#ordinarygetownmetadata
611 function OrdinaryGetOwnMetadata(MetadataKey, O, P) {
612 var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
613 if (IsUndefined(metadataMap))
614 return undefined;
615 return metadataMap.get(MetadataKey);
616 }
617 // 3.1.5.1 OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P)
618 // https://rbuckton.github.io/reflect-metadata/#ordinarydefineownmetadata
619 function OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P) {
620 var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ true);
621 metadataMap.set(MetadataKey, MetadataValue);
622 }
623 // 3.1.6.1 OrdinaryMetadataKeys(O, P)
624 // https://rbuckton.github.io/reflect-metadata/#ordinarymetadatakeys
625 function OrdinaryMetadataKeys(O, P) {
626 var ownKeys = OrdinaryOwnMetadataKeys(O, P);
627 var parent = OrdinaryGetPrototypeOf(O);
628 if (parent === null)
629 return ownKeys;
630 var parentKeys = OrdinaryMetadataKeys(parent, P);
631 if (parentKeys.length <= 0)
632 return ownKeys;
633 if (ownKeys.length <= 0)
634 return parentKeys;
635 var set = new _Set();
636 var keys = [];
637 for (var _i = 0, ownKeys_1 = ownKeys; _i < ownKeys_1.length; _i++) {
638 var key = ownKeys_1[_i];
639 var hasKey = set.has(key);
640 if (!hasKey) {
641 set.add(key);
642 keys.push(key);
643 }
644 }
645 for (var _a = 0, parentKeys_1 = parentKeys; _a < parentKeys_1.length; _a++) {
646 var key = parentKeys_1[_a];
647 var hasKey = set.has(key);
648 if (!hasKey) {
649 set.add(key);
650 keys.push(key);
651 }
652 }
653 return keys;
654 }
655 // 3.1.7.1 OrdinaryOwnMetadataKeys(O, P)
656 // https://rbuckton.github.io/reflect-metadata/#ordinaryownmetadatakeys
657 function OrdinaryOwnMetadataKeys(O, P) {
658 var keys = [];
659 var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
660 if (IsUndefined(metadataMap))
661 return keys;
662 var keysObj = metadataMap.keys();
663 var iterator = GetIterator(keysObj);
664 var k = 0;
665 while (true) {
666 var next = IteratorStep(iterator);
667 if (!next) {
668 keys.length = k;
669 return keys;
670 }
671 var nextValue = IteratorValue(next);
672 try {
673 keys[k] = nextValue;
674 }
675 catch (e) {
676 try {
677 IteratorClose(iterator);
678 }
679 finally {
680 throw e;
681 }
682 }
683 k++;
684 }
685 }
686 // 6 ECMAScript Data Typ0es and Values
687 // https://tc39.github.io/ecma262/#sec-ecmascript-data-types-and-values
688 function Type(x) {
689 if (x === null)
690 return 1 /* Null */;
691 switch (typeof x) {
692 case "undefined": return 0 /* Undefined */;
693 case "boolean": return 2 /* Boolean */;
694 case "string": return 3 /* String */;
695 case "symbol": return 4 /* Symbol */;
696 case "number": return 5 /* Number */;
697 case "object": return x === null ? 1 /* Null */ : 6 /* Object */;
698 default: return 6 /* Object */;
699 }
700 }
701 // 6.1.1 The Undefined Type
702 // https://tc39.github.io/ecma262/#sec-ecmascript-language-types-undefined-type
703 function IsUndefined(x) {
704 return x === undefined;
705 }
706 // 6.1.2 The Null Type
707 // https://tc39.github.io/ecma262/#sec-ecmascript-language-types-null-type
708 function IsNull(x) {
709 return x === null;
710 }
711 // 6.1.5 The Symbol Type
712 // https://tc39.github.io/ecma262/#sec-ecmascript-language-types-symbol-type
713 function IsSymbol(x) {
714 return typeof x === "symbol";
715 }
716 // 6.1.7 The Object Type
717 // https://tc39.github.io/ecma262/#sec-object-type
718 function IsObject(x) {
719 return typeof x === "object" ? x !== null : typeof x === "function";
720 }
721 // 7.1 Type Conversion
722 // https://tc39.github.io/ecma262/#sec-type-conversion
723 // 7.1.1 ToPrimitive(input [, PreferredType])
724 // https://tc39.github.io/ecma262/#sec-toprimitive
725 function ToPrimitive(input, PreferredType) {
726 switch (Type(input)) {
727 case 0 /* Undefined */: return input;
728 case 1 /* Null */: return input;
729 case 2 /* Boolean */: return input;
730 case 3 /* String */: return input;
731 case 4 /* Symbol */: return input;
732 case 5 /* Number */: return input;
733 }
734 var hint = PreferredType === 3 /* String */ ? "string" : PreferredType === 5 /* Number */ ? "number" : "default";
735 var exoticToPrim = GetMethod(input, toPrimitiveSymbol);
736 if (exoticToPrim !== undefined) {
737 var result = exoticToPrim.call(input, hint);
738 if (IsObject(result))
739 throw new TypeError();
740 return result;
741 }
742 return OrdinaryToPrimitive(input, hint === "default" ? "number" : hint);
743 }
744 // 7.1.1.1 OrdinaryToPrimitive(O, hint)
745 // https://tc39.github.io/ecma262/#sec-ordinarytoprimitive
746 function OrdinaryToPrimitive(O, hint) {
747 if (hint === "string") {
748 var toString_1 = O.toString;
749 if (IsCallable(toString_1)) {
750 var result = toString_1.call(O);
751 if (!IsObject(result))
752 return result;
753 }
754 var valueOf = O.valueOf;
755 if (IsCallable(valueOf)) {
756 var result = valueOf.call(O);
757 if (!IsObject(result))
758 return result;
759 }
760 }
761 else {
762 var valueOf = O.valueOf;
763 if (IsCallable(valueOf)) {
764 var result = valueOf.call(O);
765 if (!IsObject(result))
766 return result;
767 }
768 var toString_2 = O.toString;
769 if (IsCallable(toString_2)) {
770 var result = toString_2.call(O);
771 if (!IsObject(result))
772 return result;
773 }
774 }
775 throw new TypeError();
776 }
777 // 7.1.2 ToBoolean(argument)
778 // https://tc39.github.io/ecma262/2016/#sec-toboolean
779 function ToBoolean(argument) {
780 return !!argument;
781 }
782 // 7.1.12 ToString(argument)
783 // https://tc39.github.io/ecma262/#sec-tostring
784 function ToString(argument) {
785 return "" + argument;
786 }
787 // 7.1.14 ToPropertyKey(argument)
788 // https://tc39.github.io/ecma262/#sec-topropertykey
789 function ToPropertyKey(argument) {
790 var key = ToPrimitive(argument, 3 /* String */);
791 if (IsSymbol(key))
792 return key;
793 return ToString(key);
794 }
795 // 7.2 Testing and Comparison Operations
796 // https://tc39.github.io/ecma262/#sec-testing-and-comparison-operations
797 // 7.2.2 IsArray(argument)
798 // https://tc39.github.io/ecma262/#sec-isarray
799 function IsArray(argument) {
800 return Array.isArray
801 ? Array.isArray(argument)
802 : argument instanceof Object
803 ? argument instanceof Array
804 : Object.prototype.toString.call(argument) === "[object Array]";
805 }
806 // 7.2.3 IsCallable(argument)
807 // https://tc39.github.io/ecma262/#sec-iscallable
808 function IsCallable(argument) {
809 // NOTE: This is an approximation as we cannot check for [[Call]] internal method.
810 return typeof argument === "function";
811 }
812 // 7.2.4 IsConstructor(argument)
813 // https://tc39.github.io/ecma262/#sec-isconstructor
814 function IsConstructor(argument) {
815 // NOTE: This is an approximation as we cannot check for [[Construct]] internal method.
816 return typeof argument === "function";
817 }
818 // 7.2.7 IsPropertyKey(argument)
819 // https://tc39.github.io/ecma262/#sec-ispropertykey
820 function IsPropertyKey(argument) {
821 switch (Type(argument)) {
822 case 3 /* String */: return true;
823 case 4 /* Symbol */: return true;
824 default: return false;
825 }
826 }
827 // 7.3 Operations on Objects
828 // https://tc39.github.io/ecma262/#sec-operations-on-objects
829 // 7.3.9 GetMethod(V, P)
830 // https://tc39.github.io/ecma262/#sec-getmethod
831 function GetMethod(V, P) {
832 var func = V[P];
833 if (func === undefined || func === null)
834 return undefined;
835 if (!IsCallable(func))
836 throw new TypeError();
837 return func;
838 }
839 // 7.4 Operations on Iterator Objects
840 // https://tc39.github.io/ecma262/#sec-operations-on-iterator-objects
841 function GetIterator(obj) {
842 var method = GetMethod(obj, iteratorSymbol);
843 if (!IsCallable(method))
844 throw new TypeError(); // from Call
845 var iterator = method.call(obj);
846 if (!IsObject(iterator))
847 throw new TypeError();
848 return iterator;
849 }
850 // 7.4.4 IteratorValue(iterResult)
851 // https://tc39.github.io/ecma262/2016/#sec-iteratorvalue
852 function IteratorValue(iterResult) {
853 return iterResult.value;
854 }
855 // 7.4.5 IteratorStep(iterator)
856 // https://tc39.github.io/ecma262/#sec-iteratorstep
857 function IteratorStep(iterator) {
858 var result = iterator.next();
859 return result.done ? false : result;
860 }
861 // 7.4.6 IteratorClose(iterator, completion)
862 // https://tc39.github.io/ecma262/#sec-iteratorclose
863 function IteratorClose(iterator) {
864 var f = iterator["return"];
865 if (f)
866 f.call(iterator);
867 }
868 // 9.1 Ordinary Object Internal Methods and Internal Slots
869 // https://tc39.github.io/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots
870 // 9.1.1.1 OrdinaryGetPrototypeOf(O)
871 // https://tc39.github.io/ecma262/#sec-ordinarygetprototypeof
872 function OrdinaryGetPrototypeOf(O) {
873 var proto = Object.getPrototypeOf(O);
874 if (typeof O !== "function" || O === functionPrototype)
875 return proto;
876 // TypeScript doesn't set __proto__ in ES5, as it's non-standard.
877 // Try to determine the superclass constructor. Compatible implementations
878 // must either set __proto__ on a subclass constructor to the superclass constructor,
879 // or ensure each class has a valid `constructor` property on its prototype that
880 // points back to the constructor.
881 // If this is not the same as Function.[[Prototype]], then this is definately inherited.
882 // This is the case when in ES6 or when using __proto__ in a compatible browser.
883 if (proto !== functionPrototype)
884 return proto;
885 // If the super prototype is Object.prototype, null, or undefined, then we cannot determine the heritage.
886 var prototype = O.prototype;
887 var prototypeProto = prototype && Object.getPrototypeOf(prototype);
888 if (prototypeProto == null || prototypeProto === Object.prototype)
889 return proto;
890 // If the constructor was not a function, then we cannot determine the heritage.
891 var constructor = prototypeProto.constructor;
892 if (typeof constructor !== "function")
893 return proto;
894 // If we have some kind of self-reference, then we cannot determine the heritage.
895 if (constructor === O)
896 return proto;
897 // we have a pretty good guess at the heritage.
898 return constructor;
899 }
900 // naive Map shim
901 function CreateMapPolyfill() {
902 var cacheSentinel = {};
903 var arraySentinel = [];
904 var MapIterator = /** @class */ (function () {
905 function MapIterator(keys, values, selector) {
906 this._index = 0;
907 this._keys = keys;
908 this._values = values;
909 this._selector = selector;
910 }
911 MapIterator.prototype["@@iterator"] = function () { return this; };
912 MapIterator.prototype[iteratorSymbol] = function () { return this; };
913 MapIterator.prototype.next = function () {
914 var index = this._index;
915 if (index >= 0 && index < this._keys.length) {
916 var result = this._selector(this._keys[index], this._values[index]);
917 if (index + 1 >= this._keys.length) {
918 this._index = -1;
919 this._keys = arraySentinel;
920 this._values = arraySentinel;
921 }
922 else {
923 this._index++;
924 }
925 return { value: result, done: false };
926 }
927 return { value: undefined, done: true };
928 };
929 MapIterator.prototype.throw = function (error) {
930 if (this._index >= 0) {
931 this._index = -1;
932 this._keys = arraySentinel;
933 this._values = arraySentinel;
934 }
935 throw error;
936 };
937 MapIterator.prototype.return = function (value) {
938 if (this._index >= 0) {
939 this._index = -1;
940 this._keys = arraySentinel;
941 this._values = arraySentinel;
942 }
943 return { value: value, done: true };
944 };
945 return MapIterator;
946 }());
947 return /** @class */ (function () {
948 function Map() {
949 this._keys = [];
950 this._values = [];
951 this._cacheKey = cacheSentinel;
952 this._cacheIndex = -2;
953 }
954 Object.defineProperty(Map.prototype, "size", {
955 get: function () { return this._keys.length; },
956 enumerable: true,
957 configurable: true
958 });
959 Map.prototype.has = function (key) { return this._find(key, /*insert*/ false) >= 0; };
960 Map.prototype.get = function (key) {
961 var index = this._find(key, /*insert*/ false);
962 return index >= 0 ? this._values[index] : undefined;
963 };
964 Map.prototype.set = function (key, value) {
965 var index = this._find(key, /*insert*/ true);
966 this._values[index] = value;
967 return this;
968 };
969 Map.prototype.delete = function (key) {
970 var index = this._find(key, /*insert*/ false);
971 if (index >= 0) {
972 var size = this._keys.length;
973 for (var i = index + 1; i < size; i++) {
974 this._keys[i - 1] = this._keys[i];
975 this._values[i - 1] = this._values[i];
976 }
977 this._keys.length--;
978 this._values.length--;
979 if (key === this._cacheKey) {
980 this._cacheKey = cacheSentinel;
981 this._cacheIndex = -2;
982 }
983 return true;
984 }
985 return false;
986 };
987 Map.prototype.clear = function () {
988 this._keys.length = 0;
989 this._values.length = 0;
990 this._cacheKey = cacheSentinel;
991 this._cacheIndex = -2;
992 };
993 Map.prototype.keys = function () { return new MapIterator(this._keys, this._values, getKey); };
994 Map.prototype.values = function () { return new MapIterator(this._keys, this._values, getValue); };
995 Map.prototype.entries = function () { return new MapIterator(this._keys, this._values, getEntry); };
996 Map.prototype["@@iterator"] = function () { return this.entries(); };
997 Map.prototype[iteratorSymbol] = function () { return this.entries(); };
998 Map.prototype._find = function (key, insert) {
999 if (this._cacheKey !== key) {
1000 this._cacheIndex = this._keys.indexOf(this._cacheKey = key);
1001 }
1002 if (this._cacheIndex < 0 && insert) {
1003 this._cacheIndex = this._keys.length;
1004 this._keys.push(key);
1005 this._values.push(undefined);
1006 }
1007 return this._cacheIndex;
1008 };
1009 return Map;
1010 }());
1011 function getKey(key, _) {
1012 return key;
1013 }
1014 function getValue(_, value) {
1015 return value;
1016 }
1017 function getEntry(key, value) {
1018 return [key, value];
1019 }
1020 }
1021 // naive Set shim
1022 function CreateSetPolyfill() {
1023 return /** @class */ (function () {
1024 function Set() {
1025 this._map = new _Map();
1026 }
1027 Object.defineProperty(Set.prototype, "size", {
1028 get: function () { return this._map.size; },
1029 enumerable: true,
1030 configurable: true
1031 });
1032 Set.prototype.has = function (value) { return this._map.has(value); };
1033 Set.prototype.add = function (value) { return this._map.set(value, value), this; };
1034 Set.prototype.delete = function (value) { return this._map.delete(value); };
1035 Set.prototype.clear = function () { this._map.clear(); };
1036 Set.prototype.keys = function () { return this._map.keys(); };
1037 Set.prototype.values = function () { return this._map.values(); };
1038 Set.prototype.entries = function () { return this._map.entries(); };
1039 Set.prototype["@@iterator"] = function () { return this.keys(); };
1040 Set.prototype[iteratorSymbol] = function () { return this.keys(); };
1041 return Set;
1042 }());
1043 }
1044 // naive WeakMap shim
1045 function CreateWeakMapPolyfill() {
1046 var UUID_SIZE = 16;
1047 var keys = HashMap.create();
1048 var rootKey = CreateUniqueKey();
1049 return /** @class */ (function () {
1050 function WeakMap() {
1051 this._key = CreateUniqueKey();
1052 }
1053 WeakMap.prototype.has = function (target) {
1054 var table = GetOrCreateWeakMapTable(target, /*create*/ false);
1055 return table !== undefined ? HashMap.has(table, this._key) : false;
1056 };
1057 WeakMap.prototype.get = function (target) {
1058 var table = GetOrCreateWeakMapTable(target, /*create*/ false);
1059 return table !== undefined ? HashMap.get(table, this._key) : undefined;
1060 };
1061 WeakMap.prototype.set = function (target, value) {
1062 var table = GetOrCreateWeakMapTable(target, /*create*/ true);
1063 table[this._key] = value;
1064 return this;
1065 };
1066 WeakMap.prototype.delete = function (target) {
1067 var table = GetOrCreateWeakMapTable(target, /*create*/ false);
1068 return table !== undefined ? delete table[this._key] : false;
1069 };
1070 WeakMap.prototype.clear = function () {
1071 // NOTE: not a real clear, just makes the previous data unreachable
1072 this._key = CreateUniqueKey();
1073 };
1074 return WeakMap;
1075 }());
1076 function CreateUniqueKey() {
1077 var key;
1078 do
1079 key = "@@WeakMap@@" + CreateUUID();
1080 while (HashMap.has(keys, key));
1081 keys[key] = true;
1082 return key;
1083 }
1084 function GetOrCreateWeakMapTable(target, create) {
1085 if (!hasOwn.call(target, rootKey)) {
1086 if (!create)
1087 return undefined;
1088 Object.defineProperty(target, rootKey, { value: HashMap.create() });
1089 }
1090 return target[rootKey];
1091 }
1092 function FillRandomBytes(buffer, size) {
1093 for (var i = 0; i < size; ++i)
1094 buffer[i] = Math.random() * 0xff | 0;
1095 return buffer;
1096 }
1097 function GenRandomBytes(size) {
1098 if (typeof Uint8Array === "function") {
1099 if (typeof crypto !== "undefined")
1100 return crypto.getRandomValues(new Uint8Array(size));
1101 if (typeof msCrypto !== "undefined")
1102 return msCrypto.getRandomValues(new Uint8Array(size));
1103 return FillRandomBytes(new Uint8Array(size), size);
1104 }
1105 return FillRandomBytes(new Array(size), size);
1106 }
1107 function CreateUUID() {
1108 var data = GenRandomBytes(UUID_SIZE);
1109 // mark as random - RFC 4122 § 4.4
1110 data[6] = data[6] & 0x4f | 0x40;
1111 data[8] = data[8] & 0xbf | 0x80;
1112 var result = "";
1113 for (var offset = 0; offset < UUID_SIZE; ++offset) {
1114 var byte = data[offset];
1115 if (offset === 4 || offset === 6 || offset === 8)
1116 result += "-";
1117 if (byte < 16)
1118 result += "0";
1119 result += byte.toString(16).toLowerCase();
1120 }
1121 return result;
1122 }
1123 }
1124 // uses a heuristic used by v8 and chakra to force an object into dictionary mode.
1125 function MakeDictionary(obj) {
1126 obj.__ = undefined;
1127 delete obj.__;
1128 return obj;
1129 }
1130 });
1131})(Reflect || (Reflect = {}));
Note: See TracBrowser for help on using the repository browser.