Skip to content

Commit 7989e04

Browse files
isheludkoCommit Bot
authored andcommitted
[builtins] Fix Array.prototype.concat with @@species
Bug: chromium:1195977 Change-Id: I16843bce2e9f776abca0f2b943b898ab5e597e42 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2810787 Reviewed-by: Camillo Bruni <[email protected]> Commit-Queue: Igor Sheludko <[email protected]> Cr-Commit-Position: refs/heads/master@{#73842}
1 parent aa13c15 commit 7989e04

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

src/builtins/builtins-array.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -651,11 +651,14 @@ class ArrayConcatVisitor {
651651
index_offset_(0u),
652652
bit_field_(FastElementsField::encode(fast_elements) |
653653
ExceedsLimitField::encode(false) |
654-
IsFixedArrayField::encode(storage->IsFixedArray()) |
654+
IsFixedArrayField::encode(storage->IsFixedArray(isolate)) |
655655
HasSimpleElementsField::encode(
656-
storage->IsFixedArray() ||
657-
!storage->map().IsCustomElementsReceiverMap())) {
658-
DCHECK(!(this->fast_elements() && !is_fixed_array()));
656+
storage->IsFixedArray(isolate) ||
657+
// Don't take fast path for storages that might have
658+
// side effects when storing to them.
659+
(!storage->map(isolate).IsCustomElementsReceiverMap() &&
660+
!storage->IsJSTypedArray(isolate)))) {
661+
DCHECK_IMPLIES(this->fast_elements(), is_fixed_array());
659662
}
660663

661664
~ArrayConcatVisitor() { clear_storage(); }
@@ -1069,8 +1072,8 @@ bool IterateElements(Isolate* isolate, Handle<JSReceiver> receiver,
10691072
return IterateElementsSlow(isolate, receiver, length, visitor);
10701073
}
10711074

1072-
if (!HasOnlySimpleElements(isolate, *receiver) ||
1073-
!visitor->has_simple_elements()) {
1075+
if (!visitor->has_simple_elements() ||
1076+
!HasOnlySimpleElements(isolate, *receiver)) {
10741077
return IterateElementsSlow(isolate, receiver, length, visitor);
10751078
}
10761079
Handle<JSObject> array = Handle<JSObject>::cast(receiver);

src/objects/fixed-array-inl.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,15 @@ int Search(T* array, Name name, int valid_entries, int* out_insertion_index,
368368
double FixedDoubleArray::get_scalar(int index) {
369369
DCHECK(map() != GetReadOnlyRoots().fixed_cow_array_map() &&
370370
map() != GetReadOnlyRoots().fixed_array_map());
371-
DCHECK(index >= 0 && index < this->length());
371+
DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
372372
DCHECK(!is_the_hole(index));
373373
return ReadField<double>(kHeaderSize + index * kDoubleSize);
374374
}
375375

376376
uint64_t FixedDoubleArray::get_representation(int index) {
377377
DCHECK(map() != GetReadOnlyRoots().fixed_cow_array_map() &&
378378
map() != GetReadOnlyRoots().fixed_array_map());
379-
DCHECK(index >= 0 && index < this->length());
379+
DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
380380
int offset = kHeaderSize + index * kDoubleSize;
381381
// Bug(v8:8875): Doubles may be unaligned.
382382
return base::ReadUnalignedValue<uint64_t>(field_address(offset));
@@ -394,6 +394,7 @@ Handle<Object> FixedDoubleArray::get(FixedDoubleArray array, int index,
394394
void FixedDoubleArray::set(int index, double value) {
395395
DCHECK(map() != GetReadOnlyRoots().fixed_cow_array_map() &&
396396
map() != GetReadOnlyRoots().fixed_array_map());
397+
DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
397398
int offset = kHeaderSize + index * kDoubleSize;
398399
if (std::isnan(value)) {
399400
WriteField<double>(offset, std::numeric_limits<double>::quiet_NaN());
@@ -410,6 +411,7 @@ void FixedDoubleArray::set_the_hole(Isolate* isolate, int index) {
410411
void FixedDoubleArray::set_the_hole(int index) {
411412
DCHECK(map() != GetReadOnlyRoots().fixed_cow_array_map() &&
412413
map() != GetReadOnlyRoots().fixed_array_map());
414+
DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
413415
int offset = kHeaderSize + index * kDoubleSize;
414416
base::WriteUnalignedValue<uint64_t>(field_address(offset), kHoleNanInt64);
415417
}

0 commit comments

Comments
 (0)