Add TextDecoder polyfill

This commit is contained in:
Adria Navarro 2025-01-29 21:01:19 +01:00
parent 11b6547c21
commit 9ff29c794e
3 changed files with 23 additions and 8 deletions

View File

@ -9,4 +9,5 @@ packages/backend-core/coverage
packages/builder/.routify
packages/sdk/sdk
packages/pro/coverage
**/*.ivm.bundle.js
**/*.ivm.bundle.js
!**/bson-polyfills.ivm.bundle.js

View File

@ -1,6 +1,21 @@
function atob(...args){
return atobCB(...args)
function atob(...args) {
return atobCB(...args)
}
function btoa(...args){
return btoaCB(...args)
function btoa(...args) {
return btoaCB(...args)
}
class TextDecoder {
constructorArgs
constructor(...constructorArgs) {
this.constructorArgs = constructorArgs
}
decode(...input) {
return textDecoderCb({
constructorArgs: this.constructorArgs,
functionArgs: input,
})
}
}

View File

@ -161,6 +161,8 @@ export class IsolatedVM implements VM {
const bsonSource = loadBundle(BundleType.BSON)
// "Polyfilling" text decoder and other utils. `bson.deserialize` requires decoding. We are creating a bridge function so we don't need to inject the full library
const bsonPolyfills = loadBundle(BundleType.BSON_POLYFILLS)
this.addToContext({
textDecoderCb: new ivm.Callback(
(args: {
@ -183,9 +185,6 @@ export class IsolatedVM implements VM {
}),
})
// "Polyfilling" text decoder and other utils. `bson.deserialize` requires decoding. We are creating a bridge function so we don't need to inject the full library
const bsonPolyfills = loadBundle(BundleType.BSON_POLYFILLS)
const script = this.isolate.compileScriptSync(
`${bsonPolyfills};${bsonSource}`
)