Index: test/mjsunit/strong/object-freeze-property.js |
diff --git a/test/mjsunit/strong/object-freeze-property.js b/test/mjsunit/strong/object-freeze-property.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ded7a0a72cee405aa0118ddce0345575633b0d47 |
--- /dev/null |
+++ b/test/mjsunit/strong/object-freeze-property.js |
@@ -0,0 +1,62 @@ |
+// Copyright 2015 the V8 project authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+// Flags: --strong-mode --allow-natives-syntax |
+ |
+// TODO(conradw): Track implementation of strong bit for other objects, add |
+// tests. |
+ |
+function getSloppyObjects() { |
+ return [(function(){}), ({})]; |
+} |
+ |
+function getStrictObjects() { |
+ "use strict"; |
+ return [(function(){}), ({})]; |
+} |
+ |
+function getStrongObjects() { |
+ "use strong"; |
+// Strong functions can't have properties added to them. |
rossberg
2015/05/22 13:10:28
Nit: indentation
conradw
2015/05/22 14:07:08
Done.
|
+ return [({})]; |
+} |
+ |
+function testStrongObjectFreezeProp() { |
+ "use strict"; |
+ let sloppyObjects = getSloppyObjects(); |
+ let strictObjects = getStrictObjects(); |
+ let strongObjects = getStrongObjects(); |
+ let nonStrongObjects = sloppyObjects.concat(strictObjects); |
rossberg
2015/05/22 13:10:28
Nit: weakObjects
conradw
2015/05/22 14:07:08
Done.
|
+ |
+ for (let o of nonStrongObjects) { |
+ Object.defineProperty(o, "foo", { enumerable:true, writable:true }); |
rossberg
2015/05/22 13:10:28
Nit: why care about enumerable in all these tests?
conradw
2015/05/22 14:07:08
The defineProperties case needs it to work, and I
rossberg
2015/05/22 14:15:29
Actually, I don't understand your use of definePro
conradw
2015/05/27 18:15:45
Fixed now.
|
+ assertDoesNotThrow( |
+ function() { |
+ "use strong"; |
+ Object.defineProperty(o, "foo", { enumerable:true, writable:false }); |
+ }); |
+ } |
+ for (let o of strongObjects) { |
+ let defProp = function(o) { |
rossberg
2015/05/22 13:10:28
Nit: function defProp(o) { (same below)
conradw
2015/05/22 14:07:08
Done.
|
+ Object.defineProperty(o, "foo", { enumerable:true, writable:false }); |
+ }; |
+ let defProps = function(o) { |
+ let props = {}; |
+ Object.defineProperty(props, "foo", { enumerable:true, writable:false }); |
+ Object.defineProperties(o, props); |
+ }; |
+ let freeze = function(o) { Object.freeze(o); }; |
+ Object.defineProperty(o, "foo", { enumerable:true, writable:true }); |
+ for (let func of [defProp, defProps, freeze]) { |
rossberg
2015/05/22 13:10:28
Nit: you can just use OBject.freeze here directly
conradw
2015/05/22 14:07:08
Wanted to give an opportunity for some sort of low
|
+ assertThrows(function(){func(o)}, TypeError); |
+ assertThrows(function(){func(o)}, TypeError); |
+ assertThrows(function(){func(o)}, TypeError); |
+ %OptimizeFunctionOnNextCall(func); |
+ assertThrows(function(){func(o)}, TypeError); |
+ %DeoptimizeFunction(func); |
+ assertThrows(function(){func(o)}, TypeError); |
+ } |
+ } |
+} |
+testStrongObjectFreezeProp(); |