Skip to content

Commit

Permalink
Testing the integrity level of non-extensible arrays.
Browse files Browse the repository at this point in the history
  • Loading branch information
iamstolis committed Feb 9, 2025
1 parent 33088c0 commit 4ce91e7
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2025, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
*/

load("assert.js");

[[], new Array(100)].forEach(function (array) {
assertFalse(Object.isSealed(array));
assertFalse(Object.isFrozen(array));

Object.preventExtensions(array);

assertTrue(Object.isSealed(array));
assertFalse(Object.isFrozen(array)); // length is writable still

Object.defineProperty(array, 'length', { writable: false });

assertTrue(Object.isSealed(array));
assertTrue(Object.isFrozen(array));
});

var array = [,42];
Object.preventExtensions(array);
assertFalse(Object.isSealed(array)); // has array[1]
assertFalse(Object.isFrozen(array));
delete array[1];
assertTrue(Object.isSealed(array));
assertFalse(Object.isFrozen(array)); // length is writable still
Object.defineProperty(array, 'length', { length: 2, writable: false });
assertTrue(Object.isSealed(array));
assertTrue(Object.isFrozen(array));

0 comments on commit 4ce91e7

Please sign in to comment.