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

Side by Side Diff: src/string.js

Issue 1384443002: [es6] Fix missing bits for full @@toPrimitive support. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove useless cctest. Created 5 years, 2 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
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; 12 var ArrayIndexOf;
13 var ArrayJoin; 13 var ArrayJoin;
14 var GlobalRegExp = global.RegExp; 14 var GlobalRegExp = global.RegExp;
15 var GlobalString = global.String; 15 var GlobalString = global.String;
16 var InternalArray = utils.InternalArray; 16 var InternalArray = utils.InternalArray;
17 var InternalPackedArray = utils.InternalPackedArray; 17 var InternalPackedArray = utils.InternalPackedArray;
18 var RegExpExec; 18 var RegExpExec;
19 var RegExpExecNoTests; 19 var RegExpExecNoTests;
20 var RegExpLastMatchInfo; 20 var RegExpLastMatchInfo;
21 var ToNumber;
22 21
23 utils.Import(function(from) { 22 utils.Import(function(from) {
24 ArrayIndexOf = from.ArrayIndexOf; 23 ArrayIndexOf = from.ArrayIndexOf;
25 ArrayJoin = from.ArrayJoin; 24 ArrayJoin = from.ArrayJoin;
26 RegExpExec = from.RegExpExec; 25 RegExpExec = from.RegExpExec;
27 RegExpExecNoTests = from.RegExpExecNoTests; 26 RegExpExecNoTests = from.RegExpExecNoTests;
28 RegExpLastMatchInfo = from.RegExpLastMatchInfo; 27 RegExpLastMatchInfo = from.RegExpLastMatchInfo;
29 ToNumber = from.ToNumber;
30 }); 28 });
31 29
32 //------------------------------------------------------------------- 30 //-------------------------------------------------------------------
33 31
34 // ECMA-262 section 15.5.4.2 32 // ECMA-262 section 15.5.4.2
35 function StringToString() { 33 function StringToString() {
36 if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) { 34 if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) {
37 throw MakeTypeError(kNotGeneric, 'String.prototype.toString'); 35 throw MakeTypeError(kNotGeneric, 'String.prototype.toString');
38 } 36 }
39 return %_ValueOf(this); 37 return %_ValueOf(this);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 // ECMA-262 section 15.5.4.8 109 // ECMA-262 section 15.5.4.8
112 function StringLastIndexOfJS(pat /* position */) { // length == 1 110 function StringLastIndexOfJS(pat /* position */) { // length == 1
113 CHECK_OBJECT_COERCIBLE(this, "String.prototype.lastIndexOf"); 111 CHECK_OBJECT_COERCIBLE(this, "String.prototype.lastIndexOf");
114 112
115 var sub = TO_STRING(this); 113 var sub = TO_STRING(this);
116 var subLength = sub.length; 114 var subLength = sub.length;
117 var pat = TO_STRING(pat); 115 var pat = TO_STRING(pat);
118 var patLength = pat.length; 116 var patLength = pat.length;
119 var index = subLength - patLength; 117 var index = subLength - patLength;
120 if (%_ArgumentsLength() > 1) { 118 if (%_ArgumentsLength() > 1) {
121 var position = ToNumber(%_Arguments(1)); 119 var position = TO_NUMBER(%_Arguments(1));
122 if (!NUMBER_IS_NAN(position)) { 120 if (!NUMBER_IS_NAN(position)) {
123 position = TO_INTEGER(position); 121 position = TO_INTEGER(position);
124 if (position < 0) { 122 if (position < 0) {
125 position = 0; 123 position = 0;
126 } 124 }
127 if (position + patLength < subLength) { 125 if (position + patLength < subLength) {
128 index = position; 126 index = position;
129 } 127 }
130 } 128 }
131 } 129 }
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 CHECK_OBJECT_COERCIBLE(this, "String.prototype.trimRight"); 795 CHECK_OBJECT_COERCIBLE(this, "String.prototype.trimRight");
798 796
799 return %StringTrim(TO_STRING(this), false, true); 797 return %StringTrim(TO_STRING(this), false, true);
800 } 798 }
801 799
802 800
803 // ECMA-262, section 15.5.3.2 801 // ECMA-262, section 15.5.3.2
804 function StringFromCharCode(code) { 802 function StringFromCharCode(code) {
805 var n = %_ArgumentsLength(); 803 var n = %_ArgumentsLength();
806 if (n == 1) { 804 if (n == 1) {
807 if (!%_IsSmi(code)) code = ToNumber(code); 805 if (!%_IsSmi(code)) code = TO_NUMBER(code);
808 return %_StringCharFromCode(code & 0xffff); 806 return %_StringCharFromCode(code & 0xffff);
809 } 807 }
810 808
811 var one_byte = %NewString(n, NEW_ONE_BYTE_STRING); 809 var one_byte = %NewString(n, NEW_ONE_BYTE_STRING);
812 var i; 810 var i;
813 for (i = 0; i < n; i++) { 811 for (i = 0; i < n; i++) {
814 var code = %_Arguments(i); 812 var code = %_Arguments(i);
815 if (!%_IsSmi(code)) code = ToNumber(code) & 0xffff; 813 if (!%_IsSmi(code)) code = TO_NUMBER(code) & 0xffff;
816 if (code < 0) code = code & 0xffff; 814 if (code < 0) code = code & 0xffff;
817 if (code > 0xff) break; 815 if (code > 0xff) break;
818 %_OneByteSeqStringSetChar(i, code, one_byte); 816 %_OneByteSeqStringSetChar(i, code, one_byte);
819 } 817 }
820 if (i == n) return one_byte; 818 if (i == n) return one_byte;
821 one_byte = %TruncateString(one_byte, i); 819 one_byte = %TruncateString(one_byte, i);
822 820
823 var two_byte = %NewString(n - i, NEW_TWO_BYTE_STRING); 821 var two_byte = %NewString(n - i, NEW_TWO_BYTE_STRING);
824 for (var j = 0; i < n; i++, j++) { 822 for (var j = 0; i < n; i++, j++) {
825 var code = %_Arguments(i); 823 var code = %_Arguments(i);
826 if (!%_IsSmi(code)) code = ToNumber(code) & 0xffff; 824 if (!%_IsSmi(code)) code = TO_NUMBER(code) & 0xffff;
827 %_TwoByteSeqStringSetChar(j, code, two_byte); 825 %_TwoByteSeqStringSetChar(j, code, two_byte);
828 } 826 }
829 return one_byte + two_byte; 827 return one_byte + two_byte;
830 } 828 }
831 829
832 830
833 // ES6 draft, revision 26 (2014-07-18), section B.2.3.2.1 831 // ES6 draft, revision 26 (2014-07-18), section B.2.3.2.1
834 function HtmlEscape(str) { 832 function HtmlEscape(str) {
835 return %_CallFunction(TO_STRING(str), /"/g, "&quot;", StringReplace); 833 return %_CallFunction(TO_STRING(str), /"/g, "&quot;", StringReplace);
836 } 834 }
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 1078
1081 // ES6 Draft 05-22-2014, section 21.1.2.2 1079 // ES6 Draft 05-22-2014, section 21.1.2.2
1082 function StringFromCodePoint(_) { // length = 1 1080 function StringFromCodePoint(_) { // length = 1
1083 var code; 1081 var code;
1084 var length = %_ArgumentsLength(); 1082 var length = %_ArgumentsLength();
1085 var index; 1083 var index;
1086 var result = ""; 1084 var result = "";
1087 for (index = 0; index < length; index++) { 1085 for (index = 0; index < length; index++) {
1088 code = %_Arguments(index); 1086 code = %_Arguments(index);
1089 if (!%_IsSmi(code)) { 1087 if (!%_IsSmi(code)) {
1090 code = ToNumber(code); 1088 code = TO_NUMBER(code);
1091 } 1089 }
1092 if (code < 0 || code > 0x10FFFF || code !== TO_INTEGER(code)) { 1090 if (code < 0 || code > 0x10FFFF || code !== TO_INTEGER(code)) {
1093 throw MakeRangeError(kInvalidCodePoint, code); 1091 throw MakeRangeError(kInvalidCodePoint, code);
1094 } 1092 }
1095 if (code <= 0xFFFF) { 1093 if (code <= 0xFFFF) {
1096 result += %_StringCharFromCode(code); 1094 result += %_StringCharFromCode(code);
1097 } else { 1095 } else {
1098 code -= 0x10000; 1096 code -= 0x10000;
1099 result += %_StringCharFromCode((code >>> 10) & 0x3FF | 0xD800); 1097 result += %_StringCharFromCode((code >>> 10) & 0x3FF | 0xD800);
1100 result += %_StringCharFromCode(code & 0x3FF | 0xDC00); 1098 result += %_StringCharFromCode(code & 0x3FF | 0xDC00);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 to.StringLastIndexOf = StringLastIndexOfJS; 1197 to.StringLastIndexOf = StringLastIndexOfJS;
1200 to.StringMatch = StringMatchJS; 1198 to.StringMatch = StringMatchJS;
1201 to.StringReplace = StringReplace; 1199 to.StringReplace = StringReplace;
1202 to.StringSlice = StringSlice; 1200 to.StringSlice = StringSlice;
1203 to.StringSplit = StringSplitJS; 1201 to.StringSplit = StringSplitJS;
1204 to.StringSubstr = StringSubstr; 1202 to.StringSubstr = StringSubstr;
1205 to.StringSubstring = StringSubstring; 1203 to.StringSubstring = StringSubstring;
1206 }); 1204 });
1207 1205
1208 }) 1206 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698