- From: Brendan Long <self@brendanlong.com>
- Date: Sun, 16 Feb 2014 11:12:46 -0600
- To: public-html@w3.org
- Message-ID: <1392570766.2494.7.camel@blong-desktop>
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">> The other question is, is there a general rule where we take a copy of</FONT> <FONT COLOR="#737373">> objects in constructors? Otherwise we get weird behavior like this:</FONT> <FONT COLOR="#737373">></FONT> <FONT COLOR="#737373">>> buf = new ArrayBuffer(4)</FONT> <FONT COLOR="#737373">> < ArrayBuffer</FONT> <FONT COLOR="#737373">></FONT> <FONT COLOR="#737373">>> bufView = new Uint16Array(buf)</FONT> <FONT COLOR="#737373">> < [0, 0]</FONT> <FONT COLOR="#737373">>> bufView[0] = "hi".charCodeAt(0=)</FONT> <FONT COLOR="#737373">> < 104</FONT> <FONT COLOR="#737373">>> bufView[1] = "hi".charCodeAt(1)</FONT> <FONT COLOR="#737373">> < 105</FONT> <FONT COLOR="#737373">></FONT> <FONT COLOR="#737373">>> cue = new DataCue(1, 2, buf)</FONT> <FONT COLOR="#737373">> < DataCue</FONT> <FONT COLOR="#737373">></FONT> <FONT COLOR="#737373">>> cue.text</FONT> <FONT COLOR="#737373">> < "hi"</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">>> bufView[0] = "no".charCodeAt(0)</FONT> <FONT COLOR="#737373">> < 110</FONT> <FONT COLOR="#737373">>> bufView[1] = "no".charCodeAt(1)</FONT> <FONT COLOR="#737373">> < 111</FONT> <FONT COLOR="#737373">>> cue.text</FONT> <FONT COLOR="#737373">> < "no"</FONT> <FONT COLOR="#737373">></FONT> <FONT COLOR="#737373">> 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">> or if we need to change the</FONT> <FONT COLOR="#737373">> spec to specify that .data is a copy of the ArrayBuffer we give it.</FONT> 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")? </PRE> </BLOCKQUOTE> 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. </BODY> </HTML> --=-BZ50xy0uC/2kdwIeJ6x1--
Received on Sunday, 16 February 2014 17:13:23 UTC