OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1024 ? static_cast<double>(reinterpret_cast<Smi*>(this)->value()) | 1024 ? static_cast<double>(reinterpret_cast<Smi*>(this)->value()) |
1025 : reinterpret_cast<HeapNumber*>(this)->value(); | 1025 : reinterpret_cast<HeapNumber*>(this)->value(); |
1026 } | 1026 } |
1027 | 1027 |
1028 | 1028 |
1029 bool Object::IsNaN() { | 1029 bool Object::IsNaN() { |
1030 return this->IsHeapNumber() && std::isnan(HeapNumber::cast(this)->value()); | 1030 return this->IsHeapNumber() && std::isnan(HeapNumber::cast(this)->value()); |
1031 } | 1031 } |
1032 | 1032 |
1033 | 1033 |
| 1034 // static |
| 1035 Handle<Object> Object::ToSmi(Isolate* isolate, Handle<Object> object) { |
| 1036 if (object->IsSmi()) return object; |
| 1037 if (object->IsHeapNumber()) { |
| 1038 double value = Handle<HeapNumber>::cast(object)->value(); |
| 1039 int int_value = FastD2I(value); |
| 1040 if (value == FastI2D(int_value) && Smi::IsValid(int_value)) { |
| 1041 return handle(Smi::FromInt(int_value), isolate); |
| 1042 } |
| 1043 } |
| 1044 return Handle<Object>(); |
| 1045 } |
| 1046 |
| 1047 |
| 1048 // TODO(ishell): Use handlified version instead. |
1034 MaybeObject* Object::ToSmi() { | 1049 MaybeObject* Object::ToSmi() { |
1035 if (IsSmi()) return this; | 1050 if (IsSmi()) return this; |
1036 if (IsHeapNumber()) { | 1051 if (IsHeapNumber()) { |
1037 double value = HeapNumber::cast(this)->value(); | 1052 double value = HeapNumber::cast(this)->value(); |
1038 int int_value = FastD2I(value); | 1053 int int_value = FastD2I(value); |
1039 if (value == FastI2D(int_value) && Smi::IsValid(int_value)) { | 1054 if (value == FastI2D(int_value) && Smi::IsValid(int_value)) { |
1040 return Smi::FromInt(int_value); | 1055 return Smi::FromInt(int_value); |
1041 } | 1056 } |
1042 } | 1057 } |
1043 return Failure::Exception(); | 1058 return Failure::Exception(); |
(...skipping 5741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6785 #undef READ_UINT32_FIELD | 6800 #undef READ_UINT32_FIELD |
6786 #undef WRITE_UINT32_FIELD | 6801 #undef WRITE_UINT32_FIELD |
6787 #undef READ_SHORT_FIELD | 6802 #undef READ_SHORT_FIELD |
6788 #undef WRITE_SHORT_FIELD | 6803 #undef WRITE_SHORT_FIELD |
6789 #undef READ_BYTE_FIELD | 6804 #undef READ_BYTE_FIELD |
6790 #undef WRITE_BYTE_FIELD | 6805 #undef WRITE_BYTE_FIELD |
6791 | 6806 |
6792 } } // namespace v8::internal | 6807 } } // namespace v8::internal |
6793 | 6808 |
6794 #endif // V8_OBJECTS_INL_H_ | 6809 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |