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

Side by Side Diff: src/string.js

Issue 1302533002: Native context: debug.js does not load from js builtins object anymore. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: make importing requirement more explicit Created 5 years, 4 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/symbol.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 (function(global, utils) {
6 6
7 %CheckIsBootstrapping(); 7 %CheckIsBootstrapping();
8 8
9 // ------------------------------------------------------------------- 9 // -------------------------------------------------------------------
10 // Imports 10 // Imports
11 11
12 var ArrayIndexOf;
13 var ArrayJoin;
12 var GlobalRegExp = global.RegExp; 14 var GlobalRegExp = global.RegExp;
13 var GlobalString = global.String; 15 var GlobalString = global.String;
14 var InternalArray = utils.InternalArray; 16 var InternalArray = utils.InternalArray;
15 var InternalPackedArray = utils.InternalPackedArray; 17 var InternalPackedArray = utils.InternalPackedArray;
16
17 var ArrayIndexOf;
18 var ArrayJoin;
19 var MathMax; 18 var MathMax;
20 var MathMin; 19 var MathMin;
21 var RegExpExec; 20 var RegExpExec;
22 var RegExpExecNoTests; 21 var RegExpExecNoTests;
23 var RegExpLastMatchInfo; 22 var RegExpLastMatchInfo;
23 var ToNumber;
24 var ToString;
24 25
25 utils.Import(function(from) { 26 utils.Import(function(from) {
26 ArrayIndexOf = from.ArrayIndexOf; 27 ArrayIndexOf = from.ArrayIndexOf;
27 ArrayJoin = from.ArrayJoin; 28 ArrayJoin = from.ArrayJoin;
28 MathMax = from.MathMax; 29 MathMax = from.MathMax;
29 MathMin = from.MathMin; 30 MathMin = from.MathMin;
30 RegExpExec = from.RegExpExec; 31 RegExpExec = from.RegExpExec;
31 RegExpExecNoTests = from.RegExpExecNoTests; 32 RegExpExecNoTests = from.RegExpExecNoTests;
32 RegExpLastMatchInfo = from.RegExpLastMatchInfo; 33 RegExpLastMatchInfo = from.RegExpLastMatchInfo;
34 ToNumber = from.ToNumber;
35 ToString = from.ToString;
33 }); 36 });
34 37
35 //------------------------------------------------------------------- 38 //-------------------------------------------------------------------
36 39
37 function StringConstructor(x) { 40 function StringConstructor(x) {
38 if (%_ArgumentsLength() == 0) x = ''; 41 if (%_ArgumentsLength() == 0) x = '';
39 if (%_IsConstructCall()) { 42 if (%_IsConstructCall()) {
40 %_SetValueOf(this, TO_STRING_INLINE(x)); 43 %_SetValueOf(this, TO_STRING_INLINE(x));
41 } else { 44 } else {
42 return IS_SYMBOL(x) ? 45 return IS_SYMBOL(x) ?
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 // ECMA-262 section 15.5.4.8 128 // ECMA-262 section 15.5.4.8
126 function StringLastIndexOfJS(pat /* position */) { // length == 1 129 function StringLastIndexOfJS(pat /* position */) { // length == 1
127 CHECK_OBJECT_COERCIBLE(this, "String.prototype.lastIndexOf"); 130 CHECK_OBJECT_COERCIBLE(this, "String.prototype.lastIndexOf");
128 131
129 var sub = TO_STRING_INLINE(this); 132 var sub = TO_STRING_INLINE(this);
130 var subLength = sub.length; 133 var subLength = sub.length;
131 var pat = TO_STRING_INLINE(pat); 134 var pat = TO_STRING_INLINE(pat);
132 var patLength = pat.length; 135 var patLength = pat.length;
133 var index = subLength - patLength; 136 var index = subLength - patLength;
134 if (%_ArgumentsLength() > 1) { 137 if (%_ArgumentsLength() > 1) {
135 var position = $toNumber(%_Arguments(1)); 138 var position = ToNumber(%_Arguments(1));
136 if (!NUMBER_IS_NAN(position)) { 139 if (!NUMBER_IS_NAN(position)) {
137 position = TO_INTEGER(position); 140 position = TO_INTEGER(position);
138 if (position < 0) { 141 if (position < 0) {
139 position = 0; 142 position = 0;
140 } 143 }
141 if (position + patLength < subLength) { 144 if (position + patLength < subLength) {
142 index = position; 145 index = position;
143 } 146 }
144 } 147 }
145 } 148 }
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 CHECK_OBJECT_COERCIBLE(this, "String.prototype.trimRight"); 819 CHECK_OBJECT_COERCIBLE(this, "String.prototype.trimRight");
817 820
818 return %StringTrim(TO_STRING_INLINE(this), false, true); 821 return %StringTrim(TO_STRING_INLINE(this), false, true);
819 } 822 }
820 823
821 824
822 // ECMA-262, section 15.5.3.2 825 // ECMA-262, section 15.5.3.2
823 function StringFromCharCode(code) { 826 function StringFromCharCode(code) {
824 var n = %_ArgumentsLength(); 827 var n = %_ArgumentsLength();
825 if (n == 1) { 828 if (n == 1) {
826 if (!%_IsSmi(code)) code = $toNumber(code); 829 if (!%_IsSmi(code)) code = ToNumber(code);
827 return %_StringCharFromCode(code & 0xffff); 830 return %_StringCharFromCode(code & 0xffff);
828 } 831 }
829 832
830 var one_byte = %NewString(n, NEW_ONE_BYTE_STRING); 833 var one_byte = %NewString(n, NEW_ONE_BYTE_STRING);
831 var i; 834 var i;
832 for (i = 0; i < n; i++) { 835 for (i = 0; i < n; i++) {
833 var code = %_Arguments(i); 836 var code = %_Arguments(i);
834 if (!%_IsSmi(code)) code = $toNumber(code) & 0xffff; 837 if (!%_IsSmi(code)) code = ToNumber(code) & 0xffff;
835 if (code < 0) code = code & 0xffff; 838 if (code < 0) code = code & 0xffff;
836 if (code > 0xff) break; 839 if (code > 0xff) break;
837 %_OneByteSeqStringSetChar(i, code, one_byte); 840 %_OneByteSeqStringSetChar(i, code, one_byte);
838 } 841 }
839 if (i == n) return one_byte; 842 if (i == n) return one_byte;
840 one_byte = %TruncateString(one_byte, i); 843 one_byte = %TruncateString(one_byte, i);
841 844
842 var two_byte = %NewString(n - i, NEW_TWO_BYTE_STRING); 845 var two_byte = %NewString(n - i, NEW_TWO_BYTE_STRING);
843 for (var j = 0; i < n; i++, j++) { 846 for (var j = 0; i < n; i++, j++) {
844 var code = %_Arguments(i); 847 var code = %_Arguments(i);
845 if (!%_IsSmi(code)) code = $toNumber(code) & 0xffff; 848 if (!%_IsSmi(code)) code = ToNumber(code) & 0xffff;
846 %_TwoByteSeqStringSetChar(j, code, two_byte); 849 %_TwoByteSeqStringSetChar(j, code, two_byte);
847 } 850 }
848 return one_byte + two_byte; 851 return one_byte + two_byte;
849 } 852 }
850 853
851 854
852 // ES6 draft, revision 26 (2014-07-18), section B.2.3.2.1 855 // ES6 draft, revision 26 (2014-07-18), section B.2.3.2.1
853 function HtmlEscape(str) { 856 function HtmlEscape(str) {
854 return %_CallFunction(TO_STRING_INLINE(str), /"/g, "&quot;", StringReplace); 857 return %_CallFunction(TO_STRING_INLINE(str), /"/g, "&quot;", StringReplace);
855 } 858 }
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 1084
1082 // ES6 Draft 05-22-2014, section 21.1.2.2 1085 // ES6 Draft 05-22-2014, section 21.1.2.2
1083 function StringFromCodePoint(_) { // length = 1 1086 function StringFromCodePoint(_) { // length = 1
1084 var code; 1087 var code;
1085 var length = %_ArgumentsLength(); 1088 var length = %_ArgumentsLength();
1086 var index; 1089 var index;
1087 var result = ""; 1090 var result = "";
1088 for (index = 0; index < length; index++) { 1091 for (index = 0; index < length; index++) {
1089 code = %_Arguments(index); 1092 code = %_Arguments(index);
1090 if (!%_IsSmi(code)) { 1093 if (!%_IsSmi(code)) {
1091 code = $toNumber(code); 1094 code = ToNumber(code);
1092 } 1095 }
1093 if (code < 0 || code > 0x10FFFF || code !== TO_INTEGER(code)) { 1096 if (code < 0 || code > 0x10FFFF || code !== TO_INTEGER(code)) {
1094 throw MakeRangeError(kInvalidCodePoint, code); 1097 throw MakeRangeError(kInvalidCodePoint, code);
1095 } 1098 }
1096 if (code <= 0xFFFF) { 1099 if (code <= 0xFFFF) {
1097 result += %_StringCharFromCode(code); 1100 result += %_StringCharFromCode(code);
1098 } else { 1101 } else {
1099 code -= 0x10000; 1102 code -= 0x10000;
1100 result += %_StringCharFromCode((code >>> 10) & 0x3FF | 0xD800); 1103 result += %_StringCharFromCode((code >>> 10) & 0x3FF | 0xD800);
1101 result += %_StringCharFromCode(code & 0x3FF | 0xDC00); 1104 result += %_StringCharFromCode(code & 0x3FF | 0xDC00);
1102 } 1105 }
1103 } 1106 }
1104 return result; 1107 return result;
1105 } 1108 }
1106 1109
1107 1110
1108 // ------------------------------------------------------------------- 1111 // -------------------------------------------------------------------
1109 // String methods related to templates 1112 // String methods related to templates
1110 1113
1111 // ES6 Draft 03-17-2015, section 21.1.2.4 1114 // ES6 Draft 03-17-2015, section 21.1.2.4
1112 function StringRaw(callSite) { 1115 function StringRaw(callSite) {
1113 // TODO(caitp): Use rest parameters when implemented 1116 // TODO(caitp): Use rest parameters when implemented
1114 var numberOfSubstitutions = %_ArgumentsLength(); 1117 var numberOfSubstitutions = %_ArgumentsLength();
1115 var cooked = TO_OBJECT(callSite); 1118 var cooked = TO_OBJECT(callSite);
1116 var raw = TO_OBJECT(cooked.raw); 1119 var raw = TO_OBJECT(cooked.raw);
1117 var literalSegments = $toLength(raw.length); 1120 var literalSegments = $toLength(raw.length);
1118 if (literalSegments <= 0) return ""; 1121 if (literalSegments <= 0) return "";
1119 1122
1120 var result = $toString(raw[0]); 1123 var result = ToString(raw[0]);
1121 1124
1122 for (var i = 1; i < literalSegments; ++i) { 1125 for (var i = 1; i < literalSegments; ++i) {
1123 if (i < numberOfSubstitutions) { 1126 if (i < numberOfSubstitutions) {
1124 result += $toString(%_Arguments(i)); 1127 result += ToString(%_Arguments(i));
1125 } 1128 }
1126 result += $toString(raw[i]); 1129 result += ToString(raw[i]);
1127 } 1130 }
1128 1131
1129 return result; 1132 return result;
1130 } 1133 }
1131 1134
1132 // ------------------------------------------------------------------- 1135 // -------------------------------------------------------------------
1133 1136
1134 // Set the String function and constructor. 1137 // Set the String function and constructor.
1135 %SetCode(GlobalString, StringConstructor); 1138 %SetCode(GlobalString, StringConstructor);
1136 %FunctionSetPrototype(GlobalString, new GlobalString()); 1139 %FunctionSetPrototype(GlobalString, new GlobalString());
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 to.StringLastIndexOf = StringLastIndexOfJS; 1204 to.StringLastIndexOf = StringLastIndexOfJS;
1202 to.StringMatch = StringMatchJS; 1205 to.StringMatch = StringMatchJS;
1203 to.StringReplace = StringReplace; 1206 to.StringReplace = StringReplace;
1204 to.StringSlice = StringSlice; 1207 to.StringSlice = StringSlice;
1205 to.StringSplit = StringSplitJS; 1208 to.StringSplit = StringSplitJS;
1206 to.StringSubstr = StringSubstr; 1209 to.StringSubstr = StringSubstr;
1207 to.StringSubstring = StringSubstring; 1210 to.StringSubstring = StringSubstring;
1208 }); 1211 });
1209 1212
1210 }) 1213 })
OLDNEW
« no previous file with comments | « src/runtime.js ('k') | src/symbol.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698