OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --strong-mode |
| 6 |
| 7 "use strict"; |
| 8 |
| 9 function getClass() { |
| 10 class Foo { |
| 11 static get bar() { return 0 } |
| 12 } |
| 13 return Foo; |
| 14 } |
| 15 |
| 16 function getClassExpr() { |
| 17 return (class { static get bar() { return 0 } }); |
| 18 } |
| 19 |
| 20 function getClassStrong() { |
| 21 "use strong"; |
| 22 class Foo { |
| 23 static get bar() { return 0 } |
| 24 } |
| 25 return Foo; |
| 26 } |
| 27 |
| 28 function getClassExprStrong() { |
| 29 "use strong"; |
| 30 return (class { static get bar() { return 0 } }); |
| 31 } |
| 32 |
| 33 function addProperty(o) { |
| 34 o.baz = 1; |
| 35 } |
| 36 |
| 37 function convertPropertyToData(o) { |
| 38 assertTrue(o.hasOwnProperty("bar")); |
| 39 Object.defineProperty(o, "bar", { value: 1 }); |
| 40 } |
| 41 |
| 42 assertDoesNotThrow(function(){addProperty(getClass())}); |
| 43 assertDoesNotThrow(function(){convertPropertyToData(getClass())}); |
| 44 assertDoesNotThrow(function(){addProperty(getClassExpr())}); |
| 45 assertDoesNotThrow(function(){convertPropertyToData(getClassExpr())}); |
| 46 |
| 47 assertThrows(function(){addProperty(getClassStrong())}, TypeError); |
| 48 assertThrows(function(){convertPropertyToData(getClassStrong())}, TypeError); |
| 49 assertThrows(function(){addProperty(getClassExprStrong())}, TypeError); |
| 50 assertThrows(function(){convertPropertyToData(getClassExprStrong())}, |
| 51 TypeError); |
| 52 |
| 53 // Check strong classes don't freeze their parents. |
| 54 (function() { |
| 55 "use strong"; |
| 56 let parent = getClass(); |
| 57 |
| 58 class Foo extends parent { |
| 59 static get bar() { return 0 } |
| 60 } |
| 61 |
| 62 assertThrows(function(){addProperty(Foo)}, TypeError); |
| 63 assertThrows(function(){convertPropertyToData(Foo)}, TypeError); |
| 64 assertDoesNotThrow(function(){addProperty(parent)}); |
| 65 assertDoesNotThrow(function(){convertPropertyToData(parent)}); |
| 66 })(); |
| 67 |
| 68 // Check strong classes don't freeze their children. |
| 69 (function() { |
| 70 let parent = getClassStrong(); |
| 71 |
| 72 class Foo extends parent { |
| 73 static get bar() { return 0 } |
| 74 } |
| 75 |
| 76 assertThrows(function(){addProperty(parent)}, TypeError); |
| 77 assertThrows(function(){convertPropertyToData(parent)}, TypeError); |
| 78 assertDoesNotThrow(function(){addProperty(Foo)}); |
| 79 assertDoesNotThrow(function(){convertPropertyToData(Foo)}); |
| 80 })(); |
OLD | NEW |