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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 // ECMA-262 section 15.5.4.3 | 51 // ECMA-262 section 15.5.4.3 |
52 function StringValueOf() { | 52 function StringValueOf() { |
53 if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) { | 53 if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) { |
54 throw MakeTypeError(kNotGeneric, 'String.prototype.valueOf'); | 54 throw MakeTypeError(kNotGeneric, 'String.prototype.valueOf'); |
55 } | 55 } |
56 return %_ValueOf(this); | 56 return %_ValueOf(this); |
57 } | 57 } |
58 | 58 |
59 | 59 |
| 60 // ECMA-262, section 15.5.4.4 |
| 61 function StringCharAtJS(pos) { |
| 62 CHECK_OBJECT_COERCIBLE(this, "String.prototype.charAt"); |
| 63 |
| 64 var result = %_StringCharAt(this, pos); |
| 65 if (%_IsSmi(result)) { |
| 66 result = %_StringCharAt(TO_STRING(this), TO_INTEGER(pos)); |
| 67 } |
| 68 return result; |
| 69 } |
| 70 |
| 71 |
| 72 // ECMA-262 section 15.5.4.5 |
| 73 function StringCharCodeAtJS(pos) { |
| 74 CHECK_OBJECT_COERCIBLE(this, "String.prototype.charCodeAt"); |
| 75 |
| 76 var result = %_StringCharCodeAt(this, pos); |
| 77 if (!%_IsSmi(result)) { |
| 78 result = %_StringCharCodeAt(TO_STRING(this), TO_INTEGER(pos)); |
| 79 } |
| 80 return result; |
| 81 } |
| 82 |
| 83 |
60 // ECMA-262, section 15.5.4.6 | 84 // ECMA-262, section 15.5.4.6 |
61 function StringConcat(other /* and more */) { // length == 1 | 85 function StringConcat(other /* and more */) { // length == 1 |
62 "use strict"; | 86 "use strict"; |
63 CHECK_OBJECT_COERCIBLE(this, "String.prototype.concat"); | 87 CHECK_OBJECT_COERCIBLE(this, "String.prototype.concat"); |
64 var s = TO_STRING(this); | 88 var s = TO_STRING(this); |
65 var len = arguments.length; | 89 var len = arguments.length; |
66 for (var i = 0; i < len; ++i) { | 90 for (var i = 0; i < len; ++i) { |
67 s = s + TO_STRING(arguments[i]); | 91 s = s + TO_STRING(arguments[i]); |
68 } | 92 } |
69 return s; | 93 return s; |
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 result += TO_STRING(arguments[i]); | 850 result += TO_STRING(arguments[i]); |
827 } | 851 } |
828 result += TO_STRING(raw[i]); | 852 result += TO_STRING(raw[i]); |
829 } | 853 } |
830 | 854 |
831 return result; | 855 return result; |
832 } | 856 } |
833 | 857 |
834 // ------------------------------------------------------------------- | 858 // ------------------------------------------------------------------- |
835 | 859 |
| 860 // Set the String function and constructor. |
| 861 %FunctionSetPrototype(GlobalString, new GlobalString()); |
| 862 |
| 863 // Set up the constructor property on the String prototype object. |
| 864 %AddNamedProperty( |
| 865 GlobalString.prototype, "constructor", GlobalString, DONT_ENUM); |
| 866 |
836 // Set up the non-enumerable functions on the String object. | 867 // Set up the non-enumerable functions on the String object. |
837 utils.InstallFunctions(GlobalString, DONT_ENUM, [ | 868 utils.InstallFunctions(GlobalString, DONT_ENUM, [ |
838 "fromCharCode", StringFromCharCode, | 869 "fromCharCode", StringFromCharCode, |
839 "fromCodePoint", StringFromCodePoint, | 870 "fromCodePoint", StringFromCodePoint, |
840 "raw", StringRaw | 871 "raw", StringRaw |
841 ]); | 872 ]); |
842 | 873 |
843 // Set up the non-enumerable functions on the String prototype object. | 874 // Set up the non-enumerable functions on the String prototype object. |
844 utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [ | 875 utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [ |
845 "valueOf", StringValueOf, | 876 "valueOf", StringValueOf, |
846 "toString", StringToString, | 877 "toString", StringToString, |
| 878 "charAt", StringCharAtJS, |
| 879 "charCodeAt", StringCharCodeAtJS, |
847 "codePointAt", StringCodePointAt, | 880 "codePointAt", StringCodePointAt, |
848 "concat", StringConcat, | 881 "concat", StringConcat, |
849 "endsWith", StringEndsWith, | 882 "endsWith", StringEndsWith, |
850 "includes", StringIncludes, | 883 "includes", StringIncludes, |
851 "indexOf", StringIndexOf, | 884 "indexOf", StringIndexOf, |
852 "lastIndexOf", StringLastIndexOf, | 885 "lastIndexOf", StringLastIndexOf, |
853 "localeCompare", StringLocaleCompareJS, | 886 "localeCompare", StringLocaleCompareJS, |
854 "match", StringMatchJS, | 887 "match", StringMatchJS, |
855 "normalize", StringNormalize, | 888 "normalize", StringNormalize, |
856 "repeat", StringRepeat, | 889 "repeat", StringRepeat, |
(...skipping 25 matching lines...) Expand all Loading... |
882 "strike", StringStrike, | 915 "strike", StringStrike, |
883 "sub", StringSub, | 916 "sub", StringSub, |
884 "sup", StringSup | 917 "sup", StringSup |
885 ]); | 918 ]); |
886 | 919 |
887 // ------------------------------------------------------------------- | 920 // ------------------------------------------------------------------- |
888 // Exports | 921 // Exports |
889 | 922 |
890 utils.Export(function(to) { | 923 utils.Export(function(to) { |
891 to.ExpandReplacement = ExpandReplacement; | 924 to.ExpandReplacement = ExpandReplacement; |
| 925 to.StringCharAt = StringCharAtJS; |
892 to.StringIndexOf = StringIndexOf; | 926 to.StringIndexOf = StringIndexOf; |
893 to.StringLastIndexOf = StringLastIndexOf; | 927 to.StringLastIndexOf = StringLastIndexOf; |
894 to.StringMatch = StringMatchJS; | 928 to.StringMatch = StringMatchJS; |
895 to.StringReplace = StringReplace; | 929 to.StringReplace = StringReplace; |
896 to.StringSlice = StringSlice; | 930 to.StringSlice = StringSlice; |
897 to.StringSplit = StringSplitJS; | 931 to.StringSplit = StringSplitJS; |
898 to.StringSubstr = StringSubstr; | 932 to.StringSubstr = StringSubstr; |
899 to.StringSubstring = StringSubstring; | 933 to.StringSubstring = StringSubstring; |
900 }); | 934 }); |
901 | 935 |
902 }) | 936 }) |
OLD | NEW |