Skip to content

wasmMemory.buffer instanceof SharedArrayBuffer === false occasionally #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sxzz opened this issue Apr 15, 2025 · 1 comment · Fixed by #144
Closed

wasmMemory.buffer instanceof SharedArrayBuffer === false occasionally #143

sxzz opened this issue Apr 15, 2025 · 1 comment · Fixed by #144

Comments

@sxzz
Copy link

sxzz commented Apr 15, 2025

Reproduction:

Source code: https://github.com/sxzz/rolldown-browser (cannot build locally)

index-DAfNCrBY.js:42708 Error: Build failed with 1 error:

TypeError: Failed to execute 'decode' on 'TextDecoder': The provided ArrayBufferView value must not be shared.
TypeError: The provided ArrayBufferView value must not be shared.
    at Object.UTF8ToString (index-DAfNCrBY.js:9305:49)
Screen.Recording.2025-04-15.at.11.33.22.mov

/cc @Brooooooklyn


Can we check buffer byusing HEAPU8.buffer[Symbol.toStringTag] === 'SharedArrayBuffer'?

@toyobayashi
Copy link
Owner

Figured out:

  1. From the beginning there is no problem until the wasm memory get grow.

  2. When WebAssembly.Memory get grow, v8 will recreated an internal SharedArrayBuffer (but not the same reference to globalThis.SharedArrayBuffer) for WebAssembly.prototype.buffer getter to access, which causes the HEAPU8.buffer instanceof ShardArrayBuffer evaluated to false.

  3. Very stupid mistake in emnapi:

    Object.prototype.toString.call(HEAPU8.buffer.constructor) === "[object SharedArrayBuffer]"

    This is always "[object Function]", the .constructor is redundant. I have tried that even HEAPU8.buffer is changed to internal SharedArrayBuffer Object.prototype.toString.call(HEAPU8.buffer) can gets the correct result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants