Reflect.js 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415
  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 globalThis === "object" ? globalThis :
  19. typeof global === "object" ? global :
  20. typeof self === "object" ? self :
  21. typeof this === "object" ? this :
  22. sloppyModeThis();
  23. var exporter = makeExporter(Reflect);
  24. if (typeof root.Reflect !== "undefined") {
  25. exporter = makeExporter(root.Reflect, exporter);
  26. }
  27. factory(exporter, root);
  28. if (typeof root.Reflect === "undefined") {
  29. root.Reflect = Reflect;
  30. }
  31. function makeExporter(target, previous) {
  32. return function (key, value) {
  33. Object.defineProperty(target, key, { configurable: true, writable: true, value: value });
  34. if (previous)
  35. previous(key, value);
  36. };
  37. }
  38. function functionThis() {
  39. try {
  40. return Function("return this;")();
  41. }
  42. catch (_) { }
  43. }
  44. function indirectEvalThis() {
  45. try {
  46. return (void 0, eval)("(function() { return this; })()");
  47. }
  48. catch (_) { }
  49. }
  50. function sloppyModeThis() {
  51. return functionThis() || indirectEvalThis();
  52. }
  53. })(function (exporter, root) {
  54. var hasOwn = Object.prototype.hasOwnProperty;
  55. // feature test for Symbol support
  56. var supportsSymbol = typeof Symbol === "function";
  57. var toPrimitiveSymbol = supportsSymbol && typeof Symbol.toPrimitive !== "undefined" ? Symbol.toPrimitive : "@@toPrimitive";
  58. var iteratorSymbol = supportsSymbol && typeof Symbol.iterator !== "undefined" ? Symbol.iterator : "@@iterator";
  59. var supportsCreate = typeof Object.create === "function"; // feature test for Object.create support
  60. var supportsProto = { __proto__: [] } instanceof Array; // feature test for __proto__ support
  61. var downLevel = !supportsCreate && !supportsProto;
  62. var HashMap = {
  63. // create an object in dictionary mode (a.k.a. "slow" mode in v8)
  64. create: supportsCreate
  65. ? function () { return MakeDictionary(Object.create(null)); }
  66. : supportsProto
  67. ? function () { return MakeDictionary({ __proto__: null }); }
  68. : function () { return MakeDictionary({}); },
  69. has: downLevel
  70. ? function (map, key) { return hasOwn.call(map, key); }
  71. : function (map, key) { return key in map; },
  72. get: downLevel
  73. ? function (map, key) { return hasOwn.call(map, key) ? map[key] : undefined; }
  74. : function (map, key) { return map[key]; },
  75. };
  76. // Load global or shim versions of Map, Set, and WeakMap
  77. var functionPrototype = Object.getPrototypeOf(Function);
  78. var _Map = typeof Map === "function" && typeof Map.prototype.entries === "function" ? Map : CreateMapPolyfill();
  79. var _Set = typeof Set === "function" && typeof Set.prototype.entries === "function" ? Set : CreateSetPolyfill();
  80. var _WeakMap = typeof WeakMap === "function" ? WeakMap : CreateWeakMapPolyfill();
  81. var registrySymbol = supportsSymbol ? Symbol.for("@reflect-metadata:registry") : undefined;
  82. var metadataRegistry = GetOrCreateMetadataRegistry();
  83. var metadataProvider = CreateMetadataProvider(metadataRegistry);
  84. /**
  85. * Applies a set of decorators to a property of a target object.
  86. * @param decorators An array of decorators.
  87. * @param target The target object.
  88. * @param propertyKey (Optional) The property key to decorate.
  89. * @param attributes (Optional) The property descriptor for the target key.
  90. * @remarks Decorators are applied in reverse order.
  91. * @example
  92. *
  93. * class Example {
  94. * // property declarations are not part of ES6, though they are valid in TypeScript:
  95. * // static staticProperty;
  96. * // property;
  97. *
  98. * constructor(p) { }
  99. * static staticMethod(p) { }
  100. * method(p) { }
  101. * }
  102. *
  103. * // constructor
  104. * Example = Reflect.decorate(decoratorsArray, Example);
  105. *
  106. * // property (on constructor)
  107. * Reflect.decorate(decoratorsArray, Example, "staticProperty");
  108. *
  109. * // property (on prototype)
  110. * Reflect.decorate(decoratorsArray, Example.prototype, "property");
  111. *
  112. * // method (on constructor)
  113. * Object.defineProperty(Example, "staticMethod",
  114. * Reflect.decorate(decoratorsArray, Example, "staticMethod",
  115. * Object.getOwnPropertyDescriptor(Example, "staticMethod")));
  116. *
  117. * // method (on prototype)
  118. * Object.defineProperty(Example.prototype, "method",
  119. * Reflect.decorate(decoratorsArray, Example.prototype, "method",
  120. * Object.getOwnPropertyDescriptor(Example.prototype, "method")));
  121. *
  122. */
  123. function decorate(decorators, target, propertyKey, attributes) {
  124. if (!IsUndefined(propertyKey)) {
  125. if (!IsArray(decorators))
  126. throw new TypeError();
  127. if (!IsObject(target))
  128. throw new TypeError();
  129. if (!IsObject(attributes) && !IsUndefined(attributes) && !IsNull(attributes))
  130. throw new TypeError();
  131. if (IsNull(attributes))
  132. attributes = undefined;
  133. propertyKey = ToPropertyKey(propertyKey);
  134. return DecorateProperty(decorators, target, propertyKey, attributes);
  135. }
  136. else {
  137. if (!IsArray(decorators))
  138. throw new TypeError();
  139. if (!IsConstructor(target))
  140. throw new TypeError();
  141. return DecorateConstructor(decorators, target);
  142. }
  143. }
  144. exporter("decorate", decorate);
  145. // 4.1.2 Reflect.metadata(metadataKey, metadataValue)
  146. // https://rbuckton.github.io/reflect-metadata/#reflect.metadata
  147. /**
  148. * A default metadata decorator factory that can be used on a class, class member, or parameter.
  149. * @param metadataKey The key for the metadata entry.
  150. * @param metadataValue The value for the metadata entry.
  151. * @returns A decorator function.
  152. * @remarks
  153. * If `metadataKey` is already defined for the target and target key, the
  154. * metadataValue for that key will be overwritten.
  155. * @example
  156. *
  157. * // constructor
  158. * @Reflect.metadata(key, value)
  159. * class Example {
  160. * }
  161. *
  162. * // property (on constructor, TypeScript only)
  163. * class Example {
  164. * @Reflect.metadata(key, value)
  165. * static staticProperty;
  166. * }
  167. *
  168. * // property (on prototype, TypeScript only)
  169. * class Example {
  170. * @Reflect.metadata(key, value)
  171. * property;
  172. * }
  173. *
  174. * // method (on constructor)
  175. * class Example {
  176. * @Reflect.metadata(key, value)
  177. * static staticMethod() { }
  178. * }
  179. *
  180. * // method (on prototype)
  181. * class Example {
  182. * @Reflect.metadata(key, value)
  183. * method() { }
  184. * }
  185. *
  186. */
  187. function metadata(metadataKey, metadataValue) {
  188. function decorator(target, propertyKey) {
  189. if (!IsObject(target))
  190. throw new TypeError();
  191. if (!IsUndefined(propertyKey) && !IsPropertyKey(propertyKey))
  192. throw new TypeError();
  193. OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey);
  194. }
  195. return decorator;
  196. }
  197. exporter("metadata", metadata);
  198. /**
  199. * Define a unique metadata entry on the target.
  200. * @param metadataKey A key used to store and retrieve metadata.
  201. * @param metadataValue A value that contains attached metadata.
  202. * @param target The target object on which to define metadata.
  203. * @param propertyKey (Optional) The property key for the target.
  204. * @example
  205. *
  206. * class Example {
  207. * // property declarations are not part of ES6, though they are valid in TypeScript:
  208. * // static staticProperty;
  209. * // property;
  210. *
  211. * constructor(p) { }
  212. * static staticMethod(p) { }
  213. * method(p) { }
  214. * }
  215. *
  216. * // constructor
  217. * Reflect.defineMetadata("custom:annotation", options, Example);
  218. *
  219. * // property (on constructor)
  220. * Reflect.defineMetadata("custom:annotation", options, Example, "staticProperty");
  221. *
  222. * // property (on prototype)
  223. * Reflect.defineMetadata("custom:annotation", options, Example.prototype, "property");
  224. *
  225. * // method (on constructor)
  226. * Reflect.defineMetadata("custom:annotation", options, Example, "staticMethod");
  227. *
  228. * // method (on prototype)
  229. * Reflect.defineMetadata("custom:annotation", options, Example.prototype, "method");
  230. *
  231. * // decorator factory as metadata-producing annotation.
  232. * function MyAnnotation(options): Decorator {
  233. * return (target, key?) => Reflect.defineMetadata("custom:annotation", options, target, key);
  234. * }
  235. *
  236. */
  237. function defineMetadata(metadataKey, metadataValue, target, propertyKey) {
  238. if (!IsObject(target))
  239. throw new TypeError();
  240. if (!IsUndefined(propertyKey))
  241. propertyKey = ToPropertyKey(propertyKey);
  242. return OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey);
  243. }
  244. exporter("defineMetadata", defineMetadata);
  245. /**
  246. * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined.
  247. * @param metadataKey A key used to store and retrieve metadata.
  248. * @param target The target object on which the metadata is defined.
  249. * @param propertyKey (Optional) The property key for the target.
  250. * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`.
  251. * @example
  252. *
  253. * class Example {
  254. * // property declarations are not part of ES6, though they are valid in TypeScript:
  255. * // static staticProperty;
  256. * // property;
  257. *
  258. * constructor(p) { }
  259. * static staticMethod(p) { }
  260. * method(p) { }
  261. * }
  262. *
  263. * // constructor
  264. * result = Reflect.hasMetadata("custom:annotation", Example);
  265. *
  266. * // property (on constructor)
  267. * result = Reflect.hasMetadata("custom:annotation", Example, "staticProperty");
  268. *
  269. * // property (on prototype)
  270. * result = Reflect.hasMetadata("custom:annotation", Example.prototype, "property");
  271. *
  272. * // method (on constructor)
  273. * result = Reflect.hasMetadata("custom:annotation", Example, "staticMethod");
  274. *
  275. * // method (on prototype)
  276. * result = Reflect.hasMetadata("custom:annotation", Example.prototype, "method");
  277. *
  278. */
  279. function hasMetadata(metadataKey, target, propertyKey) {
  280. if (!IsObject(target))
  281. throw new TypeError();
  282. if (!IsUndefined(propertyKey))
  283. propertyKey = ToPropertyKey(propertyKey);
  284. return OrdinaryHasMetadata(metadataKey, target, propertyKey);
  285. }
  286. exporter("hasMetadata", hasMetadata);
  287. /**
  288. * Gets a value indicating whether the target object has the provided metadata key defined.
  289. * @param metadataKey A key used to store and retrieve metadata.
  290. * @param target The target object on which the metadata is defined.
  291. * @param propertyKey (Optional) The property key for the target.
  292. * @returns `true` if the metadata key was defined on the target object; otherwise, `false`.
  293. * @example
  294. *
  295. * class Example {
  296. * // property declarations are not part of ES6, though they are valid in TypeScript:
  297. * // static staticProperty;
  298. * // property;
  299. *
  300. * constructor(p) { }
  301. * static staticMethod(p) { }
  302. * method(p) { }
  303. * }
  304. *
  305. * // constructor
  306. * result = Reflect.hasOwnMetadata("custom:annotation", Example);
  307. *
  308. * // property (on constructor)
  309. * result = Reflect.hasOwnMetadata("custom:annotation", Example, "staticProperty");
  310. *
  311. * // property (on prototype)
  312. * result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "property");
  313. *
  314. * // method (on constructor)
  315. * result = Reflect.hasOwnMetadata("custom:annotation", Example, "staticMethod");
  316. *
  317. * // method (on prototype)
  318. * result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "method");
  319. *
  320. */
  321. function hasOwnMetadata(metadataKey, target, propertyKey) {
  322. if (!IsObject(target))
  323. throw new TypeError();
  324. if (!IsUndefined(propertyKey))
  325. propertyKey = ToPropertyKey(propertyKey);
  326. return OrdinaryHasOwnMetadata(metadataKey, target, propertyKey);
  327. }
  328. exporter("hasOwnMetadata", hasOwnMetadata);
  329. /**
  330. * Gets the metadata value for the provided metadata key on the target object or its prototype chain.
  331. * @param metadataKey A key used to store and retrieve metadata.
  332. * @param target The target object on which the metadata is defined.
  333. * @param propertyKey (Optional) The property key for the target.
  334. * @returns The metadata value for the metadata key if found; otherwise, `undefined`.
  335. * @example
  336. *
  337. * class Example {
  338. * // property declarations are not part of ES6, though they are valid in TypeScript:
  339. * // static staticProperty;
  340. * // property;
  341. *
  342. * constructor(p) { }
  343. * static staticMethod(p) { }
  344. * method(p) { }
  345. * }
  346. *
  347. * // constructor
  348. * result = Reflect.getMetadata("custom:annotation", Example);
  349. *
  350. * // property (on constructor)
  351. * result = Reflect.getMetadata("custom:annotation", Example, "staticProperty");
  352. *
  353. * // property (on prototype)
  354. * result = Reflect.getMetadata("custom:annotation", Example.prototype, "property");
  355. *
  356. * // method (on constructor)
  357. * result = Reflect.getMetadata("custom:annotation", Example, "staticMethod");
  358. *
  359. * // method (on prototype)
  360. * result = Reflect.getMetadata("custom:annotation", Example.prototype, "method");
  361. *
  362. */
  363. function getMetadata(metadataKey, target, propertyKey) {
  364. if (!IsObject(target))
  365. throw new TypeError();
  366. if (!IsUndefined(propertyKey))
  367. propertyKey = ToPropertyKey(propertyKey);
  368. return OrdinaryGetMetadata(metadataKey, target, propertyKey);
  369. }
  370. exporter("getMetadata", getMetadata);
  371. /**
  372. * Gets the metadata value for the provided metadata key on the target object.
  373. * @param metadataKey A key used to store and retrieve metadata.
  374. * @param target The target object on which the metadata is defined.
  375. * @param propertyKey (Optional) The property key for the target.
  376. * @returns The metadata value for the metadata key if found; otherwise, `undefined`.
  377. * @example
  378. *
  379. * class Example {
  380. * // property declarations are not part of ES6, though they are valid in TypeScript:
  381. * // static staticProperty;
  382. * // property;
  383. *
  384. * constructor(p) { }
  385. * static staticMethod(p) { }
  386. * method(p) { }
  387. * }
  388. *
  389. * // constructor
  390. * result = Reflect.getOwnMetadata("custom:annotation", Example);
  391. *
  392. * // property (on constructor)
  393. * result = Reflect.getOwnMetadata("custom:annotation", Example, "staticProperty");
  394. *
  395. * // property (on prototype)
  396. * result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "property");
  397. *
  398. * // method (on constructor)
  399. * result = Reflect.getOwnMetadata("custom:annotation", Example, "staticMethod");
  400. *
  401. * // method (on prototype)
  402. * result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "method");
  403. *
  404. */
  405. function getOwnMetadata(metadataKey, target, propertyKey) {
  406. if (!IsObject(target))
  407. throw new TypeError();
  408. if (!IsUndefined(propertyKey))
  409. propertyKey = ToPropertyKey(propertyKey);
  410. return OrdinaryGetOwnMetadata(metadataKey, target, propertyKey);
  411. }
  412. exporter("getOwnMetadata", getOwnMetadata);
  413. /**
  414. * Gets the metadata keys defined on the target object or its prototype chain.
  415. * @param target The target object on which the metadata is defined.
  416. * @param propertyKey (Optional) The property key for the target.
  417. * @returns An array of unique metadata keys.
  418. * @example
  419. *
  420. * class Example {
  421. * // property declarations are not part of ES6, though they are valid in TypeScript:
  422. * // static staticProperty;
  423. * // property;
  424. *
  425. * constructor(p) { }
  426. * static staticMethod(p) { }
  427. * method(p) { }
  428. * }
  429. *
  430. * // constructor
  431. * result = Reflect.getMetadataKeys(Example);
  432. *
  433. * // property (on constructor)
  434. * result = Reflect.getMetadataKeys(Example, "staticProperty");
  435. *
  436. * // property (on prototype)
  437. * result = Reflect.getMetadataKeys(Example.prototype, "property");
  438. *
  439. * // method (on constructor)
  440. * result = Reflect.getMetadataKeys(Example, "staticMethod");
  441. *
  442. * // method (on prototype)
  443. * result = Reflect.getMetadataKeys(Example.prototype, "method");
  444. *
  445. */
  446. function getMetadataKeys(target, propertyKey) {
  447. if (!IsObject(target))
  448. throw new TypeError();
  449. if (!IsUndefined(propertyKey))
  450. propertyKey = ToPropertyKey(propertyKey);
  451. return OrdinaryMetadataKeys(target, propertyKey);
  452. }
  453. exporter("getMetadataKeys", getMetadataKeys);
  454. /**
  455. * Gets the unique metadata keys defined on the target object.
  456. * @param target The target object on which the metadata is defined.
  457. * @param propertyKey (Optional) The property key for the target.
  458. * @returns An array of unique metadata keys.
  459. * @example
  460. *
  461. * class Example {
  462. * // property declarations are not part of ES6, though they are valid in TypeScript:
  463. * // static staticProperty;
  464. * // property;
  465. *
  466. * constructor(p) { }
  467. * static staticMethod(p) { }
  468. * method(p) { }
  469. * }
  470. *
  471. * // constructor
  472. * result = Reflect.getOwnMetadataKeys(Example);
  473. *
  474. * // property (on constructor)
  475. * result = Reflect.getOwnMetadataKeys(Example, "staticProperty");
  476. *
  477. * // property (on prototype)
  478. * result = Reflect.getOwnMetadataKeys(Example.prototype, "property");
  479. *
  480. * // method (on constructor)
  481. * result = Reflect.getOwnMetadataKeys(Example, "staticMethod");
  482. *
  483. * // method (on prototype)
  484. * result = Reflect.getOwnMetadataKeys(Example.prototype, "method");
  485. *
  486. */
  487. function getOwnMetadataKeys(target, propertyKey) {
  488. if (!IsObject(target))
  489. throw new TypeError();
  490. if (!IsUndefined(propertyKey))
  491. propertyKey = ToPropertyKey(propertyKey);
  492. return OrdinaryOwnMetadataKeys(target, propertyKey);
  493. }
  494. exporter("getOwnMetadataKeys", getOwnMetadataKeys);
  495. /**
  496. * Deletes the metadata entry from the target object with the provided key.
  497. * @param metadataKey A key used to store and retrieve metadata.
  498. * @param target The target object on which the metadata is defined.
  499. * @param propertyKey (Optional) The property key for the target.
  500. * @returns `true` if the metadata entry was found and deleted; otherwise, false.
  501. * @example
  502. *
  503. * class Example {
  504. * // property declarations are not part of ES6, though they are valid in TypeScript:
  505. * // static staticProperty;
  506. * // property;
  507. *
  508. * constructor(p) { }
  509. * static staticMethod(p) { }
  510. * method(p) { }
  511. * }
  512. *
  513. * // constructor
  514. * result = Reflect.deleteMetadata("custom:annotation", Example);
  515. *
  516. * // property (on constructor)
  517. * result = Reflect.deleteMetadata("custom:annotation", Example, "staticProperty");
  518. *
  519. * // property (on prototype)
  520. * result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "property");
  521. *
  522. * // method (on constructor)
  523. * result = Reflect.deleteMetadata("custom:annotation", Example, "staticMethod");
  524. *
  525. * // method (on prototype)
  526. * result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "method");
  527. *
  528. */
  529. function deleteMetadata(metadataKey, target, propertyKey) {
  530. if (!IsObject(target))
  531. throw new TypeError();
  532. if (!IsUndefined(propertyKey))
  533. propertyKey = ToPropertyKey(propertyKey);
  534. if (!IsObject(target))
  535. throw new TypeError();
  536. if (!IsUndefined(propertyKey))
  537. propertyKey = ToPropertyKey(propertyKey);
  538. var provider = GetMetadataProvider(target, propertyKey, /*Create*/ false);
  539. if (IsUndefined(provider))
  540. return false;
  541. return provider.OrdinaryDeleteMetadata(metadataKey, target, propertyKey);
  542. }
  543. exporter("deleteMetadata", deleteMetadata);
  544. function DecorateConstructor(decorators, target) {
  545. for (var i = decorators.length - 1; i >= 0; --i) {
  546. var decorator = decorators[i];
  547. var decorated = decorator(target);
  548. if (!IsUndefined(decorated) && !IsNull(decorated)) {
  549. if (!IsConstructor(decorated))
  550. throw new TypeError();
  551. target = decorated;
  552. }
  553. }
  554. return target;
  555. }
  556. function DecorateProperty(decorators, target, propertyKey, descriptor) {
  557. for (var i = decorators.length - 1; i >= 0; --i) {
  558. var decorator = decorators[i];
  559. var decorated = decorator(target, propertyKey, descriptor);
  560. if (!IsUndefined(decorated) && !IsNull(decorated)) {
  561. if (!IsObject(decorated))
  562. throw new TypeError();
  563. descriptor = decorated;
  564. }
  565. }
  566. return descriptor;
  567. }
  568. // 3.1.1.1 OrdinaryHasMetadata(MetadataKey, O, P)
  569. // https://rbuckton.github.io/reflect-metadata/#ordinaryhasmetadata
  570. function OrdinaryHasMetadata(MetadataKey, O, P) {
  571. var hasOwn = OrdinaryHasOwnMetadata(MetadataKey, O, P);
  572. if (hasOwn)
  573. return true;
  574. var parent = OrdinaryGetPrototypeOf(O);
  575. if (!IsNull(parent))
  576. return OrdinaryHasMetadata(MetadataKey, parent, P);
  577. return false;
  578. }
  579. // 3.1.2.1 OrdinaryHasOwnMetadata(MetadataKey, O, P)
  580. // https://rbuckton.github.io/reflect-metadata/#ordinaryhasownmetadata
  581. function OrdinaryHasOwnMetadata(MetadataKey, O, P) {
  582. var provider = GetMetadataProvider(O, P, /*Create*/ false);
  583. if (IsUndefined(provider))
  584. return false;
  585. return ToBoolean(provider.OrdinaryHasOwnMetadata(MetadataKey, O, P));
  586. }
  587. // 3.1.3.1 OrdinaryGetMetadata(MetadataKey, O, P)
  588. // https://rbuckton.github.io/reflect-metadata/#ordinarygetmetadata
  589. function OrdinaryGetMetadata(MetadataKey, O, P) {
  590. var hasOwn = OrdinaryHasOwnMetadata(MetadataKey, O, P);
  591. if (hasOwn)
  592. return OrdinaryGetOwnMetadata(MetadataKey, O, P);
  593. var parent = OrdinaryGetPrototypeOf(O);
  594. if (!IsNull(parent))
  595. return OrdinaryGetMetadata(MetadataKey, parent, P);
  596. return undefined;
  597. }
  598. // 3.1.4.1 OrdinaryGetOwnMetadata(MetadataKey, O, P)
  599. // https://rbuckton.github.io/reflect-metadata/#ordinarygetownmetadata
  600. function OrdinaryGetOwnMetadata(MetadataKey, O, P) {
  601. var provider = GetMetadataProvider(O, P, /*Create*/ false);
  602. if (IsUndefined(provider))
  603. return;
  604. return provider.OrdinaryGetOwnMetadata(MetadataKey, O, P);
  605. }
  606. // 3.1.5.1 OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P)
  607. // https://rbuckton.github.io/reflect-metadata/#ordinarydefineownmetadata
  608. function OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P) {
  609. var provider = GetMetadataProvider(O, P, /*Create*/ true);
  610. provider.OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P);
  611. }
  612. // 3.1.6.1 OrdinaryMetadataKeys(O, P)
  613. // https://rbuckton.github.io/reflect-metadata/#ordinarymetadatakeys
  614. function OrdinaryMetadataKeys(O, P) {
  615. var ownKeys = OrdinaryOwnMetadataKeys(O, P);
  616. var parent = OrdinaryGetPrototypeOf(O);
  617. if (parent === null)
  618. return ownKeys;
  619. var parentKeys = OrdinaryMetadataKeys(parent, P);
  620. if (parentKeys.length <= 0)
  621. return ownKeys;
  622. if (ownKeys.length <= 0)
  623. return parentKeys;
  624. var set = new _Set();
  625. var keys = [];
  626. for (var _i = 0, ownKeys_1 = ownKeys; _i < ownKeys_1.length; _i++) {
  627. var key = ownKeys_1[_i];
  628. var hasKey = set.has(key);
  629. if (!hasKey) {
  630. set.add(key);
  631. keys.push(key);
  632. }
  633. }
  634. for (var _a = 0, parentKeys_1 = parentKeys; _a < parentKeys_1.length; _a++) {
  635. var key = parentKeys_1[_a];
  636. var hasKey = set.has(key);
  637. if (!hasKey) {
  638. set.add(key);
  639. keys.push(key);
  640. }
  641. }
  642. return keys;
  643. }
  644. // 3.1.7.1 OrdinaryOwnMetadataKeys(O, P)
  645. // https://rbuckton.github.io/reflect-metadata/#ordinaryownmetadatakeys
  646. function OrdinaryOwnMetadataKeys(O, P) {
  647. var provider = GetMetadataProvider(O, P, /*create*/ false);
  648. if (!provider) {
  649. return [];
  650. }
  651. return provider.OrdinaryOwnMetadataKeys(O, P);
  652. }
  653. // 6 ECMAScript Data Types and Values
  654. // https://tc39.github.io/ecma262/#sec-ecmascript-data-types-and-values
  655. function Type(x) {
  656. if (x === null)
  657. return 1 /* Null */;
  658. switch (typeof x) {
  659. case "undefined": return 0 /* Undefined */;
  660. case "boolean": return 2 /* Boolean */;
  661. case "string": return 3 /* String */;
  662. case "symbol": return 4 /* Symbol */;
  663. case "number": return 5 /* Number */;
  664. case "object": return x === null ? 1 /* Null */ : 6 /* Object */;
  665. default: return 6 /* Object */;
  666. }
  667. }
  668. // 6.1.1 The Undefined Type
  669. // https://tc39.github.io/ecma262/#sec-ecmascript-language-types-undefined-type
  670. function IsUndefined(x) {
  671. return x === undefined;
  672. }
  673. // 6.1.2 The Null Type
  674. // https://tc39.github.io/ecma262/#sec-ecmascript-language-types-null-type
  675. function IsNull(x) {
  676. return x === null;
  677. }
  678. // 6.1.5 The Symbol Type
  679. // https://tc39.github.io/ecma262/#sec-ecmascript-language-types-symbol-type
  680. function IsSymbol(x) {
  681. return typeof x === "symbol";
  682. }
  683. // 6.1.7 The Object Type
  684. // https://tc39.github.io/ecma262/#sec-object-type
  685. function IsObject(x) {
  686. return typeof x === "object" ? x !== null : typeof x === "function";
  687. }
  688. // 7.1 Type Conversion
  689. // https://tc39.github.io/ecma262/#sec-type-conversion
  690. // 7.1.1 ToPrimitive(input [, PreferredType])
  691. // https://tc39.github.io/ecma262/#sec-toprimitive
  692. function ToPrimitive(input, PreferredType) {
  693. switch (Type(input)) {
  694. case 0 /* Undefined */: return input;
  695. case 1 /* Null */: return input;
  696. case 2 /* Boolean */: return input;
  697. case 3 /* String */: return input;
  698. case 4 /* Symbol */: return input;
  699. case 5 /* Number */: return input;
  700. }
  701. var hint = PreferredType === 3 /* String */ ? "string" : PreferredType === 5 /* Number */ ? "number" : "default";
  702. var exoticToPrim = GetMethod(input, toPrimitiveSymbol);
  703. if (exoticToPrim !== undefined) {
  704. var result = exoticToPrim.call(input, hint);
  705. if (IsObject(result))
  706. throw new TypeError();
  707. return result;
  708. }
  709. return OrdinaryToPrimitive(input, hint === "default" ? "number" : hint);
  710. }
  711. // 7.1.1.1 OrdinaryToPrimitive(O, hint)
  712. // https://tc39.github.io/ecma262/#sec-ordinarytoprimitive
  713. function OrdinaryToPrimitive(O, hint) {
  714. if (hint === "string") {
  715. var toString_1 = O.toString;
  716. if (IsCallable(toString_1)) {
  717. var result = toString_1.call(O);
  718. if (!IsObject(result))
  719. return result;
  720. }
  721. var valueOf = O.valueOf;
  722. if (IsCallable(valueOf)) {
  723. var result = valueOf.call(O);
  724. if (!IsObject(result))
  725. return result;
  726. }
  727. }
  728. else {
  729. var valueOf = O.valueOf;
  730. if (IsCallable(valueOf)) {
  731. var result = valueOf.call(O);
  732. if (!IsObject(result))
  733. return result;
  734. }
  735. var toString_2 = O.toString;
  736. if (IsCallable(toString_2)) {
  737. var result = toString_2.call(O);
  738. if (!IsObject(result))
  739. return result;
  740. }
  741. }
  742. throw new TypeError();
  743. }
  744. // 7.1.2 ToBoolean(argument)
  745. // https://tc39.github.io/ecma262/2016/#sec-toboolean
  746. function ToBoolean(argument) {
  747. return !!argument;
  748. }
  749. // 7.1.12 ToString(argument)
  750. // https://tc39.github.io/ecma262/#sec-tostring
  751. function ToString(argument) {
  752. return "" + argument;
  753. }
  754. // 7.1.14 ToPropertyKey(argument)
  755. // https://tc39.github.io/ecma262/#sec-topropertykey
  756. function ToPropertyKey(argument) {
  757. var key = ToPrimitive(argument, 3 /* String */);
  758. if (IsSymbol(key))
  759. return key;
  760. return ToString(key);
  761. }
  762. // 7.2 Testing and Comparison Operations
  763. // https://tc39.github.io/ecma262/#sec-testing-and-comparison-operations
  764. // 7.2.2 IsArray(argument)
  765. // https://tc39.github.io/ecma262/#sec-isarray
  766. function IsArray(argument) {
  767. return Array.isArray
  768. ? Array.isArray(argument)
  769. : argument instanceof Object
  770. ? argument instanceof Array
  771. : Object.prototype.toString.call(argument) === "[object Array]";
  772. }
  773. // 7.2.3 IsCallable(argument)
  774. // https://tc39.github.io/ecma262/#sec-iscallable
  775. function IsCallable(argument) {
  776. // NOTE: This is an approximation as we cannot check for [[Call]] internal method.
  777. return typeof argument === "function";
  778. }
  779. // 7.2.4 IsConstructor(argument)
  780. // https://tc39.github.io/ecma262/#sec-isconstructor
  781. function IsConstructor(argument) {
  782. // NOTE: This is an approximation as we cannot check for [[Construct]] internal method.
  783. return typeof argument === "function";
  784. }
  785. // 7.2.7 IsPropertyKey(argument)
  786. // https://tc39.github.io/ecma262/#sec-ispropertykey
  787. function IsPropertyKey(argument) {
  788. switch (Type(argument)) {
  789. case 3 /* String */: return true;
  790. case 4 /* Symbol */: return true;
  791. default: return false;
  792. }
  793. }
  794. function SameValueZero(x, y) {
  795. return x === y || x !== x && y !== y;
  796. }
  797. // 7.3 Operations on Objects
  798. // https://tc39.github.io/ecma262/#sec-operations-on-objects
  799. // 7.3.9 GetMethod(V, P)
  800. // https://tc39.github.io/ecma262/#sec-getmethod
  801. function GetMethod(V, P) {
  802. var func = V[P];
  803. if (func === undefined || func === null)
  804. return undefined;
  805. if (!IsCallable(func))
  806. throw new TypeError();
  807. return func;
  808. }
  809. // 7.4 Operations on Iterator Objects
  810. // https://tc39.github.io/ecma262/#sec-operations-on-iterator-objects
  811. function GetIterator(obj) {
  812. var method = GetMethod(obj, iteratorSymbol);
  813. if (!IsCallable(method))
  814. throw new TypeError(); // from Call
  815. var iterator = method.call(obj);
  816. if (!IsObject(iterator))
  817. throw new TypeError();
  818. return iterator;
  819. }
  820. // 7.4.4 IteratorValue(iterResult)
  821. // https://tc39.github.io/ecma262/2016/#sec-iteratorvalue
  822. function IteratorValue(iterResult) {
  823. return iterResult.value;
  824. }
  825. // 7.4.5 IteratorStep(iterator)
  826. // https://tc39.github.io/ecma262/#sec-iteratorstep
  827. function IteratorStep(iterator) {
  828. var result = iterator.next();
  829. return result.done ? false : result;
  830. }
  831. // 7.4.6 IteratorClose(iterator, completion)
  832. // https://tc39.github.io/ecma262/#sec-iteratorclose
  833. function IteratorClose(iterator) {
  834. var f = iterator["return"];
  835. if (f)
  836. f.call(iterator);
  837. }
  838. // 9.1 Ordinary Object Internal Methods and Internal Slots
  839. // https://tc39.github.io/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots
  840. // 9.1.1.1 OrdinaryGetPrototypeOf(O)
  841. // https://tc39.github.io/ecma262/#sec-ordinarygetprototypeof
  842. function OrdinaryGetPrototypeOf(O) {
  843. var proto = Object.getPrototypeOf(O);
  844. if (typeof O !== "function" || O === functionPrototype)
  845. return proto;
  846. // TypeScript doesn't set __proto__ in ES5, as it's non-standard.
  847. // Try to determine the superclass constructor. Compatible implementations
  848. // must either set __proto__ on a subclass constructor to the superclass constructor,
  849. // or ensure each class has a valid `constructor` property on its prototype that
  850. // points back to the constructor.
  851. // If this is not the same as Function.[[Prototype]], then this is definately inherited.
  852. // This is the case when in ES6 or when using __proto__ in a compatible browser.
  853. if (proto !== functionPrototype)
  854. return proto;
  855. // If the super prototype is Object.prototype, null, or undefined, then we cannot determine the heritage.
  856. var prototype = O.prototype;
  857. var prototypeProto = prototype && Object.getPrototypeOf(prototype);
  858. if (prototypeProto == null || prototypeProto === Object.prototype)
  859. return proto;
  860. // If the constructor was not a function, then we cannot determine the heritage.
  861. var constructor = prototypeProto.constructor;
  862. if (typeof constructor !== "function")
  863. return proto;
  864. // If we have some kind of self-reference, then we cannot determine the heritage.
  865. if (constructor === O)
  866. return proto;
  867. // we have a pretty good guess at the heritage.
  868. return constructor;
  869. }
  870. // Global metadata registry
  871. // - Allows `import "reflect-metadata"` and `import "reflect-metadata/no-conflict"` to interoperate.
  872. // - Uses isolated metadata if `Reflect` is frozen before the registry can be installed.
  873. /**
  874. * Creates a registry used to allow multiple `reflect-metadata` providers.
  875. */
  876. function CreateMetadataRegistry() {
  877. var fallback;
  878. if (!IsUndefined(registrySymbol) &&
  879. typeof root.Reflect !== "undefined" &&
  880. !(registrySymbol in root.Reflect) &&
  881. typeof root.Reflect.defineMetadata === "function") {
  882. // interoperate with older version of `reflect-metadata` that did not support a registry.
  883. fallback = CreateFallbackProvider(root.Reflect);
  884. }
  885. var first;
  886. var second;
  887. var rest;
  888. var targetProviderMap = new _WeakMap();
  889. var registry = {
  890. registerProvider: registerProvider,
  891. getProvider: getProvider,
  892. setProvider: setProvider,
  893. };
  894. return registry;
  895. function registerProvider(provider) {
  896. if (!Object.isExtensible(registry)) {
  897. throw new Error("Cannot add provider to a frozen registry.");
  898. }
  899. switch (true) {
  900. case fallback === provider: break;
  901. case IsUndefined(first):
  902. first = provider;
  903. break;
  904. case first === provider: break;
  905. case IsUndefined(second):
  906. second = provider;
  907. break;
  908. case second === provider: break;
  909. default:
  910. if (rest === undefined)
  911. rest = new _Set();
  912. rest.add(provider);
  913. break;
  914. }
  915. }
  916. function getProviderNoCache(O, P) {
  917. if (!IsUndefined(first)) {
  918. if (first.isProviderFor(O, P))
  919. return first;
  920. if (!IsUndefined(second)) {
  921. if (second.isProviderFor(O, P))
  922. return first;
  923. if (!IsUndefined(rest)) {
  924. var iterator = GetIterator(rest);
  925. while (true) {
  926. var next = IteratorStep(iterator);
  927. if (!next) {
  928. return undefined;
  929. }
  930. var provider = IteratorValue(next);
  931. if (provider.isProviderFor(O, P)) {
  932. IteratorClose(iterator);
  933. return provider;
  934. }
  935. }
  936. }
  937. }
  938. }
  939. if (!IsUndefined(fallback) && fallback.isProviderFor(O, P)) {
  940. return fallback;
  941. }
  942. return undefined;
  943. }
  944. function getProvider(O, P) {
  945. var providerMap = targetProviderMap.get(O);
  946. var provider;
  947. if (!IsUndefined(providerMap)) {
  948. provider = providerMap.get(P);
  949. }
  950. if (!IsUndefined(provider)) {
  951. return provider;
  952. }
  953. provider = getProviderNoCache(O, P);
  954. if (!IsUndefined(provider)) {
  955. if (IsUndefined(providerMap)) {
  956. providerMap = new _Map();
  957. targetProviderMap.set(O, providerMap);
  958. }
  959. providerMap.set(P, provider);
  960. }
  961. return provider;
  962. }
  963. function hasProvider(provider) {
  964. if (IsUndefined(provider))
  965. throw new TypeError();
  966. return first === provider || second === provider || !IsUndefined(rest) && rest.has(provider);
  967. }
  968. function setProvider(O, P, provider) {
  969. if (!hasProvider(provider)) {
  970. throw new Error("Metadata provider not registered.");
  971. }
  972. var existingProvider = getProvider(O, P);
  973. if (existingProvider !== provider) {
  974. if (!IsUndefined(existingProvider)) {
  975. return false;
  976. }
  977. var providerMap = targetProviderMap.get(O);
  978. if (IsUndefined(providerMap)) {
  979. providerMap = new _Map();
  980. targetProviderMap.set(O, providerMap);
  981. }
  982. providerMap.set(P, provider);
  983. }
  984. return true;
  985. }
  986. }
  987. /**
  988. * Gets or creates the shared registry of metadata providers.
  989. */
  990. function GetOrCreateMetadataRegistry() {
  991. var metadataRegistry;
  992. if (!IsUndefined(registrySymbol) && IsObject(root.Reflect) && Object.isExtensible(root.Reflect)) {
  993. metadataRegistry = root.Reflect[registrySymbol];
  994. }
  995. if (IsUndefined(metadataRegistry)) {
  996. metadataRegistry = CreateMetadataRegistry();
  997. }
  998. if (!IsUndefined(registrySymbol) && IsObject(root.Reflect) && Object.isExtensible(root.Reflect)) {
  999. Object.defineProperty(root.Reflect, registrySymbol, {
  1000. enumerable: false,
  1001. configurable: false,
  1002. writable: false,
  1003. value: metadataRegistry
  1004. });
  1005. }
  1006. return metadataRegistry;
  1007. }
  1008. function CreateMetadataProvider(registry) {
  1009. // [[Metadata]] internal slot
  1010. // https://rbuckton.github.io/reflect-metadata/#ordinary-object-internal-methods-and-internal-slots
  1011. var metadata = new _WeakMap();
  1012. var provider = {
  1013. isProviderFor: function (O, P) {
  1014. var targetMetadata = metadata.get(O);
  1015. if (IsUndefined(targetMetadata))
  1016. return false;
  1017. return targetMetadata.has(P);
  1018. },
  1019. OrdinaryDefineOwnMetadata: OrdinaryDefineOwnMetadata,
  1020. OrdinaryHasOwnMetadata: OrdinaryHasOwnMetadata,
  1021. OrdinaryGetOwnMetadata: OrdinaryGetOwnMetadata,
  1022. OrdinaryOwnMetadataKeys: OrdinaryOwnMetadataKeys,
  1023. OrdinaryDeleteMetadata: OrdinaryDeleteMetadata,
  1024. };
  1025. metadataRegistry.registerProvider(provider);
  1026. return provider;
  1027. function GetOrCreateMetadataMap(O, P, Create) {
  1028. var targetMetadata = metadata.get(O);
  1029. var createdTargetMetadata = false;
  1030. if (IsUndefined(targetMetadata)) {
  1031. if (!Create)
  1032. return undefined;
  1033. targetMetadata = new _Map();
  1034. metadata.set(O, targetMetadata);
  1035. createdTargetMetadata = true;
  1036. }
  1037. var metadataMap = targetMetadata.get(P);
  1038. if (IsUndefined(metadataMap)) {
  1039. if (!Create)
  1040. return undefined;
  1041. metadataMap = new _Map();
  1042. targetMetadata.set(P, metadataMap);
  1043. if (!registry.setProvider(O, P, provider)) {
  1044. targetMetadata.delete(P);
  1045. if (createdTargetMetadata) {
  1046. metadata.delete(O);
  1047. }
  1048. throw new Error("Wrong provider for target.");
  1049. }
  1050. }
  1051. return metadataMap;
  1052. }
  1053. // 3.1.2.1 OrdinaryHasOwnMetadata(MetadataKey, O, P)
  1054. // https://rbuckton.github.io/reflect-metadata/#ordinaryhasownmetadata
  1055. function OrdinaryHasOwnMetadata(MetadataKey, O, P) {
  1056. var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
  1057. if (IsUndefined(metadataMap))
  1058. return false;
  1059. return ToBoolean(metadataMap.has(MetadataKey));
  1060. }
  1061. // 3.1.4.1 OrdinaryGetOwnMetadata(MetadataKey, O, P)
  1062. // https://rbuckton.github.io/reflect-metadata/#ordinarygetownmetadata
  1063. function OrdinaryGetOwnMetadata(MetadataKey, O, P) {
  1064. var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
  1065. if (IsUndefined(metadataMap))
  1066. return undefined;
  1067. return metadataMap.get(MetadataKey);
  1068. }
  1069. // 3.1.5.1 OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P)
  1070. // https://rbuckton.github.io/reflect-metadata/#ordinarydefineownmetadata
  1071. function OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P) {
  1072. var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ true);
  1073. metadataMap.set(MetadataKey, MetadataValue);
  1074. }
  1075. // 3.1.7.1 OrdinaryOwnMetadataKeys(O, P)
  1076. // https://rbuckton.github.io/reflect-metadata/#ordinaryownmetadatakeys
  1077. function OrdinaryOwnMetadataKeys(O, P) {
  1078. var keys = [];
  1079. var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
  1080. if (IsUndefined(metadataMap))
  1081. return keys;
  1082. var keysObj = metadataMap.keys();
  1083. var iterator = GetIterator(keysObj);
  1084. var k = 0;
  1085. while (true) {
  1086. var next = IteratorStep(iterator);
  1087. if (!next) {
  1088. keys.length = k;
  1089. return keys;
  1090. }
  1091. var nextValue = IteratorValue(next);
  1092. try {
  1093. keys[k] = nextValue;
  1094. }
  1095. catch (e) {
  1096. try {
  1097. IteratorClose(iterator);
  1098. }
  1099. finally {
  1100. throw e;
  1101. }
  1102. }
  1103. k++;
  1104. }
  1105. }
  1106. function OrdinaryDeleteMetadata(MetadataKey, O, P) {
  1107. var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
  1108. if (IsUndefined(metadataMap))
  1109. return false;
  1110. if (!metadataMap.delete(MetadataKey))
  1111. return false;
  1112. if (metadataMap.size === 0) {
  1113. var targetMetadata = metadata.get(O);
  1114. if (!IsUndefined(targetMetadata)) {
  1115. targetMetadata.delete(P);
  1116. if (targetMetadata.size === 0) {
  1117. metadata.delete(targetMetadata);
  1118. }
  1119. }
  1120. }
  1121. return true;
  1122. }
  1123. }
  1124. function CreateFallbackProvider(reflect) {
  1125. var defineMetadata = reflect.defineMetadata, hasOwnMetadata = reflect.hasOwnMetadata, getOwnMetadata = reflect.getOwnMetadata, getOwnMetadataKeys = reflect.getOwnMetadataKeys, deleteMetadata = reflect.deleteMetadata;
  1126. var metadataOwner = new _WeakMap();
  1127. var provider = {
  1128. isProviderFor: function (O, P) {
  1129. var metadataPropertySet = metadataOwner.get(O);
  1130. if (!IsUndefined(metadataPropertySet) && metadataPropertySet.has(P)) {
  1131. return true;
  1132. }
  1133. if (getOwnMetadataKeys(O, P).length) {
  1134. if (IsUndefined(metadataPropertySet)) {
  1135. metadataPropertySet = new _Set();
  1136. metadataOwner.set(O, metadataPropertySet);
  1137. }
  1138. metadataPropertySet.add(P);
  1139. return true;
  1140. }
  1141. return false;
  1142. },
  1143. OrdinaryDefineOwnMetadata: defineMetadata,
  1144. OrdinaryHasOwnMetadata: hasOwnMetadata,
  1145. OrdinaryGetOwnMetadata: getOwnMetadata,
  1146. OrdinaryOwnMetadataKeys: getOwnMetadataKeys,
  1147. OrdinaryDeleteMetadata: deleteMetadata,
  1148. };
  1149. return provider;
  1150. }
  1151. /**
  1152. * Gets the metadata provider for an object. If the object has no metadata provider and this is for a create operation,
  1153. * then this module's metadata provider is assigned to the object.
  1154. */
  1155. function GetMetadataProvider(O, P, Create) {
  1156. var registeredProvider = metadataRegistry.getProvider(O, P);
  1157. if (!IsUndefined(registeredProvider)) {
  1158. return registeredProvider;
  1159. }
  1160. if (Create) {
  1161. if (metadataRegistry.setProvider(O, P, metadataProvider)) {
  1162. return metadataProvider;
  1163. }
  1164. throw new Error("Illegal state.");
  1165. }
  1166. return undefined;
  1167. }
  1168. // naive Map shim
  1169. function CreateMapPolyfill() {
  1170. var cacheSentinel = {};
  1171. var arraySentinel = [];
  1172. var MapIterator = /** @class */ (function () {
  1173. function MapIterator(keys, values, selector) {
  1174. this._index = 0;
  1175. this._keys = keys;
  1176. this._values = values;
  1177. this._selector = selector;
  1178. }
  1179. MapIterator.prototype["@@iterator"] = function () { return this; };
  1180. MapIterator.prototype[iteratorSymbol] = function () { return this; };
  1181. MapIterator.prototype.next = function () {
  1182. var index = this._index;
  1183. if (index >= 0 && index < this._keys.length) {
  1184. var result = this._selector(this._keys[index], this._values[index]);
  1185. if (index + 1 >= this._keys.length) {
  1186. this._index = -1;
  1187. this._keys = arraySentinel;
  1188. this._values = arraySentinel;
  1189. }
  1190. else {
  1191. this._index++;
  1192. }
  1193. return { value: result, done: false };
  1194. }
  1195. return { value: undefined, done: true };
  1196. };
  1197. MapIterator.prototype.throw = function (error) {
  1198. if (this._index >= 0) {
  1199. this._index = -1;
  1200. this._keys = arraySentinel;
  1201. this._values = arraySentinel;
  1202. }
  1203. throw error;
  1204. };
  1205. MapIterator.prototype.return = function (value) {
  1206. if (this._index >= 0) {
  1207. this._index = -1;
  1208. this._keys = arraySentinel;
  1209. this._values = arraySentinel;
  1210. }
  1211. return { value: value, done: true };
  1212. };
  1213. return MapIterator;
  1214. }());
  1215. var Map = /** @class */ (function () {
  1216. function Map() {
  1217. this._keys = [];
  1218. this._values = [];
  1219. this._cacheKey = cacheSentinel;
  1220. this._cacheIndex = -2;
  1221. }
  1222. Object.defineProperty(Map.prototype, "size", {
  1223. get: function () { return this._keys.length; },
  1224. enumerable: true,
  1225. configurable: true
  1226. });
  1227. Map.prototype.has = function (key) { return this._find(key, /*insert*/ false) >= 0; };
  1228. Map.prototype.get = function (key) {
  1229. var index = this._find(key, /*insert*/ false);
  1230. return index >= 0 ? this._values[index] : undefined;
  1231. };
  1232. Map.prototype.set = function (key, value) {
  1233. var index = this._find(key, /*insert*/ true);
  1234. this._values[index] = value;
  1235. return this;
  1236. };
  1237. Map.prototype.delete = function (key) {
  1238. var index = this._find(key, /*insert*/ false);
  1239. if (index >= 0) {
  1240. var size = this._keys.length;
  1241. for (var i = index + 1; i < size; i++) {
  1242. this._keys[i - 1] = this._keys[i];
  1243. this._values[i - 1] = this._values[i];
  1244. }
  1245. this._keys.length--;
  1246. this._values.length--;
  1247. if (SameValueZero(key, this._cacheKey)) {
  1248. this._cacheKey = cacheSentinel;
  1249. this._cacheIndex = -2;
  1250. }
  1251. return true;
  1252. }
  1253. return false;
  1254. };
  1255. Map.prototype.clear = function () {
  1256. this._keys.length = 0;
  1257. this._values.length = 0;
  1258. this._cacheKey = cacheSentinel;
  1259. this._cacheIndex = -2;
  1260. };
  1261. Map.prototype.keys = function () { return new MapIterator(this._keys, this._values, getKey); };
  1262. Map.prototype.values = function () { return new MapIterator(this._keys, this._values, getValue); };
  1263. Map.prototype.entries = function () { return new MapIterator(this._keys, this._values, getEntry); };
  1264. Map.prototype["@@iterator"] = function () { return this.entries(); };
  1265. Map.prototype[iteratorSymbol] = function () { return this.entries(); };
  1266. Map.prototype._find = function (key, insert) {
  1267. if (!SameValueZero(this._cacheKey, key)) {
  1268. this._cacheIndex = -1;
  1269. for (var i = 0; i < this._keys.length; i++) {
  1270. if (SameValueZero(this._keys[i], key)) {
  1271. this._cacheIndex = i;
  1272. break;
  1273. }
  1274. }
  1275. }
  1276. if (this._cacheIndex < 0 && insert) {
  1277. this._cacheIndex = this._keys.length;
  1278. this._keys.push(key);
  1279. this._values.push(undefined);
  1280. }
  1281. return this._cacheIndex;
  1282. };
  1283. return Map;
  1284. }());
  1285. return Map;
  1286. function getKey(key, _) {
  1287. return key;
  1288. }
  1289. function getValue(_, value) {
  1290. return value;
  1291. }
  1292. function getEntry(key, value) {
  1293. return [key, value];
  1294. }
  1295. }
  1296. // naive Set shim
  1297. function CreateSetPolyfill() {
  1298. var Set = /** @class */ (function () {
  1299. function Set() {
  1300. this._map = new _Map();
  1301. }
  1302. Object.defineProperty(Set.prototype, "size", {
  1303. get: function () { return this._map.size; },
  1304. enumerable: true,
  1305. configurable: true
  1306. });
  1307. Set.prototype.has = function (value) { return this._map.has(value); };
  1308. Set.prototype.add = function (value) { return this._map.set(value, value), this; };
  1309. Set.prototype.delete = function (value) { return this._map.delete(value); };
  1310. Set.prototype.clear = function () { this._map.clear(); };
  1311. Set.prototype.keys = function () { return this._map.keys(); };
  1312. Set.prototype.values = function () { return this._map.keys(); };
  1313. Set.prototype.entries = function () { return this._map.entries(); };
  1314. Set.prototype["@@iterator"] = function () { return this.keys(); };
  1315. Set.prototype[iteratorSymbol] = function () { return this.keys(); };
  1316. return Set;
  1317. }());
  1318. return Set;
  1319. }
  1320. // naive WeakMap shim
  1321. function CreateWeakMapPolyfill() {
  1322. var UUID_SIZE = 16;
  1323. var keys = HashMap.create();
  1324. var rootKey = CreateUniqueKey();
  1325. return /** @class */ (function () {
  1326. function WeakMap() {
  1327. this._key = CreateUniqueKey();
  1328. }
  1329. WeakMap.prototype.has = function (target) {
  1330. var table = GetOrCreateWeakMapTable(target, /*create*/ false);
  1331. return table !== undefined ? HashMap.has(table, this._key) : false;
  1332. };
  1333. WeakMap.prototype.get = function (target) {
  1334. var table = GetOrCreateWeakMapTable(target, /*create*/ false);
  1335. return table !== undefined ? HashMap.get(table, this._key) : undefined;
  1336. };
  1337. WeakMap.prototype.set = function (target, value) {
  1338. var table = GetOrCreateWeakMapTable(target, /*create*/ true);
  1339. table[this._key] = value;
  1340. return this;
  1341. };
  1342. WeakMap.prototype.delete = function (target) {
  1343. var table = GetOrCreateWeakMapTable(target, /*create*/ false);
  1344. return table !== undefined ? delete table[this._key] : false;
  1345. };
  1346. WeakMap.prototype.clear = function () {
  1347. // NOTE: not a real clear, just makes the previous data unreachable
  1348. this._key = CreateUniqueKey();
  1349. };
  1350. return WeakMap;
  1351. }());
  1352. function CreateUniqueKey() {
  1353. var key;
  1354. do
  1355. key = "@@WeakMap@@" + CreateUUID();
  1356. while (HashMap.has(keys, key));
  1357. keys[key] = true;
  1358. return key;
  1359. }
  1360. function GetOrCreateWeakMapTable(target, create) {
  1361. if (!hasOwn.call(target, rootKey)) {
  1362. if (!create)
  1363. return undefined;
  1364. Object.defineProperty(target, rootKey, { value: HashMap.create() });
  1365. }
  1366. return target[rootKey];
  1367. }
  1368. function FillRandomBytes(buffer, size) {
  1369. for (var i = 0; i < size; ++i)
  1370. buffer[i] = Math.random() * 0xff | 0;
  1371. return buffer;
  1372. }
  1373. function GenRandomBytes(size) {
  1374. if (typeof Uint8Array === "function") {
  1375. var array = new Uint8Array(size);
  1376. if (typeof crypto !== "undefined") {
  1377. crypto.getRandomValues(array);
  1378. }
  1379. else if (typeof msCrypto !== "undefined") {
  1380. msCrypto.getRandomValues(array);
  1381. }
  1382. else {
  1383. FillRandomBytes(array, size);
  1384. }
  1385. return array;
  1386. }
  1387. return FillRandomBytes(new Array(size), size);
  1388. }
  1389. function CreateUUID() {
  1390. var data = GenRandomBytes(UUID_SIZE);
  1391. // mark as random - RFC 4122 § 4.4
  1392. data[6] = data[6] & 0x4f | 0x40;
  1393. data[8] = data[8] & 0xbf | 0x80;
  1394. var result = "";
  1395. for (var offset = 0; offset < UUID_SIZE; ++offset) {
  1396. var byte = data[offset];
  1397. if (offset === 4 || offset === 6 || offset === 8)
  1398. result += "-";
  1399. if (byte < 16)
  1400. result += "0";
  1401. result += byte.toString(16).toLowerCase();
  1402. }
  1403. return result;
  1404. }
  1405. }
  1406. // uses a heuristic used by v8 and chakra to force an object into dictionary mode.
  1407. function MakeDictionary(obj) {
  1408. obj.__ = undefined;
  1409. delete obj.__;
  1410. return obj;
  1411. }
  1412. });
  1413. })(Reflect || (Reflect = {}));