Polyfill WeakRef (#34025) (#34028)

Backport #34025 by wxiaoguang

Fix #33407

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Giteabot
2025-03-27 00:13:22 +08:00
committed by GitHub
parent 4b3400bd9c
commit 35983ac0a8
2 changed files with 23 additions and 0 deletions

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;
}