2015-10-06 11:26:13 +08:00
|
|
|
'use strict';
|
|
|
|
// Flags: --expose-gc
|
|
|
|
|
2016-09-29 02:14:23 +08:00
|
|
|
const common = require('../../common');
|
|
|
|
const binding = require(`./build/${common.buildType}/binding`);
|
2015-10-13 04:08:13 +08:00
|
|
|
|
2016-03-17 09:56:15 +08:00
|
|
|
function check(size, alignment, offset) {
|
2017-01-08 21:19:00 +08:00
|
|
|
let buf = binding.alloc(size, alignment, offset);
|
|
|
|
let slice = buf.slice(size >>> 1);
|
2015-10-13 04:08:13 +08:00
|
|
|
|
|
|
|
buf = null;
|
|
|
|
binding.check(slice);
|
|
|
|
slice = null;
|
2016-04-21 14:05:44 +08:00
|
|
|
global.gc();
|
|
|
|
global.gc();
|
|
|
|
global.gc();
|
2015-10-13 04:08:13 +08:00
|
|
|
}
|
|
|
|
|
2019-12-24 14:24:00 +08:00
|
|
|
// NOTE: If adding more check() test cases,
|
|
|
|
// be sure to not duplicate alignment/offset.
|
|
|
|
// Refs: https://github.com/nodejs/node/issues/31061#issuecomment-568612283
|
|
|
|
|
2016-03-17 09:56:15 +08:00
|
|
|
check(64, 1, 0);
|
|
|
|
|
|
|
|
// Buffers can have weird sizes.
|
2019-12-24 14:24:00 +08:00
|
|
|
check(97, 1, 1);
|
2016-03-17 09:56:15 +08:00
|
|
|
|
|
|
|
// Buffers can be unaligned
|
2016-05-09 14:04:17 +08:00
|
|
|
check(64, 8, 0);
|
2016-03-17 09:56:15 +08:00
|
|
|
check(64, 16, 0);
|
2016-05-09 14:04:17 +08:00
|
|
|
check(64, 8, 1);
|
2016-03-17 09:56:15 +08:00
|
|
|
check(64, 16, 1);
|
2016-05-09 14:04:17 +08:00
|
|
|
check(97, 8, 3);
|
2016-03-17 09:56:15 +08:00
|
|
|
check(97, 16, 3);
|
2019-12-24 14:24:00 +08:00
|
|
|
check(97, 8, 5);
|
|
|
|
check(97, 16, 5);
|
2015-10-13 04:08:13 +08:00
|
|
|
|
|
|
|
// Empty ArrayBuffer does not allocate data, worth checking
|
2019-12-24 14:24:00 +08:00
|
|
|
check(0, 1, 2);
|