DataCue questions

I've been working on implementing the DataCue interface in WebKit, and I
have some questions.

According to this, .text can be null:

> The text attribute, on getting, must return UTF-16 text converted from
> data of the text track cue that the TextTrackCue object represents. If
> a conversion of the content in data is not possible, e.g. because the
> UA is unable to identify the encoding, it must return null.

So shouldn't the WebIDL say "DOMString?" with a question mark to
indicate that it's nullable?

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"
> > 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, or if we need to change
the spec to specify that .data is a copy of the ArrayBuffer we give it.

--=-Pm3MARjRlI6QoBeTpxVc
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>
I've been working on implementing the <A HREF="http://www.w3.org/html/wg/drafts/html/CR/embedded-content-0.html">DataCue interface</A> in WebKit, and I have some questions.<BR>
<BR>
According to this, .text can be null:<BR>
<BLOCKQUOTE TYPE=CITE>
    The <TT>text</TT> attribute, on getting, must return UTF-16 text converted from <TT><A HREF="http://www.w3.org/html/wg/drafts/html/CR/text-level-semantics.html#the-data-element">data</A></TT> of the <A HREF="http://www.w3.org/html/wg/drafts/html/CR/embedded-content-0.html#text-track-cue">text track cue</A> that the <TT><A HREF="http://www.w3.org/html/wg/drafts/html/CR/embedded-content-0.html#texttrackcue">TextTrackCue</A></TT> object represents. If a conversion of the content in <TT><A HREF="http://www.w3.org/html/wg/drafts/html/CR/text-level-semantics.html#the-data-element">data</A></TT> is not possible, e.g. because the UA is unable to identify the encoding, it must return null.<BR>
</BLOCKQUOTE>
So shouldn't the WebIDL say &quot;DOMString?&quot; with a question mark <A HREF="http://www.w3.org/TR/WebIDL/">to indicate that it's nullable</A>?<BR>
<BR>
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:
<BLOCKQUOTE TYPE=CITE>
<PRE>
&gt; buf = new ArrayBuffer(4)
&lt; ArrayBuffer

&gt; bufView = new Uint16Array(buf)
&lt; [0, 0]
&gt; bufView[0] = &quot;hi&quot;.charCodeAt(0=)
&lt; 104
&gt; bufView[1] = &quot;hi&quot;.charCodeAt(1)
&lt; 105

&gt; cue = new DataCue(1, 2, buf)
&lt; DataCue

&gt; cue.text
&lt; &quot;hi&quot;
&gt; bufView[0] = &quot;no&quot;.charCodeAt(0)
&lt; 110
&gt; bufView[1] = &quot;no&quot;.charCodeAt(1)
&lt; 111
&gt; cue.text
&lt; &quot;no&quot;
</PRE>
</BLOCKQUOTE>
I'm not sure if I was implementing this wrong, or if we need to change the spec to specify that .data is a copy of the ArrayBuffer we give it.
</BODY>
</HTML>

--=-Pm3MARjRlI6QoBeTpxVc--

Received on Monday, 10 February 2014 21:32:17 UTC