Re: DataCue questions

On Sat, 2014-02-15 at 15:59 +1100, Silvia Pfeiffer wrote:

> > The other question is, is there a general rule where we take a copy of
> > objects in constructors? Otherwise we get weird behavior like this:
> >
> >> buf = new ArrayBuffer(4)
> > < ArrayBuffer
> >
> >> bufView = new Uint16Array(buf)
> > < [0, 0]
> >> bufView[0] = "hi".charCodeAt(0=)
> > < 104
> >> bufView[1] = "hi".charCodeAt(1)
> > < 105
> >
> >> cue = new DataCue(1, 2, buf)
> > < DataCue
> >
> >> cue.text
> > < "hi"
> 
> The constructor is just a function. So, its parameters could be
> interpreted by the object either as an object to copy or as a storage
> location.
> E.g. Uint16Array provides both:
> https://developer.mozilla.org/en-US/docs/Web/API/Uint16Array
> 
> In our case, I thought it was clear that a copy was taken and stored
> withing the DataCue object.
> 
> >> bufView[0] = "no".charCodeAt(0)
> > < 110
> >> bufView[1] = "no".charCodeAt(1)
> > < 111
> >> cue.text
> > < "no"
> >
> > I'm not sure if I was implementing this wrong,
> 
> Yes, I think that's wrong. That should not be possible.
> 
> > or if we need to change the
> > spec to specify that .data is a copy of the ArrayBuffer we give it.
> 
> Well, the spec for the constructor says "The data argument sets the
> raw data of the text track cue." Not sure if "set" implies copying.
> 
> I wonder if we need to say that .data is a "structured clone" of the
> data parameter object (referring to "2.7.6 Safe passing of structured
> data")?

I read "sets" as "=" and "someObject.data = someArrayBuffer" won't
create a copy. I'll fix my implementation, and it's up to you if you
think the spec should say something about that.

--=-BZ50xy0uC/2kdwIeJ6x1
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: 7bit

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/4.6.6">
</HEAD>
<BODY>
On Sat, 2014-02-15 at 15:59 +1100, Silvia Pfeiffer wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
<FONT COLOR="#737373">&gt; The other question is, is there a general rule where we take a copy of</FONT>
<FONT COLOR="#737373">&gt; objects in constructors? Otherwise we get weird behavior like this:</FONT>
<FONT COLOR="#737373">&gt;</FONT>
<FONT COLOR="#737373">&gt;&gt; buf = new ArrayBuffer(4)</FONT>
<FONT COLOR="#737373">&gt; &lt; ArrayBuffer</FONT>
<FONT COLOR="#737373">&gt;</FONT>
<FONT COLOR="#737373">&gt;&gt; bufView = new Uint16Array(buf)</FONT>
<FONT COLOR="#737373">&gt; &lt; [0, 0]</FONT>
<FONT COLOR="#737373">&gt;&gt; bufView[0] = &quot;hi&quot;.charCodeAt(0=)</FONT>
<FONT COLOR="#737373">&gt; &lt; 104</FONT>
<FONT COLOR="#737373">&gt;&gt; bufView[1] = &quot;hi&quot;.charCodeAt(1)</FONT>
<FONT COLOR="#737373">&gt; &lt; 105</FONT>
<FONT COLOR="#737373">&gt;</FONT>
<FONT COLOR="#737373">&gt;&gt; cue = new DataCue(1, 2, buf)</FONT>
<FONT COLOR="#737373">&gt; &lt; DataCue</FONT>
<FONT COLOR="#737373">&gt;</FONT>
<FONT COLOR="#737373">&gt;&gt; cue.text</FONT>
<FONT COLOR="#737373">&gt; &lt; &quot;hi&quot;</FONT>

The constructor is just a function. So, its parameters could be
interpreted by the object either as an object to copy or as a storage
location.
E.g. Uint16Array provides both:
<A HREF="https://developer.mozilla.org/en-US/docs/Web/API/Uint16Array">https://developer.mozilla.org/en-US/docs/Web/API/Uint16Array</A>

In our case, I thought it was clear that a copy was taken and stored
withing the DataCue object.

<FONT COLOR="#737373">&gt;&gt; bufView[0] = &quot;no&quot;.charCodeAt(0)</FONT>
<FONT COLOR="#737373">&gt; &lt; 110</FONT>
<FONT COLOR="#737373">&gt;&gt; bufView[1] = &quot;no&quot;.charCodeAt(1)</FONT>
<FONT COLOR="#737373">&gt; &lt; 111</FONT>
<FONT COLOR="#737373">&gt;&gt; cue.text</FONT>
<FONT COLOR="#737373">&gt; &lt; &quot;no&quot;</FONT>
<FONT COLOR="#737373">&gt;</FONT>
<FONT COLOR="#737373">&gt; I'm not sure if I was implementing this wrong,</FONT>

Yes, I think that's wrong. That should not be possible.

<FONT COLOR="#737373">&gt; or if we need to change the</FONT>
<FONT COLOR="#737373">&gt; spec to specify that .data is a copy of the ArrayBuffer we give it.</FONT>

Well, the spec for the constructor says &quot;The data argument sets the
raw data of the text track cue.&quot; Not sure if &quot;set&quot; implies copying.

I wonder if we need to say that .data is a &quot;structured clone&quot; of the
data parameter object (referring to &quot;2.7.6 Safe passing of structured
data&quot;)?
</PRE>
</BLOCKQUOTE>
I read &quot;sets&quot; as &quot;=&quot; and &quot;someObject.data = someArrayBuffer&quot; won't create a copy. I'll fix my implementation, and it's up to you if you think the spec should say something about that.
</BODY>
</HTML>

--=-BZ50xy0uC/2kdwIeJ6x1--

Received on Sunday, 16 February 2014 17:13:23 UTC