Files
Your Name 38652eb9b5 Initalize
2026-05-03 12:12:57 -04:00

17 lines
603 B
JavaScript

const nativePromisePrototype = (async () => {})().constructor.prototype;
const descriptors = ['then', 'catch', 'finally']
.map(property => [
property,
Reflect.getOwnPropertyDescriptor(nativePromisePrototype, property),
]);
export default function(thing, promise) {
for (const [property, descriptor] of descriptors) {
// eslint-disable-next-line max-len
const value = typeof promise === 'function' ? (...args) => Reflect.apply(descriptor.value, promise(), args) : descriptor.value.bind(promise);
Reflect.defineProperty(thing, property, {...descriptor, value});
}
return thing;
};