Match Node 24's node:string_decoder for values known only at run time

This commit is contained in:
Chris Tate
2026-10-29 18:19:38 -05:00
parent 0f684ad25f
commit 77d608e80b
16 changed files with 294 additions and 13 deletions
+31 -2
View File
@@ -8,6 +8,7 @@ const os = require("os");
const { inspect } = require("util");
const hasIntl = true;
const enoughTestMem = require("os").totalmem() > 0x70000000; /* 1.75 Gb */
const isDebug = false;
const isWindows = process.platform === "win32";
const isAIX = os.type() === "AIX";
@@ -102,11 +103,37 @@ function invalidArgTypeHelper(input) {
return ` Received type ${typeof input} (${inspected})`;
}
function spawnPromisified(...args) {
function getArrayBufferViews(buf) {
const { buffer, byteOffset, byteLength } = buf;
const out = [];
const arrayBufferViews = [
Int8Array,
Uint8Array,
Uint8ClampedArray,
Int16Array,
Uint16Array,
Int32Array,
Uint32Array,
Float16Array,
Float32Array,
Float64Array,
BigInt64Array,
BigUint64Array,
DataView,
];
for (const type of arrayBufferViews) {
const { BYTES_PER_ELEMENT = 1 } = type;
if (byteLength % BYTES_PER_ELEMENT === 0)
out.push(new type(buffer, byteOffset, byteLength / BYTES_PER_ELEMENT));
}
return out;
}
function spawnPromisified(command, args, options) {
const { spawn } = require("child_process");
let stderr = "";
let stdout = "";
const child = spawn(...args);
const child = spawn(command, args, options);
child.stderr.setEncoding("utf8");
child.stderr.on("data", (data) => {
stderr += data;
@@ -122,6 +149,7 @@ function spawnPromisified(...args) {
}
module.exports = {
enoughTestMem,
hasIntl,
isAIX,
isDebug,
@@ -133,6 +161,7 @@ module.exports = {
mustNotCall,
skip,
expectWarning,
getArrayBufferViews,
invalidArgTypeHelper,
spawnPromisified,
};