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