| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 JSFunction::cast(native_context->get(constructor_function_index)), | 108 JSFunction::cast(native_context->get(constructor_function_index)), |
| 109 isolate); | 109 isolate); |
| 110 } | 110 } |
| 111 Handle<JSObject> result = isolate->factory()->NewJSObject(constructor); | 111 Handle<JSObject> result = isolate->factory()->NewJSObject(constructor); |
| 112 Handle<JSValue>::cast(result)->set_value(*object); | 112 Handle<JSValue>::cast(result)->set_value(*object); |
| 113 return result; | 113 return result; |
| 114 } | 114 } |
| 115 | 115 |
| 116 | 116 |
| 117 // static | 117 // static |
| 118 MaybeHandle<Name> Object::ToName(Isolate* isolate, Handle<Object> input) { | |
| 119 ASSIGN_RETURN_ON_EXCEPTION( | |
| 120 isolate, input, Object::ToPrimitive(input, ToPrimitiveHint::kString), | |
| 121 Name); | |
| 122 if (input->IsName()) return Handle<Name>::cast(input); | |
| 123 return ToString(isolate, input); | |
| 124 } | |
| 125 | |
| 126 | |
| 127 // static | |
| 128 MaybeHandle<Object> Object::ToNumber(Handle<Object> input) { | 118 MaybeHandle<Object> Object::ToNumber(Handle<Object> input) { |
| 129 while (true) { | 119 while (true) { |
| 130 if (input->IsNumber()) { | 120 if (input->IsNumber()) { |
| 131 return input; | 121 return input; |
| 132 } | 122 } |
| 133 if (input->IsString()) { | 123 if (input->IsString()) { |
| 134 return String::ToNumber(Handle<String>::cast(input)); | 124 return String::ToNumber(Handle<String>::cast(input)); |
| 135 } | 125 } |
| 136 if (input->IsOddball()) { | 126 if (input->IsOddball()) { |
| 137 return Oddball::ToNumber(Handle<Oddball>::cast(input)); | 127 return Oddball::ToNumber(Handle<Oddball>::cast(input)); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 168 | 158 |
| 169 | 159 |
| 170 // static | 160 // static |
| 171 MaybeHandle<Object> Object::ToUint32(Isolate* isolate, Handle<Object> input) { | 161 MaybeHandle<Object> Object::ToUint32(Isolate* isolate, Handle<Object> input) { |
| 172 ASSIGN_RETURN_ON_EXCEPTION(isolate, input, ToNumber(input), Object); | 162 ASSIGN_RETURN_ON_EXCEPTION(isolate, input, ToNumber(input), Object); |
| 173 return isolate->factory()->NewNumberFromUint(DoubleToUint32(input->Number())); | 163 return isolate->factory()->NewNumberFromUint(DoubleToUint32(input->Number())); |
| 174 } | 164 } |
| 175 | 165 |
| 176 | 166 |
| 177 // static | 167 // static |
| 168 MaybeHandle<Name> Object::ConvertToName(Isolate* isolate, |
| 169 Handle<Object> input) { |
| 170 ASSIGN_RETURN_ON_EXCEPTION( |
| 171 isolate, input, Object::ToPrimitive(input, ToPrimitiveHint::kString), |
| 172 Name); |
| 173 if (input->IsName()) return Handle<Name>::cast(input); |
| 174 return ToString(isolate, input); |
| 175 } |
| 176 |
| 177 // static |
| 178 MaybeHandle<String> Object::ToString(Isolate* isolate, Handle<Object> input) { | 178 MaybeHandle<String> Object::ToString(Isolate* isolate, Handle<Object> input) { |
| 179 while (true) { | 179 while (true) { |
| 180 if (input->IsString()) { | 180 if (input->IsString()) { |
| 181 return Handle<String>::cast(input); | 181 return Handle<String>::cast(input); |
| 182 } | 182 } |
| 183 if (input->IsOddball()) { | 183 if (input->IsOddball()) { |
| 184 return handle(Handle<Oddball>::cast(input)->to_string(), isolate); | 184 return handle(Handle<Oddball>::cast(input)->to_string(), isolate); |
| 185 } | 185 } |
| 186 if (input->IsNumber()) { | 186 if (input->IsNumber()) { |
| 187 return isolate->factory()->NumberToString(input); | 187 return isolate->factory()->NumberToString(input); |
| (...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 double num = HeapNumber::cast(this)->value(); | 885 double num = HeapNumber::cast(this)->value(); |
| 886 if (FastI2D(FastD2I(num)) == num) { | 886 if (FastI2D(FastD2I(num)) == num) { |
| 887 *value = FastD2I(num); | 887 *value = FastD2I(num); |
| 888 return true; | 888 return true; |
| 889 } | 889 } |
| 890 } | 890 } |
| 891 return false; | 891 return false; |
| 892 } | 892 } |
| 893 | 893 |
| 894 | 894 |
| 895 bool Object::ToUint32(uint32_t* value) { | |
| 896 if (IsSmi()) { | |
| 897 int num = Smi::cast(this)->value(); | |
| 898 if (num < 0) return false; | |
| 899 *value = static_cast<uint32_t>(num); | |
| 900 return true; | |
| 901 } | |
| 902 if (IsHeapNumber()) { | |
| 903 double num = HeapNumber::cast(this)->value(); | |
| 904 if (num < 0) return false; | |
| 905 uint32_t uint_value = FastD2UI(num); | |
| 906 if (FastUI2D(uint_value) == num) { | |
| 907 *value = uint_value; | |
| 908 return true; | |
| 909 } | |
| 910 } | |
| 911 return false; | |
| 912 } | |
| 913 | |
| 914 | |
| 915 bool FunctionTemplateInfo::IsTemplateFor(Object* object) { | 895 bool FunctionTemplateInfo::IsTemplateFor(Object* object) { |
| 916 if (!object->IsHeapObject()) return false; | 896 if (!object->IsHeapObject()) return false; |
| 917 return IsTemplateFor(HeapObject::cast(object)->map()); | 897 return IsTemplateFor(HeapObject::cast(object)->map()); |
| 918 } | 898 } |
| 919 | 899 |
| 920 | 900 |
| 921 bool FunctionTemplateInfo::IsTemplateFor(Map* map) { | 901 bool FunctionTemplateInfo::IsTemplateFor(Map* map) { |
| 922 // There is a constraint on the object; check. | 902 // There is a constraint on the object; check. |
| 923 if (!map->IsJSObjectMap()) return false; | 903 if (!map->IsJSObjectMap()) return false; |
| 924 // Fetch the constructor function of the object. | 904 // Fetch the constructor function of the object. |
| (...skipping 18953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19878 if (cell->value() != *new_value) { | 19858 if (cell->value() != *new_value) { |
| 19879 cell->set_value(*new_value); | 19859 cell->set_value(*new_value); |
| 19880 Isolate* isolate = cell->GetIsolate(); | 19860 Isolate* isolate = cell->GetIsolate(); |
| 19881 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 19861 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
| 19882 isolate, DependentCode::kPropertyCellChangedGroup); | 19862 isolate, DependentCode::kPropertyCellChangedGroup); |
| 19883 } | 19863 } |
| 19884 } | 19864 } |
| 19885 | 19865 |
| 19886 } // namespace internal | 19866 } // namespace internal |
| 19887 } // namespace v8 | 19867 } // namespace v8 |
| OLD | NEW |