OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 <iomanip> | 5 #include <iomanip> |
6 #include <sstream> | 6 #include <sstream> |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/accessors.h" | 10 #include "src/accessors.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 if (object->IsJSReceiver()) return Handle<JSReceiver>::cast(object); | 74 if (object->IsJSReceiver()) return Handle<JSReceiver>::cast(object); |
75 Handle<JSFunction> constructor; | 75 Handle<JSFunction> constructor; |
76 if (object->IsNumber()) { | 76 if (object->IsNumber()) { |
77 constructor = handle(native_context->number_function(), isolate); | 77 constructor = handle(native_context->number_function(), isolate); |
78 } else if (object->IsBoolean()) { | 78 } else if (object->IsBoolean()) { |
79 constructor = handle(native_context->boolean_function(), isolate); | 79 constructor = handle(native_context->boolean_function(), isolate); |
80 } else if (object->IsString()) { | 80 } else if (object->IsString()) { |
81 constructor = handle(native_context->string_function(), isolate); | 81 constructor = handle(native_context->string_function(), isolate); |
82 } else if (object->IsSymbol()) { | 82 } else if (object->IsSymbol()) { |
83 constructor = handle(native_context->symbol_function(), isolate); | 83 constructor = handle(native_context->symbol_function(), isolate); |
84 } else if (object->IsFloat32x4()) { | |
85 constructor = handle(native_context->float32x4_function(), isolate); | |
86 } else { | 84 } else { |
87 return MaybeHandle<JSReceiver>(); | 85 return MaybeHandle<JSReceiver>(); |
88 } | 86 } |
89 Handle<JSObject> result = isolate->factory()->NewJSObject(constructor); | 87 Handle<JSObject> result = isolate->factory()->NewJSObject(constructor); |
90 Handle<JSValue>::cast(result)->set_value(*object); | 88 Handle<JSValue>::cast(result)->set_value(*object); |
91 return result; | 89 return result; |
92 } | 90 } |
93 | 91 |
94 | 92 |
95 bool Object::BooleanValue() { | 93 bool Object::BooleanValue() { |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 | 598 |
601 Map* Object::GetRootMap(Isolate* isolate) { | 599 Map* Object::GetRootMap(Isolate* isolate) { |
602 DisallowHeapAllocation no_alloc; | 600 DisallowHeapAllocation no_alloc; |
603 if (IsSmi()) { | 601 if (IsSmi()) { |
604 Context* context = isolate->context()->native_context(); | 602 Context* context = isolate->context()->native_context(); |
605 return context->number_function()->initial_map(); | 603 return context->number_function()->initial_map(); |
606 } | 604 } |
607 | 605 |
608 HeapObject* heap_object = HeapObject::cast(this); | 606 HeapObject* heap_object = HeapObject::cast(this); |
609 | 607 |
610 // The object is either a number, a string, a symbol, a boolean, a SIMD value, | 608 // The object is either a number, a string, a boolean, |
611 // a real JS object, or a Harmony proxy. | 609 // a real JS object, or a Harmony proxy. |
612 if (heap_object->IsJSReceiver()) { | 610 if (heap_object->IsJSReceiver()) { |
613 return heap_object->map(); | 611 return heap_object->map(); |
614 } | 612 } |
615 Context* context = isolate->context()->native_context(); | 613 Context* context = isolate->context()->native_context(); |
616 | 614 |
617 if (heap_object->IsHeapNumber()) { | 615 if (heap_object->IsHeapNumber()) { |
618 return context->number_function()->initial_map(); | 616 return context->number_function()->initial_map(); |
619 } | 617 } |
620 if (heap_object->IsString()) { | 618 if (heap_object->IsString()) { |
621 return context->string_function()->initial_map(); | 619 return context->string_function()->initial_map(); |
622 } | 620 } |
623 if (heap_object->IsSymbol()) { | 621 if (heap_object->IsSymbol()) { |
624 return context->symbol_function()->initial_map(); | 622 return context->symbol_function()->initial_map(); |
625 } | 623 } |
626 if (heap_object->IsBoolean()) { | 624 if (heap_object->IsBoolean()) { |
627 return context->boolean_function()->initial_map(); | 625 return context->boolean_function()->initial_map(); |
628 } | 626 } |
629 if (heap_object->IsFloat32x4()) { | |
630 return context->float32x4_function()->initial_map(); | |
631 } | |
632 return isolate->heap()->null_value()->map(); | 627 return isolate->heap()->null_value()->map(); |
633 } | 628 } |
634 | 629 |
635 | 630 |
636 Object* Object::GetHash() { | 631 Object* Object::GetHash() { |
637 Object* hash = GetSimpleHash(); | 632 Object* hash = GetSimpleHash(); |
638 if (hash->IsSmi()) return hash; | 633 if (hash->IsSmi()) return hash; |
639 | 634 |
640 DCHECK(IsJSReceiver()); | 635 DCHECK(IsJSReceiver()); |
641 return JSReceiver::cast(this)->GetIdentityHash(); | 636 return JSReceiver::cast(this)->GetIdentityHash(); |
642 } | 637 } |
643 | 638 |
644 | 639 |
645 Object* Object::GetSimpleHash() { | 640 Object* Object::GetSimpleHash() { |
646 // The object is either a Smi, a HeapNumber, a name, an odd-ball, | 641 // The object is either a Smi, a HeapNumber, a name, an odd-ball, |
647 // a SIMD value type, a real JS object, or a Harmony proxy. | 642 // a real JS object, or a Harmony proxy. |
648 if (IsSmi()) { | 643 if (IsSmi()) { |
649 uint32_t hash = ComputeIntegerHash(Smi::cast(this)->value(), kZeroHashSeed); | 644 uint32_t hash = ComputeIntegerHash(Smi::cast(this)->value(), kZeroHashSeed); |
650 return Smi::FromInt(hash & Smi::kMaxValue); | 645 return Smi::FromInt(hash & Smi::kMaxValue); |
651 } | 646 } |
652 if (IsHeapNumber()) { | 647 if (IsHeapNumber()) { |
653 double num = HeapNumber::cast(this)->value(); | 648 double num = HeapNumber::cast(this)->value(); |
654 if (std::isnan(num)) return Smi::FromInt(Smi::kMaxValue); | 649 if (std::isnan(num)) return Smi::FromInt(Smi::kMaxValue); |
655 if (i::IsMinusZero(num)) num = 0; | 650 if (i::IsMinusZero(num)) num = 0; |
656 if (IsSmiDouble(num)) { | 651 if (IsSmiDouble(num)) { |
657 return Smi::FromInt(FastD2I(num))->GetHash(); | 652 return Smi::FromInt(FastD2I(num))->GetHash(); |
658 } | 653 } |
659 uint32_t hash = ComputeLongHash(double_to_uint64(num)); | 654 uint32_t hash = ComputeLongHash(double_to_uint64(num)); |
660 return Smi::FromInt(hash & Smi::kMaxValue); | 655 return Smi::FromInt(hash & Smi::kMaxValue); |
661 } | 656 } |
662 if (IsName()) { | 657 if (IsName()) { |
663 uint32_t hash = Name::cast(this)->Hash(); | 658 uint32_t hash = Name::cast(this)->Hash(); |
664 return Smi::FromInt(hash); | 659 return Smi::FromInt(hash); |
665 } | 660 } |
666 if (IsOddball()) { | 661 if (IsOddball()) { |
667 uint32_t hash = Oddball::cast(this)->to_string()->Hash(); | 662 uint32_t hash = Oddball::cast(this)->to_string()->Hash(); |
668 return Smi::FromInt(hash); | 663 return Smi::FromInt(hash); |
669 } | 664 } |
670 if (IsFloat32x4()) { | |
671 Float32x4* simd = Float32x4::cast(this); | |
672 uint32_t seed = v8::internal::kZeroHashSeed; | |
673 uint32_t hash; | |
674 hash = ComputeIntegerHash(bit_cast<uint32_t>(simd->get_lane(0)), seed); | |
675 hash = ComputeIntegerHash(bit_cast<uint32_t>(simd->get_lane(1)), hash * 31); | |
676 hash = ComputeIntegerHash(bit_cast<uint32_t>(simd->get_lane(2)), hash * 31); | |
677 hash = ComputeIntegerHash(bit_cast<uint32_t>(simd->get_lane(3)), hash * 31); | |
678 return Smi::FromInt(hash & Smi::kMaxValue); | |
679 } | |
680 DCHECK(IsJSReceiver()); | 665 DCHECK(IsJSReceiver()); |
681 JSReceiver* receiver = JSReceiver::cast(this); | 666 JSReceiver* receiver = JSReceiver::cast(this); |
682 return receiver->GetHeap()->undefined_value(); | 667 return receiver->GetHeap()->undefined_value(); |
683 } | 668 } |
684 | 669 |
685 | 670 |
686 Handle<Smi> Object::GetOrCreateHash(Isolate* isolate, Handle<Object> object) { | 671 Handle<Smi> Object::GetOrCreateHash(Isolate* isolate, Handle<Object> object) { |
687 Handle<Object> hash(object->GetSimpleHash(), isolate); | 672 Handle<Object> hash(object->GetSimpleHash(), isolate); |
688 if (hash->IsSmi()) return Handle<Smi>::cast(hash); | 673 if (hash->IsSmi()) return Handle<Smi>::cast(hash); |
689 | 674 |
690 DCHECK(object->IsJSReceiver()); | 675 DCHECK(object->IsJSReceiver()); |
691 return JSReceiver::GetOrCreateIdentityHash(Handle<JSReceiver>::cast(object)); | 676 return JSReceiver::GetOrCreateIdentityHash(Handle<JSReceiver>::cast(object)); |
692 } | 677 } |
693 | 678 |
694 | 679 |
695 bool Object::SameValue(Object* other) { | 680 bool Object::SameValue(Object* other) { |
696 if (other == this) return true; | 681 if (other == this) return true; |
697 | 682 |
698 // The object is either a number, a name, an odd-ball, | 683 // The object is either a number, a name, an odd-ball, |
699 // a real JS object, or a Harmony proxy. | 684 // a real JS object, or a Harmony proxy. |
700 if (IsNumber() && other->IsNumber()) { | 685 if (IsNumber() && other->IsNumber()) { |
701 return v8::internal::SameValue(Number(), other->Number()); | 686 return v8::internal::SameValue(Number(), other->Number()); |
702 } | 687 } |
703 if (IsString() && other->IsString()) { | 688 if (IsString() && other->IsString()) { |
704 return String::cast(this)->Equals(String::cast(other)); | 689 return String::cast(this)->Equals(String::cast(other)); |
705 } | 690 } |
706 if (IsFloat32x4() && other->IsFloat32x4()) { | |
707 Float32x4* x = Float32x4::cast(this); | |
708 Float32x4* y = Float32x4::cast(other); | |
709 return v8::internal::SameValue(x->get_lane(0), y->get_lane(0)) && | |
710 v8::internal::SameValue(x->get_lane(1), y->get_lane(1)) && | |
711 v8::internal::SameValue(x->get_lane(2), y->get_lane(2)) && | |
712 v8::internal::SameValue(x->get_lane(3), y->get_lane(3)); | |
713 } | |
714 return false; | 691 return false; |
715 } | 692 } |
716 | 693 |
717 | 694 |
718 bool Object::SameValueZero(Object* other) { | 695 bool Object::SameValueZero(Object* other) { |
719 if (other == this) return true; | 696 if (other == this) return true; |
720 | 697 |
721 // The object is either a number, a name, an odd-ball, | 698 // The object is either a number, a name, an odd-ball, |
722 // a real JS object, or a Harmony proxy. | 699 // a real JS object, or a Harmony proxy. |
723 if (IsNumber() && other->IsNumber()) { | 700 if (IsNumber() && other->IsNumber()) { |
724 return v8::internal::SameValueZero(Number(), other->Number()); | 701 return v8::internal::SameValueZero(Number(), other->Number()); |
725 } | 702 } |
726 if (IsString() && other->IsString()) { | 703 if (IsString() && other->IsString()) { |
727 return String::cast(this)->Equals(String::cast(other)); | 704 return String::cast(this)->Equals(String::cast(other)); |
728 } | 705 } |
729 if (IsFloat32x4() && other->IsFloat32x4()) { | |
730 Float32x4* x = Float32x4::cast(this); | |
731 Float32x4* y = Float32x4::cast(other); | |
732 return v8::internal::SameValueZero(x->get_lane(0), y->get_lane(0)) && | |
733 v8::internal::SameValueZero(x->get_lane(1), y->get_lane(1)) && | |
734 v8::internal::SameValueZero(x->get_lane(2), y->get_lane(2)) && | |
735 v8::internal::SameValueZero(x->get_lane(3), y->get_lane(3)); | |
736 } | |
737 return false; | 706 return false; |
738 } | 707 } |
739 | 708 |
740 | 709 |
741 void Object::ShortPrint(FILE* out) { | 710 void Object::ShortPrint(FILE* out) { |
742 OFStream os(out); | 711 OFStream os(out); |
743 os << Brief(this); | 712 os << Brief(this); |
744 } | 713 } |
745 | 714 |
746 | 715 |
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1539 return DoubleToBoolean(value()); | 1508 return DoubleToBoolean(value()); |
1540 } | 1509 } |
1541 | 1510 |
1542 | 1511 |
1543 void HeapNumber::HeapNumberPrint(std::ostream& os) { // NOLINT | 1512 void HeapNumber::HeapNumberPrint(std::ostream& os) { // NOLINT |
1544 os << value(); | 1513 os << value(); |
1545 } | 1514 } |
1546 | 1515 |
1547 | 1516 |
1548 void Float32x4::Float32x4Print(std::ostream& os) { // NOLINT | 1517 void Float32x4::Float32x4Print(std::ostream& os) { // NOLINT |
1549 char arr[100]; | 1518 os << get_lane(0) << ", " << get_lane(1) << ", " << get_lane(2) << ", " |
1550 Vector<char> buffer(arr, arraysize(arr)); | 1519 << get_lane(3); |
1551 os << std::string(DoubleToCString(get_lane(0), buffer)) << ", " | |
1552 << std::string(DoubleToCString(get_lane(1), buffer)) << ", " | |
1553 << std::string(DoubleToCString(get_lane(2), buffer)) << ", " | |
1554 << std::string(DoubleToCString(get_lane(3), buffer)); | |
1555 } | 1520 } |
1556 | 1521 |
1557 | 1522 |
1558 String* JSReceiver::class_name() { | 1523 String* JSReceiver::class_name() { |
1559 if (IsJSFunction() || IsJSFunctionProxy()) { | 1524 if (IsJSFunction() || IsJSFunctionProxy()) { |
1560 return GetHeap()->Function_string(); | 1525 return GetHeap()->Function_string(); |
1561 } | 1526 } |
1562 Object* maybe_constructor = map()->GetConstructor(); | 1527 Object* maybe_constructor = map()->GetConstructor(); |
1563 if (maybe_constructor->IsJSFunction()) { | 1528 if (maybe_constructor->IsJSFunction()) { |
1564 JSFunction* constructor = JSFunction::cast(maybe_constructor); | 1529 JSFunction* constructor = JSFunction::cast(maybe_constructor); |
(...skipping 14333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15898 Handle<Object> new_value) { | 15863 Handle<Object> new_value) { |
15899 if (cell->value() != *new_value) { | 15864 if (cell->value() != *new_value) { |
15900 cell->set_value(*new_value); | 15865 cell->set_value(*new_value); |
15901 Isolate* isolate = cell->GetIsolate(); | 15866 Isolate* isolate = cell->GetIsolate(); |
15902 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 15867 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
15903 isolate, DependentCode::kPropertyCellChangedGroup); | 15868 isolate, DependentCode::kPropertyCellChangedGroup); |
15904 } | 15869 } |
15905 } | 15870 } |
15906 } // namespace internal | 15871 } // namespace internal |
15907 } // namespace v8 | 15872 } // namespace v8 |
OLD | NEW |