-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
TextDecoder sometimes fails when used through an iframe #15217
Comments
Here's a short example of how this works. In the iframe's code, e.g.
In the parent window's code, e.g.
Note how the parent window calls into a function in an object on the iframe's window. All The other advice in the O'Reilly book on handling this is to just not make cross-realm calls. I think we can make Emscripten robust against this though. |
Note this can be worked around at a performance hit (especially for large strings) with |
I hit the same problem in a different context. When pthread is enabled, and a tab is duplicated (Chrome, right click tab -> Duplicate), somehow the buffer sent from wasm (via embind) is actually a SAB but |
@jiulongw Does "duplicate tab" not just open a new tab with the same URL? Or does it involve an iframe somehow? If it does not involve an iframe then it sounds like a browser bug, and we should file a bug on Chrome. Also we can file a bug if we are not sure either way. |
I feel duplicating a tab is not simply a new tab with same URL. It carries some sort of state or context from the tab being duplicated. I will try to repro it without involving Emscripten and open a bug to Chromium. Either way, this patch might still be useful for people hitting this issue, given |
…ffer from different JavaScript realm When performing tasks such as allocating or marshalling large amounts of memory in multithreaded .NET land, inconsistent and frequent crashing behavior is exhibited. Related issues: emscripten-core/emscripten#15217 https://github.com/dotnet/aspnetcore/issues/48390
String types via embind sometimes fail with:
When the embind functions are called through an iframe. The
instanceof
check inTextDecoderWrapper
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
orObject.getPrototypeOf(foo).toString()
->[object ArrayBuffer]
.This should work in all WebAssembly-supporting browsers.
The text was updated successfully, but these errors were encountered: