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: --experimental-classes --harmony-classes | 5 // Flags: --experimental-classes --harmony-classes |
6 | 6 |
7 'use strict'; | 7 'use strict'; |
8 | 8 |
9 class Base { | 9 class Base { |
10 constructor(a, b) { | 10 constructor(a, b) { |
(...skipping 16 matching lines...) Expand all Loading... |
27 assertSame(a + b, this.prp); | 27 assertSame(a + b, this.prp); |
28 assertSame(undefined, this.prp1); | 28 assertSame(undefined, this.prp1); |
29 assertFalse(this.hasOwnProperty("prp1")); | 29 assertFalse(this.hasOwnProperty("prp1")); |
30 return this; | 30 return this; |
31 } | 31 } |
32 } | 32 } |
33 | 33 |
34 let b = new Base(1, 2); | 34 let b = new Base(1, 2); |
35 assertSame(3, b.prp); | 35 assertSame(3, b.prp); |
36 | 36 |
| 37 |
37 let s = new Subclass(2, -1); | 38 let s = new Subclass(2, -1); |
38 assertSame(1, s.prp); | 39 assertSame(1, s.prp); |
39 assertSame(undefined, s.prp1); | 40 assertSame(undefined, s.prp1); |
40 assertFalse(s.hasOwnProperty("prp1")); | 41 assertFalse(s.hasOwnProperty("prp1")); |
41 | 42 |
42 class Subclass2 extends Base { | 43 class Subclass2 extends Base { |
43 constructor() { | 44 constructor(x) { |
44 super(1,2); | 45 super(1,2); |
45 | 46 |
| 47 if (x < 0) return; |
| 48 |
46 let called = false; | 49 let called = false; |
47 function tmp() { called = true; return 3; } | 50 function tmp() { called = true; return 3; } |
48 var exn = null; | 51 var exn = null; |
49 try { | 52 try { |
50 super(tmp(),4); | 53 super(tmp(),4); |
51 } catch(e) { exn = e; } | 54 } catch(e) { exn = e; } |
52 assertTrue(exn !== null); | 55 assertTrue(exn !== null); |
53 assertFalse(called); | 56 assertFalse(called); |
54 } | 57 } |
55 } | 58 } |
56 | 59 |
57 new Subclass2(); | 60 var s2 = new Subclass2(1); |
| 61 assertSame(3, s2.prp); |
| 62 |
| 63 var s3 = new Subclass2(-1); |
| 64 assertSame(3, s3.prp); |
| 65 |
| 66 assertThrows(function() { Subclass.call(new Object(), 1, 2); }, TypeError); |
| 67 assertThrows(function() { Base.call(new Object(), 1, 2); }, TypeError); |
OLD | NEW |