We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d28a7f9 commit d70be9dCopy full SHA for d70be9d
web_src/js/webcomponents/polyfill.test.ts
@@ -0,0 +1,7 @@
1
+import {weakRefClass} from './polyfills.ts';
2
+
3
+test('polyfillWeakRef', () => {
4
+ const WeakRef = weakRefClass();
5
+ const r = new WeakRef(123);
6
+ expect(r.deref()).toEqual(123);
7
+});
web_src/js/webcomponents/polyfills.ts
@@ -16,3 +16,19 @@ try {
16
return intlNumberFormat(locales, options);
17
};
18
}
19
20
+export function weakRefClass() {
21
+ const weakMap = new WeakMap();
22
+ return class {
23
+ constructor(target: any) {
24
+ weakMap.set(this, target);
25
+ }
26
+ deref() {
27
+ return weakMap.get(this);
28
29
+ };
30
+}
31
32
+if (!window.WeakRef) {
33
+ window.WeakRef = weakRefClass() as any;
34
0 commit comments