OLD | NEW |
---|---|
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 // This file relies on the fact that the following declaration has been made | 7 // This file relies on the fact that the following declaration has been made |
8 // in runtime.js: | 8 // in runtime.js: |
9 // var $String = global.String; | 9 // var $String = global.String; |
10 // var $Array = global.Array; | 10 // var $Array = global.Array; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 } else { | 164 } else { |
165 code -= 0x10000; | 165 code -= 0x10000; |
166 result += %_StringCharFromCode((code >>> 10) & 0x3FF | 0xD800); | 166 result += %_StringCharFromCode((code >>> 10) & 0x3FF | 0xD800); |
167 result += %_StringCharFromCode(code & 0x3FF | 0xDC00); | 167 result += %_StringCharFromCode(code & 0x3FF | 0xDC00); |
168 } | 168 } |
169 } | 169 } |
170 return result; | 170 return result; |
171 } | 171 } |
172 | 172 |
173 | 173 |
174 // ES6 Draft 10-14-2014, section 21.1.2.4 | |
175 function StringRaw(callSite) { | |
176 // TODO(*): Use rest parameters when implemented | |
177 var substitutions = $Array.prototype.slice.call(arguments, 1); | |
arv (Not doing code reviews)
2014/11/14 22:54:25
This is not safe. Use a c-style for loop using %_A
caitp (gmail)
2014/11/14 23:29:58
Done.
| |
178 var numberOfSubstitutions = substitutions.length; | |
179 var cooked = ToObject(callSite); | |
180 var raw = ToObject(cooked.raw); | |
181 var literalSegments = ToLength(raw.length); | |
182 if (literalSegments <= 0) return ""; | |
183 | |
184 var result = ""; | |
185 var nextIndex = 0; | |
186 | |
187 while (true) { | |
arv (Not doing code reviews)
2014/11/14 22:54:25
for (var nextIndex = 0; ; nextIndex++) {
caitp (gmail)
2014/11/14 23:29:58
I've fixed this slightly differently, so it looks
arv (Not doing code reviews)
2014/11/14 23:42:17
I like your new code better. Easier to grok.
| |
188 var next = ToString(raw[nextIndex]); | |
arv (Not doing code reviews)
2014/11/14 22:54:25
Don't we know that these are all strings?
caitp (gmail)
2014/11/14 23:29:58
The algorithm specifically calls for ToString(), w
arv (Not doing code reviews)
2014/11/14 23:42:17
I guess it doesn't hurt to call ToString on a stri
| |
189 result = result + next; | |
arv (Not doing code reviews)
2014/11/14 22:54:25
+=
caitp (gmail)
2014/11/14 23:29:58
Acknowledged.
| |
190 if (nextIndex + 1 === literalSegments) return result; | |
191 if (nextIndex < numberOfSubstitutions) { | |
192 next = ToString(substitutions[nextIndex]); | |
193 result = result + next; | |
194 } | |
195 nextIndex++; | |
196 } | |
197 } | |
198 | |
199 | |
174 // ------------------------------------------------------------------- | 200 // ------------------------------------------------------------------- |
175 | 201 |
176 function ExtendStringPrototype() { | 202 function ExtendStringPrototype() { |
177 %CheckIsBootstrapping(); | 203 %CheckIsBootstrapping(); |
178 | 204 |
179 // Set up the non-enumerable functions on the String object. | 205 // Set up the non-enumerable functions on the String object. |
180 InstallFunctions($String, DONT_ENUM, $Array( | 206 InstallFunctions($String, DONT_ENUM, $Array( |
181 "fromCodePoint", StringFromCodePoint | 207 "fromCodePoint", StringFromCodePoint, |
208 "raw", StringRaw | |
182 )); | 209 )); |
183 | 210 |
184 // Set up the non-enumerable functions on the String prototype object. | 211 // Set up the non-enumerable functions on the String prototype object. |
185 InstallFunctions($String.prototype, DONT_ENUM, $Array( | 212 InstallFunctions($String.prototype, DONT_ENUM, $Array( |
186 "codePointAt", StringCodePointAt, | 213 "codePointAt", StringCodePointAt, |
187 "contains", StringContains, | 214 "contains", StringContains, |
188 "endsWith", StringEndsWith, | 215 "endsWith", StringEndsWith, |
189 "repeat", StringRepeat, | 216 "repeat", StringRepeat, |
190 "startsWith", StringStartsWith | 217 "startsWith", StringStartsWith |
191 )); | 218 )); |
192 } | 219 } |
193 | 220 |
194 ExtendStringPrototype(); | 221 ExtendStringPrototype(); |
OLD | NEW |