This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 20731 - Sequence algorithm seems incorrect
Summary: Sequence algorithm seems incorrect
Status: RESOLVED INVALID
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: WebIDL (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Cameron McCormack
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-01-22 11:51 UTC by Marcos Caceres
Modified: 2013-01-22 17:24 UTC (History)
4 users (show)

See Also:


Attachments

Description Marcos Caceres 2013-01-22 11:51:16 UTC
Reading http://dev.w3.org/2006/webapi/WebIDL/#es-sequence

Where the algorithm goes: 

"
Let n be the result of calling ToUint32(length).
Initialize S0..n−1 to be an IDL sequence with elements of type T, where each element is uninitialized.
While i < n:
Let P be the result of calling ToString(i).
Let E be the result of calling [[Get]] on V with property name P.
"

P will just be "1", "2", "3", and so on, but not the actual property name. And hence E will just be undefined.
Comment 1 Boris Zbarsky 2013-01-22 13:07:56 UTC
What do you mean by "actual property name"?

In ECMAScript, all property names are strings.  So for example the array [ "a", "b" ] has properties named "0" and "1" (as well as "length").
Comment 2 Marcos Caceres 2013-01-22 13:21:25 UTC
You are correct, but how does this work if the object passed is:

{foo: "x", bar: "y"}
Comment 3 Boris Zbarsky 2013-01-22 13:25:13 UTC
Then it doesn't have indexed properties, right?  And no length, either.  So in terms of conversion to a sequence it's exactly the same as passing in the empty array [].
Comment 4 Marcos Caceres 2013-01-22 16:26:04 UTC
(In reply to comment #3)
> Then it doesn't have indexed properties, right?  And no length, either.  So
> in terms of conversion to a sequence it's exactly the same as passing in the
> empty array [].

ah, ok. In the case of [[Get]] length being ``undefined`` calling `ToUint32(length)` converts it to a +0.

Thanks for clarifying, Boris. Closing as invalid.
Comment 5 Marcos Caceres 2013-01-22 16:49:45 UTC
Just one more minor thing (which may be JS implementation specific)... calling new Array(-1) causes Array to throw a "RangeError: Invalid array length", as happens in the following case: 

length = undefined; 

//Let n be the result of calling ToUint32(length).
n = ToUint32(length); //0

//Initialize S[0..n−1] to be an IDL sequence with elements of type T,
//where each element is uninitialized.
S = new Array(n - 1);

Does that matter?
Comment 6 Boris Zbarsky 2013-01-22 17:05:03 UTC
> S = new Array(n - 1);

That line of code is just wrong, no?
Comment 7 Marcos Caceres 2013-01-22 17:08:43 UTC
(In reply to comment #6)
> > S = new Array(n - 1);
> 
> That line of code is just wrong, no?

Dunno. I'm just doing what the spec says.
Comment 8 Boris Zbarsky 2013-01-22 17:12:30 UTC
No, you're not.  You're passing in the wrong length.  The correct thing to pass in is "n".
Comment 9 Marcos Caceres 2013-01-22 17:20:29 UTC
(In reply to comment #8)
> No, you're not.  You're passing in the wrong length.  The correct thing to
> pass in is "n".

ah, got thrown by the "..n−1" bit.
Comment 10 Boris Zbarsky 2013-01-22 17:24:20 UTC
Right, the indices range from 0 to n-1.