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

Side by Side Diff: src/builtins.cc

Issue 1159433003: Use GetProperty for getting elements. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments Created 5 years, 6 months 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 | « src/array.js ('k') | src/compiler/js-typed-lowering.cc » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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/api.h" 7 #include "src/api.h"
8 #include "src/api-natives.h" 8 #include "src/api-natives.h"
9 #include "src/arguments.h" 9 #include "src/arguments.h"
10 #include "src/base/once.h" 10 #include "src/base/once.h"
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 MaybeHandle<FixedArrayBase> maybe_elms_obj = 431 MaybeHandle<FixedArrayBase> maybe_elms_obj =
432 EnsureJSArrayWithWritableFastElements(isolate, receiver, NULL, 0); 432 EnsureJSArrayWithWritableFastElements(isolate, receiver, NULL, 0);
433 Handle<FixedArrayBase> elms_obj; 433 Handle<FixedArrayBase> elms_obj;
434 if (!maybe_elms_obj.ToHandle(&elms_obj)) { 434 if (!maybe_elms_obj.ToHandle(&elms_obj)) {
435 return CallJsBuiltin(isolate, "$arrayPop", args); 435 return CallJsBuiltin(isolate, "$arrayPop", args);
436 } 436 }
437 437
438 Handle<JSArray> array = Handle<JSArray>::cast(receiver); 438 Handle<JSArray> array = Handle<JSArray>::cast(receiver);
439 DCHECK(!array->map()->is_observed()); 439 DCHECK(!array->map()->is_observed());
440 440
441 int len = Smi::cast(array->length())->value(); 441 uint32_t len = static_cast<uint32_t>(Smi::cast(array->length())->value());
442 if (len == 0) return isolate->heap()->undefined_value(); 442 if (len == 0) return isolate->heap()->undefined_value();
443 443
444 if (JSArray::HasReadOnlyLength(array)) { 444 if (JSArray::HasReadOnlyLength(array)) {
445 return CallJsBuiltin(isolate, "$arrayPop", args); 445 return CallJsBuiltin(isolate, "$arrayPop", args);
446 } 446 }
447 447
448 ElementsAccessor* accessor = array->GetElementsAccessor(); 448 ElementsAccessor* accessor = array->GetElementsAccessor();
449 int new_length = len - 1; 449 uint32_t new_length = len - 1;
450 Handle<Object> element = 450 Handle<Object> element;
451 accessor->Get(array, array, new_length, elms_obj).ToHandleChecked(); 451 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
452 if (element->IsTheHole()) { 452 isolate, element, Object::GetElement(isolate, array, new_length));
453 return CallJsBuiltin(isolate, "$arrayPop", args); 453
454 }
455 RETURN_FAILURE_ON_EXCEPTION( 454 RETURN_FAILURE_ON_EXCEPTION(
456 isolate, 455 isolate,
457 accessor->SetLength(array, handle(Smi::FromInt(new_length), isolate))); 456 accessor->SetLength(array, handle(Smi::FromInt(new_length), isolate)));
458 return *element; 457 return *element;
459 } 458 }
460 459
461 460
462 BUILTIN(ArrayShift) { 461 BUILTIN(ArrayShift) {
463 HandleScope scope(isolate); 462 HandleScope scope(isolate);
464 Heap* heap = isolate->heap(); 463 Heap* heap = isolate->heap();
465 Handle<Object> receiver = args.receiver(); 464 Handle<Object> receiver = args.receiver();
466 MaybeHandle<FixedArrayBase> maybe_elms_obj = 465 MaybeHandle<FixedArrayBase> maybe_elms_obj =
467 EnsureJSArrayWithWritableFastElements(isolate, receiver, NULL, 0); 466 EnsureJSArrayWithWritableFastElements(isolate, receiver, NULL, 0);
468 Handle<FixedArrayBase> elms_obj; 467 Handle<FixedArrayBase> elms_obj;
469 if (!maybe_elms_obj.ToHandle(&elms_obj) || 468 if (!maybe_elms_obj.ToHandle(&elms_obj) ||
470 !IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(*receiver))) { 469 !IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(*receiver))) {
471 return CallJsBuiltin(isolate, "$arrayShift", args); 470 return CallJsBuiltin(isolate, "$arrayShift", args);
472 } 471 }
473 Handle<JSArray> array = Handle<JSArray>::cast(receiver); 472 Handle<JSArray> array = Handle<JSArray>::cast(receiver);
474 DCHECK(!array->map()->is_observed()); 473 DCHECK(!array->map()->is_observed());
475 474
476 int len = Smi::cast(array->length())->value(); 475 int len = Smi::cast(array->length())->value();
477 if (len == 0) return heap->undefined_value(); 476 if (len == 0) return heap->undefined_value();
478 477
479 if (JSArray::HasReadOnlyLength(array)) { 478 if (JSArray::HasReadOnlyLength(array)) {
480 return CallJsBuiltin(isolate, "$arrayShift", args); 479 return CallJsBuiltin(isolate, "$arrayShift", args);
481 } 480 }
482 481
483 // Get first element 482 // Get first element
484 ElementsAccessor* accessor = array->GetElementsAccessor(); 483 Handle<Object> first;
485 Handle<Object> first = 484 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, first,
486 accessor->Get(array, array, 0, elms_obj).ToHandleChecked(); 485 Object::GetElement(isolate, array, 0));
487 if (first->IsTheHole()) {
488 return CallJsBuiltin(isolate, "$arrayShift", args);
489 }
490 486
491 if (heap->CanMoveObjectStart(*elms_obj)) { 487 if (heap->CanMoveObjectStart(*elms_obj)) {
492 array->set_elements(heap->LeftTrimFixedArray(*elms_obj, 1)); 488 array->set_elements(heap->LeftTrimFixedArray(*elms_obj, 1));
493 } else { 489 } else {
494 // Shift the elements. 490 // Shift the elements.
495 if (elms_obj->IsFixedArray()) { 491 if (elms_obj->IsFixedArray()) {
496 Handle<FixedArray> elms = Handle<FixedArray>::cast(elms_obj); 492 Handle<FixedArray> elms = Handle<FixedArray>::cast(elms_obj);
497 DisallowHeapAllocation no_gc; 493 DisallowHeapAllocation no_gc;
498 heap->MoveElements(*elms, 0, 1, len - 1); 494 heap->MoveElements(*elms, 0, 1, len - 1);
499 elms->set(len - 1, heap->the_hole_value()); 495 elms->set(len - 1, heap->the_hole_value());
(...skipping 1161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1661 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) 1657 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C)
1662 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) 1658 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A)
1663 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 1659 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
1664 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 1660 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
1665 #undef DEFINE_BUILTIN_ACCESSOR_C 1661 #undef DEFINE_BUILTIN_ACCESSOR_C
1666 #undef DEFINE_BUILTIN_ACCESSOR_A 1662 #undef DEFINE_BUILTIN_ACCESSOR_A
1667 1663
1668 1664
1669 } // namespace internal 1665 } // namespace internal
1670 } // namespace v8 1666 } // namespace v8
OLDNEW
« no previous file with comments | « src/array.js ('k') | src/compiler/js-typed-lowering.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698