| 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 "src/objects.h" | 5 #include "src/objects.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <iomanip> | 8 #include <iomanip> |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 | 10 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 } | 126 } |
| 127 ASSIGN_RETURN_ON_EXCEPTION( | 127 ASSIGN_RETURN_ON_EXCEPTION( |
| 128 isolate, input, JSReceiver::ToPrimitive(Handle<JSReceiver>::cast(input), | 128 isolate, input, JSReceiver::ToPrimitive(Handle<JSReceiver>::cast(input), |
| 129 ToPrimitiveHint::kNumber), | 129 ToPrimitiveHint::kNumber), |
| 130 Object); | 130 Object); |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 134 | 134 |
| 135 // static | 135 // static |
| 136 MaybeHandle<Object> Object::ToInteger(Isolate* isolate, Handle<Object> input) { |
| 137 ASSIGN_RETURN_ON_EXCEPTION(isolate, input, ToNumber(input), Object); |
| 138 return isolate->factory()->NewNumber(DoubleToInteger(input->Number())); |
| 139 } |
| 140 |
| 141 |
| 142 // static |
| 143 MaybeHandle<Object> Object::ToInt32(Isolate* isolate, Handle<Object> input) { |
| 144 ASSIGN_RETURN_ON_EXCEPTION(isolate, input, ToNumber(input), Object); |
| 145 return isolate->factory()->NewNumberFromInt(DoubleToInt32(input->Number())); |
| 146 } |
| 147 |
| 148 |
| 149 // static |
| 150 MaybeHandle<Object> Object::ToUint32(Isolate* isolate, Handle<Object> input) { |
| 151 ASSIGN_RETURN_ON_EXCEPTION(isolate, input, ToNumber(input), Object); |
| 152 return isolate->factory()->NewNumberFromUint(DoubleToUint32(input->Number())); |
| 153 } |
| 154 |
| 155 |
| 156 // static |
| 136 MaybeHandle<String> Object::ToString(Isolate* isolate, Handle<Object> input) { | 157 MaybeHandle<String> Object::ToString(Isolate* isolate, Handle<Object> input) { |
| 137 while (true) { | 158 while (true) { |
| 138 if (input->IsString()) { | 159 if (input->IsString()) { |
| 139 return Handle<String>::cast(input); | 160 return Handle<String>::cast(input); |
| 140 } | 161 } |
| 141 if (input->IsOddball()) { | 162 if (input->IsOddball()) { |
| 142 return handle(Handle<Oddball>::cast(input)->to_string(), isolate); | 163 return handle(Handle<Oddball>::cast(input)->to_string(), isolate); |
| 143 } | 164 } |
| 144 if (input->IsNumber()) { | 165 if (input->IsNumber()) { |
| 145 return isolate->factory()->NumberToString(input); | 166 return isolate->factory()->NumberToString(input); |
| 146 } | 167 } |
| 147 if (input->IsSymbol()) { | 168 if (input->IsSymbol()) { |
| 148 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kSymbolToString), | 169 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kSymbolToString), |
| 149 String); | 170 String); |
| 150 } | 171 } |
| 151 if (input->IsSimd128Value()) { | 172 if (input->IsSimd128Value()) { |
| 152 return Simd128Value::ToString(Handle<Simd128Value>::cast(input)); | 173 return Simd128Value::ToString(Handle<Simd128Value>::cast(input)); |
| 153 } | 174 } |
| 154 ASSIGN_RETURN_ON_EXCEPTION( | 175 ASSIGN_RETURN_ON_EXCEPTION( |
| 155 isolate, input, JSReceiver::ToPrimitive(Handle<JSReceiver>::cast(input), | 176 isolate, input, JSReceiver::ToPrimitive(Handle<JSReceiver>::cast(input), |
| 156 ToPrimitiveHint::kString), | 177 ToPrimitiveHint::kString), |
| 157 String); | 178 String); |
| 158 } | 179 } |
| 159 } | 180 } |
| 160 | 181 |
| 161 | 182 |
| 183 // static |
| 184 MaybeHandle<Object> Object::ToLength(Isolate* isolate, Handle<Object> input) { |
| 185 ASSIGN_RETURN_ON_EXCEPTION(isolate, input, ToNumber(input), Object); |
| 186 double len = DoubleToInteger(input->Number()); |
| 187 if (len <= 0.0) { |
| 188 len = 0.0; |
| 189 } else if (len >= kMaxSafeInteger) { |
| 190 len = kMaxSafeInteger; |
| 191 } |
| 192 return isolate->factory()->NewNumber(len); |
| 193 } |
| 194 |
| 195 |
| 162 bool Object::BooleanValue() { | 196 bool Object::BooleanValue() { |
| 163 if (IsBoolean()) return IsTrue(); | 197 if (IsBoolean()) return IsTrue(); |
| 164 if (IsSmi()) return Smi::cast(this)->value() != 0; | 198 if (IsSmi()) return Smi::cast(this)->value() != 0; |
| 165 if (IsUndefined() || IsNull()) return false; | 199 if (IsUndefined() || IsNull()) return false; |
| 166 if (IsUndetectableObject()) return false; // Undetectable object is false. | 200 if (IsUndetectableObject()) return false; // Undetectable object is false. |
| 167 if (IsString()) return String::cast(this)->length() != 0; | 201 if (IsString()) return String::cast(this)->length() != 0; |
| 168 if (IsHeapNumber()) return HeapNumber::cast(this)->HeapNumberBooleanValue(); | 202 if (IsHeapNumber()) return HeapNumber::cast(this)->HeapNumberBooleanValue(); |
| 169 return true; | 203 return true; |
| 170 } | 204 } |
| 171 | 205 |
| (...skipping 16582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16754 if (cell->value() != *new_value) { | 16788 if (cell->value() != *new_value) { |
| 16755 cell->set_value(*new_value); | 16789 cell->set_value(*new_value); |
| 16756 Isolate* isolate = cell->GetIsolate(); | 16790 Isolate* isolate = cell->GetIsolate(); |
| 16757 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 16791 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
| 16758 isolate, DependentCode::kPropertyCellChangedGroup); | 16792 isolate, DependentCode::kPropertyCellChangedGroup); |
| 16759 } | 16793 } |
| 16760 } | 16794 } |
| 16761 | 16795 |
| 16762 } // namespace internal | 16796 } // namespace internal |
| 16763 } // namespace v8 | 16797 } // namespace v8 |
| OLD | NEW |