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

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

Issue 2399423003: [builtins] Move StringIncludes to a builtin. (Closed)
Patch Set: Rename incorrectly named var 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
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->IsJSReceiver()) {
792 Handle<Symbol> match_symbol = isolate->factory()->match_symbol();
793 Handle<Object> match_property;
794 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
795 isolate, match_property, Object::GetProperty(search, match_symbol));
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
784 // ES6 section 21.1.3.8 String.prototype.indexOf ( searchString [ , position ] ) 820 // ES6 section 21.1.3.8 String.prototype.indexOf ( searchString [ , position ] )
785 BUILTIN(StringPrototypeIndexOf) { 821 BUILTIN(StringPrototypeIndexOf) {
786 HandleScope handle_scope(isolate); 822 HandleScope handle_scope(isolate);
787 823
788 return String::IndexOf(isolate, args.receiver(), 824 return String::IndexOf(isolate, args.receiver(),
789 args.atOrUndefined(isolate, 1), 825 args.atOrUndefined(isolate, 1),
790 args.atOrUndefined(isolate, 2)); 826 args.atOrUndefined(isolate, 2));
791 } 827 }
792 828
793 // ES6 section 21.1.3.9 829 // ES6 section 21.1.3.9
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 Runtime::kThrowIncompatibleMethodReceiver, context, 1386 Runtime::kThrowIncompatibleMethodReceiver, context,
1351 assembler->HeapConstant(assembler->factory()->NewStringFromAsciiChecked( 1387 assembler->HeapConstant(assembler->factory()->NewStringFromAsciiChecked(
1352 "String Iterator.prototype.next", TENURED)), 1388 "String Iterator.prototype.next", TENURED)),
1353 iterator); 1389 iterator);
1354 assembler->Return(result); // Never reached. 1390 assembler->Return(result); // Never reached.
1355 } 1391 }
1356 } 1392 }
1357 1393
1358 } // namespace internal 1394 } // namespace internal
1359 } // namespace v8 1395 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins/builtins.h ('k') | src/js/string.js » ('j') | test/mjsunit/es6/string-includes.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698