| 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/regexp/jsregexp-inl.h" | 8 #include "src/regexp/jsregexp-inl.h" |
| 9 #include "src/string-builder.h" | 9 #include "src/string-builder.h" |
| 10 #include "src/string-search.h" | 10 #include "src/string-search.h" |
| (...skipping 1070 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1081 } | 1081 } |
| 1082 | 1082 |
| 1083 | 1083 |
| 1084 RUNTIME_FUNCTION(Runtime_StringToUpperCase) { | 1084 RUNTIME_FUNCTION(Runtime_StringToUpperCase) { |
| 1085 HandleScope scope(isolate); | 1085 HandleScope scope(isolate); |
| 1086 DCHECK_EQ(args.length(), 1); | 1086 DCHECK_EQ(args.length(), 1); |
| 1087 CONVERT_ARG_HANDLE_CHECKED(String, s, 0); | 1087 CONVERT_ARG_HANDLE_CHECKED(String, s, 0); |
| 1088 return ConvertCase(s, isolate, isolate->runtime_state()->to_upper_mapping()); | 1088 return ConvertCase(s, isolate, isolate->runtime_state()->to_upper_mapping()); |
| 1089 } | 1089 } |
| 1090 | 1090 |
| 1091 | |
| 1092 RUNTIME_FUNCTION(Runtime_StringTrim) { | |
| 1093 HandleScope scope(isolate); | |
| 1094 DCHECK(args.length() == 3); | |
| 1095 | |
| 1096 CONVERT_ARG_HANDLE_CHECKED(String, string, 0); | |
| 1097 CONVERT_BOOLEAN_ARG_CHECKED(trimLeft, 1); | |
| 1098 CONVERT_BOOLEAN_ARG_CHECKED(trimRight, 2); | |
| 1099 | |
| 1100 string = String::Flatten(string); | |
| 1101 int length = string->length(); | |
| 1102 | |
| 1103 int left = 0; | |
| 1104 UnicodeCache* unicode_cache = isolate->unicode_cache(); | |
| 1105 if (trimLeft) { | |
| 1106 while (left < length && | |
| 1107 unicode_cache->IsWhiteSpaceOrLineTerminator(string->Get(left))) { | |
| 1108 left++; | |
| 1109 } | |
| 1110 } | |
| 1111 | |
| 1112 int right = length; | |
| 1113 if (trimRight) { | |
| 1114 while ( | |
| 1115 right > left && | |
| 1116 unicode_cache->IsWhiteSpaceOrLineTerminator(string->Get(right - 1))) { | |
| 1117 right--; | |
| 1118 } | |
| 1119 } | |
| 1120 | |
| 1121 return *isolate->factory()->NewSubString(string, left, right); | |
| 1122 } | |
| 1123 | |
| 1124 RUNTIME_FUNCTION(Runtime_StringLessThan) { | 1091 RUNTIME_FUNCTION(Runtime_StringLessThan) { |
| 1125 HandleScope handle_scope(isolate); | 1092 HandleScope handle_scope(isolate); |
| 1126 DCHECK_EQ(2, args.length()); | 1093 DCHECK_EQ(2, args.length()); |
| 1127 CONVERT_ARG_HANDLE_CHECKED(String, x, 0); | 1094 CONVERT_ARG_HANDLE_CHECKED(String, x, 0); |
| 1128 CONVERT_ARG_HANDLE_CHECKED(String, y, 1); | 1095 CONVERT_ARG_HANDLE_CHECKED(String, y, 1); |
| 1129 switch (String::Compare(x, y)) { | 1096 switch (String::Compare(x, y)) { |
| 1130 case ComparisonResult::kLessThan: | 1097 case ComparisonResult::kLessThan: |
| 1131 return isolate->heap()->true_value(); | 1098 return isolate->heap()->true_value(); |
| 1132 case ComparisonResult::kEqual: | 1099 case ComparisonResult::kEqual: |
| 1133 case ComparisonResult::kGreaterThan: | 1100 case ComparisonResult::kGreaterThan: |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1240 SealHandleScope shs(isolate); | 1207 SealHandleScope shs(isolate); |
| 1241 DCHECK(args.length() == 2); | 1208 DCHECK(args.length() == 2); |
| 1242 if (!args[0]->IsString()) return isolate->heap()->undefined_value(); | 1209 if (!args[0]->IsString()) return isolate->heap()->undefined_value(); |
| 1243 if (!args[1]->IsNumber()) return isolate->heap()->undefined_value(); | 1210 if (!args[1]->IsNumber()) return isolate->heap()->undefined_value(); |
| 1244 if (std::isinf(args.number_at(1))) return isolate->heap()->nan_value(); | 1211 if (std::isinf(args.number_at(1))) return isolate->heap()->nan_value(); |
| 1245 return __RT_impl_Runtime_StringCharCodeAtRT(args, isolate); | 1212 return __RT_impl_Runtime_StringCharCodeAtRT(args, isolate); |
| 1246 } | 1213 } |
| 1247 | 1214 |
| 1248 } // namespace internal | 1215 } // namespace internal |
| 1249 } // namespace v8 | 1216 } // namespace v8 |
| OLD | NEW |