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 var $stringCharAt; | 5 var $stringCharAt; |
6 var $stringIndexOf; | 6 var $stringIndexOf; |
7 var $stringSubstring; | 7 var $stringSubstring; |
8 | 8 |
9 (function() { | 9 (function() { |
10 | 10 |
(...skipping 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1084 } else { | 1084 } else { |
1085 code -= 0x10000; | 1085 code -= 0x10000; |
1086 result += %_StringCharFromCode((code >>> 10) & 0x3FF | 0xD800); | 1086 result += %_StringCharFromCode((code >>> 10) & 0x3FF | 0xD800); |
1087 result += %_StringCharFromCode(code & 0x3FF | 0xDC00); | 1087 result += %_StringCharFromCode(code & 0x3FF | 0xDC00); |
1088 } | 1088 } |
1089 } | 1089 } |
1090 return result; | 1090 return result; |
1091 } | 1091 } |
1092 | 1092 |
1093 | 1093 |
| 1094 // ------------------------------------------------------------------- |
| 1095 // String methods related to templates |
| 1096 |
| 1097 // ES6 Draft 03-17-2015, section 21.1.2.4 |
| 1098 function StringRaw(callSite) { |
| 1099 // TODO(caitp): Use rest parameters when implemented |
| 1100 var numberOfSubstitutions = %_ArgumentsLength(); |
| 1101 var cooked = ToObject(callSite); |
| 1102 var raw = ToObject(cooked.raw); |
| 1103 var literalSegments = ToLength(raw.length); |
| 1104 if (literalSegments <= 0) return ""; |
| 1105 |
| 1106 var result = ToString(raw[0]); |
| 1107 |
| 1108 for (var i = 1; i < literalSegments; ++i) { |
| 1109 if (i < numberOfSubstitutions) { |
| 1110 result += ToString(%_Arguments(i)); |
| 1111 } |
| 1112 result += ToString(raw[i]); |
| 1113 } |
| 1114 |
| 1115 return result; |
| 1116 } |
1094 | 1117 |
1095 // ------------------------------------------------------------------- | 1118 // ------------------------------------------------------------------- |
1096 | 1119 |
1097 // Set the String function and constructor. | 1120 // Set the String function and constructor. |
1098 %SetCode(GlobalString, StringConstructor); | 1121 %SetCode(GlobalString, StringConstructor); |
1099 %FunctionSetPrototype(GlobalString, new GlobalString()); | 1122 %FunctionSetPrototype(GlobalString, new GlobalString()); |
1100 | 1123 |
1101 // Set up the constructor property on the String prototype object. | 1124 // Set up the constructor property on the String prototype object. |
1102 %AddNamedProperty( | 1125 %AddNamedProperty( |
1103 GlobalString.prototype, "constructor", GlobalString, DONT_ENUM); | 1126 GlobalString.prototype, "constructor", GlobalString, DONT_ENUM); |
1104 | 1127 |
1105 // Set up the non-enumerable functions on the String object. | 1128 // Set up the non-enumerable functions on the String object. |
1106 InstallFunctions(GlobalString, DONT_ENUM, GlobalArray( | 1129 InstallFunctions(GlobalString, DONT_ENUM, GlobalArray( |
1107 "fromCharCode", StringFromCharCode, | 1130 "fromCharCode", StringFromCharCode, |
1108 "fromCodePoint", StringFromCodePoint | 1131 "fromCodePoint", StringFromCodePoint, |
| 1132 "raw", StringRaw |
1109 )); | 1133 )); |
1110 | 1134 |
1111 // Set up the non-enumerable functions on the String prototype object. | 1135 // Set up the non-enumerable functions on the String prototype object. |
1112 InstallFunctions(GlobalString.prototype, DONT_ENUM, GlobalArray( | 1136 InstallFunctions(GlobalString.prototype, DONT_ENUM, GlobalArray( |
1113 "valueOf", StringValueOf, | 1137 "valueOf", StringValueOf, |
1114 "toString", StringToString, | 1138 "toString", StringToString, |
1115 "charAt", StringCharAtJS, | 1139 "charAt", StringCharAtJS, |
1116 "charCodeAt", StringCharCodeAtJS, | 1140 "charCodeAt", StringCharCodeAtJS, |
1117 "codePointAt", StringCodePointAt, | 1141 "codePointAt", StringCodePointAt, |
1118 "concat", StringConcat, | 1142 "concat", StringConcat, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1152 "strike", StringStrike, | 1176 "strike", StringStrike, |
1153 "sub", StringSub, | 1177 "sub", StringSub, |
1154 "sup", StringSup | 1178 "sup", StringSup |
1155 )); | 1179 )); |
1156 | 1180 |
1157 $stringCharAt = StringCharAtJS; | 1181 $stringCharAt = StringCharAtJS; |
1158 $stringIndexOf = StringIndexOfJS; | 1182 $stringIndexOf = StringIndexOfJS; |
1159 $stringSubstring = StringSubstring; | 1183 $stringSubstring = StringSubstring; |
1160 | 1184 |
1161 })(); | 1185 })(); |
OLD | NEW |