<?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>22471</bug_id>
          
          <creation_ts>2013-06-26 05:37:44 +0000</creation_ts>
          <short_desc>&quot;buffered&quot; attribute returns a new object each time</short_desc>
          <delta_ts>2017-08-02 07:17:37 +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>MOVED</resolution>
          
          
          <bug_file_loc>http://www.whatwg.org/specs/web-apps/current-work/#loading-the-media-resource</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P3</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>Unsorted</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>contributor</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>acolwell</cc>
    
    <cc>annevk</cc>
    
    <cc>bzbarsky</cc>
    
    <cc>d</cc>
    
    <cc>ian</cc>
    
    <cc>kinetik</cc>
    
    <cc>mike</cc>
    
    <cc>philipj</cc>
          
          <qa_contact>contributor</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>89870</commentid>
    <comment_count>0</comment_count>
    <who name="">contributor</who>
    <bug_when>2013-06-26 05:37:44 +0000</bug_when>
    <thetext>Specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html
Multipage: http://www.whatwg.org/C#loading-the-media-resource
Complete: http://www.whatwg.org/c#loading-the-media-resource
Referrer: http://www.whatwg.org/specs/web-apps/current-work/multipage/

Comment:
&quot;buffered&quot; attribute returns a new object each time

Posted from: 98.110.194.206 by bzbarsky@mit.edu
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20130606 Firefox/24.0</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>89871</commentid>
    <comment_count>1</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-06-26 05:38:59 +0000</bug_when>
    <thetext>Returning a new object each time from an attribute getter (as opposed to a method) is terrible API, because it breaks the very reasonable expectation that &quot;foo.bar == foo.bar&quot;.

We should stop doing this, if we can.  If we can&apos;t, we should deprecate these attributes and replace them with methods...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>89872</commentid>
    <comment_count>2</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-06-26 05:40:41 +0000</bug_when>
    <thetext>&quot;played&quot; and &quot;seekable&quot; have the same issue.

One other note: even if we don&apos;t plan to change these attributes we should at least add a note on them saying they&apos;re bad API, since people are cargo-culting them in other specs....</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>90184</commentid>
    <comment_count>3</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-07-02 23:34:51 +0000</bug_when>
    <thetext>What would you like the note to say, exactly, and where should I put it?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>90194</commentid>
    <comment_count>4</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-07-02 23:49:08 +0000</bug_when>
    <thetext>Next to the prose that says that this attribute returns a new object each time, and it should say something like:

  This is a terrible API that should not be cargo-culted.  If you want to return
  a new object each time, use a method, not an attribute.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>90275</commentid>
    <comment_count>5</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-07-03 22:23:17 +0000</bug_when>
    <thetext>That would not set a good precedent — there&apos;s tons of other things in the Web API that we could say that about, and I don&apos;t want the HTML spec to become a treatise in the failings of the Web. It&apos;s already trying to wear too many hats.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>90276</commentid>
    <comment_count>6</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-07-03 22:25:41 +0000</bug_when>
    <thetext>I&apos;d put it in a &lt;!-- comment --&gt;, but I don&apos;t think most spec writers are reading the spec source when they copy an API. Frankly, there&apos;s a good chance that they&apos;re not even copying the spec, just APIs as they find them — should we add this warning to all the MDN pages? To the JS console?

I think maybe we would be better off solving this problem by having people review specs more, and by having implementors refuse to implement stuff like this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>90321</commentid>
    <comment_count>7</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-07-04 03:19:14 +0000</bug_when>
    <thetext>&gt; I think maybe we would be better off solving this problem by having people
&gt; review specs more

That&apos;s how I came across the problem, yes.  I was asked for feedback on a patch that was implementing a spec that had cargo-culted this pattern from .buffered.

&gt; Frankly, there&apos;s a good chance that they&apos;re not even copying the spec

The spec author explicitly said they had copied what the .buffered spec says, when I asked them why they had set it up that way....</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>90533</commentid>
    <comment_count>8</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-07-09 21:07:18 +0000</bug_when>
    <thetext>Sure, that particular one, but maybe the next one copies seekable, and another copies some other spec, and another copies MDN, etc.

There&apos;s tons of bad APIs in the Web. I don&apos;t think it is in the overall interests of the Web for us to keep drawing attention to this. It doesn&apos;t scale well, it makes newcomers who want to learn the Web get discouraged more quickly than they otherwise would, it gives detractors fodder for trolling, it&apos;s just not a long-term workable plan, IMHO. See also comment 5.

Did you happen to ask them if they looked at the spec source to cargo-cult this?

