OLD | NEW |
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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/allocation-site-scopes.h" | 7 #include "src/allocation-site-scopes.h" |
8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
9 #include "src/ast/ast.h" | 9 #include "src/ast/ast.h" |
10 #include "src/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 | 393 |
394 Handle<JSObject> result; | 394 Handle<JSObject> result; |
395 Handle<LiteralsArray> literals(closure->literals(), isolate); | 395 Handle<LiteralsArray> literals(closure->literals(), isolate); |
396 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 396 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
397 isolate, result, | 397 isolate, result, |
398 CreateArrayLiteralImpl(isolate, literals, literals_index, elements, | 398 CreateArrayLiteralImpl(isolate, literals, literals_index, elements, |
399 ArrayLiteral::kShallowElements)); | 399 ArrayLiteral::kShallowElements)); |
400 return *result; | 400 return *result; |
401 } | 401 } |
402 | 402 |
403 | |
404 RUNTIME_FUNCTION(Runtime_StoreArrayLiteralElement) { | |
405 HandleScope scope(isolate); | |
406 RUNTIME_ASSERT(args.length() == 5); | |
407 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | |
408 CONVERT_SMI_ARG_CHECKED(store_index, 1); | |
409 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); | |
410 CONVERT_ARG_HANDLE_CHECKED(LiteralsArray, literals, 3); | |
411 CONVERT_SMI_ARG_CHECKED(literal_index, 4); | |
412 | |
413 Object* raw_literal_cell = literals->literal(literal_index); | |
414 JSArray* boilerplate = NULL; | |
415 if (raw_literal_cell->IsAllocationSite()) { | |
416 AllocationSite* site = AllocationSite::cast(raw_literal_cell); | |
417 boilerplate = JSArray::cast(site->transition_info()); | |
418 } else { | |
419 boilerplate = JSArray::cast(raw_literal_cell); | |
420 } | |
421 Handle<JSArray> boilerplate_object(boilerplate); | |
422 ElementsKind elements_kind = object->GetElementsKind(); | |
423 DCHECK(IsFastElementsKind(elements_kind)); | |
424 // Smis should never trigger transitions. | |
425 DCHECK(!value->IsSmi()); | |
426 | |
427 if (value->IsNumber()) { | |
428 DCHECK(IsFastSmiElementsKind(elements_kind)); | |
429 ElementsKind transitioned_kind = IsFastHoleyElementsKind(elements_kind) | |
430 ? FAST_HOLEY_DOUBLE_ELEMENTS | |
431 : FAST_DOUBLE_ELEMENTS; | |
432 if (IsMoreGeneralElementsKindTransition( | |
433 boilerplate_object->GetElementsKind(), transitioned_kind)) { | |
434 JSObject::TransitionElementsKind(boilerplate_object, transitioned_kind); | |
435 } | |
436 JSObject::TransitionElementsKind(object, transitioned_kind); | |
437 DCHECK(IsFastDoubleElementsKind(object->GetElementsKind())); | |
438 FixedDoubleArray* double_array = FixedDoubleArray::cast(object->elements()); | |
439 HeapNumber* number = HeapNumber::cast(*value); | |
440 double_array->set(store_index, number->Number()); | |
441 } else { | |
442 if (!IsFastObjectElementsKind(elements_kind)) { | |
443 ElementsKind transitioned_kind = IsFastHoleyElementsKind(elements_kind) | |
444 ? FAST_HOLEY_ELEMENTS | |
445 : FAST_ELEMENTS; | |
446 JSObject::TransitionElementsKind(object, transitioned_kind); | |
447 if (IsMoreGeneralElementsKindTransition( | |
448 boilerplate_object->GetElementsKind(), transitioned_kind)) { | |
449 JSObject::TransitionElementsKind(boilerplate_object, transitioned_kind); | |
450 } | |
451 } | |
452 FixedArray* object_array = FixedArray::cast(object->elements()); | |
453 object_array->set(store_index, *value); | |
454 } | |
455 return *object; | |
456 } | |
457 } // namespace internal | 403 } // namespace internal |
458 } // namespace v8 | 404 } // namespace v8 |
OLD | NEW |