<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>27030</bug_id>
          
          <creation_ts>2014-10-13 13:31:23 +0000</creation_ts>
          <short_desc>ArrayBuffer and friends are now covered by IDL.</short_desc>
          <delta_ts>2019-03-29 20:29:43 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WHATWG</product>
          <component>HTML</component>
          <version>unspecified</version>
          <rep_platform>Other</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>LATER</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P3</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>Unsorted</target_milestone>
          <dependson>28798</dependson>
          <blocked>27031</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter>contributor</reporter>
          <assigned_to name="Ian &apos;Hixie&apos; Hickson">ian</assigned_to>
          <cc>annevk</cc>
    
    <cc>bzbarsky</cc>
    
    <cc>d</cc>
    
    <cc>ian</cc>
    
    <cc>mike</cc>
          
          <qa_contact>contributor</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>113022</commentid>
    <comment_count>0</comment_count>
    <who name="">contributor</who>
    <bug_when>2014-10-13 13:31:23 +0000</bug_when>
    <thetext>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</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115164</commentid>
    <comment_count>1</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-11-19 22:49:58 +0000</bug_when>
    <thetext>This is just a change to the &quot;Dependencies&quot; section right?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115209</commentid>
    <comment_count>2</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-11-20 11:38:15 +0000</bug_when>
    <thetext>The other usage can be cleaned up as well. E.g. IDL defines algorithms for extracting bytes, defines BufferSource as typedef for ArrayBuffer/ArrayBufferView.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115259</commentid>
    <comment_count>3</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-11-20 20:45:59 +0000</bug_when>
    <thetext>I don&apos;t understand what exactly it is you want updated. I don&apos;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?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115270</commentid>
    <comment_count>4</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-11-21 08:16:25 +0000</bug_when>
    <thetext>WebSocket, yes, it also extracts the data.

Structured cloning extracts the data.

But yes, also &quot;Dependencies&quot;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115335</commentid>
    <comment_count>5</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-11-21 23:51:27 +0000</bug_when>
    <thetext>I guess I don&apos;t understand what you mean by &quot;extracts the data&quot; then? Can you elaborate on what you&apos;d like changed?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115352</commentid>
    <comment_count>6</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-11-22 10:10:40 +0000</bug_when>
    <thetext>For WebSocket:

&quot;The data to be sent is the data stored in the buffer described by the ArrayBuffer object.&quot;

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

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:

