slice-same-memory.js (668B)
1 // |jit-test| skip-if: !this.SharedArrayBuffer 2 3 load(libdir + "asserts.js"); 4 5 var sab = new SharedArrayBuffer(1 * Int32Array.BYTES_PER_ELEMENT); 6 7 // Make a copy, sharing the same memory 8 var sab2 = (setSharedObject(sab), getSharedObject()); 9 10 // Assert it's not the same object 11 assertEq(sab === sab2, false); 12 13 // Assert they're sharing memory 14 new Int32Array(sab)[0] = 0x12345678; 15 assertEq(new Int32Array(sab2)[0], 0x12345678) 16 17 sab.constructor = { 18 [Symbol.species]: function(length) { 19 return sab2; 20 } 21 }; 22 23 // This should throw because the buffer being sliced shares memory with the new 24 // buffer it constructs. 25 assertThrowsInstanceOf(() => sab.slice(), TypeError);