Do you know if they looked at the W3C copy or the WHATWG copy?

Did they read any of the introductory material? I could put something there, if people would read it

Did they click on this part of the spec e.g. to copy-and-paste it? I could make something appear on mouse down or something like that... maybe a warning icon in the margin, similar to the fingerprinting thing? The question is, would they have followed it to find out what it said?

Can you have said spec editor come to this bug and comment on the above?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>90545</commentid>
    <comment_count>9</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-07-09 21:58:45 +0000</bug_when>
    <thetext>&gt; Can you have said spec editor come to this bug and comment on the above?

Let&apos;s try that.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>90553</commentid>
    <comment_count>10</comment_count>
    <who name="Aaron Colwell">acolwell</who>
    <bug_when>2013-07-09 22:53:50 +0000</bug_when>
    <thetext>I don&apos;t particularly care for the cargo-culting charactarization since it implies that I didn&apos;t actually think about this. 

The reason I copied buffered to match the HTMLMediaElement attribute is because the result of the SourceBuffer.buffered attribute is a subset of what HTMLMediaElement.buffered reports. It seemed natural to make this functionality look and act the same way as the HTMLMediaElement version since people familiar with the one would automatically be familiar with the behavior of the other. 

I don&apos;t think it is particularly useful to get so worked up about this. I did bring up this issue on our MSE spec teleconference call today and others favored keeping the spec as is so that it matches the HTMLMediaElement. I changed the other attribute you objected to in the Media Source spec since your argument made sense for that and there weren&apos;t any other reasons to prefer the attribute construct over a method.

I don&apos;t believe there is much to gain by deprecating these attributes in favor of methods. It seems like it would just break sites for no apparent gain other than &quot;API purity&quot;. I&apos;m just trying to be pragmatic here. If a new set of TimeRanges are added to HTMLMediaElement, then yes by all means we should use methods, but I don&apos;t think it is worth trying to convert the existing TimeRanges attributes that are already there. In the grand scheme of things this seems like a pretty minor bit of legacy to keep around.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>90566</commentid>
    <comment_count>11</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-07-10 00:16:14 +0000</bug_when>
    <thetext>Thanks Aaron.

bz: I think, based on the above, that a comment in the spec, whether in the source, or visible to all, or in the introduction section, would actually have had no effect at all. So I don&apos;t know that it&apos;s worth adding anything here.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>90575</commentid>
    <comment_count>12</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-07-10 02:04:57 +0000</bug_when>
    <thetext>I&apos;m sorry; I did not mean to imply that you didn&apos;t think when you copied the pattern.

