| 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" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 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); |
| 29 return *String::ToNumber(subject); | 29 return *String::ToNumber(subject); |
| 30 } | 30 } |
| 31 | 31 |
| 32 | 32 |
| 33 // ES6 18.2.5 parseInt(string, radix) slow path | 33 // ES6 18.2.5 parseInt(string, radix) slow path |
| 34 RUNTIME_FUNCTION(Runtime_StringParseInt) { | 34 RUNTIME_FUNCTION(Runtime_StringParseInt) { |
| 35 HandleScope handle_scope(isolate); | 35 HandleScope handle_scope(isolate); |
| 36 DCHECK(args.length() == 2); | 36 DCHECK_EQ(2, args.length()); |
| 37 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); | 37 CONVERT_ARG_HANDLE_CHECKED(Object, string, 0); |
| 38 CONVERT_NUMBER_CHECKED(int, radix, Int32, args[1]); | 38 CONVERT_ARG_HANDLE_CHECKED(Object, radix, 1); |
| 39 // Step 8.a. is already handled in the JS function. | |
| 40 CHECK(radix == 0 || (2 <= radix && radix <= 36)); | |
| 41 | 39 |
| 40 // Convert {string} to a String first, and flatten it. |
| 41 Handle<String> subject; |
| 42 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, subject, |
| 43 Object::ToString(isolate, string)); |
| 42 subject = String::Flatten(subject); | 44 subject = String::Flatten(subject); |
| 43 double value; | |
| 44 | 45 |
| 46 // Convert {radix} to Int32. |
| 47 if (!radix->IsNumber()) { |
| 48 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, radix, Object::ToNumber(radix)); |
| 49 } |
| 50 int radix32 = DoubleToInt32(radix->Number()); |
| 51 if (radix32 != 0 && (radix32 < 2 || radix32 > 36)) { |
| 52 return isolate->heap()->nan_value(); |
| 53 } |
| 54 |
| 55 double result; |
| 45 { | 56 { |
| 46 DisallowHeapAllocation no_gc; | 57 DisallowHeapAllocation no_gc; |
| 47 String::FlatContent flat = subject->GetFlatContent(); | 58 String::FlatContent flat = subject->GetFlatContent(); |
| 48 | 59 |
| 49 if (flat.IsOneByte()) { | 60 if (flat.IsOneByte()) { |
| 50 value = | 61 result = StringToInt(isolate->unicode_cache(), flat.ToOneByteVector(), |
| 51 StringToInt(isolate->unicode_cache(), flat.ToOneByteVector(), radix); | 62 radix32); |
| 52 } else { | 63 } else { |
| 53 value = StringToInt(isolate->unicode_cache(), flat.ToUC16Vector(), radix); | 64 result = |
| 65 StringToInt(isolate->unicode_cache(), flat.ToUC16Vector(), radix32); |
| 54 } | 66 } |
| 55 } | 67 } |
| 56 | 68 |
| 57 return *isolate->factory()->NewNumber(value); | 69 return *isolate->factory()->NewNumber(result); |
| 58 } | 70 } |
| 59 | 71 |
| 60 | 72 |
| 61 // ES6 18.2.4 parseFloat(string) | 73 // ES6 18.2.4 parseFloat(string) |
| 62 RUNTIME_FUNCTION(Runtime_StringParseFloat) { | 74 RUNTIME_FUNCTION(Runtime_StringParseFloat) { |
| 63 HandleScope shs(isolate); | 75 HandleScope shs(isolate); |
| 64 DCHECK(args.length() == 1); | 76 DCHECK(args.length() == 1); |
| 65 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); | 77 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); |
| 66 | 78 |
| 67 double value = | 79 double value = |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 229 |
| 218 RUNTIME_FUNCTION(Runtime_GetHoleNaNLower) { | 230 RUNTIME_FUNCTION(Runtime_GetHoleNaNLower) { |
| 219 HandleScope scope(isolate); | 231 HandleScope scope(isolate); |
| 220 DCHECK(args.length() == 0); | 232 DCHECK(args.length() == 0); |
| 221 return *isolate->factory()->NewNumberFromUint(kHoleNanLower32); | 233 return *isolate->factory()->NewNumberFromUint(kHoleNanLower32); |
| 222 } | 234 } |
| 223 | 235 |
| 224 | 236 |
| 225 } // namespace internal | 237 } // namespace internal |
| 226 } // namespace v8 | 238 } // namespace v8 |
| OLD | NEW |