Closed Bug 527421 Opened 17 years ago Closed 16 years ago

Vector.splice does not handle single 'Vector' argument

Categories

(Tamarin Graveyard :: Virtual Machine, defect)

x86
macOS
defect
Not set
normal

Tracking

(Not tracked)

VERIFIED INVALID

People

(Reporter: lhansen, Unassigned)

Details

According to this page: <URL:http://help.adobe.com/en_US/AS3LCR/Flash_10.0/Vector.html#splice%28%29> we allow splice to take exactly three arguments with the third being a vector, which is then expanded into the 'this' vector. (Evidently this is an extension of ECMAScript.) We allow the same for Array too: <URL:http://help.adobe.com/en_US/AS3LCR/Flash_10.0/Array.html#splice%28%29>. This test shows that we implement this behavior correctly for Array but not for Vector: var v = new <int>[1,2]; var w = new <int>[3,4]; v.splice(v.length,0,w); print(v); var a = [1,2] var b = [3,4] a.splice(a.length,0,b); print(a); Here is the output from a current Tamarin shell: 1,2,0 1,2,3,4 The second line is correct, the first line should have been like it. From a cursory examination of the Tamarin source code it looks like there's a bug in capturing the arguments to the splice() function and passing it into the C++ implementation. The arguments to splice are captured as ...items. This is always an Array. In the C++ code it is tested to see whether it's a Vector, which is never true - what should be done is to see if the length of the items array is 1 and if the first element is a Vector.
Flags: in-testsuite?
Flags: flashplayer-needsversioning+
There is no special implementation of this for Array, it only works because Array is untyped, and you can insert anything in it. If you add this: for( var i:uint = 0 ; i<a.length; ++i) print(a[i]); The array now has three elements, and the third is another array. It now contains '1', '2', and ['3', '4']. It didn't expand the array passed in to splice. Also, the number of arguments has no effect on this behavior - 1 argument is no different than any other number of arguments. I don't know why the Array docs talk about this "special" case - it makes it sound like Array.splice is doing something it isn't - after reading it I'd expect the Array to have 4 elements, not 3. As for Vector, I believe the Vector docs were just copied from the Array docs, since Vector was intended as a replacement for Array. Clearly the Array.splice behavior can't be exactly replicated in a typed Vector. Vector.splice was never implemented to have this special behavior (It was not in the Vector proposal from ES4, which is what the Vector implementation was based on), which explains why it doesn't work.
Aha, I let myself be tricked by the lack of delimiters for Array.toString! Good, and minus one point to me for not checking more thoroughly. We need to fix the docs, then.
Status: NEW → RESOLVED
Closed: 16 years ago
Resolution: --- → INVALID
Verified that documentation has been changed for argo. 10.0 Doc for ...items parameter for vector.splice: ... items — An optional list of one or more comma-separated values, or a Vector, to insert into the Vector at the position specified in the startIndex parameter. 10.1 Docs: ... items — An optional list of one or more comma-separated values to insert into the Vector at the position specified in the startIndex parameter.
Status: RESOLVED → VERIFIED
Flags: in-testsuite? → in-testsuite-
You need to log in before you can comment on or make changes to this bug.