1'use strict'; 2 3const common = require('../common'); 4const assert = require('assert'); 5 6function test(arrayBuffer, offset, length) { 7 const uint8Array = new Uint8Array(arrayBuffer, offset, length); 8 for (let i = 0; i < length; i += 1) { 9 uint8Array[i] = 1; 10 } 11 12 const buffer = Buffer.from(arrayBuffer, offset, length); 13 for (let i = 0; i < length; i += 1) { 14 assert.strictEqual(buffer[i], 1); 15 } 16} 17 18const acceptableOOMErrors = [ 19 'Array buffer allocation failed', 20 'Invalid array buffer length', 21]; 22 23const length = 1000; 24const offset = 4294967296; /* 1 << 32 */ 25const size = offset + length; 26let arrayBuffer; 27 28try { 29 arrayBuffer = new ArrayBuffer(size); 30} catch (e) { 31 if (e instanceof RangeError && acceptableOOMErrors.includes(e.message)) 32 common.skip(`Unable to allocate ${size} bytes for ArrayBuffer`); 33 throw e; 34} 35 36test(arrayBuffer, offset, length); 37