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