Chromium Code Reviews| Index: test/mjsunit/object-freeze.js |
| diff --git a/test/mjsunit/object-freeze.js b/test/mjsunit/object-freeze.js |
| index 5d1f8b7c5b0abb092639c90945c70aec48753a44..23f5af0f0c2c9de4489828fa5f0e628ad5d05d3d 100644 |
| --- a/test/mjsunit/object-freeze.js |
| +++ b/test/mjsunit/object-freeze.js |
| @@ -25,33 +25,20 @@ |
| // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| -// Tests the Object.freeze and Object.isFrozen methods - ES 15.2.3.9 and |
| -// ES 15.2.3.12 |
| +// Tests the Object.freeze and Object.isFrozen methods - ES 19.1.2.5 and |
| +// ES 19.1.2.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); |
| +// Test that we return obj if non-object is passed as argument |
| +var non_objects = new Array(undefined, null, 1, -1, 0, 42.43, Symbol("test")); |
| for (var key in non_objects) { |
| - var exception = false; |
| - try { |
| - Object.freeze(non_objects[key]); |
| - } catch(e) { |
| - exception = true; |
| - assertTrue(/Object.freeze called on non-object/.test(e)); |
| - } |
| - assertTrue(exception); |
| + assertSame(non_objects[key], Object.freeze(non_objects[key])); |
| } |
| +// Test that isFrozen always returns true for non-objects |
| for (var key in non_objects) { |
| - exception = false; |
| - try { |
| - Object.isFrozen(non_objects[key]); |
| - } catch(e) { |
| - exception = true; |
| - assertTrue(/Object.isFrozen called on non-object/.test(e)); |
| - } |
| - assertTrue(exception); |
| + assertTrue(Object.isFrozen(non_objects[key])); |
| } |
| // Test normal data properties. |
| @@ -348,3 +335,64 @@ assertFalse(Object.isFrozen(obj)); |
| Object.freeze(obj); |
| assertTrue(Object.isSealed(obj)); |
| assertTrue(Object.isFrozen(obj)); |
| + |
| + |
| +(function propertiesOfFrozenObjectNotFrozen() { |
|
arv (Not doing code reviews)
2015/03/19 19:38:08
How are these tests related to this CL?
|
| + function Frozen() {} |
| + Object.freeze(Frozen); |
| + assertDoesNotThrow(function() { return new Frozen(); }); |
| + Frozen.prototype.prototypeExists = true; |
| + assertTrue((new Frozen()).prototypeExists); |
| +})(); |
| + |
| + |
| +(function frozenPrototypePreventsPUT() { |
| + // A read-only property on the prototype should prevent a [[Put]] . |
| + function Constructor() {} |
| + Constructor.prototype.foo = 1; |
| + Object.freeze(Constructor.prototype); |
| + var obj = new Constructor(); |
| + obj.foo = 2; |
| + assertSame(1, obj.foo); |
| +})(); |
| + |
| + |
| +(function frozenFunctionSloppy() { |
| + // Check that freezing a function works correctly. |
| + var func = Object.freeze(function foo(){}); |
| + assertTrue(Object.isFrozen(func)); |
| + func.prototype = 42; |
| + assertFalse(func.prototype === 42); |
| + assertFalse(Object.getOwnPropertyDescriptor(func, "prototype").writable); |
| +})(); |
| + |
| + |
| +(function frozenFunctionStrict() { |
| + // Check that freezing a strict function works correctly. |
| + var func = Object.freeze(function foo(){ "use strict"; }); |
| + assertTrue(Object.isFrozen(func)); |
| + func.prototype = 42; |
| + assertFalse(func.prototype === 42); |
| + assertFalse(Object.getOwnPropertyDescriptor(func, "prototype").writable); |
| +})(); |
| + |
| + |
| +(function frozenArrayObject() { |
| + // Check that freezing array objects works correctly. |
| + var array = Object.freeze([0,1,2]); |
| + assertTrue(Object.isFrozen(array)); |
| + array[0] = 3; |
| + assertEquals(0, array[0]); |
| + assertFalse(Object.getOwnPropertyDescriptor(array, "length").writable); |
| +})(); |
| + |
| + |
| +(function frozenArgumentsObject() { |
| + // Check that freezing arguments objects works correctly. |
| + var args = Object.freeze((function(){ return arguments; })(0,1,2)); |
| + assertTrue(Object.isFrozen(args)); |
| + args[0] = 3; |
| + assertEquals(0, args[0]); |
| + assertFalse(Object.getOwnPropertyDescriptor(args, "length").writable); |
| + assertFalse(Object.getOwnPropertyDescriptor(args, "callee").writable); |
| +})(); |