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_NumberToRadixString) { | 16 RUNTIME_FUNCTION(Runtime_NumberToRadixString) { |
17 HandleScope scope(isolate); | 17 HandleScope scope(isolate); |
18 DCHECK(args.length() == 2); | 18 DCHECK(args.length() == 2); |
19 CONVERT_SMI_ARG_CHECKED(radix, 1); | 19 CONVERT_SMI_ARG_CHECKED(radix, 1); |
20 RUNTIME_ASSERT(2 <= radix && radix <= 36); | 20 CHECK(2 <= radix && radix <= 36); |
21 | 21 |
22 // Fast case where the result is a one character string. | 22 // Fast case where the result is a one character string. |
23 if (args[0]->IsSmi()) { | 23 if (args[0]->IsSmi()) { |
24 int value = args.smi_at(0); | 24 int value = args.smi_at(0); |
25 if (value >= 0 && value < radix) { | 25 if (value >= 0 && value < radix) { |
26 // Character array used for conversion. | 26 // Character array used for conversion. |
27 static const char kCharTable[] = "0123456789abcdefghijklmnopqrstuvwxyz"; | 27 static const char kCharTable[] = "0123456789abcdefghijklmnopqrstuvwxyz"; |
28 return *isolate->factory()->LookupSingleCharacterStringFromCode( | 28 return *isolate->factory()->LookupSingleCharacterStringFromCode( |
29 kCharTable[value]); | 29 kCharTable[value]); |
30 } | 30 } |
(...skipping 18 matching lines...) Expand all Loading... |
49 | 49 |
50 | 50 |
51 RUNTIME_FUNCTION(Runtime_NumberToFixed) { | 51 RUNTIME_FUNCTION(Runtime_NumberToFixed) { |
52 HandleScope scope(isolate); | 52 HandleScope scope(isolate); |
53 DCHECK(args.length() == 2); | 53 DCHECK(args.length() == 2); |
54 | 54 |
55 CONVERT_DOUBLE_ARG_CHECKED(value, 0); | 55 CONVERT_DOUBLE_ARG_CHECKED(value, 0); |
56 CONVERT_DOUBLE_ARG_CHECKED(f_number, 1); | 56 CONVERT_DOUBLE_ARG_CHECKED(f_number, 1); |
57 int f = FastD2IChecked(f_number); | 57 int f = FastD2IChecked(f_number); |
58 // See DoubleToFixedCString for these constants: | 58 // See DoubleToFixedCString for these constants: |
59 RUNTIME_ASSERT(f >= 0 && f <= 20); | 59 CHECK(f >= 0 && f <= 20); |
60 RUNTIME_ASSERT(!Double(value).IsSpecial()); | 60 CHECK(!Double(value).IsSpecial()); |
61 char* str = DoubleToFixedCString(value, f); | 61 char* str = DoubleToFixedCString(value, f); |
62 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str); | 62 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str); |
63 DeleteArray(str); | 63 DeleteArray(str); |
64 return *result; | 64 return *result; |
65 } | 65 } |
66 | 66 |
67 | 67 |
68 RUNTIME_FUNCTION(Runtime_NumberToExponential) { | 68 RUNTIME_FUNCTION(Runtime_NumberToExponential) { |
69 HandleScope scope(isolate); | 69 HandleScope scope(isolate); |
70 DCHECK(args.length() == 2); | 70 DCHECK(args.length() == 2); |
71 | 71 |
72 CONVERT_DOUBLE_ARG_CHECKED(value, 0); | 72 CONVERT_DOUBLE_ARG_CHECKED(value, 0); |
73 CONVERT_DOUBLE_ARG_CHECKED(f_number, 1); | 73 CONVERT_DOUBLE_ARG_CHECKED(f_number, 1); |
74 int f = FastD2IChecked(f_number); | 74 int f = FastD2IChecked(f_number); |
75 RUNTIME_ASSERT(f >= -1 && f <= 20); | 75 CHECK(f >= -1 && f <= 20); |
76 RUNTIME_ASSERT(!Double(value).IsSpecial()); | 76 CHECK(!Double(value).IsSpecial()); |
77 char* str = DoubleToExponentialCString(value, f); | 77 char* str = DoubleToExponentialCString(value, f); |
78 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str); | 78 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str); |
79 DeleteArray(str); | 79 DeleteArray(str); |
80 return *result; | 80 return *result; |
81 } | 81 } |
82 | 82 |
83 | 83 |
84 RUNTIME_FUNCTION(Runtime_NumberToPrecision) { | 84 RUNTIME_FUNCTION(Runtime_NumberToPrecision) { |
85 HandleScope scope(isolate); | 85 HandleScope scope(isolate); |
86 DCHECK(args.length() == 2); | 86 DCHECK(args.length() == 2); |
87 | 87 |
88 CONVERT_DOUBLE_ARG_CHECKED(value, 0); | 88 CONVERT_DOUBLE_ARG_CHECKED(value, 0); |
89 CONVERT_DOUBLE_ARG_CHECKED(f_number, 1); | 89 CONVERT_DOUBLE_ARG_CHECKED(f_number, 1); |
90 int f = FastD2IChecked(f_number); | 90 int f = FastD2IChecked(f_number); |
91 RUNTIME_ASSERT(f >= 1 && f <= 21); | 91 CHECK(f >= 1 && f <= 21); |
92 RUNTIME_ASSERT(!Double(value).IsSpecial()); | 92 CHECK(!Double(value).IsSpecial()); |
93 char* str = DoubleToPrecisionCString(value, f); | 93 char* str = DoubleToPrecisionCString(value, f); |
94 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str); | 94 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str); |
95 DeleteArray(str); | 95 DeleteArray(str); |
96 return *result; | 96 return *result; |
97 } | 97 } |
98 | 98 |
99 | 99 |
100 RUNTIME_FUNCTION(Runtime_IsValidSmi) { | 100 RUNTIME_FUNCTION(Runtime_IsValidSmi) { |
101 SealHandleScope shs(isolate); | 101 SealHandleScope shs(isolate); |
102 DCHECK(args.length() == 1); | 102 DCHECK(args.length() == 1); |
(...skipping 11 matching lines...) Expand all Loading... |
114 } | 114 } |
115 | 115 |
116 | 116 |
117 // ES6 18.2.5 parseInt(string, radix) slow path | 117 // ES6 18.2.5 parseInt(string, radix) slow path |
118 RUNTIME_FUNCTION(Runtime_StringParseInt) { | 118 RUNTIME_FUNCTION(Runtime_StringParseInt) { |
119 HandleScope handle_scope(isolate); | 119 HandleScope handle_scope(isolate); |
120 DCHECK(args.length() == 2); | 120 DCHECK(args.length() == 2); |
121 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); | 121 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); |
122 CONVERT_NUMBER_CHECKED(int, radix, Int32, args[1]); | 122 CONVERT_NUMBER_CHECKED(int, radix, Int32, args[1]); |
123 // Step 8.a. is already handled in the JS function. | 123 // Step 8.a. is already handled in the JS function. |
124 RUNTIME_ASSERT(radix == 0 || (2 <= radix && radix <= 36)); | 124 CHECK(radix == 0 || (2 <= radix && radix <= 36)); |
125 | 125 |
126 subject = String::Flatten(subject); | 126 subject = String::Flatten(subject); |
127 double value; | 127 double value; |
128 | 128 |
129 { | 129 { |
130 DisallowHeapAllocation no_gc; | 130 DisallowHeapAllocation no_gc; |
131 String::FlatContent flat = subject->GetFlatContent(); | 131 String::FlatContent flat = subject->GetFlatContent(); |
132 | 132 |
133 if (flat.IsOneByte()) { | 133 if (flat.IsOneByte()) { |
134 value = | 134 value = |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 | 301 |
302 RUNTIME_FUNCTION(Runtime_GetHoleNaNLower) { | 302 RUNTIME_FUNCTION(Runtime_GetHoleNaNLower) { |
303 HandleScope scope(isolate); | 303 HandleScope scope(isolate); |
304 DCHECK(args.length() == 0); | 304 DCHECK(args.length() == 0); |
305 return *isolate->factory()->NewNumberFromUint(kHoleNanLower32); | 305 return *isolate->factory()->NewNumberFromUint(kHoleNanLower32); |
306 } | 306 } |
307 | 307 |
308 | 308 |
309 } // namespace internal | 309 } // namespace internal |
310 } // namespace v8 | 310 } // namespace v8 |
OLD | NEW |