OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 var log = []; | 5 var log = []; |
6 | 6 |
7 var fake = | 7 var fake = |
8 { | 8 { |
9 pattern: function() { | 9 get source() { |
10 log.push("p"); | 10 log.push("p"); |
11 return { | 11 return { |
12 toString: function() { | 12 toString: function() { |
13 log.push("ps"); | 13 log.push("ps"); |
14 return "pattern"; | 14 return "pattern"; |
15 } | 15 } |
16 }; | 16 }; |
17 }, | 17 }, |
18 flags: function() { | 18 get flags() { |
19 log.push("f"); | 19 log.push("f"); |
20 return { | 20 return { |
21 toString: function() { | 21 toString: function() { |
22 log.push("fs"); | 22 log.push("fs"); |
23 return "flags"; | 23 return "flags"; |
24 } | 24 } |
25 }; | 25 }; |
26 } | 26 } |
27 } | 27 } |
28 | 28 |
29 function testThrows(x) { | 29 function testThrows(x) { |
30 try { | 30 try { |
31 RegExp.prototype.toString.call(x); | 31 RegExp.prototype.toString.call(x); |
32 } catch (e) { | 32 } catch (e) { |
33 assertTrue(/incompatible receiver/.test(e.message)); | 33 assertTrue(/incompatible receiver/.test(e.message)); |
34 return; | 34 return; |
35 } | 35 } |
36 assertUnreachable(); | 36 assertUnreachable(); |
37 } | 37 } |
38 | 38 |
39 testThrows(1); | 39 testThrows(1); |
40 testThrows(null); | 40 testThrows(null); |
41 Number.prototype.pattern = () => "a"; | 41 Number.prototype.source = "a"; |
42 Number.prototype.flags = () => "b"; | 42 Number.prototype.flags = "b"; |
43 testThrows(1); | 43 testThrows(1); |
44 | 44 |
45 assertEquals("/pattern/flags", RegExp.prototype.toString.call(fake)); | 45 assertEquals("/pattern/flags", RegExp.prototype.toString.call(fake)); |
46 assertEquals(["p", "ps", "f", "fs"], log); | 46 assertEquals(["p", "ps", "f", "fs"], log); |
OLD | NEW |