Only assign `vmContext.global.crypto` if not already global (#143)
Fixes https://github.com/matrix-org/matrix-public-archive/issues/141 Node.js v19 has `crypto` set on the global already, so this change causes `vmContext.global.crypto` to be assigned only if `vmContext.global.crypto` isn’t already defined. Otherwise, without this change, the room directory fails to render in Node.js v19+, and instead _"TypeError: Cannot set property crypto of `#<Object>` which has only a getter"_ gets thrown.
This commit is contained in:
parent
6e2a56d726
commit
6b493ff807
|
@ -47,7 +47,11 @@ function createDomAndSetupVmContext() {
|
|||
vmContext.global.DOMParser = dom.DOMParser;
|
||||
// Make sure `webcrypto` exists since it was only introduced in Node.js v17
|
||||
assert(crypto.webcrypto);
|
||||
vmContext.global.crypto = crypto.webcrypto;
|
||||
// Only assign vmContext.global.crypto if it's undefined
|
||||
// (Node.js v19 has crypto set on the global already)
|
||||
if (!vmContext.global.crypto) {
|
||||
vmContext.global.crypto = crypto.webcrypto;
|
||||
}
|
||||
|
||||
// So require(...) works in the vm
|
||||
vmContext.global.require = require;
|
||||
|
|
Loading…
Reference in New Issue