Skip to content

Transferable objects are not supported. #4

@x1unix

Description

@x1unix

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 })

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions