<?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>12404</bug_id>
          
          <creation_ts>2011-03-31 06:51:38 +0000</creation_ts>
          <short_desc>Structured Clone and Arrays (implementation notes and clarifications sought)</short_desc>
          <delta_ts>2011-08-04 05:02:18 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>HTML WG</product>
          <component>LC1 HTML5 spec</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows NT</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>LC</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Travis Leithead [MSFT]">travil</reporter>
          <assigned_to name="Ian &apos;Hixie&apos; Hickson">ian</assigned_to>
          <cc>ayg</cc>
    
    <cc>bzbarsky</cc>
    
    <cc>ian</cc>
    
    <cc>jonas</cc>
    
    <cc>mike</cc>
    
    <cc>public-html-admin</cc>
    
    <cc>public-html-wg-issue-tracking</cc>
    
    <cc>travil</cc>
          
          <qa_contact name="HTML WG Bugzilla archive list">public-html-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>47069</commentid>
    <comment_count>0</comment_count>
    <who name="Travis Leithead [MSFT]">travil</who>
    <bug_when>2011-03-31 06:51:38 +0000</bug_when>
    <thetext>In some recent testing of structured cloning across various browsers using Arrays, we found some de-facto conformity that diverges from a literal interpretation of the spec text of step 5 of the _internal structured cloning algorithm_ (section 2.8.5). We&apos;re proposing some clarifying text be added to the spec.

-----

a = [&quot;zero&quot;,&quot;one&quot;];
a.foo = &quot;bar&quot;;

Clarifiction 1: 
Per step 5 of the algorithm, an implementation should clone &quot;each enumerable property&quot;. In the example, a has 3 enumerable properties, but in all browsers tested only the properties &quot;0&quot; and &quot;1&quot; (and their values) were cloned.

We propose that this section have a special section for Array objects and note that only the index properties of the array be cloned.

Clarification 2:

a.length = 4;

Now the Array a has a length of 4, but only two entries (a sparce-array). In all browsers tested (with the exception of Safari 5), only the first two entries in the array were cloned. The length of the resultant clone was truncated to the last non-null/undefined value in the array (2).

We propose that sparce-arrays likewise be &quot;clipped&quot; to the last non-null/undefined value, or that the behavior for sparce-arrays be otherwise more clearly described in the algorithm.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>47071</commentid>
    <comment_count>1</comment_count>
    <who name="Jonas Sicking (Not reading bugmail)">jonas</who>
    <bug_when>2011-03-31 07:56:58 +0000</bug_when>
    <thetext>I think we should treat these as bugs in existing implementations. If these problems exist in Firefox (note that we currently only use the structured clone algorithm in worker.postMessage), then we should and will fix them.

Especially the second point in comment 0 seems like a dangerous change to make to the structured data. I definitely think that would cause author bugs and confusion.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>47074</commentid>
    <comment_count>2</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2011-03-31 13:51:58 +0000</bug_when>
    <thetext>Indeed.  In particular, the given description of clarification 2 is manifestly incorrect, as it doesn&apos;t differentiate between these two arrays:

 [&quot;zero&quot;, &quot;one&quot;, undefined, undefined]
 [&quot;zero&quot;, &quot;one&quot;, , , ]

which are both arrays of length 4; the former is dense but the latter is sparse.

That said, I believe that this part of the behavior is correct, given what the spec says right now: the second array above, as well as the array in your example, only has two enumerable properties: &quot;0&quot; and &quot;1&quot;.  I agree that for arrays it would make sense to clone the length as well, even though it&apos;s not enumerable.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>47174</commentid>
    <comment_count>3</comment_count>
    <who name="Travis Leithead [MSFT]">travil</who>
    <bug_when>2011-04-06 00:08:45 +0000</bug_when>
    <thetext>Based on this feedback, it looks like the general consensus (which I agree with) is that:

1. Any enumerable &quot;own&quot; property on an array should be cloned (this does not require a spec change, as the current wording implies that this should happen for Object/Arrays)

2. The length of a sparce-array should be preserved when cloning. This requirement will necessitate a small spec change to alert implementors of this condition.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>49805</commentid>
    <comment_count>4</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2011-06-17 21:14:31 +0000</bug_when>
    <thetext>I can add some non-normative text to cover both of these, and some examples, assuming we&apos;re indeed ok with the basic requirements already in the spec.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>49843</commentid>
    <comment_count>5</comment_count>
    <who name="Travis Leithead [MSFT]">travil</who>
    <bug_when>2011-06-18 19:47:12 +0000</bug_when>
    <thetext>Sounds good to me. Please also make sure to highlight the preservation of the array&apos;s length property for sparce arrays too.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>50200</commentid>
    <comment_count>6</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2011-06-24 00:32:24 +0000</bug_when>
    <thetext>Done.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>50201</commentid>
    <comment_count>7</comment_count>
    <who name="">contributor</who>
    <bug_when>2011-06-24 00:32:53 +0000</bug_when>
    <thetext>Checked in as WHATWG revision r6274.
Check-in comment: Structured clone: Preserve sparse arrays and mention that non-index properties of arrays are preserved too.
http://html5.org/tools/web-apps-tracker?from=6273&amp;to=6274</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>52526</commentid>
    <comment_count>8</comment_count>
    <who name="Michael[tm] Smith">mike</who>
    <bug_when>2011-08-04 05:02:18 +0000</bug_when>
    <thetext>mass-moved component to LC1</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>