ReflectLite.js 50 KB

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