diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2025-03-26 23:56:25 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-26 23:56:25 +0800 |
commit | d70be9d0fe648a7b593c4df46ac61e18d4166d07 (patch) | |
tree | 19efc16f659304973d4a16a678cea1122fcc59a7 | |
parent | d28a7f9feac36f3c1afaf9362298ae5d50d596b6 (diff) | |
download | gitea-d70be9d0fe648a7b593c4df46ac61e18d4166d07.tar.gz gitea-d70be9d0fe648a7b593c4df46ac61e18d4166d07.zip |
Polyfill WeakRef (#34025)
Fix #33407
-rw-r--r-- | web_src/js/webcomponents/polyfill.test.ts | 7 | ||||
-rw-r--r-- | web_src/js/webcomponents/polyfills.ts | 16 |
2 files changed, 23 insertions, 0 deletions
diff --git a/web_src/js/webcomponents/polyfill.test.ts b/web_src/js/webcomponents/polyfill.test.ts new file mode 100644 index 0000000000..4fb4621547 --- /dev/null +++ b/web_src/js/webcomponents/polyfill.test.ts @@ -0,0 +1,7 @@ +import {weakRefClass} from './polyfills.ts'; + +test('polyfillWeakRef', () => { + const WeakRef = weakRefClass(); + const r = new WeakRef(123); + expect(r.deref()).toEqual(123); +}); diff --git a/web_src/js/webcomponents/polyfills.ts b/web_src/js/webcomponents/polyfills.ts index 4a84ee9562..9575324b5a 100644 --- a/web_src/js/webcomponents/polyfills.ts +++ b/web_src/js/webcomponents/polyfills.ts @@ -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; +} |