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 // Flags: --harmony-unicode | 5 // Flags: --harmony-unicode |
6 | 6 |
7 var num = 5; | 7 var num = 5; |
8 var str = "str"; | 8 var str = "str"; |
9 function fn() { return "result"; } | 9 function fn() { return "result"; } |
10 var obj = { | 10 var obj = { |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 } | 581 } |
582 assertEquals("test3", tag`test1``test2``test3`); | 582 assertEquals("test3", tag`test1``test2``test3`); |
583 assertEquals([ | 583 assertEquals([ |
584 "tag;test1", | 584 "tag;test1", |
585 "tag;test2", | 585 "tag;test2", |
586 "raw;test3" | 586 "raw;test3" |
587 ], raw); | 587 ], raw); |
588 })(); | 588 })(); |
589 | 589 |
590 | 590 |
| 591 (function testReturnValueAsTagFn() { |
| 592 "use strict"; |
| 593 var i = 0; |
| 594 function makeTag() { |
| 595 return function tag(cs) { |
| 596 var args = Array.prototype.slice.call(arguments, 1); |
| 597 var rcs = []; |
| 598 rcs.raw = cs.map(function(s) { |
| 599 return '!' + s + '!'; |
| 600 }); |
| 601 args.unshift(rcs); |
| 602 return String.raw.apply(null, args); |
| 603 } |
| 604 } |
| 605 assertEquals('!hi!', makeTag()`hi`); |
| 606 assertEquals('!test!0!test!', makeTag()`test${0}test`); |
| 607 assertEquals('!!', makeTag()``); |
| 608 }); |
| 609 |
| 610 |
591 (function testToStringSubstitutions() { | 611 (function testToStringSubstitutions() { |
592 var a = { | 612 var a = { |
593 toString: function() { return "a"; }, | 613 toString: function() { return "a"; }, |
594 valueOf: function() { return "-a-"; } | 614 valueOf: function() { return "-a-"; } |
595 }; | 615 }; |
596 var b = { | 616 var b = { |
597 toString: function() { return "b"; }, | 617 toString: function() { return "b"; }, |
598 valueOf: function() { return "-b-"; } | 618 valueOf: function() { return "-b-"; } |
599 }; | 619 }; |
600 assertEquals("a", `${a}`); | 620 assertEquals("a", `${a}`); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 assertEquals("-1-2-3-", tag`-${subs[0]}-${subs[1]}-${subs[2]}-`); | 692 assertEquals("-1-2-3-", tag`-${subs[0]}-${subs[1]}-${subs[2]}-`); |
673 assertArrayEquals(["get0", "get1", "get2"], log); | 693 assertArrayEquals(["get0", "get1", "get2"], log); |
674 assertArrayEquals([1, 2, 3], tagged); | 694 assertArrayEquals([1, 2, 3], tagged); |
675 | 695 |
676 tagged.length = 0; | 696 tagged.length = 0; |
677 log.length = 0; | 697 log.length = 0; |
678 assertEquals("-1-", tag`-${subs[0]}-`); | 698 assertEquals("-1-", tag`-${subs[0]}-`); |
679 assertArrayEquals(["get0"], log); | 699 assertArrayEquals(["get0"], log); |
680 assertArrayEquals([1], tagged); | 700 assertArrayEquals([1], tagged); |
681 })(); | 701 })(); |
OLD | NEW |