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.h" | 5 #include "src/builtins/builtins.h" |
6 #include "src/builtins/builtins-utils.h" | 6 #include "src/builtins/builtins-utils.h" |
7 | 7 |
8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
9 #include "src/regexp/regexp-utils.h" | 9 #include "src/regexp/regexp-utils.h" |
10 | 10 |
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
751 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, position, | 751 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, position, |
752 Object::ToInteger(isolate, position)); | 752 Object::ToInteger(isolate, position)); |
753 double index = std::max(position->Number(), 0.0); | 753 double index = std::max(position->Number(), 0.0); |
754 index = std::min(index, static_cast<double>(str->length())); | 754 index = std::min(index, static_cast<double>(str->length())); |
755 end = static_cast<uint32_t>(index); | 755 end = static_cast<uint32_t>(index); |
756 } | 756 } |
757 | 757 |
758 int start = end - search_string->length(); | 758 int start = end - search_string->length(); |
759 if (start < 0) return isolate->heap()->false_value(); | 759 if (start < 0) return isolate->heap()->false_value(); |
760 | 760 |
761 FlatStringReader str_reader(isolate, String::Flatten(str)); | 761 str = String::Flatten(str); |
762 FlatStringReader search_reader(isolate, String::Flatten(search_string)); | 762 search_string = String::Flatten(search_string); |
763 | |
764 DisallowHeapAllocation no_gc; // ensure vectors stay valid | |
765 String::FlatContent str_content = str->GetFlatContent(); | |
766 String::FlatContent search_content = search_string->GetFlatContent(); | |
767 | |
768 if (str_content.IsOneByte() && search_content.IsOneByte()) { | |
769 Vector<const uint8_t> str_vector = str_content.ToOneByteVector(); | |
770 Vector<const uint8_t> search_vector = search_content.ToOneByteVector(); | |
771 const char* str_ptr = | |
772 reinterpret_cast<const char*>(str_vector.start() + start); | |
773 const char* search_ptr = | |
774 reinterpret_cast<const char*>(search_vector.start()); | |
775 | |
776 if (strncmp(str_ptr, search_ptr, search_string->length()) == 0) { | |
777 return *isolate->factory()->true_value(); | |
Yang
2016/11/16 12:13:24
isolate->heap()->true_value()
also, why don't we
petermarshall
2016/11/16 12:19:15
Oops, yep.
| |
778 } | |
779 } | |
780 | |
781 FlatStringReader str_reader(isolate, str); | |
782 FlatStringReader search_reader(isolate, search_string); | |
763 | 783 |
764 for (int i = 0; i < search_string->length(); i++) { | 784 for (int i = 0; i < search_string->length(); i++) { |
765 if (str_reader.Get(start + i) != search_reader.Get(i)) { | 785 if (str_reader.Get(start + i) != search_reader.Get(i)) { |
766 return isolate->heap()->false_value(); | 786 return isolate->heap()->false_value(); |
767 } | 787 } |
768 } | 788 } |
769 return isolate->heap()->true_value(); | 789 return isolate->heap()->true_value(); |
770 } | 790 } |
771 | 791 |
772 // ES6 section 21.1.3.7 | 792 // ES6 section 21.1.3.7 |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1427 Runtime::kThrowIncompatibleMethodReceiver, context, | 1447 Runtime::kThrowIncompatibleMethodReceiver, context, |
1428 assembler->HeapConstant(assembler->factory()->NewStringFromAsciiChecked( | 1448 assembler->HeapConstant(assembler->factory()->NewStringFromAsciiChecked( |
1429 "String Iterator.prototype.next", TENURED)), | 1449 "String Iterator.prototype.next", TENURED)), |
1430 iterator); | 1450 iterator); |
1431 assembler->Return(result); // Never reached. | 1451 assembler->Return(result); // Never reached. |
1432 } | 1452 } |
1433 } | 1453 } |
1434 | 1454 |
1435 } // namespace internal | 1455 } // namespace internal |
1436 } // namespace v8 | 1456 } // namespace v8 |
OLD | NEW |