| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
| 6 | 6 |
| 7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
| 8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
| 9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
| 10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
| 11 #include "src/isolate-inl.h" | 11 #include "src/isolate-inl.h" |
| 12 | 12 |
| 13 namespace v8 { | 13 namespace v8 { |
| 14 namespace internal { | 14 namespace internal { |
| 15 | 15 |
| 16 RUNTIME_FUNCTION(Runtime_IsValidSmi) { | 16 RUNTIME_FUNCTION(Runtime_IsValidSmi) { |
| 17 SealHandleScope shs(isolate); | 17 SealHandleScope shs(isolate); |
| 18 DCHECK(args.length() == 1); | 18 DCHECK_EQ(1, args.length()); |
| 19 | 19 |
| 20 CONVERT_NUMBER_CHECKED(int32_t, number, Int32, args[0]); | 20 CONVERT_NUMBER_CHECKED(int32_t, number, Int32, args[0]); |
| 21 return isolate->heap()->ToBoolean(Smi::IsValid(number)); | 21 return isolate->heap()->ToBoolean(Smi::IsValid(number)); |
| 22 } | 22 } |
| 23 | 23 |
| 24 | 24 |
| 25 RUNTIME_FUNCTION(Runtime_StringToNumber) { | 25 RUNTIME_FUNCTION(Runtime_StringToNumber) { |
| 26 HandleScope handle_scope(isolate); | 26 HandleScope handle_scope(isolate); |
| 27 DCHECK_EQ(1, args.length()); | 27 DCHECK_EQ(1, args.length()); |
| 28 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); | 28 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 | 68 |
| 69 return *isolate->factory()->NewNumber(result); | 69 return *isolate->factory()->NewNumber(result); |
| 70 } | 70 } |
| 71 | 71 |
| 72 | 72 |
| 73 // ES6 18.2.4 parseFloat(string) | 73 // ES6 18.2.4 parseFloat(string) |
| 74 RUNTIME_FUNCTION(Runtime_StringParseFloat) { | 74 RUNTIME_FUNCTION(Runtime_StringParseFloat) { |
| 75 HandleScope shs(isolate); | 75 HandleScope shs(isolate); |
| 76 DCHECK(args.length() == 1); | 76 DCHECK_EQ(1, args.length()); |
| 77 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); | 77 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); |
| 78 | 78 |
| 79 double value = | 79 double value = |
| 80 StringToDouble(isolate->unicode_cache(), subject, ALLOW_TRAILING_JUNK, | 80 StringToDouble(isolate->unicode_cache(), subject, ALLOW_TRAILING_JUNK, |
| 81 std::numeric_limits<double>::quiet_NaN()); | 81 std::numeric_limits<double>::quiet_NaN()); |
| 82 | 82 |
| 83 return *isolate->factory()->NewNumber(value); | 83 return *isolate->factory()->NewNumber(value); |
| 84 } | 84 } |
| 85 | 85 |
| 86 | 86 |
| 87 RUNTIME_FUNCTION(Runtime_NumberToString) { | 87 RUNTIME_FUNCTION(Runtime_NumberToString) { |
| 88 HandleScope scope(isolate); | 88 HandleScope scope(isolate); |
| 89 DCHECK(args.length() == 1); | 89 DCHECK_EQ(1, args.length()); |
| 90 CONVERT_NUMBER_ARG_HANDLE_CHECKED(number, 0); | 90 CONVERT_NUMBER_ARG_HANDLE_CHECKED(number, 0); |
| 91 | 91 |
| 92 return *isolate->factory()->NumberToString(number); | 92 return *isolate->factory()->NumberToString(number); |
| 93 } | 93 } |
| 94 | 94 |
| 95 | 95 |
| 96 RUNTIME_FUNCTION(Runtime_NumberToStringSkipCache) { | 96 RUNTIME_FUNCTION(Runtime_NumberToStringSkipCache) { |
| 97 HandleScope scope(isolate); | 97 HandleScope scope(isolate); |
| 98 DCHECK(args.length() == 1); | 98 DCHECK_EQ(1, args.length()); |
| 99 CONVERT_NUMBER_ARG_HANDLE_CHECKED(number, 0); | 99 CONVERT_NUMBER_ARG_HANDLE_CHECKED(number, 0); |
| 100 | 100 |
| 101 return *isolate->factory()->NumberToString(number, false); | 101 return *isolate->factory()->NumberToString(number, false); |
| 102 } | 102 } |
| 103 | 103 |
| 104 | 104 |
| 105 // Converts a Number to a Smi, if possible. Returns NaN if the number is not | 105 // Converts a Number to a Smi, if possible. Returns NaN if the number is not |
| 106 // a small integer. | 106 // a small integer. |
| 107 RUNTIME_FUNCTION(Runtime_NumberToSmi) { | 107 RUNTIME_FUNCTION(Runtime_NumberToSmi) { |
| 108 SealHandleScope shs(isolate); | 108 SealHandleScope shs(isolate); |
| 109 DCHECK(args.length() == 1); | 109 DCHECK_EQ(1, args.length()); |
| 110 CONVERT_ARG_CHECKED(Object, obj, 0); | 110 CONVERT_ARG_CHECKED(Object, obj, 0); |
| 111 if (obj->IsSmi()) { | 111 if (obj->IsSmi()) { |
| 112 return obj; | 112 return obj; |
| 113 } | 113 } |
| 114 if (obj->IsHeapNumber()) { | 114 if (obj->IsHeapNumber()) { |
| 115 double value = HeapNumber::cast(obj)->value(); | 115 double value = HeapNumber::cast(obj)->value(); |
| 116 int int_value = FastD2I(value); | 116 int int_value = FastD2I(value); |
| 117 if (value == FastI2D(int_value) && Smi::IsValid(int_value)) { | 117 if (value == FastI2D(int_value) && Smi::IsValid(int_value)) { |
| 118 return Smi::FromInt(int_value); | 118 return Smi::FromInt(int_value); |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 return isolate->heap()->nan_value(); | 121 return isolate->heap()->nan_value(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 | 124 |
| 125 // Compare two Smis as if they were converted to strings and then | 125 // Compare two Smis as if they were converted to strings and then |
| 126 // compared lexicographically. | 126 // compared lexicographically. |
| 127 RUNTIME_FUNCTION(Runtime_SmiLexicographicCompare) { | 127 RUNTIME_FUNCTION(Runtime_SmiLexicographicCompare) { |
| 128 SealHandleScope shs(isolate); | 128 SealHandleScope shs(isolate); |
| 129 DCHECK(args.length() == 2); | 129 DCHECK_EQ(2, args.length()); |
| 130 CONVERT_SMI_ARG_CHECKED(x_value, 0); | 130 CONVERT_SMI_ARG_CHECKED(x_value, 0); |
| 131 CONVERT_SMI_ARG_CHECKED(y_value, 1); | 131 CONVERT_SMI_ARG_CHECKED(y_value, 1); |
| 132 | 132 |
| 133 // If the integers are equal so are the string representations. | 133 // If the integers are equal so are the string representations. |
| 134 if (x_value == y_value) return Smi::FromInt(EQUAL); | 134 if (x_value == y_value) return Smi::FromInt(EQUAL); |
| 135 | 135 |
| 136 // If one of the integers is zero the normal integer order is the | 136 // If one of the integers is zero the normal integer order is the |
| 137 // same as the lexicographic order of the string representations. | 137 // same as the lexicographic order of the string representations. |
| 138 if (x_value == 0 || y_value == 0) | 138 if (x_value == 0 || y_value == 0) |
| 139 return Smi::FromInt(x_value < y_value ? LESS : GREATER); | 139 return Smi::FromInt(x_value < y_value ? LESS : GREATER); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 } | 193 } |
| 194 | 194 |
| 195 if (x_scaled < y_scaled) return Smi::FromInt(LESS); | 195 if (x_scaled < y_scaled) return Smi::FromInt(LESS); |
| 196 if (x_scaled > y_scaled) return Smi::FromInt(GREATER); | 196 if (x_scaled > y_scaled) return Smi::FromInt(GREATER); |
| 197 return Smi::FromInt(tie); | 197 return Smi::FromInt(tie); |
| 198 } | 198 } |
| 199 | 199 |
| 200 | 200 |
| 201 RUNTIME_FUNCTION(Runtime_MaxSmi) { | 201 RUNTIME_FUNCTION(Runtime_MaxSmi) { |
| 202 SealHandleScope shs(isolate); | 202 SealHandleScope shs(isolate); |
| 203 DCHECK(args.length() == 0); | 203 DCHECK_EQ(0, args.length()); |
| 204 return Smi::FromInt(Smi::kMaxValue); | 204 return Smi::FromInt(Smi::kMaxValue); |
| 205 } | 205 } |
| 206 | 206 |
| 207 | 207 |
| 208 RUNTIME_FUNCTION(Runtime_IsSmi) { | 208 RUNTIME_FUNCTION(Runtime_IsSmi) { |
| 209 SealHandleScope shs(isolate); | 209 SealHandleScope shs(isolate); |
| 210 DCHECK(args.length() == 1); | 210 DCHECK_EQ(1, args.length()); |
| 211 CONVERT_ARG_CHECKED(Object, obj, 0); | 211 CONVERT_ARG_CHECKED(Object, obj, 0); |
| 212 return isolate->heap()->ToBoolean(obj->IsSmi()); | 212 return isolate->heap()->ToBoolean(obj->IsSmi()); |
| 213 } | 213 } |
| 214 | 214 |
| 215 | 215 |
| 216 RUNTIME_FUNCTION(Runtime_GetRootNaN) { | 216 RUNTIME_FUNCTION(Runtime_GetRootNaN) { |
| 217 SealHandleScope shs(isolate); | 217 SealHandleScope shs(isolate); |
| 218 DCHECK(args.length() == 0); | 218 DCHECK_EQ(0, args.length()); |
| 219 return isolate->heap()->nan_value(); | 219 return isolate->heap()->nan_value(); |
| 220 } | 220 } |
| 221 | 221 |
| 222 | 222 |
| 223 RUNTIME_FUNCTION(Runtime_GetHoleNaNUpper) { | 223 RUNTIME_FUNCTION(Runtime_GetHoleNaNUpper) { |
| 224 HandleScope scope(isolate); | 224 HandleScope scope(isolate); |
| 225 DCHECK(args.length() == 0); | 225 DCHECK_EQ(0, args.length()); |
| 226 return *isolate->factory()->NewNumberFromUint(kHoleNanUpper32); | 226 return *isolate->factory()->NewNumberFromUint(kHoleNanUpper32); |
| 227 } | 227 } |
| 228 | 228 |
| 229 | 229 |
| 230 RUNTIME_FUNCTION(Runtime_GetHoleNaNLower) { | 230 RUNTIME_FUNCTION(Runtime_GetHoleNaNLower) { |
| 231 HandleScope scope(isolate); | 231 HandleScope scope(isolate); |
| 232 DCHECK(args.length() == 0); | 232 DCHECK_EQ(0, args.length()); |
| 233 return *isolate->factory()->NewNumberFromUint(kHoleNanLower32); | 233 return *isolate->factory()->NewNumberFromUint(kHoleNanLower32); |
| 234 } | 234 } |
| 235 | 235 |
| 236 | 236 |
| 237 } // namespace internal | 237 } // namespace internal |
| 238 } // namespace v8 | 238 } // namespace v8 |
| OLD | NEW |