-
Notifications
You must be signed in to change notification settings - Fork 0
/
polyfill.js
48 lines (42 loc) · 1.14 KB
/
polyfill.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import {
symbolDispose,
symbolAsyncDispose,
Disposable,
AsyncDisposable,
} from "./index.js";
import {
AsyncIteratorPrototype,
IteratorPrototype,
} from "./iterator-prototypes.js";
if (!("dispose" in Symbol)) {
Object.defineProperty(Symbol, "dispose", { value: symbolDispose });
}
if (!("asyncDispose" in Symbol)) {
Object.defineProperty(Symbol, "asyncDispose", { value: symbolAsyncDispose });
}
if (typeof IteratorPrototype[symbolDispose] !== "function") {
Object.defineProperty(IteratorPrototype, symbolDispose, {
value() {
this.return != null && this.return();
},
enumerable: true,
configurable: true,
writable: true,
});
}
if (typeof AsyncIteratorPrototype[symbolAsyncDispose] !== "function") {
Object.defineProperty(AsyncIteratorPrototype, symbolAsyncDispose, {
async value() {
await (this.return != null && this.return());
},
enumerable: true,
configurable: true,
writable: true,
});
}
if (typeof globalThis.Disposable !== "function") {
globalThis.Disposable = Disposable;
}
if (typeof globalThis.AsyncDisposable !== "function") {
globalThis.AsyncDisposable = AsyncDisposable;
}