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(*): Use rest parameters when implemented | |
arv (Not doing code reviews)
2014/11/18 19:05:27
We always use a name here. The name should be of t
caitp (gmail)
2014/11/18 19:11:54
Done.
| |
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 // ------------------------------------------------------------------- | |
arv (Not doing code reviews)
2014/11/18 19:05:27
skip this line
caitp (gmail)
2014/11/18 19:11:54
Done.
| |
40 | |
41 function ExtendStringForTemplates() { | |
42 %CheckIsBootstrapping(); | |
43 | |
44 // Set up the non-enumerable functions on the String object. | |
45 InstallFunctions($String, DONT_ENUM, $Array( | |
46 "raw", StringRaw | |
47 )); | |
48 } | |
49 | |
50 ExtendStringForTemplates(); | |
OLD | NEW |