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 function GetTemplateCallSite(siteObj, rawStrings) { | 7 function GetTemplateCallSite(siteObj, rawStrings) { |
8 // TODO(caitp): ensure same template callsite is used for subsequent tag calls | 8 // TODO(caitp): ensure same template callsite is used for subsequent tag calls |
9 | 9 |
10 %AddNamedProperty(siteObj, "raw", %ObjectFreeze(rawStrings), | 10 %AddNamedProperty(siteObj, "raw", %ObjectFreeze(rawStrings), |
11 READ_ONLY | DONT_ENUM | DONT_DELETE); | 11 READ_ONLY | DONT_ENUM | DONT_DELETE); |
12 | 12 |
13 return %ObjectFreeze(siteObj); | 13 return %ObjectFreeze(siteObj); |
14 } | 14 } |
| 15 |
| 16 |
| 17 // ES6 Draft 10-14-2014, section 21.1.2.4 |
| 18 function StringRaw(callSite) { |
| 19 // TODO(caitp): Use rest parameters when implemented |
| 20 var numberOfSubstitutions = %_ArgumentsLength(); |
| 21 var cooked = ToObject(callSite); |
| 22 var raw = ToObject(cooked.raw); |
| 23 var literalSegments = ToLength(raw.length); |
| 24 if (literalSegments <= 0) return ""; |
| 25 |
| 26 var result = ToString(raw[0]); |
| 27 |
| 28 for (var i = 1; i < literalSegments; ++i) { |
| 29 if (i < numberOfSubstitutions) { |
| 30 result += ToString(%_Arguments(i)); |
| 31 } |
| 32 result += ToString(raw[i]); |
| 33 } |
| 34 |
| 35 return result; |
| 36 } |
| 37 |
| 38 |
| 39 function ExtendStringForTemplates() { |
| 40 %CheckIsBootstrapping(); |
| 41 |
| 42 // Set up the non-enumerable functions on the String object. |
| 43 InstallFunctions($String, DONT_ENUM, $Array( |
| 44 "raw", StringRaw |
| 45 )); |
| 46 } |
| 47 |
| 48 ExtendStringForTemplates(); |
OLD | NEW |