Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(502)

Side by Side Diff: src/runtime/runtime-array.cc

Issue 799803003: Fix ArrayConcat for JSValues/JSFunctions/JSRegExps with @@isConcatSpreadable (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/mjsunit/harmony/array-concat.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/runtime/runtime-utils.h" 8 #include "src/runtime/runtime-utils.h"
9 9
10 namespace v8 { 10 namespace v8 {
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 if (!iter.IsAtEnd()) { 432 if (!iter.IsAtEnd()) {
433 // The prototype will usually have no inherited element indices, 433 // The prototype will usually have no inherited element indices,
434 // but we have to check. 434 // but we have to check.
435 CollectElementIndices( 435 CollectElementIndices(
436 Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)), range, 436 Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)), range,
437 indices); 437 indices);
438 } 438 }
439 } 439 }
440 440
441 441
442 static bool IterateElementsSlow(Isolate* isolate, Handle<JSObject> receiver,
443 uint32_t length, ArrayConcatVisitor* visitor) {
444 for (uint32_t i = 0; i < length; ++i) {
445 HandleScope loop_scope(isolate);
446 Maybe<bool> maybe = JSReceiver::HasElement(receiver, i);
447 if (!maybe.has_value) return false;
448 if (maybe.value) {
449 Handle<Object> element_value;
450 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
451 isolate, element_value,
452 Runtime::GetElementOrCharAt(isolate, receiver, i), false);
453 visitor->visit(i, element_value);
454 }
455 }
456 visitor->increase_index_offset(length);
457 return true;
458 }
459
460
442 /** 461 /**
443 * A helper function that visits elements of a JSObject in numerical 462 * A helper function that visits elements of a JSObject in numerical
444 * order. 463 * order.
445 * 464 *
446 * The visitor argument called for each existing element in the array 465 * The visitor argument called for each existing element in the array
447 * with the element index and the element's value. 466 * with the element index and the element's value.
448 * Afterwards it increments the base-index of the visitor by the array 467 * Afterwards it increments the base-index of the visitor by the array
449 * length. 468 * length.
450 * Returns false if any access threw an exception, otherwise true. 469 * Returns false if any access threw an exception, otherwise true.
451 */ 470 */
(...skipping 10 matching lines...) Expand all
462 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, val, 481 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, val,
463 Runtime::GetObjectProperty(isolate, receiver, key), false); 482 Runtime::GetObjectProperty(isolate, receiver, key), false);
464 // TODO(caitp): Support larger element indexes (up to 2^53-1). 483 // TODO(caitp): Support larger element indexes (up to 2^53-1).
465 if (!val->ToUint32(&length)) { 484 if (!val->ToUint32(&length)) {
466 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, val, 485 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, val,
467 Execution::ToLength(isolate, val), false); 486 Execution::ToLength(isolate, val), false);
468 val->ToUint32(&length); 487 val->ToUint32(&length);
469 } 488 }
470 } 489 }
471 490
491 if (!(receiver->IsJSArray() || receiver->IsJSTypedArray())) {
492 // For classes which are not known to be safe to access via elements alone,
493 // use the slow case.
494 return IterateElementsSlow(isolate, receiver, length, visitor);
495 }
496
472 switch (receiver->GetElementsKind()) { 497 switch (receiver->GetElementsKind()) {
473 case FAST_SMI_ELEMENTS: 498 case FAST_SMI_ELEMENTS:
474 case FAST_ELEMENTS: 499 case FAST_ELEMENTS:
475 case FAST_HOLEY_SMI_ELEMENTS: 500 case FAST_HOLEY_SMI_ELEMENTS:
476 case FAST_HOLEY_ELEMENTS: { 501 case FAST_HOLEY_ELEMENTS: {
477 // Run through the elements FixedArray and use HasElement and GetElement 502 // Run through the elements FixedArray and use HasElement and GetElement
478 // to check the prototype for missing elements. 503 // to check the prototype for missing elements.
479 Handle<FixedArray> elements(FixedArray::cast(receiver->elements())); 504 Handle<FixedArray> elements(FixedArray::cast(receiver->elements()));
480 int fast_length = static_cast<int>(length); 505 int fast_length = static_cast<int>(length);
481 DCHECK(fast_length <= elements->length()); 506 DCHECK(fast_length <= elements->length());
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 } 1308 }
1284 1309
1285 1310
1286 RUNTIME_FUNCTION(RuntimeReference_FastOneByteArrayJoin) { 1311 RUNTIME_FUNCTION(RuntimeReference_FastOneByteArrayJoin) {
1287 SealHandleScope shs(isolate); 1312 SealHandleScope shs(isolate);
1288 DCHECK(args.length() == 2); 1313 DCHECK(args.length() == 2);
1289 return isolate->heap()->undefined_value(); 1314 return isolate->heap()->undefined_value();
1290 } 1315 }
1291 } 1316 }
1292 } // namespace v8::internal 1317 } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/harmony/array-concat.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698