OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 (function(global, utils) { | 5 (function(global, utils) { |
6 | 6 |
7 %CheckIsBootstrapping(); | 7 %CheckIsBootstrapping(); |
8 | 8 |
9 // ------------------------------------------------------------------- | 9 // ------------------------------------------------------------------- |
10 // Imports | 10 // Imports |
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 return first; | 740 return first; |
741 } | 741 } |
742 var second = %_StringCharCodeAt(string, pos + 1); | 742 var second = %_StringCharCodeAt(string, pos + 1); |
743 if (second < 0xDC00 || second > 0xDFFF) { | 743 if (second < 0xDC00 || second > 0xDFFF) { |
744 return first; | 744 return first; |
745 } | 745 } |
746 return (first - 0xD800) * 0x400 + second + 0x2400; | 746 return (first - 0xD800) * 0x400 + second + 0x2400; |
747 } | 747 } |
748 | 748 |
749 | 749 |
750 // ES6 Draft 05-22-2014, section 21.1.2.2 | |
751 function StringFromCodePoint(_) { // length = 1 | |
752 "use strict"; | |
753 var code; | |
754 var length = arguments.length; | |
755 var index; | |
756 var result = ""; | |
757 for (index = 0; index < length; index++) { | |
758 code = arguments[index]; | |
759 if (!%_IsSmi(code)) { | |
760 code = TO_NUMBER(code); | |
761 } | |
762 if (code < 0 || code > 0x10FFFF || code !== TO_INTEGER(code)) { | |
763 throw MakeRangeError(kInvalidCodePoint, code); | |
764 } | |
765 if (code <= 0xFFFF) { | |
766 result += %_StringCharFromCode(code); | |
767 } else { | |
768 code -= 0x10000; | |
769 result += %_StringCharFromCode((code >>> 10) & 0x3FF | 0xD800); | |
770 result += %_StringCharFromCode(code & 0x3FF | 0xDC00); | |
771 } | |
772 } | |
773 return result; | |
774 } | |
775 | |
776 | |
777 // ------------------------------------------------------------------- | 750 // ------------------------------------------------------------------- |
778 // String methods related to templates | 751 // String methods related to templates |
779 | 752 |
780 // ES6 Draft 03-17-2015, section 21.1.2.4 | 753 // ES6 Draft 03-17-2015, section 21.1.2.4 |
781 function StringRaw(callSite) { | 754 function StringRaw(callSite) { |
782 "use strict"; | 755 "use strict"; |
783 var numberOfSubstitutions = arguments.length; | 756 var numberOfSubstitutions = arguments.length; |
784 var cooked = TO_OBJECT(callSite); | 757 var cooked = TO_OBJECT(callSite); |
785 var raw = TO_OBJECT(cooked.raw); | 758 var raw = TO_OBJECT(cooked.raw); |
786 var literalSegments = TO_LENGTH(raw.length); | 759 var literalSegments = TO_LENGTH(raw.length); |
787 if (literalSegments <= 0) return ""; | 760 if (literalSegments <= 0) return ""; |
788 | 761 |
789 var result = TO_STRING(raw[0]); | 762 var result = TO_STRING(raw[0]); |
790 | 763 |
791 for (var i = 1; i < literalSegments; ++i) { | 764 for (var i = 1; i < literalSegments; ++i) { |
792 if (i < numberOfSubstitutions) { | 765 if (i < numberOfSubstitutions) { |
793 result += TO_STRING(arguments[i]); | 766 result += TO_STRING(arguments[i]); |
794 } | 767 } |
795 result += TO_STRING(raw[i]); | 768 result += TO_STRING(raw[i]); |
796 } | 769 } |
797 | 770 |
798 return result; | 771 return result; |
799 } | 772 } |
800 | 773 |
801 // ------------------------------------------------------------------- | 774 // ------------------------------------------------------------------- |
802 | 775 |
803 // Set up the non-enumerable functions on the String object. | 776 // Set up the non-enumerable functions on the String object. |
804 utils.InstallFunctions(GlobalString, DONT_ENUM, [ | 777 utils.InstallFunctions(GlobalString, DONT_ENUM, [ |
805 "fromCodePoint", StringFromCodePoint, | |
806 "raw", StringRaw | 778 "raw", StringRaw |
807 ]); | 779 ]); |
808 | 780 |
809 // Set up the non-enumerable functions on the String prototype object. | 781 // Set up the non-enumerable functions on the String prototype object. |
810 utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [ | 782 utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [ |
811 "valueOf", StringValueOf, | 783 "valueOf", StringValueOf, |
812 "toString", StringToString, | 784 "toString", StringToString, |
813 "codePointAt", StringCodePointAt, | 785 "codePointAt", StringCodePointAt, |
814 "concat", StringConcat, | 786 "concat", StringConcat, |
815 "endsWith", StringEndsWith, | 787 "endsWith", StringEndsWith, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 to.StringLastIndexOf = StringLastIndexOf; | 828 to.StringLastIndexOf = StringLastIndexOf; |
857 to.StringMatch = StringMatchJS; | 829 to.StringMatch = StringMatchJS; |
858 to.StringReplace = StringReplace; | 830 to.StringReplace = StringReplace; |
859 to.StringSlice = StringSlice; | 831 to.StringSlice = StringSlice; |
860 to.StringSplit = StringSplitJS; | 832 to.StringSplit = StringSplitJS; |
861 to.StringSubstr = StringSubstr; | 833 to.StringSubstr = StringSubstr; |
862 to.StringSubstring = StringSubstring; | 834 to.StringSubstring = StringSubstring; |
863 }); | 835 }); |
864 | 836 |
865 }) | 837 }) |
OLD | NEW |