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