&quot;ArrayBuffer [ECMA262]&quot;

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&apos;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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115417</commentid>
    <comment_count>7</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-11-24 18:56:15 +0000</bug_when>
    <thetext>(In reply to Anne from comment #6)
&gt; For WebSocket:
&gt; 
&gt; &quot;The data to be sent is the data stored in the buffer described by the
&gt; ArrayBuffer object.&quot;
&gt; 
&gt; &quot;The data to be sent is the data stored in the section of the buffer
&gt; described by the ArrayBuffer object that data references.&quot;
&gt; 
&gt; This should instead reference the copy algorithm from IDL (and use
&gt; BufferSource).

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


&gt; In particular I think the second sentence is currently wrong
&gt; 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).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115447</commentid>
    <comment_count>8</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-11-25 10:10:34 +0000</bug_when>
    <thetext>(In reply to Ian &apos;Hixie&apos; Hickson from comment #7)
&gt; I don&apos;t understand why.

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


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

I don&apos;t really see how. You introduce terms such as &quot;buffer&quot; 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&apos;s not at all clear to me.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115550</commentid>
    <comment_count>9</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-11-26 19:39:12 +0000</bug_when>
    <thetext>(In reply to Anne from comment #8)
&gt; If only for the simple fact that then nobody thinks this situation is
&gt; somehow special.

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


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

It references &quot;the section of the buffer&quot; not just &quot;the buffer&quot;. This is just English, the word &quot;buffer&quot; is a well-known computer science term that seems to map fine to the WebIDL/JS terminology. I mean, it&apos;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 &quot;a reference to or copy of (as required) the length bytes in data starting at byte offset offset&quot; which is no more defined than what HTML says, when you get right down to it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115557</commentid>
    <comment_count>10</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-11-26 20:04:07 +0000</bug_when>
    <thetext>*** Bug 26968 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115597</commentid>
    <comment_count>11</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-11-27 08:07:19 +0000</bug_when>
    <thetext>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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115644</commentid>
    <comment_count>12</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-11-28 04:27:16 +0000</bug_when>
    <thetext>Don&apos;t all APIs know whether they&apos;re copying or referencing the data?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115650</commentid>
    <comment_count>13</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-11-28 07:55:06 +0000</bug_when>
    <thetext>I think they do, yes.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115676</commentid>
    <comment_count>14</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-11-29 00:25:03 +0000</bug_when>
    <thetext>If the APIs know what they&apos;re doing, then I think the IDL should just do the checking up-front. That way the behaviour is much more consistent.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115686</commentid>
    <comment_count>15</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-11-29 15:35:50 +0000</bug_when>
    <thetext>As I said, I recommend filing a bug on IDL.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>117234</commentid>
    <comment_count>16</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2015-01-15 20:14:45 +0000</bug_when>
    <thetext>bz, would it make sense to update IDL for this?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>117238</commentid>
    <comment_count>17</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2015-01-15 20:43:21 +0000</bug_when>
    <thetext>Not all consumers know whether they&apos;re copying or referencing.  For example, a WebGL implementation might do either one depending on how it&apos;s actually implemented.

That said, what exact checking would you expect to be done up front if an API _did_ know whether it&apos;s copying or referencing?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>117253</commentid>
    <comment_count>18</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2015-01-15 23:29:37 +0000</bug_when>
    <thetext>Well the behaviour can&apos;t depend on how it&apos;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&apos;m not sure if I misread it before or if it changed. The checking I&apos;m referring to is the checking in the algorithm introduced as &quot;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:&quot; in the Web IDL spec. I argue that this should just move to argument checking step of method invocation, so that we don&apos;t get weirdness about exactly when these checks happen.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>117265</commentid>
    <comment_count>19</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2015-01-16 02:51:51 +0000</bug_when>
    <thetext>Ah, I see.

So just to make sure we&apos;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 &quot;[[ViewedArrayBuffer]] exists&quot; 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&apos;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&apos;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 &quot;getting a reference to&quot; algorithm running and the last use of the data.

Is there some other check I&apos;m missing that&apos;s at issue here?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>117266</commentid>
    <comment_count>20</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2015-01-16 03:00:27 +0000</bug_when>
    <thetext>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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>117291</commentid>
    <comment_count>21</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2015-01-17 18:10:10 +0000</bug_when>
    <thetext>At this point, the algorithm doesn&apos;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&apos;d just say:

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

Similarly, the &quot;detach&quot; algorithm seems pointlessly trivial as specced. What value does it add? We should just make the JS spec referenceable directly.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>117293</commentid>
    <comment_count>22</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2015-01-17 20:19:25 +0000</bug_when>
    <thetext>&gt;   6. Let _data_ be the data represented by /foo/.

Then we need to define &quot;the data represented by /foo/&quot;, right?  This is not a theoretical concern; implementors and spec authors have screwed this up in the past.  Which is why it&apos;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 &quot;neutered&quot; anymore.  It&apos;s called &quot;detached&quot;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>117294</commentid>
    <comment_count>23</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2015-01-18 08:02:40 +0000</bug_when>
    <thetext>Referencing JavaScript directly doesn&apos;t make sense, unless IDL values can sometimes be JavaScript objects. The layering is:

  JavaScript -&gt; IDL -&gt; feature spec -&gt; IDL -&gt; JavaScript</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>117412</commentid>
    <comment_count>24</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2015-01-21 21:03:36 +0000</bug_when>
    <thetext>IDL values can totally be JS objects, right?  I mean, consider the &quot;object&quot; type.  It&apos;s &quot;an IDL value that represents the given JS object&quot;, but presumably that means that as long as you&apos;re willing to make your prose JS-specific you can unambiguously talk about the JS object represented by the &quot;object&quot; type IDL value.

The various BufferSource types have similar behavior.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>124445</commentid>
    <comment_count>25</comment_count>
    <who name="Domenic Denicola">d</who>
    <bug_when>2015-12-16 16:40:55 +0000</bug_when>
    <thetext>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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>125523</commentid>
    <comment_count>26</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2016-03-16 14:07:02 +0000</bug_when>
    <thetext>I thought about fixing this, but bug 28798 should really be fixed first. With that bug fixed for our cases we don&apos;t even have to worry about extracting bytes, IDL will just hand us bytes.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>129676</commentid>
    <comment_count>27</comment_count>
    <who name="Domenic Denicola">d</who>
    <bug_when>2019-03-29 20:29:43 +0000</bug_when>
    <thetext>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.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>