But, imo, that makes it even more important to point out that the pattern should not be copied in new APIs...  It&apos;s a _really_ bad pattern from the point of view of JS programmers, because it badly violates basic expectations about how attribute gets should behave.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>90578</commentid>
    <comment_count>13</comment_count>
    <who name="Aaron Colwell">acolwell</who>
    <bug_when>2013-07-10 03:43:47 +0000</bug_when>
    <thetext>(In reply to comment #12)
&gt; I&apos;m sorry; I did not mean to imply that you didn&apos;t think when you copied the
&gt; pattern.

Thanks. I appreciate this.

&gt; 
&gt; But, imo, that makes it even more important to point out that the pattern
&gt; should not be copied in new APIs...  It&apos;s a _really_ bad pattern from the
&gt; point of view of JS programmers, because it badly violates basic
&gt; expectations about how attribute gets should behave.

I understand, but I don&apos;t think the HTML spec itself is the best place to do this.

It would be nice if there was a &quot;Best Practices&quot; or &quot;Web API Design&quot; document that spec authors could refer to so they could learn from the mistakes of the past and avoid introducing new APIs with the same old mistakes. It seems like such a document would be a better place for do&apos;s and don&apos;ts almost like the coding style guides we use for Chromium (http://www.chromium.org/developers/coding-style , http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml). I know that such a document would have been enormously helpful when I started writing the MSE spec. It is hard to know when to emulate patterns from the past and when to just adopt the new hotness even if it doesn&apos;t match anything that surrounds it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91166</commentid>
    <comment_count>14</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-07-23 22:53:35 +0000</bug_when>
    <thetext>I&apos;ve added something about this here:

   http://wiki.whatwg.org/wiki/Howto_spec#Defining_an_attribute

Feel free to add more such things on that page.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>116959</commentid>
    <comment_count>15</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2015-01-09 12:52:49 +0000</bug_when>
    <thetext>This is not fixed.  You can call it wontfix if you want, but the basic brokenness of the API is still there; the bit added in comment 14 certainly doesn&apos;t fix that.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>116960</commentid>
    <comment_count>16</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2015-01-09 12:53:23 +0000</bug_when>
    <thetext>&gt; You can call it wontfix if you want

Though obviously it would be better to fix the API....</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>116980</commentid>
    <comment_count>17</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2015-01-09 23:36:43 +0000</bug_when>
    <thetext>It seems unlikely that we can make a breaking change to this API. What change would you suggest?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>116989</commentid>
    <comment_count>18</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2015-01-10 03:01:38 +0000</bug_when>
    <thetext>At what point can the set of time ranges actually change?

It it can&apos;t change during JS execution that doesn&apos;t call into DOM methods, then the simplest thing is to keep returning the same value until the set of time ranges changes, then create a new object with the new set of time ranges.

That way the behavior will fundamentally be the same as that of the .firstChild property: it keeps reporting the same value until you do something that changes it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>117093</commentid>
    <comment_count>19</comment_count>
    <who name="Philip Jägenstedt">philipj</who>
    <bug_when>2015-01-13 19:11:07 +0000</bug_when>
    <thetext>(In reply to Boris Zbarsky from comment #18)
&gt; At what point can the set of time ranges actually change?
&gt; 
&gt; It it can&apos;t change during JS execution that doesn&apos;t call into DOM methods,
&gt; then the simplest thing is to keep returning the same value until the set of
&gt; time ranges changes, then create a new object with the new set of time
&gt; ranges.
&gt; 
&gt; That way the behavior will fundamentally be the same as that of the
&gt; .firstChild property: it keeps reporting the same value until you do
&gt; something that changes it.

Aaron is OK with this model in bug 27790 and I agree. Hixie, do you think this is model is acceptable, so that we can do the same in HTML and MSE?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>117114</commentid>
    <comment_count>20</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2015-01-13 23:18:09 +0000</bug_when>
    <thetext>We can change the API if you don&apos;t think it&apos;ll break usage, but it seems unlikely to me that it won&apos;t break usage.

Having said that, it seems to me to be a weird change. I don&apos;t really understand what&apos;s wrong with the current API, but it seems that sometimes returning the same object and sometimes not is even more weird than always returning a new object. Especially for something which conceptually changes every nanosecond (I don&apos;t recall off-hand if this particular API is actually being frozen per task).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>117130</commentid>
    <comment_count>21</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2015-01-14 02:19:07 +0000</bug_when>
    <thetext>&gt; but it seems unlikely to me that it won&apos;t break usage.

What do you think it would break?

&gt; it seems that sometimes returning the same object and sometimes not is even
&gt; more weird than always returning a new object.

No, it&apos;s not.  It&apos;s no more weird than .firstChild, as I said.  The key is that this behavior makes perfect sense if the value can only change when you give up control to some code that changes it.  That&apos;s quite different from &quot;sometimes returning the same object and sometimes not&quot; in that it&apos;s fairly predictable in terms of when it can change: when the event loop runs or when you explicitly invoke some method or setter that changes the value.  If you&apos;re just running script to completion and don&apos;t modify the value yourself, you know it won&apos;t change.

&gt; Especially for something which conceptually changes every nanosecond

This would be a bigger issue.  If that&apos;s really the behavior, this should _really_ never have been an attribute....  But yes, if the expected behavior here is more like that of performance.now(), then updating only on event loops spins or explicit changes is clearly wrong.  Hence the question I asked in comment 18.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>117143</commentid>
    <comment_count>22</comment_count>
    <who name="Philip Jägenstedt">philipj</who>
    <bug_when>2015-01-14 09:19:12 +0000</bug_when>
    <thetext>(In reply to Ian &apos;Hixie&apos; Hickson from comment #20)
&gt; Especially for something which conceptually changes
&gt; every nanosecond (I don&apos;t recall off-hand if this particular API is actually
&gt; being frozen per task).

currentTime uses &quot;The official playback position is an approximation of the current playback position that is kept stable while scripts are running.&quot;

I think buffered should be updated to say something similar, it currently says &quot;The buffered attribute must return a new static normalised TimeRanges object that represents the intersection of the ranges of the media resources of the slaved media elements that the user agent has buffered, at the time the attribute is evaluated.&quot;

More generally, I think that the whole state of HTMLMediaElement should be consistent and unchanging while a script is running.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>117223</commentid>
    <comment_count>23</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2015-01-15 19:25:06 +0000</bug_when>
    <thetext>IMHO the problem with this API is not that it can change while script is running, nor that it returns a new object each time you fetch it, it&apos;s just that it uses an attribute for an expensive operation, and attributes are an affordance that appears cheap, so it misleads authors regarding its cost.

I really don&apos;t see why an attribute can&apos;t change value every time you fetch it. Nor do I see why it&apos;s bad for the value to change while script is running.

Testing this, it seems like Firefox, Chrome, and Safari all return new objects each time but don&apos;t update the values while script is running:
   http://software.hixie.ch/utilities/js/live-dom-viewer/?saved=3372

So I guess we could update the spec to say that the value returned is that at the time the event loop last reached step 1. Changing the attribute&apos;s allocation behaviour seems unwise given the interop though.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>117229</commentid>
    <comment_count>24</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2015-01-15 19:43:10 +0000</bug_when>
    <thetext>&gt; it&apos;s just that it uses an attribute for an expensive operation

Yes, that&apos;s an issue too.  But it&apos;s less of an issue if the value gets cached for after the first get...

&gt; I really don&apos;t see why an attribute can&apos;t change value every time you fetch it.

It _can_, clearly; getters let you do that.

But it _shouldn&apos;t_, because it really confuses authors (in addition to making the operation more expensive in this case).  People have been saying this for years.

I would really like to change the Firefox behavior here, for what it&apos;s worth.  I don&apos;t expect it to be a compat problem.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>125403</commentid>
    <comment_count>25</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2016-03-09 14:26:38 +0000</bug_when>
    <thetext>This seems like something we should change, indeed. Philip, can you work on this?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>125496</commentid>
    <comment_count>26</comment_count>
    <who name="Philip Jägenstedt">philipj</who>
    <bug_when>2016-03-15 08:30:38 +0000</bug_when>
    <thetext>OK, I took a quick peek, but MediaController also has TimeRanges attributes and I don&apos;t want to spend any time on that. I suggest revisiting once MediaController has been removed: https://github.com/whatwg/html/issues/192

An implementor interested in fixing this and writing web-platform-tests in the process would also be good. The way this currently works in Blink makes it very tempting to cheat by only returning a new object if the ranges have changed since last accessed, but that wouldn&apos;t match what I intend for the spec to say. If the buffered ranges change and then change back (most easily in the case of no ranges) then it should still be a new object, if it *could* have been observed but just wasn&apos;t.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>128732</commentid>
    <comment_count>27</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2017-07-21 09:38:04 +0000</bug_when>
    <thetext>MediaController is gone now. I assume you&apos;re still interested in working on this Philip?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>128815</commentid>
    <comment_count>28</comment_count>
    <who name="Philip Jägenstedt">philip</who>
    <bug_when>2017-08-01 08:53:08 +0000</bug_when>
    <thetext>I&apos;m OK with being the assignee, but am no longer so sure we should attempt to change this. https://jsbin.com/nugiloq/edit?html,output is a test that passes in Chrome, Edge, Firefox and Safari, and fixing this would mean moving away from that interoperable state. I can&apos;t see a way to estimate the risk with use counters either, because it depends on how the returned objects are used.

So, I think we should go the path of adding tests for this (if they don&apos;t already exist) and adding comments in the spec that this behavior is weird and not to be copied.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>128816</commentid>
    <comment_count>29</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2017-08-01 13:26:26 +0000</bug_when>
    <thetext>Notes, not comments.  They need to be visible to spec readers, not spec authors.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>128817</commentid>
    <comment_count>30</comment_count>
    <who name="Philip Jägenstedt">philip</who>
    <bug_when>2017-08-01 13:40:03 +0000</bug_when>
    <thetext>Yes, that&apos;s what I meant but didn&apos;t write :)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>128818</commentid>
    <comment_count>31</comment_count>
    <who name="Domenic Denicola">d</who>
    <bug_when>2017-08-01 14:58:08 +0000</bug_when>
    <thetext>Do you anticipate this causing compat problems to change? We&apos;ve changed several similar things in the past...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>128819</commentid>
    <comment_count>32</comment_count>
    <who name="Philip Jägenstedt">philip</who>
    <bug_when>2017-08-01 15:20:41 +0000</bug_when>
    <thetext>I don&apos;t have a specific piece of breaking code that I suspect is out there, and it seems fairly likely that such a change would be web compatible. I suppose I&apos;m just not feeling super motivated to spend time on it given that at best nobody will notice, but maybe I should mark it available instead?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>128820</commentid>
    <comment_count>33</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2017-08-02 07:17:37 +0000</bug_when>
    <thetext>https://github.com/whatwg/html/pull/2884

If someone wants to put effort into changing it, I recommend we do that through a new set of issues.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>