fix more node:stream (#16385)

Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
This commit is contained in:
Meghan Denny
2025-01-16 22:40:39 -08:00
committed by GitHub
parent 6cdcb1c867
commit 2d481e7bcb
143 changed files with 14248 additions and 6394 deletions

View File

@@ -6,6 +6,18 @@ if (!outputDir) {
throw new Error("Missing output directory");
}
const extra_count = NodeErrors.map(x => x.slice(3))
.filter(x => x.length > 0)
.reduce((ac, cv) => ac + cv.length, 0);
const count = NodeErrors.length + extra_count;
if (count > 256) {
// increase size of enum's to have more tags
// src/bun.js/node/types.zig#Encoding
// src/bun.js/bindings/BufferEncodingType.h
throw new Error("NodeError count exceeds u8");
}
let enumHeader = ``;
let listHeader = ``;
let zig = ``;
@@ -18,7 +30,7 @@ enumHeader = `
#include <cstdint>
namespace Bun {
static constexpr size_t NODE_ERROR_COUNT = ${NodeErrors.length};
static constexpr size_t NODE_ERROR_COUNT = ${count};
enum class ErrorCode : uint8_t {
`;
@@ -34,7 +46,7 @@ struct ErrorCodeData {
WTF::ASCIILiteral name;
WTF::ASCIILiteral code;
};
static constexpr ErrorCodeData errors[${NodeErrors.length}] = {
static constexpr ErrorCodeData errors[${count}] = {
`;
zig = `
@@ -71,7 +83,7 @@ pub const Error = enum(u8) {
let i = 0;
let listForUsingNamespace = "";
for (let [code, constructor, name] of NodeErrors) {
for (let [code, constructor, name, ...other_constructors] of NodeErrors) {
if (name == null) name = constructor.name;
enumHeader += ` ${code} = ${i},\n`;
listHeader += ` { JSC::ErrorType::${constructor.name}, "${name}"_s, "${code}"_s },\n`;
@@ -81,6 +93,19 @@ for (let [code, constructor, name] of NodeErrors) {
listForUsingNamespace += ` return .{ .globalThis = globalThis, .args = args };\n`;
listForUsingNamespace += ` }\n`;
i++;
for (const con of other_constructors) {
if (con == null) continue;
if (name == null) name = con.name;
enumHeader += ` ${code}_${con.name} = ${i},\n`;
listHeader += ` { JSC::ErrorType::${con.name}, "${con.name}"_s, "${code}"_s },\n`;
zig += ` ${code}_${con.name} = ${i},\n`;
listForUsingNamespace += ` /// ${name}: ${code} (instanceof ${con.name})\n`;
listForUsingNamespace += ` pub inline fn ${code}_${con.name}(globalThis: *JSC.JSGlobalObject, comptime fmt: [:0]const u8, args: anytype) ErrorBuilder(Error.${code}_${con.name}, fmt, @TypeOf(args)) {\n`;
listForUsingNamespace += ` return .{ .globalThis = globalThis, .args = args };\n`;
listForUsingNamespace += ` }\n`;
i++;
}
}
enumHeader += `