| 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 testStrongObjectFreezePropValid() { | |
| 26 "use strict"; | |
| 27 let strongObjects = getStrongObjects(); | |
| 28 | |
| 29 for (let o of strongObjects) { | |
| 30 Object.defineProperty(o, "foo", { configurable: true, writable: true }); | |
| 31 assertDoesNotThrow( | |
| 32 function() { | |
| 33 "use strong"; | |
| 34 Object.defineProperty(o, "foo", {configurable: true, writable: false }); | |
| 35 }); | |
| 36 } | |
| 37 })(); | |
| 38 | |
| 39 (function testStrongObjectFreezePropInvalid() { | |
| 40 "use strict"; | |
| 41 let sloppyObjects = getSloppyObjects(); | |
| 42 let strictObjects = getStrictObjects(); | |
| 43 let strongObjects = getStrongObjects(); | |
| 44 let weakObjects = sloppyObjects.concat(strictObjects); | |
| 45 | |
| 46 for (let o of weakObjects) { | |
| 47 Object.defineProperty(o, "foo", { writable: true }); | |
| 48 assertDoesNotThrow( | |
| 49 function() { | |
| 50 "use strong"; | |
| 51 Object.defineProperty(o, "foo", { writable: false }); | |
| 52 }); | |
| 53 } | |
| 54 for (let o of strongObjects) { | |
| 55 function defProp(o) { | |
| 56 Object.defineProperty(o, "foo", { writable: false }); | |
| 57 } | |
| 58 function defProps(o) { | |
| 59 Object.defineProperties(o, { "foo": { writable: false } }); | |
| 60 } | |
| 61 function freezeProp(o) { | |
| 62 Object.freeze(o); | |
| 63 } | |
| 64 Object.defineProperty(o, "foo", { writable: true }); | |
| 65 for (let func of [defProp, defProps, freezeProp]) { | |
| 66 assertThrows(function(){func(o)}, TypeError); | |
| 67 assertThrows(function(){func(o)}, TypeError); | |
| 68 assertThrows(function(){func(o)}, TypeError); | |
| 69 %OptimizeFunctionOnNextCall(func); | |
| 70 assertThrows(function(){func(o)}, TypeError); | |
| 71 %DeoptimizeFunction(func); | |
| 72 assertThrows(function(){func(o)}, TypeError); | |
| 73 } | |
| 74 } | |
| 75 })(); | |
| OLD | NEW |