1'use strict'; 2// Flags: --expose-gc 3 4const common = require('../../common'); 5const binding = require(`./build/${common.buildType}/binding`); 6 7function check(size, alignment, offset) { 8 let buf = binding.alloc(size, alignment, offset); 9 let slice = buf.slice(size >>> 1); 10 11 buf = null; 12 binding.check(slice); 13 slice = null; 14 global.gc(); 15 global.gc(); 16 global.gc(); 17} 18 19// NOTE: If adding more check() test cases, 20// be sure to not duplicate alignment/offset. 21// Refs: https://github.com/nodejs/node/issues/31061#issuecomment-568612283 22 23check(64, 1, 0); 24 25// Buffers can have weird sizes. 26check(97, 1, 1); 27 28// Buffers can be unaligned 29check(64, 8, 0); 30check(64, 16, 0); 31check(64, 8, 1); 32check(64, 16, 1); 33check(97, 8, 3); 34check(97, 16, 3); 35check(97, 8, 5); 36check(97, 16, 5); 37 38// Empty ArrayBuffer does not allocate data, worth checking 39check(0, 1, 2); 40