webidl-conversions icon indicating copy to clipboard operation
webidl-conversions copied to clipboard

Throwing on detached buffers is not correct

Open domenic opened this issue 5 years ago • 1 comments

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.

domenic avatar Apr 18 '20 16:04 domenic

I'm not sure the best way to handle this. I see a few options:

  1. 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.

  2. 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.

  3. 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.

  4. 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.

domenic avatar Apr 18 '20 16:04 domenic