mirror of
https://github.com/go-gitea/gitea.git
synced 2025-06-29 17:48:47 +00:00
Backport #34025 by wxiaoguang Fix #33407 Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
4b3400bd9c
commit
35983ac0a8
7
web_src/js/webcomponents/polyfill.test.ts
Normal file
7
web_src/js/webcomponents/polyfill.test.ts
Normal 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);
|
||||
});
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user