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 (function testStringRawArity() { | 5 (function testStringRawArity() { |
6 assertEquals(1, String.raw.length); | 6 assertEquals(1, String.raw.length); |
7 })(); | 7 })(); |
8 | 8 |
9 | 9 |
10 (function testStringRawCallSiteToObject() { | 10 (function testStringRawCallSiteToObject() { |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 }); | 247 }); |
248 [1, 3, 5].forEach(function(v, i) { | 248 [1, 3, 5].forEach(function(v, i) { |
249 Object.defineProperty(callSiteObj.raw, i, { | 249 Object.defineProperty(callSiteObj.raw, i, { |
250 get: function() { order.push("raw" + v); return v; } | 250 get: function() { order.push("raw" + v); return v; } |
251 }); | 251 }); |
252 }); | 252 }); |
253 | 253 |
254 assertEquals("12345", String.raw(callSiteObj, arg(2), arg(4), arg(6))); | 254 assertEquals("12345", String.raw(callSiteObj, arg(2), arg(4), arg(6))); |
255 assertEquals(["length", "raw1", "arg2", "raw3", "arg4", "raw5"], order); | 255 assertEquals(["length", "raw1", "arg2", "raw3", "arg4", "raw5"], order); |
256 })(); | 256 })(); |
| 257 |
| 258 |
| 259 (function testStringRawToStringSubstitutionsOrder() { |
| 260 var subs = []; |
| 261 var log = []; |
| 262 function stringify(toString) { |
| 263 var valueOf = "_" + toString + "_"; |
| 264 return { |
| 265 toString: function() { return toString; }, |
| 266 valueOf: function() { return valueOf; } |
| 267 }; |
| 268 } |
| 269 function getter(name, value) { |
| 270 return { |
| 271 get: function() { |
| 272 log.push("get" + name); |
| 273 return value; |
| 274 }, |
| 275 set: function(v) { |
| 276 log.push("set" + name); |
| 277 } |
| 278 }; |
| 279 } |
| 280 Object.defineProperties(subs, { |
| 281 0: getter(0, stringify("a")), |
| 282 1: getter(1, stringify("b")), |
| 283 2: getter(2, stringify("c")) |
| 284 }); |
| 285 |
| 286 assertEquals("-a-b-c-", String.raw`-${subs[0]}-${subs[1]}-${subs[2]}-`); |
| 287 assertArrayEquals(["get0", "get1", "get2"], log); |
| 288 |
| 289 log.length = 0; |
| 290 assertEquals("-a-", String.raw`-${subs[0]}-`); |
| 291 assertArrayEquals(["get0"], log); |
| 292 })(); |
OLD | NEW |