OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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: --strong-mode | 5 // Flags: --strong-mode |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 function getClass() { | 9 function getClass() { |
10 class Foo { | 10 class Foo { |
11 static get bar() { return 0 } | 11 static get bar() { return 0 } |
| 12 get bar() { return 0 } |
12 } | 13 } |
13 return Foo; | 14 return Foo; |
14 } | 15 } |
15 | 16 |
16 function getClassExpr() { | 17 function getClassExpr() { |
17 return (class { static get bar() { return 0 } }); | 18 return (class { static get bar() { return 0 } get bar() { return 0 } }); |
18 } | 19 } |
19 | 20 |
20 function getClassStrong() { | 21 function getClassStrong() { |
21 "use strong"; | 22 "use strong"; |
22 class Foo { | 23 class Foo { |
23 static get bar() { return 0 } | 24 static get bar() { return 0 } |
| 25 get bar() { return 0 } |
24 } | 26 } |
25 return Foo; | 27 return Foo; |
26 } | 28 } |
27 | 29 |
28 function getClassExprStrong() { | 30 function getClassExprStrong() { |
29 "use strong"; | 31 "use strong"; |
30 return (class { static get bar() { return 0 } }); | 32 return (class { static get bar() { return 0 } get bar() { return 0 } }); |
31 } | 33 } |
32 | 34 |
33 function addProperty(o) { | 35 function addProperty(o) { |
34 o.baz = 1; | 36 o.baz = 1; |
35 } | 37 } |
36 | 38 |
37 function convertPropertyToData(o) { | 39 function convertPropertyToData(o) { |
38 assertTrue(o.hasOwnProperty("bar")); | 40 assertTrue(o.hasOwnProperty("bar")); |
39 Object.defineProperty(o, "bar", { value: 1 }); | 41 Object.defineProperty(o, "bar", { value: 1 }); |
40 } | 42 } |
41 | 43 |
42 assertDoesNotThrow(function(){addProperty(getClass())}); | 44 function testWeakClass(classFunc) { |
43 assertDoesNotThrow(function(){convertPropertyToData(getClass())}); | 45 assertDoesNotThrow(function(){addProperty(classFunc())}); |
44 assertDoesNotThrow(function(){addProperty(getClassExpr())}); | 46 assertDoesNotThrow(function(){addProperty(classFunc().prototype)}); |
45 assertDoesNotThrow(function(){convertPropertyToData(getClassExpr())}); | 47 assertDoesNotThrow(function(){convertPropertyToData(classFunc())}); |
| 48 assertDoesNotThrow(function(){convertPropertyToData(classFunc().prototype)}); |
| 49 } |
46 | 50 |
47 assertThrows(function(){addProperty(getClassStrong())}, TypeError); | 51 function testStrongClass(classFunc) { |
48 assertThrows(function(){convertPropertyToData(getClassStrong())}, TypeError); | 52 assertThrows(function(){addProperty(classFunc())}, TypeError); |
49 assertThrows(function(){addProperty(getClassExprStrong())}, TypeError); | 53 assertThrows(function(){addProperty(classFunc().prototype)}, TypeError); |
50 assertThrows(function(){convertPropertyToData(getClassExprStrong())}, | 54 assertThrows(function(){convertPropertyToData(classFunc())}, TypeError); |
51 TypeError); | 55 assertThrows(function(){convertPropertyToData(classFunc().prototype)}, |
| 56 TypeError); |
| 57 } |
| 58 |
| 59 testWeakClass(getClass); |
| 60 testWeakClass(getClassExpr); |
| 61 |
| 62 testStrongClass(getClassStrong); |
| 63 testStrongClass(getClassExprStrong); |
52 | 64 |
53 // Check strong classes don't freeze their parents. | 65 // Check strong classes don't freeze their parents. |
54 (function() { | 66 (function() { |
55 "use strong"; | |
56 let parent = getClass(); | 67 let parent = getClass(); |
57 | 68 |
58 class Foo extends parent { | 69 let classFunc = function() { |
59 static get bar() { return 0 } | 70 "use strong"; |
| 71 class Foo extends parent { |
| 72 static get bar() { return 0 } |
| 73 get bar() { return 0 } |
| 74 } |
| 75 return Foo; |
60 } | 76 } |
61 | 77 |
62 assertThrows(function(){addProperty(Foo)}, TypeError); | 78 testStrongClass(classFunc); |
63 assertThrows(function(){convertPropertyToData(Foo)}, TypeError); | |
64 assertDoesNotThrow(function(){addProperty(parent)}); | 79 assertDoesNotThrow(function(){addProperty(parent)}); |
65 assertDoesNotThrow(function(){convertPropertyToData(parent)}); | 80 assertDoesNotThrow(function(){convertPropertyToData(parent)}); |
66 })(); | 81 })(); |
67 | 82 |
68 // Check strong classes don't freeze their children. | 83 // Check strong classes don't freeze their children. |
69 (function() { | 84 (function() { |
70 let parent = getClassStrong(); | 85 let parent = getClassStrong(); |
71 | 86 |
72 class Foo extends parent { | 87 let classFunc = function() { |
73 static get bar() { return 0 } | 88 class Foo extends parent { |
| 89 static get bar() { return 0 } |
| 90 get bar() { return 0 } |
| 91 } |
| 92 return Foo; |
74 } | 93 } |
75 | 94 |
76 assertThrows(function(){addProperty(parent)}, TypeError); | 95 assertThrows(function(){addProperty(parent)}, TypeError); |
77 assertThrows(function(){convertPropertyToData(parent)}, TypeError); | 96 assertThrows(function(){convertPropertyToData(parent)}, TypeError); |
78 assertDoesNotThrow(function(){addProperty(Foo)}); | 97 testWeakClass(classFunc); |
79 assertDoesNotThrow(function(){convertPropertyToData(Foo)}); | |
80 })(); | 98 })(); |
OLD | NEW |