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-templates --harmony-unicode | 5 // Flags: --harmony-templates --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 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
416 "Iñtërnâtiônàlizætiøn\\u2603\\uD83D\\uDCA9", callSites[0].raw[0]); | 416 "Iñtërnâtiônàlizætiøn\\u2603\\uD83D\\uDCA9", callSites[0].raw[0]); |
417 assertEquals("Iñtërnâtiônàlizætiøn☃💩", callSites[1][0]); | 417 assertEquals("Iñtërnâtiônàlizætiøn☃💩", callSites[1][0]); |
418 assertEquals("Iñtërnâtiônàlizætiøn☃💩", callSites[1].raw[0]); | 418 assertEquals("Iñtërnâtiônàlizætiøn☃💩", callSites[1].raw[0]); |
419 })(); | 419 })(); |
420 | 420 |
421 | 421 |
422 (function testExtendedArrayPrototype() { | 422 (function testExtendedArrayPrototype() { |
423 Object.defineProperty(Array.prototype, 0, { | 423 Object.defineProperty(Array.prototype, 0, { |
424 set: function() { | 424 set: function() { |
425 assertUnreachable(); | 425 assertUnreachable(); |
426 } | 426 }, |
427 configurable: true | |
427 }); | 428 }); |
428 function tag(){} | 429 function tag(){} |
429 tag`a${1}b`; | 430 tag`a${1}b`; |
431 delete Array.prototype[0]; | |
430 })(); | 432 })(); |
431 | 433 |
432 | 434 |
433 (function testRawLineNormalization() { | 435 (function testRawLineNormalization() { |
434 function raw0(callSiteObj) { | 436 function raw0(callSiteObj) { |
435 return callSiteObj.raw[0]; | 437 return callSiteObj.raw[0]; |
436 } | 438 } |
437 assertEquals(eval("raw0`\r`"), "\n"); | 439 assertEquals(eval("raw0`\r`"), "\n"); |
438 assertEquals(eval("raw0`\r\n`"), "\n"); | 440 assertEquals(eval("raw0`\r\n`"), "\n"); |
439 assertEquals(eval("raw0`\r\r\n`"), "\n\n"); | 441 assertEquals(eval("raw0`\r\r\n`"), "\n\n"); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
511 // Allowed in sloppy expression | 513 // Allowed in sloppy expression |
512 assertEquals("\x07", `${"\07"}`); | 514 assertEquals("\x07", `${"\07"}`); |
513 | 515 |
514 // Disallowed in template tail | 516 // Disallowed in template tail |
515 assertThrows("`${\"\\07\"}\\07`", SyntaxError); | 517 assertThrows("`${\"\\07\"}\\07`", SyntaxError); |
516 | 518 |
517 // Disallowed in strict expression | 519 // Disallowed in strict expression |
518 assertThrows("`${(function() { \"use strict\"; return \"\\07\"; })()}`", | 520 assertThrows("`${(function() { \"use strict\"; return \"\\07\"; })()}`", |
519 SyntaxError); | 521 SyntaxError); |
520 })(); | 522 })(); |
523 | |
524 | |
525 var global = this; | |
526 (function testCallNew() { | |
527 "use strict"; | |
528 var called = false; | |
529 var calledWith; | |
530 global.log = function(x) { called = true; calledWith = x; } | |
531 | |
532 assertInstanceof(new(Function`log("test")`), Object); | |
533 assertTrue(called); | |
534 assertSame("test", calledWith); | |
535 delete global.log; | |
536 })(); | |
537 | |
538 | |
539 (function testCallNew2() { | |
540 "use strict"; | |
541 var log = []; | |
542 function tag(x) { | |
543 log.push(x); | |
544 if (!(this instanceof tag)) { | |
545 return tag; | |
546 } | |
547 this.x = x === void 0 ? null : x; | |
marja
2015/03/12 11:43:35
What's the added value of storing this.x, since we
caitp (gmail)
2015/03/12 13:34:15
it's distinct because only the one which is actual
| |
548 return this; | |
549 } | |
550 var instance = new tag`x``y``z`; | |
551 assertInstanceof(instance, tag); | |
552 assertSame(tag.prototype, Object.getPrototypeOf(instance)); | |
553 assertEquals([["x"], ["y"], ["z"], undefined], log); | |
554 assertSame(null, instance.x); | |
555 })(); | |
556 | |
557 | |
558 (function testCallResultOfTagFn() { | |
559 "use strict"; | |
560 var i = 0; | |
561 var raw = []; | |
562 function tag(cs) { | |
563 var args = Array.prototype.slice.call(arguments); | |
564 var text = String.raw.apply(null, args); | |
565 if (i++ < 2) { | |
566 raw.push("tag;" + text); | |
567 return tag; | |
568 } | |
569 | |
570 raw.push("raw;" + text); | |
571 return text; | |
572 } | |
573 assertEquals("test3", tag`test1``test2``test3`); | |
574 assertEquals([ | |
575 "tag;test1", | |
576 "tag;test2", | |
577 "raw;test3" | |
578 ], raw); | |
579 })(); | |
arv (Not doing code reviews)
2015/03/12 15:20:02
One more thing we could test would be:
new tag `x
| |
OLD | NEW |