This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 27030 - ArrayBuffer and friends are now covered by IDL.
Summary: ArrayBuffer and friends are now covered by IDL.
Status: RESOLVED LATER
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: Other All
: P3 normal
Target Milestone: Unsorted
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
URL:
Whiteboard:
Keywords:
: 26968 (view as bug list)
Depends on: 28798
Blocks: 27031
  Show dependency treegraph
 
Reported: 2014-10-13 13:31 UTC by contributor
Modified: 2019-03-29 20:29 UTC (History)
5 users (show)

See Also:


Attachments

Description contributor 2014-10-13 13:31:23 UTC
Specification: https://html.spec.whatwg.org/
Multipage: https://html.spec.whatwg.org/multipage/#arraybuffer
Complete: https://html.spec.whatwg.org/#arraybuffer
Referrer: 

Comment:
ArrayBuffer and friends are now covered by IDL.

Posted from: 46.127.136.57
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.13 Safari/537.36
Comment 1 Ian 'Hixie' Hickson 2014-11-19 22:49:58 UTC
This is just a change to the "Dependencies" section right?
Comment 2 Anne 2014-11-20 11:38:15 UTC
The other usage can be cleaned up as well. E.g. IDL defines algorithms for extracting bytes, defines BufferSource as typedef for ArrayBuffer/ArrayBufferView.
Comment 3 Ian 'Hixie' Hickson 2014-11-20 20:45:59 UTC
I don't understand what exactly it is you want updated. I don't extract bytes anywhere, do I? Do you see anything where BufferSource would be useful other than removing one line of IDL from the WebSocket IDL?
Comment 4 Anne 2014-11-21 08:16:25 UTC
WebSocket, yes, it also extracts the data.

Structured cloning extracts the data.

But yes, also "Dependencies".
Comment 5 Ian 'Hixie' Hickson 2014-11-21 23:51:27 UTC
I guess I don't understand what you mean by "extracts the data" then? Can you elaborate on what you'd like changed?
Comment 6 Anne 2014-11-22 10:10:40 UTC
For WebSocket:

"The data to be sent is the data stored in the buffer described by the ArrayBuffer object."

"The data to be sent is the data stored in the section of the buffer described by the ArrayBuffer object that data references."

This should instead reference the copy algorithm from IDL (and use BufferSource). In particular I think the second sentence is currently wrong as a view can represent a segment of an underlying buffer.


For Transferable objects:

"ArrayBuffer [ECMA262]"

That is defined in IDL now. (You also cannot reference JavaScript objects and then use them in a typedef.)

The neuter bit here is out of sync as well, but there's a separate bug for that.


For internal structured cloning algorithm: this could reference the copy algorithm for ArrayBuffer, but it might not be worth it to change that.



For dependencies:

The ArrayBufferView typedef is no longer needed. ArrayBuffer no longer needs to be defined as part of JavaScript.
Comment 7 Ian 'Hixie' Hickson 2014-11-24 18:56:15 UTC
(In reply to Anne from comment #6)
> For WebSocket:
> 
> "The data to be sent is the data stored in the buffer described by the
> ArrayBuffer object."
> 
> "The data to be sent is the data stored in the section of the buffer
> described by the ArrayBuffer object that data references."
> 
> This should instead reference the copy algorithm from IDL (and use
> BufferSource).

I don't understand why. The algorithms just do type checking, and otherwise basically do exactly what the HTML spec says. Why isn't the type-checking done when the arguments are passed?


> In particular I think the second sentence is currently wrong
> as a view can represent a segment of an underlying buffer.

The second sentence handles that find as far as I can tell.


The other changes are those mentioned in comment 1 (and the things that implicitly result from those changes).
Comment 8 Anne 2014-11-25 10:10:34 UTC
(In reply to Ian 'Hixie' Hickson from comment #7)
> I don't understand why.

If only for the simple fact that then nobody thinks this situation is somehow special.


> The second sentence handles that find as far as I can tell.

I don't really see how. You introduce terms such as "buffer" that have no meaning in either IDL or JavaScript. You say the buffer is described by the ArrayBuffer object, while the ArrayBuffer object can represent a larger buffer than the view represents. It's not at all clear to me.
Comment 9 Ian 'Hixie' Hickson 2014-11-26 19:39:12 UTC
(In reply to Anne from comment #8)
> If only for the simple fact that then nobody thinks this situation is
> somehow special.

I'm not arguing that HTML should be different, I'm saying nobody should have to do this. Why aren't we just checking this in the argument checking step, instead of requiring that all users of ArrayBuffer have this boilerplate?


> > The second sentence handles that find as far as I can tell.
> 
> I don't really see how. You introduce terms such as "buffer" that have no
> meaning in either IDL or JavaScript. You say the buffer is described by the
> ArrayBuffer object, while the ArrayBuffer object can represent a larger
> buffer than the view represents. It's not at all clear to me.

It references "the section of the buffer" not just "the buffer". This is just English, the word "buffer" is a well-known computer science term that seems to map fine to the WebIDL/JS terminology. I mean, it's basically the same as what the WebIDL spec says — it just does a bunch of type checking which I think should happen at argument checking time, and then just returns "a reference to or copy of (as required) the length bytes in data starting at byte offset offset" which is no more defined than what HTML says, when you get right down to it.
Comment 10 Ian 'Hixie' Hickson 2014-11-26 20:04:07 UTC
*** Bug 26968 has been marked as a duplicate of this bug. ***
Comment 11 Anne 2014-11-27 08:07:19 UTC
I think IDL does not do it at the point of argument checking because then it would require an upfront decision about whether to get the bytes by-copy or by-reference (when we introduced this we were not quite sure what would be a better default). If we can find a decent way to do that, that might be better model though. I recommend filing a bug on IDL.
Comment 12 Ian 'Hixie' Hickson 2014-11-28 04:27:16 UTC
Don't all APIs know whether they're copying or referencing the data?
Comment 13 Anne 2014-11-28 07:55:06 UTC
I think they do, yes.
Comment 14 Ian 'Hixie' Hickson 2014-11-29 00:25:03 UTC
If the APIs know what they're doing, then I think the IDL should just do the checking up-front. That way the behaviour is much more consistent.
Comment 15 Anne 2014-11-29 15:35:50 UTC
As I said, I recommend filing a bug on IDL.
Comment 16 Ian 'Hixie' Hickson 2015-01-15 20:14:45 UTC
bz, would it make sense to update IDL for this?
Comment 17 Boris Zbarsky 2015-01-15 20:43:21 UTC
Not all consumers know whether they're copying or referencing.  For example, a WebGL implementation might do either one depending on how it's actually implemented.

That said, what exact checking would you expect to be done up front if an API _did_ know whether it's copying or referencing?
Comment 18 Ian 'Hixie' Hickson 2015-01-15 23:29:37 UTC
Well the behaviour can't depend on how it's implemented, that would be visibly non-interoperable. The question is just whether any specs sometimes do one and sometimes do the other, as opposed to any method always doing one or the other.

In any case it looks like the behaviour now is just always the same. I'm not sure if I misread it before or if it changed. The checking I'm referring to is the checking in the algorithm introduced as "When getting a reference to or getting a copy of the bytes held by a buffer source that is an ECMAScript ArrayBuffer, DataView or typed array object, these steps must be followed:" in the Web IDL spec. I argue that this should just move to argument checking step of method invocation, so that we don't get weirdness about exactly when these checks happen.
Comment 19 Boris Zbarsky 2015-01-16 02:51:51 UTC
Ah, I see.

So just to make sure we're on the same page, this algorithm does the following checks:

Step 5: Check whether O has a [[ViewedArrayBuffer]] internal slot.  If it does, O is a typed array or data view; if it does not, O is a ArrayBuffer.  This check is just needed to decide where exactly the data lives.

Step 5.2: In the "[[ViewedArrayBuffer]] exists" case, check for the value in the slot being undefined.  This is only possible if the typed array is in the middle of being constructed and hasn't been initialized yet.  And that state is going to go away with the edits Allen is making to the ES6 constructor protocol right now.  So at that point, this check will go away, I'd think.

Step 7: Checks for a detached buffer.  This presumes that extracting data from a detached buffer should be a TypeError as opposed to silently getting an empty buffer.  This check cannot be performed during argument conversion, because conversion of a later argument can detach the buffer, as can anything else which allows JS to run.  Therefore, this check MUST be performed immediately before the data is extracted.  Furthermore, specifications and implementations that reference the data instead of copying it must ensure that no script runs between the "getting a reference to" algorithm running and the last use of the data.

Is there some other check I'm missing that's at issue here?
Comment 20 Boris Zbarsky 2015-01-16 03:00:27 UTC
Ah, and right after that comment I got the mail about http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts#january_15_2015_draft_rev_31 now existing and all the checks for the value in [[ViewedArrayBuffer]] being undefined are gone in there.
Comment 21 Ian 'Hixie' Hickson 2015-01-17 18:10:10 UTC
At this point, the algorithm doesn't seem necessary any more. We should just define what bytes these objects represent, and then the calling specs would be much more readable. IMHO.

That is, instead of:

   ...
   5. Let _data_ be the result of _getting a copy of the bytes held by a buffer
      source_ /foo/. If this throws an exception, then ...
   ...

...we'd just say:

   ...
   5. If /foo/ is neutered, then ...
   6. Let _data_ be the data represented by /foo/.
   ...

Similarly, the "detach" algorithm seems pointlessly trivial as specced. What value does it add? We should just make the JS spec referenceable directly.
Comment 22 Boris Zbarsky 2015-01-17 20:19:25 UTC
>   6. Let _data_ be the data represented by /foo/.

Then we need to define "the data represented by /foo/", right?  This is not a theoretical concern; implementors and spec authors have screwed this up in the past.  Which is why it's good to have one place which defines this concept that everyone else can then reference.

Given such a shared definition, your proposal sounds ok to me, except there is no such thing as "neutered" anymore.  It's called "detached".
Comment 23 Anne 2015-01-18 08:02:40 UTC
Referencing JavaScript directly doesn't make sense, unless IDL values can sometimes be JavaScript objects. The layering is:

  JavaScript -> IDL -> feature spec -> IDL -> JavaScript
Comment 24 Boris Zbarsky 2015-01-21 21:03:36 UTC
IDL values can totally be JS objects, right?  I mean, consider the "object" type.  It's "an IDL value that represents the given JS object", but presumably that means that as long as you're willing to make your prose JS-specific you can unambiguously talk about the JS object represented by the "object" type IDL value.

The various BufferSource types have similar behavior.
Comment 25 Domenic Denicola 2015-12-16 16:40:55 UTC
https://github.com/whatwg/html/commit/52f96c455a53763a7fe00162c067da6adb20e62c fixes the dependencies section, but the changes to use BufferSource and to be clear about copying vs. not are still to-do.
Comment 26 Anne 2016-03-16 14:07:02 UTC
I thought about fixing this, but bug 28798 should really be fixed first. With that bug fixed for our cases we don't even have to worry about extracting bytes, IDL will just hand us bytes.
Comment 27 Domenic Denicola 2019-03-29 20:29:43 UTC
It seems this needs to be fixed across the specification ecosystem as part of the Web IDL work, and is not worth tracking as HTML specifically. So, I will close this and let us continue tracking work in https://www.w3.org/Bugs/Public/show_bug.cgi?id=28798 and its GitHub successor.