test/mjsunit/object-seal.js
// Test packed element array built-in functions with seal.
Test packed element array built-in functions with seal.
Test packed element array built - in functions with seal .
function testDoubleSealedArray1(obj) {
  assertTrue(Object.isSealed(obj));
  assertFalse(Object.isFrozen(obj));
  assertTrue(Array.isArray(obj));
  assertThrows(function() { obj.pop(); }, TypeError);
  assertThrows(function() { obj.push(1); }, TypeError);
  assertThrows(function() { obj.shift(); }, TypeError);
  assertThrows(function() { obj.unshift(1); }, TypeError);
  assertThrows(function() { obj.splice(0); }, TypeError);
  assertDoesNotThrow(function() { obj.splice(0, 0); });
  assertEquals(obj.lastIndexOf(1), 1);
  assertEquals(obj.indexOf(undefined), -1);
  assertFalse(obj.includes(Symbol("test")));
  assertTrue(obj.includes(1));
  assertTrue(obj.includes(-1.1));
  assertFalse(obj.includes());
  assertEquals(obj.find(x => x==0), undefined);
  assertEquals(obj.findIndex(x => x==2), 3);
  assertFalse(obj.some(x => typeof x == 'symbol'));
  assertFalse(obj.every(x => x == -1));
  var filteredArray = obj.filter(e => typeof e == "symbol");
  assertEquals(filteredArray.length, 0);
  assertEquals(obj.map(x => x), obj);
  var countPositiveNumber = 0;
  obj.forEach(function(item, index) {
    if (item === 1) {
      countPositiveNumber++;
      assertEquals(index, 1);
    }
  });
  assertEquals(countPositiveNumber, 1);
  assertEquals(obj.length, obj.concat([]).length);
  var iterator = obj.values();
  assertEquals(iterator.next().value, -1.1);
  assertEquals(iterator.next().value, 1);
  var iterator = obj.keys();
  assertEquals(iterator.next().value, 0);
  assertEquals(iterator.next().value, 1);
  var iterator = obj.entries();
  assertEquals(iterator.next().value, [0, -1.1]);
  assertEquals(iterator.next().value, [1, 1]);
  var length = obj.length;
  for (var i = 0; i < length; i++) {
    obj[i] = 'new';
    assertEquals('new', obj[i]);
  }
}
function testDoubleSealedArray1 ( obj ) { assertTrue ( Object . isSealed ( obj ) ) ; assertFalse ( Object . isFrozen ( obj ) ) ; assertTrue ( Array . isArray ( obj ) ) ; assertThrows ( function ( ) { obj . pop ( ) ; } , TypeError ) ; assertThrows ( function ( ) { obj . push ( 1 ) ; } , TypeError ) ; assertThrows ( function ( ) { obj . shift ( ) ; } , TypeError ) ; assertThrows ( function ( ) { obj . unshift ( 1 ) ; } , TypeError ) ; assertThrows ( function ( ) { obj . splice ( 0 ) ; } , TypeError ) ; assertDoesNotThrow ( function ( ) { obj . splice ( 0 , 0 ) ; } ) ; assertEquals ( obj . lastIndexOf ( 1 ) , 1 ) ; assertEquals ( obj . indexOf ( undefined ) , - 1 ) ; assertFalse ( obj . includes ( Symbol ( "test" ) ) ) ; assertTrue ( obj . includes ( 1 ) ) ; assertTrue ( obj . includes ( - 1.1 ) ) ; assertFalse ( obj . includes ( ) ) ; assertEquals ( obj . find ( x => x == 0 ) , undefined ) ; assertEquals ( obj . findIndex ( x => x == 2 ) , 3 ) ; assertFalse ( obj . some ( x => typeof x == 'symbol' ) ) ; assertFalse ( obj . every ( x => x == - 1 ) ) ; var filteredArray = obj . filter ( e => typeof e == "symbol" ) ; assertEquals ( filteredArray . length , 0 ) ; assertEquals ( obj . map ( x => x ) , obj ) ; var countPositiveNumber = 0 ; obj . forEach ( function ( item , index ) { if ( item === 1 ) { countPositiveNumber ++ ; assertEquals ( index , 1 ) ; } } ) ; assertEquals ( countPositiveNumber , 1 ) ; assertEquals ( obj . length , obj . concat ( [ ] ) . length ) ; var iterator = obj . values ( ) ; assertEquals ( iterator . next ( ) . value , - 1.1 ) ; assertEquals ( iterator . next ( ) . value , 1 ) ; var iterator = obj . keys ( ) ; assertEquals ( iterator . next ( ) . value , 0 ) ; assertEquals ( iterator . next ( ) . value , 1 ) ; var iterator = obj . entries ( ) ; assertEquals ( iterator . next ( ) . value , [ 0 , - 1.1 ] ) ; assertEquals ( iterator . next ( ) . value , [ 1 , 1 ] ) ; var length = obj . length ; for ( var i = 0 ; i < length ; i ++ ) { obj [ i ] = 'new' ; assertEquals ( 'new' , obj [ i ] ) ; } }
Test packed element array built-in functions with seal.
Test packed element array built - in functions with seal .
// Verify that the length can't be written by builtins. // Verify search, filter, iterator // Verify that the value can't be written