Skip to content

Commit 2f3f974

Browse files
psmarshallCommit Bot
authored andcommitted
[builtins] Fix TypedArray slice for species constructor.
Bug: chromium:725865 Change-Id: I94006d45aefb969fb0cf98ec475c30c14b3837fa Reviewed-on: https://chromium-review.googlesource.com/517488 Reviewed-by: Camillo Bruni <[email protected]> Commit-Queue: Peter Marshall <[email protected]> Cr-Commit-Position: refs/heads/master@{#45567}
1 parent 804ac5f commit 2f3f974

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/elements.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3103,7 +3103,7 @@ class TypedElementsAccessor
31033103
ElementsAccessor* result_accessor = result_array->GetElementsAccessor();
31043104
for (uint32_t i = start; i < end; i++) {
31053105
Handle<Object> elem = AccessorClass::GetImpl(isolate, *from, i);
3106-
result_accessor->Set(result_array, i, *elem);
3106+
result_accessor->Set(result_array, i - start, *elem);
31073107
}
31083108
return result_array;
31093109
}

src/objects-inl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3950,7 +3950,7 @@ typename Traits::ElementType FixedTypedArray<Traits>::get_scalar(int index) {
39503950

39513951
template <class Traits>
39523952
void FixedTypedArray<Traits>::set(int index, ElementType value) {
3953-
DCHECK((index >= 0) && (index < this->length()));
3953+
CHECK((index >= 0) && (index < this->length()));
39543954
ElementType* ptr = reinterpret_cast<ElementType*>(DataPtr());
39553955
ptr[index] = value;
39563956
}

test/mjsunit/es6/typedarray-slice.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,18 @@ for (var constructor of typedArrayConstructors) {
9595
for (var constructor1 of typedArrayConstructors) {
9696
for (var constructor2 of typedArrayConstructors) {
9797
testCustomSubclass(constructor1, constructor2);
98+
testSpeciesConstructor(constructor1, constructor2);
9899
}
99100
}
100101

102+
function testSpeciesConstructor(cons1, cons2) {
103+
var ta = new cons1([1, 2, 3, 4, 5, 6]);
104+
ta.constructor = {
105+
[Symbol.species]: cons2
106+
};
107+
assertArrayEquals([4, 5, 6], ta.slice(3));
108+
}
109+
101110
function testCustomSubclass(superClass, speciesClass) {
102111
// Simple subclass that has another TypedArray as species
103112
class CustomTypedArray extends superClass {

0 commit comments

Comments
 (0)