Skip to content

Commit

Permalink
Add test showing fallback issue
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuckton committed Mar 29, 2024
1 parent 6dd6417 commit 67ae05d
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
1 change: 0 additions & 1 deletion test/reflect-definemetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ for (const { name, header, context } of suites) {
describe(name, () => {
describe("Reflect.defineMetadata", () => {
it("InvalidTarget", () => {
debugger;
const { Reflect, TypeError } = script(context)`
${header}
exports.Reflect = Reflect;
Expand Down
60 changes: 60 additions & 0 deletions test/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,64 @@ for (const { name, header, context } of suites.filter(s => s.global && !s.polyfi
});
});
});
}

for (const { name, header, context } of suites) {
describe(`fallback + ${name}`, () => {
it("MetadataRegistry", () => {
const { provider1, provider2 } = script({ ESMap: Map, ...context })`
{
const Map = ESMap;
const map = new Map();
Reflect.defineMetadata = function(key, value, target, prop) {
let props = map.get(target);
if (!props) map.set(target, props = new Map());
let meta = props.get(prop);
if (!meta) props.set(prop, meta = new Map());
meta.set(key, value);
};
Reflect.hasOwnMetadata = function(key, target, prop) {
let props = map.get(target);
let meta = props && props.get(prop);
return meta && meta.has(key) || false;
};
Reflect.getOwnMetadata = function(key, target, prop) {
let props = map.get(target);
let meta = props && props.get(prop);
return meta && meta.get(key);
};
Reflect.getOwnMetadataKeys = function(target, prop) {
let props = map.get(target);
let meta = props && props.get(prop);
const keys = meta && meta.keys() || [];
return [...keys];
};
Reflect.deleteMetadata = function(key, target, prop) {
let props = map.get(target);
let meta = props && props.get(prop);
return meta && meta.delete(key) || false;
};
}
const obj = {};
Reflect.defineMetadata("a", 1, obj);
Reflect.defineMetadata("b", 2, obj, "c");
{
${header}
}
const registrySymbol = Symbol.for("@reflect-metadata:registry");
const registry = Reflect[registrySymbol];
const provider1 = registry.getProvider(obj, undefined);
const provider2 = registry.getProvider(obj, "c");
exports.provider1 = provider1;
exports.provider2 = provider2;
`;
assert.isDefined(provider1);
assert.isDefined(provider2);
assert.strictEqual(provider1, provider2);
});
});
}

0 comments on commit 67ae05d

Please sign in to comment.