Index: test/mjsunit/object-freeze.js |
diff --git a/test/mjsunit/object-freeze.js b/test/mjsunit/object-freeze.js |
index c3a9278bbd9c4629489f143e52cedba78684ddb4..6a177a4441fcc2ecb34a3dc16e07fc101ce267c2 100644 |
--- a/test/mjsunit/object-freeze.js |
+++ b/test/mjsunit/object-freeze.js |
@@ -28,6 +28,7 @@ |
// Tests the Object.freeze and Object.isFrozen methods - ES 15.2.3.9 and |
// ES 15.2.3.12 |
+// Flags: --allow-natives-syntax |
// Test that we throw an error if an object is not passed as argument. |
var non_objects = new Array(undefined, null, 1, -1, 0, 42.43); |
@@ -191,3 +192,64 @@ assertFalse(Object.isFrozen(obj5)); |
// Make sure that Object.freeze returns the frozen object. |
var obj6 = {} |
assertTrue(obj6 === Object.freeze(obj6)) |
+ |
+// Test that the enumerable attribute is unperturbed by freezing. |
+obj = { x: 42, y: 'foo' }; |
+Object.defineProperty(obj, 'y', {enumerable: false}); |
+Object.freeze(obj); |
+desc = Object.getOwnPropertyDescriptor(obj, 'x'); |
+assertTrue(desc.enumerable); |
+desc = Object.getOwnPropertyDescriptor(obj, 'y'); |
+assertFalse(desc.enumerable); |
+ |
+// Fast properties should remain fast |
+obj = { x: 42, y: 'foo' }; |
+assertTrue(%HasFastProperties(obj)); |
+Object.freeze(obj); |
+assertTrue(%HasFastProperties(obj)); |
+ |
+// Frozen objects should share maps where possible |
+obj = { prop1: 1, prop2: 2 }; |
+obj2 = { prop1: 3, prop2: 4 }; |
+assertTrue(%HaveSameMap(obj, obj2)); |
+Object.freeze(obj); |
+Object.freeze(obj2); |
+assertTrue(%HaveSameMap(obj, obj2)); |
+ |
+// Frozen objects should share maps even when they have elements |
+obj = { prop1: 1, prop2: 2, 75: 'foo' }; |
+obj2 = { prop1: 3, prop2: 4, 150: 'bar' }; |
+assertTrue(%HaveSameMap(obj, obj2)); |
+Object.freeze(obj); |
+Object.freeze(obj2); |
+assertTrue(%HaveSameMap(obj, obj2)); |
+ |
+// Setting elements after freezing should not be allowed |
+obj = { prop: 'thing' }; |
+Object.freeze(obj); |
+obj[0] = 'hello'; |
+assertFalse(obj.hasOwnProperty(0)); |
+ |
+// Freezing an object in dictionary mode should work |
+obj = { }; |
+for (var i = 0; i < 100; ++i) { |
+ obj['x' + i] = i; |
+} |
+assertFalse(%HasFastProperties(obj)); |
+Object.freeze(obj); |
+assertFalse(%HasFastProperties(obj)); |
+assertTrue(Object.isFrozen(obj)); |
+assertFalse(Object.isExtensible(obj)); |
+for (var i = 0; i < 100; ++i) { |
+ desc = Object.getOwnPropertyDescriptor(obj, 'x' + i); |
+ assertFalse(desc.writable); |
+ assertFalse(desc.configurable); |
+} |
+ |
+// Freezing arguments should work |
+var func = function(arg) { |
+ Object.freeze(arguments); |
+ assertTrue(Object.isFrozen(arguments)); |
+}; |
+func('hello', 'world'); |
+func('goodbye', 'world'); |