Skip to content

Commit 998b033

Browse files
committed
fixup! src: fix timing of snapshot serialize callback
1 parent 454caf1 commit 998b033

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Flags: --expose-internals --zero-fill-buffers
2+
// Verifies that Buffer.allocUnsafe() allocates initialized memory under --zero-fill-buffers by
3+
// checking the usage count of the relevant native allocator code path.
4+
'use strict';
5+
6+
const common = require('../common');
7+
if (!common.isDebug) {
8+
common.skip('Only works in debug mode');
9+
}
10+
const { internalBinding } = require('internal/test/binding');
11+
const { getGenericUsageCount } = internalBinding('debug');
12+
const assert = require('assert');
13+
14+
const initialCount = getGenericUsageCount('NodeArrayBufferAllocator.Allocate.ZeroFilled');
15+
const buffer = Buffer.allocUnsafe(Buffer.poolSize + 1);
16+
assert.strictEqual(buffer.every((b) => b === 0), true);
17+
const newCount = getGenericUsageCount('NodeArrayBufferAllocator.Allocate.ZeroFilled');
18+
assert.notStrictEqual(newCount, initialCount);

test/parallel/test-buffer-alloc-unsafe-is-uninitialized.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ const assert = require('assert');
1313

1414
const initialCount = getGenericUsageCount('NodeArrayBufferAllocator.Allocate.Uninitialized');
1515
Buffer.allocUnsafe(Buffer.poolSize + 1);
16+
// We can't reliably check the contents of the buffer here because the OS or memory allocator
17+
// used might zero-fill memory for us, or they might happen to return reused memory that was
18+
// previously used by a process that zero-filled it.
1619
const newCount = getGenericUsageCount('NodeArrayBufferAllocator.Allocate.Uninitialized');
1720
assert.notStrictEqual(newCount, initialCount);

0 commit comments

Comments
 (0)