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 --allow-natives-syntax |
| 6 |
| 7 // TODO(conradw): Track implementation of strong bit for other objects, add |
| 8 // tests. |
| 9 |
| 10 function getSloppyObjects() { |
| 11 return [(function(){}), ({})]; |
| 12 } |
| 13 |
| 14 function getStrictObjects() { |
| 15 "use strict"; |
| 16 return [(function(){}), ({})]; |
| 17 } |
| 18 |
| 19 function getStrongObjects() { |
| 20 "use strong"; |
| 21 // Strong functions can't have properties added to them. |
| 22 return [({})]; |
| 23 } |
| 24 |
| 25 function testStrongObjectFreezeProp() { |
| 26 "use strict"; |
| 27 let sloppyObjects = getSloppyObjects(); |
| 28 let strictObjects = getStrictObjects(); |
| 29 let strongObjects = getStrongObjects(); |
| 30 let weakObjects = sloppyObjects.concat(strictObjects); |
| 31 |
| 32 for (let o of nonStrongObjects) { |
| 33 Object.defineProperty(o, "foo", { enumerable:true, writable:true }); |
| 34 assertDoesNotThrow( |
| 35 function() { |
| 36 "use strong"; |
| 37 Object.defineProperty(o, "foo", { enumerable:true, writable:false }); |
| 38 }); |
| 39 } |
| 40 for (let o of strongObjects) { |
| 41 function defProp(o) { |
| 42 Object.defineProperty(o, "foo", { enumerable:true, writable:false }); |
| 43 } |
| 44 function defProps(o) { |
| 45 let props = {}; |
| 46 Object.defineProperty(props, "foo", { enumerable:true, writable:false }); |
| 47 Object.defineProperties(o, props); |
| 48 } |
| 49 function freezeProp(o) { |
| 50 Object.freeze(o); |
| 51 } |
| 52 Object.defineProperty(o, "foo", { enumerable:true, writable:true }); |
| 53 for (let func of [defProp, defProps, freezeProp]) { |
| 54 assertThrows(function(){func(o)}, TypeError); |
| 55 assertThrows(function(){func(o)}, TypeError); |
| 56 assertThrows(function(){func(o)}, TypeError); |
| 57 %OptimizeFunctionOnNextCall(func); |
| 58 assertThrows(function(){func(o)}, TypeError); |
| 59 %DeoptimizeFunction(func); |
| 60 assertThrows(function(){func(o)}, TypeError); |
| 61 } |
| 62 } |
| 63 } |
| 64 testStrongObjectFreezeProp(); |
OLD | NEW |