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

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

Issue 2348493003: [builtins] move String.prototype[@@iterator] to C++ builtin (Closed)
Patch Set: V8 (rebase + fix bytecode expectations) Created 4 years, 3 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-iterator.cc ('k') | src/compiler/types.cc » ('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 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 typedef compiler::Node Node; 609 typedef compiler::Node Node;
610 610
611 Node* receiver = assembler->Parameter(0); 611 Node* receiver = assembler->Parameter(0);
612 Node* context = assembler->Parameter(3); 612 Node* context = assembler->Parameter(3);
613 613
614 Node* result = assembler->ToThisValue( 614 Node* result = assembler->ToThisValue(
615 context, receiver, PrimitiveType::kString, "String.prototype.valueOf"); 615 context, receiver, PrimitiveType::kString, "String.prototype.valueOf");
616 assembler->Return(result); 616 assembler->Return(result);
617 } 617 }
618 618
619 BUILTIN(StringPrototypeIterator) {
620 HandleScope scope(isolate);
621 TO_THIS_STRING(object, "String.prototype[Symbol.iterator]");
622
623 Handle<String> string;
624 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, string,
625 Object::ToString(isolate, object));
626
627 return *isolate->factory()->NewJSStringIterator(string);
628 }
629
630 BUILTIN(StringIteratorPrototypeNext) {
631 HandleScope scope(isolate);
632
633 if (!args.receiver()->IsJSStringIterator()) {
634 Handle<String> reason = isolate->factory()->NewStringFromAsciiChecked(
635 "String Iterator.prototype.next");
636 THROW_NEW_ERROR_RETURN_FAILURE(
637 isolate,
638 NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, reason));
639 }
640 Handle<JSStringIterator> iterator =
641 Handle<JSStringIterator>::cast(args.receiver());
642 Handle<String> string(iterator->string());
643
644 int position = iterator->index();
645 int length = string->length();
646
647 if (position < length) {
648 uint16_t lead = string->Get(position);
649 if (lead >= 0xD800 && lead <= 0xDBFF && position + 1 < length) {
650 uint16_t trail = string->Get(position + 1);
651 if (V8_LIKELY(trail >= 0xDC00 && trail <= 0xDFFF)) {
652 // Return surrogate pair code units
653 iterator->set_index(position + 2);
654 Handle<String> value =
655 isolate->factory()->NewSurrogatePairString(lead, trail);
656 return *isolate->factory()->NewJSIteratorResult(value, false);
657 }
658 }
659
660 // Return single code unit
661 iterator->set_index(position + 1);
662 Handle<String> value =
663 isolate->factory()->LookupSingleCharacterStringFromCode(lead);
664 return *isolate->factory()->NewJSIteratorResult(value, false);
665 }
666
667 iterator->set_string(isolate->heap()->empty_string());
668
669 return *isolate->factory()->NewJSIteratorResult(
670 isolate->factory()->undefined_value(), true);
671 }
672
619 } // namespace internal 673 } // namespace internal
620 } // namespace v8 674 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins/builtins-iterator.cc ('k') | src/compiler/types.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698