0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-04-07 08:14:49 +02:00

Polyfill WeakRef (#34025)

Fix #33407
This commit is contained in:
wxiaoguang 2025-03-26 23:56:25 +08:00 committed by GitHub
parent d28a7f9fea
commit d70be9d0fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,7 @@
import {weakRefClass} from './polyfills.ts';
test('polyfillWeakRef', () => {
const WeakRef = weakRefClass();
const r = new WeakRef(123);
expect(r.deref()).toEqual(123);
});

View File

@ -16,3 +16,19 @@ try {
return intlNumberFormat(locales, options);
};
}
export function weakRefClass() {
const weakMap = new WeakMap();
return class {
constructor(target: any) {
weakMap.set(this, target);
}
deref() {
return weakMap.get(this);
}
};
}
if (!window.WeakRef) {
window.WeakRef = weakRefClass() as any;
}