Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(421)

Side by Side Diff: src/builtins/builtins-string.cc

Issue 2407793002: Revert of [builtins] Move StringIncludes to a builtin. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/builtins/builtins.h ('k') | src/js/string.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 9
10 namespace v8 { 10 namespace v8 {
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 774
775 assembler->Bind(&if_positioninbounds); 775 assembler->Bind(&if_positioninbounds);
776 } 776 }
777 777
778 // Load the character at the {position} from the {receiver}. 778 // Load the character at the {position} from the {receiver}.
779 Node* value = assembler->StringCharCodeAt(receiver, position); 779 Node* value = assembler->StringCharCodeAt(receiver, position);
780 Node* result = assembler->SmiFromWord32(value); 780 Node* result = assembler->SmiFromWord32(value);
781 assembler->Return(result); 781 assembler->Return(result);
782 } 782 }
783 783
784 // ES6 section 21.1.3.7
785 // String.prototype.includes ( searchString [ , position ] )
786 BUILTIN(StringPrototypeIncludes) {
787 HandleScope handle_scope(isolate);
788 TO_THIS_STRING(str, "String.prototype.includes");
789
790 Handle<Object> search = args.atOrUndefined(isolate, 1);
791 if (search->IsObject()) {
792 Handle<Symbol> match_name = isolate->factory()->match_symbol();
793 Handle<Object> match_property;
794 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, match_property,
795 Object::GetProperty(search, match_name));
796 if (!match_property->IsUndefined(isolate) &&
797 match_property->BooleanValue()) {
798 THROW_NEW_ERROR_RETURN_FAILURE(
799 isolate, NewTypeError(MessageTemplate::kFirstArgumentNotRegExp,
800 isolate->factory()->NewStringFromStaticChars(
801 "String.prototype.includes")));
802 }
803 }
804 Handle<String> search_string;
805 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, search_string,
806 Object::ToString(isolate, search));
807 Handle<Object> position;
808 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
809 isolate, position,
810 Object::ToInteger(isolate, args.atOrUndefined(isolate, 2)));
811
812 double index = std::max(position->Number(), 0.0);
813 index = std::min(index, static_cast<double>(str->length()));
814
815 int index_in_str = String::IndexOf(isolate, str, search_string,
816 static_cast<uint32_t>(index));
817 return *isolate->factory()->ToBoolean(index_in_str != -1);
818 }
819
820 // ES6 section 21.1.3.8 String.prototype.indexOf ( searchString [ , position ] ) 784 // ES6 section 21.1.3.8 String.prototype.indexOf ( searchString [ , position ] )
821 BUILTIN(StringPrototypeIndexOf) { 785 BUILTIN(StringPrototypeIndexOf) {
822 HandleScope handle_scope(isolate); 786 HandleScope handle_scope(isolate);
823 787
824 return String::IndexOf(isolate, args.receiver(), 788 return String::IndexOf(isolate, args.receiver(),
825 args.atOrUndefined(isolate, 1), 789 args.atOrUndefined(isolate, 1),
826 args.atOrUndefined(isolate, 2)); 790 args.atOrUndefined(isolate, 2));
827 } 791 }
828 792
829 // ES6 section 21.1.3.9 793 // ES6 section 21.1.3.9
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 Runtime::kThrowIncompatibleMethodReceiver, context, 1350 Runtime::kThrowIncompatibleMethodReceiver, context,
1387 assembler->HeapConstant(assembler->factory()->NewStringFromAsciiChecked( 1351 assembler->HeapConstant(assembler->factory()->NewStringFromAsciiChecked(
1388 "String Iterator.prototype.next", TENURED)), 1352 "String Iterator.prototype.next", TENURED)),
1389 iterator); 1353 iterator);
1390 assembler->Return(result); // Never reached. 1354 assembler->Return(result); // Never reached.
1391 } 1355 }
1392 } 1356 }
1393 1357
1394 } // namespace internal 1358 } // namespace internal
1395 } // namespace v8 1359 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins/builtins.h ('k') | src/js/string.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698