webidl-conversions
webidl-conversions copied to clipboard
Throwing on detached buffers is not correct
https://github.com/jsdom/webidl-conversions/commit/647d8736ce969bcabab4a75e2ed61616c8fb0747 added throwing on detached buffers, but this is not correct. See https://github.com/heycam/webidl/issues/352 and https://github.com/heycam/webidl/issues/151 .
Sigh. I guess I just implemented that from memory.
I'm not sure the best way to handle this. I see a few options:
-
Return a new empty array buffer (or corresponding view) when the incoming array buffer is detached. This is a bit tricky since then 99% of the time a non-throwing conversion returns the input, but sometimes it doesn't.
-
Revert to having no special detached handling. This is similar to returning a new empty buffer in practice, since V8 treats detached buffers as zero-length buffers in most parts of the API.
-
Implement the full " getting a reference to" / "getting a copy of" algorithms. This is not so great because specs generally don't use these algorithms yet and there's planned work to change them in https://www.w3.org/Bugs/Public/show_bug.cgi?id=28798.
-
Try to implement https://www.w3.org/Bugs/Public/show_bug.cgi?id=28798. This seems kind of reasonable. However, any implementation that actually performs a copy would add a performance hit to jsdom. And I'm not sure that's really necessary given that we're single-threaded anyway?
I'm leaning toward (2), and potentially reassessing if we run into an API where this actually matters.