Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: src/string.js

Issue 1144163002: Revert of Use shared container to manage imports/exports. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/runtime.js ('k') | src/string-iterator.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 var $stringCharAt;
6 var $stringIndexOf;
7 var $stringSubstring;
8
9 (function(global, shared, exports) {
6 10
7 %CheckIsBootstrapping(); 11 %CheckIsBootstrapping();
8 12
9 // ------------------------------------------------------------------- 13 // -------------------------------------------------------------------
10 // Imports 14 // Imports
11 15
12 var GlobalRegExp = global.RegExp; 16 var GlobalRegExp = global.RegExp;
13 var GlobalString = global.String; 17 var GlobalString = global.String;
14 var InternalArray = utils.InternalArray; 18 var InternalArray = shared.InternalArray;
15 var InternalPackedArray = utils.InternalPackedArray; 19 var InternalPackedArray = shared.InternalPackedArray;
16
17 var MathMax;
18 var MathMin;
19
20 utils.Import(function(from) {
21 MathMax = from.MathMax;
22 MathMin = from.MathMin;
23 });
24 20
25 //------------------------------------------------------------------- 21 //-------------------------------------------------------------------
26 22
27 function StringConstructor(x) { 23 function StringConstructor(x) {
28 if (%_ArgumentsLength() == 0) x = ''; 24 if (%_ArgumentsLength() == 0) x = '';
29 if (%_IsConstructCall()) { 25 if (%_IsConstructCall()) {
30 %_SetValueOf(this, TO_STRING_INLINE(x)); 26 %_SetValueOf(this, TO_STRING_INLINE(x));
31 } else { 27 } else {
32 return IS_SYMBOL(x) ? 28 return IS_SYMBOL(x) ?
33 %_CallFunction(x, $symbolToString) : TO_STRING_INLINE(x); 29 %_CallFunction(x, $symbolToString) : TO_STRING_INLINE(x);
(...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 } 961 }
966 962
967 var ss = TO_STRING_INLINE(searchString); 963 var ss = TO_STRING_INLINE(searchString);
968 var pos = 0; 964 var pos = 0;
969 if (%_ArgumentsLength() > 1) { 965 if (%_ArgumentsLength() > 1) {
970 pos = %_Arguments(1); // position 966 pos = %_Arguments(1); // position
971 pos = $toInteger(pos); 967 pos = $toInteger(pos);
972 } 968 }
973 969
974 var s_len = s.length; 970 var s_len = s.length;
975 var start = MathMin(MathMax(pos, 0), s_len); 971 var start = $min($max(pos, 0), s_len);
976 var ss_len = ss.length; 972 var ss_len = ss.length;
977 if (ss_len + start > s_len) { 973 if (ss_len + start > s_len) {
978 return false; 974 return false;
979 } 975 }
980 976
981 return %StringIndexOf(s, ss, start) === start; 977 return %StringIndexOf(s, ss, start) === start;
982 } 978 }
983 979
984 980
985 // ES6 draft 04-05-14, section 21.1.3.7 981 // ES6 draft 04-05-14, section 21.1.3.7
986 function StringEndsWith(searchString /* position */) { // length == 1 982 function StringEndsWith(searchString /* position */) { // length == 1
987 CHECK_OBJECT_COERCIBLE(this, "String.prototype.endsWith"); 983 CHECK_OBJECT_COERCIBLE(this, "String.prototype.endsWith");
988 984
989 var s = TO_STRING_INLINE(this); 985 var s = TO_STRING_INLINE(this);
990 986
991 if (IS_REGEXP(searchString)) { 987 if (IS_REGEXP(searchString)) {
992 throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.endsWith"); 988 throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.endsWith");
993 } 989 }
994 990
995 var ss = TO_STRING_INLINE(searchString); 991 var ss = TO_STRING_INLINE(searchString);
996 var s_len = s.length; 992 var s_len = s.length;
997 var pos = s_len; 993 var pos = s_len;
998 if (%_ArgumentsLength() > 1) { 994 if (%_ArgumentsLength() > 1) {
999 var arg = %_Arguments(1); // position 995 var arg = %_Arguments(1); // position
1000 if (!IS_UNDEFINED(arg)) { 996 if (!IS_UNDEFINED(arg)) {
1001 pos = $toInteger(arg); 997 pos = $toInteger(arg);
1002 } 998 }
1003 } 999 }
1004 1000
1005 var end = MathMin(MathMax(pos, 0), s_len); 1001 var end = $min($max(pos, 0), s_len);
1006 var ss_len = ss.length; 1002 var ss_len = ss.length;
1007 var start = end - ss_len; 1003 var start = end - ss_len;
1008 if (start < 0) { 1004 if (start < 0) {
1009 return false; 1005 return false;
1010 } 1006 }
1011 1007
1012 return %StringLastIndexOf(s, ss, start) === start; 1008 return %StringLastIndexOf(s, ss, start) === start;
1013 } 1009 }
1014 1010
1015 1011
1016 // ES6 draft 04-05-14, section 21.1.3.6 1012 // ES6 draft 04-05-14, section 21.1.3.6
1017 function StringIncludes(searchString /* position */) { // length == 1 1013 function StringIncludes(searchString /* position */) { // length == 1
1018 CHECK_OBJECT_COERCIBLE(this, "String.prototype.includes"); 1014 CHECK_OBJECT_COERCIBLE(this, "String.prototype.includes");
1019 1015
1020 var s = TO_STRING_INLINE(this); 1016 var s = TO_STRING_INLINE(this);
1021 1017
1022 if (IS_REGEXP(searchString)) { 1018 if (IS_REGEXP(searchString)) {
1023 throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.includes"); 1019 throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.includes");
1024 } 1020 }
1025 1021
1026 var ss = TO_STRING_INLINE(searchString); 1022 var ss = TO_STRING_INLINE(searchString);
1027 var pos = 0; 1023 var pos = 0;
1028 if (%_ArgumentsLength() > 1) { 1024 if (%_ArgumentsLength() > 1) {
1029 pos = %_Arguments(1); // position 1025 pos = %_Arguments(1); // position
1030 pos = $toInteger(pos); 1026 pos = $toInteger(pos);
1031 } 1027 }
1032 1028
1033 var s_len = s.length; 1029 var s_len = s.length;
1034 var start = MathMin(MathMax(pos, 0), s_len); 1030 var start = $min($max(pos, 0), s_len);
1035 var ss_len = ss.length; 1031 var ss_len = ss.length;
1036 if (ss_len + start > s_len) { 1032 if (ss_len + start > s_len) {
1037 return false; 1033 return false;
1038 } 1034 }
1039 1035
1040 return %StringIndexOf(s, ss, start) !== -1; 1036 return %StringIndexOf(s, ss, start) !== -1;
1041 } 1037 }
1042 1038
1043 1039
1044 // ES6 Draft 05-22-2014, section 21.1.3.3 1040 // ES6 Draft 05-22-2014, section 21.1.3.3
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 "blink", StringBlink, 1165 "blink", StringBlink,
1170 "bold", StringBold, 1166 "bold", StringBold,
1171 "fixed", StringFixed, 1167 "fixed", StringFixed,
1172 "italics", StringItalics, 1168 "italics", StringItalics,
1173 "small", StringSmall, 1169 "small", StringSmall,
1174 "strike", StringStrike, 1170 "strike", StringStrike,
1175 "sub", StringSub, 1171 "sub", StringSub,
1176 "sup", StringSup 1172 "sup", StringSup
1177 ]); 1173 ]);
1178 1174
1179 // ------------------------------------------------------------------- 1175 $stringCharAt = StringCharAtJS;
1180 // Exports 1176 $stringIndexOf = StringIndexOfJS;
1181 1177 $stringSubstring = StringSubstring;
1182 utils.Export(function(to) {
1183 to.StringCharAt = StringCharAtJS;
1184 to.StringIndexOf = StringIndexOfJS;
1185 to.StringSubstring = StringSubstring;
1186 });
1187 1178
1188 }) 1179 })
OLDNEW
« no previous file with comments | « src/runtime.js ('k') | src/string-iterator.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698