Skip to content

Commit 5f14b24

Browse files
committed
fix: only polyfill if necessary
1 parent 69c0e1f commit 5f14b24

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

globals.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,23 @@ class CustomEventPolyfill extends Event {
2929
}
3030
}
3131

32-
global.CustomEvent = CustomEventPolyfill
32+
global.CustomEvent = global.CustomEvent ?? CustomEventPolyfill
3333

34-
global.AbortSignal.timeout = (ms) => {
34+
global.AbortSignal.timeout = global.AbortSignal.timeout ?? ((ms) => {
3535
const controller = new AbortController()
3636
setTimeout(() => {
3737
controller.abort(new Error('Aborted'))
3838
}, ms)
39-
}
40-
global.AbortSignal.prototype.throwIfAborted = () => {
39+
})
40+
global.AbortSignal.prototype.throwIfAborted = global.AbortSignal.prototype.throwIfAborted ?? (() => {
4141
if (this.aborted) {
4242
throw new Error('Aborted')
4343
}
44-
}
44+
})
4545

46-
global.Buffer = Buffer
47-
global.crypto.subtle = new Crypto().subtle
46+
global.Buffer = global.Buffer ?? Buffer
47+
global.crypto = global.crypto ?? {}
48+
global.crypto.subtle = global.crypto.subtle ?? new Crypto().subtle
4849

4950
/**
5051
* Polyfill missing ES2024 promise methods

0 commit comments

Comments
 (0)