-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
Description
Transferable objects like ArrayBuffer
cannot be passed.
TypeError: Cross-Realm Error: TypeError: need primitive or callable, got [object ArrayBuffer]
at Object.wrapError (helpers.ts:78:16)
at foobar (eval at createWrappedFunction (helpers.ts:116:44), <anonymous>:12:14)
at test (index.ts:14:19)
See: MDN - Transferable objects
Demo
script-in-realm.js
export const foobar = (...args) => {
console.log(args)
}
main-script.js
import ShadowRealm from 'shadowrealm-api'
const realm = new ShadowRealm()
const foobar = await realm.importValue('/script-in-realm.js', 'foobar')
// Create transferable object.
// Transferable objects can be passed between frames and workers without copy.
const buff = new Uint8Array(32)
const view = new DataView(buff.buffer)
view.setUint32(0, 0xcafebafe, true)
// Run the function and get an error.
const result = (foobar as Function)(buff.buffer)
console.log({ result })
tennox
Metadata
Metadata
Assignees
Labels
No labels