| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/builtins/builtins-utils.h" | 5 #include "src/builtins/builtins-utils.h" |
| 6 #include "src/builtins/builtins.h" | 6 #include "src/builtins/builtins.h" |
| 7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
| 8 #include "src/code-stub-assembler.h" | 8 #include "src/code-stub-assembler.h" |
| 9 #include "src/regexp/regexp-utils.h" | 9 #include "src/regexp/regexp-utils.h" |
| 10 | 10 |
| (...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 Object::ToString(isolate, search)); | 754 Object::ToString(isolate, search)); |
| 755 | 755 |
| 756 Handle<Object> position = args.atOrUndefined(isolate, 2); | 756 Handle<Object> position = args.atOrUndefined(isolate, 2); |
| 757 int end; | 757 int end; |
| 758 | 758 |
| 759 if (position->IsUndefined(isolate)) { | 759 if (position->IsUndefined(isolate)) { |
| 760 end = str->length(); | 760 end = str->length(); |
| 761 } else { | 761 } else { |
| 762 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, position, | 762 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, position, |
| 763 Object::ToInteger(isolate, position)); | 763 Object::ToInteger(isolate, position)); |
| 764 double index = std::max(position->Number(), 0.0); | 764 end = str->ToValidIndex(*position); |
| 765 index = std::min(index, static_cast<double>(str->length())); | |
| 766 end = static_cast<uint32_t>(index); | |
| 767 } | 765 } |
| 768 | 766 |
| 769 int start = end - search_string->length(); | 767 int start = end - search_string->length(); |
| 770 if (start < 0) return isolate->heap()->false_value(); | 768 if (start < 0) return isolate->heap()->false_value(); |
| 771 | 769 |
| 772 str = String::Flatten(str); | 770 str = String::Flatten(str); |
| 773 search_string = String::Flatten(search_string); | 771 search_string = String::Flatten(search_string); |
| 774 | 772 |
| 775 DisallowHeapAllocation no_gc; // ensure vectors stay valid | 773 DisallowHeapAllocation no_gc; // ensure vectors stay valid |
| 776 String::FlatContent str_content = str->GetFlatContent(); | 774 String::FlatContent str_content = str->GetFlatContent(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 "String.prototype.includes"))); | 814 "String.prototype.includes"))); |
| 817 } | 815 } |
| 818 Handle<String> search_string; | 816 Handle<String> search_string; |
| 819 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, search_string, | 817 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, search_string, |
| 820 Object::ToString(isolate, search)); | 818 Object::ToString(isolate, search)); |
| 821 Handle<Object> position; | 819 Handle<Object> position; |
| 822 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 820 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 823 isolate, position, | 821 isolate, position, |
| 824 Object::ToInteger(isolate, args.atOrUndefined(isolate, 2))); | 822 Object::ToInteger(isolate, args.atOrUndefined(isolate, 2))); |
| 825 | 823 |
| 826 double index = std::max(position->Number(), 0.0); | 824 uint32_t index = str->ToValidIndex(*position); |
| 827 index = std::min(index, static_cast<double>(str->length())); | 825 int index_in_str = String::IndexOf(isolate, str, search_string, index); |
| 828 | |
| 829 int index_in_str = String::IndexOf(isolate, str, search_string, | |
| 830 static_cast<uint32_t>(index)); | |
| 831 return *isolate->factory()->ToBoolean(index_in_str != -1); | 826 return *isolate->factory()->ToBoolean(index_in_str != -1); |
| 832 } | 827 } |
| 833 | 828 |
| 834 // ES6 section 21.1.3.8 String.prototype.indexOf ( searchString [ , position ] ) | 829 // ES6 section 21.1.3.8 String.prototype.indexOf ( searchString [ , position ] ) |
| 835 BUILTIN(StringPrototypeIndexOf) { | 830 BUILTIN(StringPrototypeIndexOf) { |
| 836 HandleScope handle_scope(isolate); | 831 HandleScope handle_scope(isolate); |
| 837 | 832 |
| 838 return String::IndexOf(isolate, args.receiver(), | 833 return String::IndexOf(isolate, args.receiver(), |
| 839 args.atOrUndefined(isolate, 1), | 834 args.atOrUndefined(isolate, 1), |
| 840 args.atOrUndefined(isolate, 2)); | 835 args.atOrUndefined(isolate, 2)); |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1195 Object::ToString(isolate, search)); | 1190 Object::ToString(isolate, search)); |
| 1196 | 1191 |
| 1197 Handle<Object> position = args.atOrUndefined(isolate, 2); | 1192 Handle<Object> position = args.atOrUndefined(isolate, 2); |
| 1198 int start; | 1193 int start; |
| 1199 | 1194 |
| 1200 if (position->IsUndefined(isolate)) { | 1195 if (position->IsUndefined(isolate)) { |
| 1201 start = 0; | 1196 start = 0; |
| 1202 } else { | 1197 } else { |
| 1203 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, position, | 1198 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, position, |
| 1204 Object::ToInteger(isolate, position)); | 1199 Object::ToInteger(isolate, position)); |
| 1205 double index = std::max(position->Number(), 0.0); | 1200 start = str->ToValidIndex(*position); |
| 1206 index = std::min(index, static_cast<double>(str->length())); | |
| 1207 start = static_cast<uint32_t>(index); | |
| 1208 } | 1201 } |
| 1209 | 1202 |
| 1210 if (start + search_string->length() > str->length()) { | 1203 if (start + search_string->length() > str->length()) { |
| 1211 return isolate->heap()->false_value(); | 1204 return isolate->heap()->false_value(); |
| 1212 } | 1205 } |
| 1213 | 1206 |
| 1214 FlatStringReader str_reader(isolate, String::Flatten(str)); | 1207 FlatStringReader str_reader(isolate, String::Flatten(str)); |
| 1215 FlatStringReader search_reader(isolate, String::Flatten(search_string)); | 1208 FlatStringReader search_reader(isolate, String::Flatten(search_string)); |
| 1216 | 1209 |
| 1217 for (int i = 0; i < search_string->length(); i++) { | 1210 for (int i = 0; i < search_string->length(); i++) { |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1462 Runtime::kThrowIncompatibleMethodReceiver, context, | 1455 Runtime::kThrowIncompatibleMethodReceiver, context, |
| 1463 assembler.HeapConstant(assembler.factory()->NewStringFromAsciiChecked( | 1456 assembler.HeapConstant(assembler.factory()->NewStringFromAsciiChecked( |
| 1464 "String Iterator.prototype.next", TENURED)), | 1457 "String Iterator.prototype.next", TENURED)), |
| 1465 iterator); | 1458 iterator); |
| 1466 assembler.Return(result); // Never reached. | 1459 assembler.Return(result); // Never reached. |
| 1467 } | 1460 } |
| 1468 } | 1461 } |
| 1469 | 1462 |
| 1470 } // namespace internal | 1463 } // namespace internal |
| 1471 } // namespace v8 | 1464 } // namespace v8 |
| OLD | NEW |