emscripten-core / emscripten-core/emscripten

TextDecoder sometimes fails when used through an iframe

Open
#15,217 5 comments 0 reactions 0 assignees View on GitHub
JavaScript
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

String types via embind sometimes fail with:
```
Failed to execute 'decode' on 'TextDecoder': The provided ArrayBufferView value must not be shared."
```
When the embind functions are called through an iframe. The [`instanceof` check in `TextDecoderWrapper`](https://github.com/emscripten-core/emscripten/pull/14399/files#diff-c6916d222b9b5a2fd732da799f1f08f1d41fc6e2b09381f5dca2054fe5ca0f45R27) fails when the object is from an iframe, which is a separate JavaScript realm.

This is a known problem with `instanceof` checks and iframes:

https://www.oreilly.com/library/view/speaking-javascript/9781449365028/ch17.html#cross-realm_instanceof
https://jakearchibald.com/2017/arrays-symbols-realms/#multiple-realms
https://esdiscuss.org/topic/cross-global-instanceof

For built-ins, the only real workaround is checking `foo.constructor.name` -> `ArrayBuffer` or `Object.getPrototypeOf(foo).toString()` -> `[object ArrayBuffer]`.

This should work in all WebAssembly-supporting browsers.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.