OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 // ReplaceResultBuilder support. | 904 // ReplaceResultBuilder support. |
905 function ReplaceResultBuilder(str) { | 905 function ReplaceResultBuilder(str) { |
906 if (%_ArgumentsLength() > 1) { | 906 if (%_ArgumentsLength() > 1) { |
907 this.elements = %_Arguments(1); | 907 this.elements = %_Arguments(1); |
908 } else { | 908 } else { |
909 this.elements = new InternalArray(); | 909 this.elements = new InternalArray(); |
910 } | 910 } |
911 this.special_string = str; | 911 this.special_string = str; |
912 } | 912 } |
913 | 913 |
914 ReplaceResultBuilder.prototype.__proto__ = null; | 914 SetUpLockedPrototype(ReplaceResultBuilder, |
915 | 915 $Array("elements", "special_string"), $Array( |
916 | 916 "add", function(str) { |
917 ReplaceResultBuilder.prototype.add = function(str) { | 917 str = TO_STRING_INLINE(str); |
918 str = TO_STRING_INLINE(str); | 918 if (str.length > 0) this.elements.push(str); |
919 if (str.length > 0) this.elements.push(str); | 919 }, |
920 } | 920 "addSpecialSlice", function(start, end) { |
921 | 921 var len = end - start; |
922 | 922 if (start < 0 || len <= 0) return; |
923 ReplaceResultBuilder.prototype.addSpecialSlice = function(start, end) { | 923 if (start < 0x80000 && len < 0x800) { |
924 var len = end - start; | 924 this.elements.push((start << 11) | len); |
925 if (start < 0 || len <= 0) return; | 925 } else { |
926 if (start < 0x80000 && len < 0x800) { | 926 // 0 < len <= String::kMaxLength and Smi::kMaxValue >= String::kMaxLength, |
927 this.elements.push((start << 11) | len); | 927 // so -len is a smi. |
928 } else { | 928 var elements = this.elements; |
929 // 0 < len <= String::kMaxLength and Smi::kMaxValue >= String::kMaxLength, | 929 elements.push(-len); |
930 // so -len is a smi. | 930 elements.push(start); |
| 931 } |
| 932 }, |
| 933 "generate", function() { |
931 var elements = this.elements; | 934 var elements = this.elements; |
932 elements.push(-len); | 935 return %StringBuilderConcat(elements, elements.length, this.special_string); |
933 elements.push(start); | |
934 } | 936 } |
935 } | 937 )); |
936 | |
937 | |
938 ReplaceResultBuilder.prototype.generate = function() { | |
939 var elements = this.elements; | |
940 return %StringBuilderConcat(elements, elements.length, this.special_string); | |
941 } | |
942 | 938 |
943 | 939 |
944 // ------------------------------------------------------------------- | 940 // ------------------------------------------------------------------- |
945 | 941 |
946 function SetupString() { | 942 function SetUpString() { |
947 // Setup the constructor property on the String prototype object. | 943 %CheckIsBootstrapping(); |
| 944 // Set up the constructor property on the String prototype object. |
948 %SetProperty($String.prototype, "constructor", $String, DONT_ENUM); | 945 %SetProperty($String.prototype, "constructor", $String, DONT_ENUM); |
949 | 946 |
950 | 947 |
951 // Setup the non-enumerable functions on the String object. | 948 // Set up the non-enumerable functions on the String object. |
952 InstallFunctions($String, DONT_ENUM, $Array( | 949 InstallFunctions($String, DONT_ENUM, $Array( |
953 "fromCharCode", StringFromCharCode | 950 "fromCharCode", StringFromCharCode |
954 )); | 951 )); |
955 | 952 |
956 | 953 |
957 // Setup the non-enumerable functions on the String prototype object. | 954 // Set up the non-enumerable functions on the String prototype object. |
958 InstallFunctionsOnHiddenPrototype($String.prototype, DONT_ENUM, $Array( | 955 InstallFunctionsOnHiddenPrototype($String.prototype, DONT_ENUM, $Array( |
959 "valueOf", StringValueOf, | 956 "valueOf", StringValueOf, |
960 "toString", StringToString, | 957 "toString", StringToString, |
961 "charAt", StringCharAt, | 958 "charAt", StringCharAt, |
962 "charCodeAt", StringCharCodeAt, | 959 "charCodeAt", StringCharCodeAt, |
963 "concat", StringConcat, | 960 "concat", StringConcat, |
964 "indexOf", StringIndexOf, | 961 "indexOf", StringIndexOf, |
965 "lastIndexOf", StringLastIndexOf, | 962 "lastIndexOf", StringLastIndexOf, |
966 "localeCompare", StringLocaleCompare, | 963 "localeCompare", StringLocaleCompare, |
967 "match", StringMatch, | 964 "match", StringMatch, |
(...skipping 19 matching lines...) Expand all Loading... |
987 "bold", StringBold, | 984 "bold", StringBold, |
988 "fixed", StringFixed, | 985 "fixed", StringFixed, |
989 "italics", StringItalics, | 986 "italics", StringItalics, |
990 "small", StringSmall, | 987 "small", StringSmall, |
991 "strike", StringStrike, | 988 "strike", StringStrike, |
992 "sub", StringSub, | 989 "sub", StringSub, |
993 "sup", StringSup | 990 "sup", StringSup |
994 )); | 991 )); |
995 } | 992 } |
996 | 993 |
997 | 994 SetUpString(); |
998 SetupString(); | |
OLD | NEW |