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 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
600 typedef compiler::Node Node; | 600 typedef compiler::Node Node; |
601 | 601 |
602 Node* receiver = assembler->Parameter(0); | 602 Node* receiver = assembler->Parameter(0); |
603 Node* context = assembler->Parameter(3); | 603 Node* context = assembler->Parameter(3); |
604 | 604 |
605 Node* result = assembler->ToThisValue( | 605 Node* result = assembler->ToThisValue( |
606 context, receiver, PrimitiveType::kString, "String.prototype.valueOf"); | 606 context, receiver, PrimitiveType::kString, "String.prototype.valueOf"); |
607 assembler->Return(result); | 607 assembler->Return(result); |
608 } | 608 } |
609 | 609 |
610 BUILTIN(StringPrototypeIterator) { | |
611 HandleScope scope(isolate); | |
612 TO_THIS_STRING(object, "String.prototype[Symbol.iterator]"); | |
613 | |
614 Handle<String> string; | |
615 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, string, | |
616 Object::ToString(isolate, object)); | |
617 | |
618 return *isolate->factory()->NewJSStringIterator(string); | |
619 } | |
620 | |
621 BUILTIN(StringIteratorPrototypeNext) { | |
622 HandleScope scope(isolate); | |
623 | |
624 if (!args.receiver()->IsJSStringIterator()) { | |
625 Handle<String> reason = isolate->factory()->NewStringFromAsciiChecked( | |
626 "String Iterator.prototype.next"); | |
627 THROW_NEW_ERROR_RETURN_FAILURE( | |
628 isolate, | |
629 NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, reason)); | |
630 } | |
631 Handle<JSStringIterator> iterator = | |
632 Handle<JSStringIterator>::cast(args.receiver()); | |
633 Handle<String> string(iterator->string()); | |
634 | |
635 if (*string != isolate->heap()->empty_string()) { | |
Benedikt Meurer
2016/09/19 04:05:18
You don't need this check, as the empty string wil
caitp
2016/09/19 16:03:04
Done.
| |
636 int position = iterator->index(); | |
637 int length = string->length(); | |
638 | |
639 do { | |
640 if (position >= length) break; | |
641 | |
642 uint16_t lead = string->Get(position); | |
643 if (lead >= 0xD800 && lead <= 0xDBFF && position + 1 < length) { | |
644 uint16_t trail = string->Get(position + 1); | |
645 if (V8_LIKELY(trail >= 0xDC00 && trail <= 0xDFFF)) { | |
646 // Return combined code units | |
647 iterator->set_index(position + 2); | |
648 Handle<String> value = isolate->factory()->NewProperSubString( | |
Benedikt Meurer
2016/09/19 04:05:18
I'd prefer to not use NewProperSubString here, as
caitp
2016/09/19 16:03:05
Done --- Should the new factory method try to look
Benedikt Meurer
2016/09/20 04:57:53
Nope, that doesn't make sense. Especially since th
caitp
2016/09/20 13:28:14
Acknowledged.
| |
649 string, position, position + 2); | |
650 return *isolate->factory()->NewJSIteratorResult(value, false); | |
651 } | |
652 } | |
653 | |
654 // Return single code unit | |
655 iterator->set_index(position + 1); | |
656 Handle<String> value = isolate->factory()->NewProperSubString( | |
657 string, position, position + 1); | |
Benedikt Meurer
2016/09/19 04:05:18
Please use LookupSingleCharacterStringFromCode dir
caitp
2016/09/19 16:03:04
Done.
| |
658 return *isolate->factory()->NewJSIteratorResult(value, false); | |
659 } while (false); | |
660 | |
661 iterator->set_string(isolate->heap()->empty_string()); | |
662 } | |
663 | |
664 return *isolate->factory()->NewJSIteratorResult( | |
665 isolate->factory()->undefined_value(), true); | |
666 } | |
667 | |
610 } // namespace internal | 668 } // namespace internal |
611 } // namespace v8 | 669 } // namespace v8 |
OLD | NEW |