Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/install/PackageInstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,14 @@ pub enum Step {

impl Step {
/// "error: failed {s} for package"
pub fn name(self) -> &'static [u8] {
pub const fn name(self) -> &'static str {
match self {
Step::Copyfile | Step::CopyingFiles => b"copying files from cache to destination",
Step::OpeningCacheDir => b"opening cache/package/version dir",
Step::OpeningDestDir => b"opening node_modules/package dir",
Step::Linking => b"linking bins",
Step::LinkingDependency => b"linking dependency/workspace to node_modules",
Step::Patching => b"patching dependency",
Step::Copyfile | Step::CopyingFiles => "copying files from cache to destination",
Step::OpeningCacheDir => "opening cache/package/version dir",
Step::OpeningDestDir => "opening node_modules/package dir",
Step::Linking => "linking bins",
Step::LinkingDependency => "linking dependency/workspace to node_modules",
Step::Patching => "patching dependency",
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/install/PackageInstaller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2005,7 +2005,7 @@ impl<'a> PackageInstaller<'a> {
cause.err,
"failed {} for package <b>{}<r>",
(
bstr::BStr::new(cause.step.name()),
cause.step.name(),
bstr::BStr::new(
self.names[package_id as usize].slice(string_buf!()),
),
Expand Down
20 changes: 10 additions & 10 deletions src/install/lockfile/Package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,16 +334,16 @@ impl PackageField {
PackageField::Scripts,
];

pub fn name(self) -> &'static [u8] {
pub const fn name(self) -> &'static str {
match self {
PackageField::Name => b"name",
PackageField::NameHash => b"name_hash",
PackageField::Resolution => b"resolution",
PackageField::Dependencies => b"dependencies",
PackageField::Resolutions => b"resolutions",
PackageField::Meta => b"meta",
PackageField::Bin => b"bin",
PackageField::Scripts => b"scripts",
PackageField::Name => "name",
PackageField::NameHash => "name_hash",
PackageField::Resolution => "resolution",
PackageField::Dependencies => "dependencies",
PackageField::Resolutions => "resolutions",
PackageField::Meta => "meta",
PackageField::Bin => "bin",
PackageField::Scripts => "scripts",
}
}
}
Expand Down Expand Up @@ -3260,7 +3260,7 @@ pub mod serializer {
bun_output::scoped_log!(
Lockfile,
"save(\"{}\") = {} bytes",
bstr::BStr::new(field.name()),
field.name(),
bytes.len(),
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/install/patch_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ impl PatchTask {
format_args!(
"{} while executing step: {}",
reason.err.name(),
BStr::new(reason.step.name())
reason.step.name()
),
Default::default(),
);
Expand Down
11 changes: 6 additions & 5 deletions src/jsc/ConsoleObject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5137,7 +5137,7 @@ pub mod formatter {
"{}type: {}\"{}\"{}{},{} ",
pf!("<r>"),
pf!("<green>"),
bstr::BStr::new(event_type.label()),
event_type.label(),
pf!("<r>"),
pf!("<d>"),
pf!("<r>")
Expand All @@ -5148,7 +5148,7 @@ pub mod formatter {
"{}type: {}\"{}\"{}{},{}\n",
pf!("<r>"),
pf!("<green>"),
bstr::BStr::new(event_type.label()),
event_type.label(),
pf!("<r>"),
pf!("<d>"),
pf!("<r>")
Expand Down Expand Up @@ -5790,14 +5790,15 @@ pub mod formatter {
if array_buffer.typed_array_type == jsc::JSType::Uint8Array
&& array_buffer.value.is_buffer(self.global_this)
{
b"Buffer"
"Buffer"
} else if array_buffer.typed_array_type == jsc::JSType::ArrayBuffer
&& array_buffer.shared
{
b"SharedArrayBuffer"
"SharedArrayBuffer"
} else {
array_buffer.typed_array_type.typed_array_name()
},
}
.as_bytes(),
);
if slice.is_empty() {
writer.print(format_args!("({}) []", array_buffer.len));
Expand Down
14 changes: 7 additions & 7 deletions src/jsc/EventType.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ impl EventType {
b"open" => EventType::OpenEvent,
};

pub fn label(self) -> &'static [u8] {
pub const fn label(self) -> &'static str {
match self {
Self::Event => b"event",
Self::MessageEvent => b"message",
Self::CloseEvent => b"close",
Self::ErrorEvent => b"error",
Self::OpenEvent => b"open",
_ => b"event",
Self::Event => "event",
Self::MessageEvent => "message",
Self::CloseEvent => "close",
Self::ErrorEvent => "error",
Self::OpenEvent => "open",
_ => "event",
}
}
}
Expand Down
32 changes: 16 additions & 16 deletions src/jsc/JSType.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,23 +596,23 @@ impl JSType {
/// Covers every `is_typed_array_or_array_buffer()` variant + `DataView`.
/// The `_ => "TypedArray"` arm is unreachable for any real
/// `ArrayBuffer.typed_array_type` (always one of the 14).
pub fn typed_array_name(self) -> &'static [u8] {
pub const fn typed_array_name(self) -> &'static str {
match self {
JSType::ArrayBuffer => b"ArrayBuffer",
JSType::Int8Array => b"Int8Array",
JSType::Uint8Array => b"Uint8Array",
JSType::Uint8ClampedArray => b"Uint8ClampedArray",
JSType::Int16Array => b"Int16Array",
JSType::Uint16Array => b"Uint16Array",
JSType::Int32Array => b"Int32Array",
JSType::Uint32Array => b"Uint32Array",
JSType::Float16Array => b"Float16Array",
JSType::Float32Array => b"Float32Array",
JSType::Float64Array => b"Float64Array",
JSType::BigInt64Array => b"BigInt64Array",
JSType::BigUint64Array => b"BigUint64Array",
JSType::DataView => b"DataView",
_ => b"TypedArray",
JSType::ArrayBuffer => "ArrayBuffer",
JSType::Int8Array => "Int8Array",
JSType::Uint8Array => "Uint8Array",
JSType::Uint8ClampedArray => "Uint8ClampedArray",
JSType::Int16Array => "Int16Array",
JSType::Uint16Array => "Uint16Array",
JSType::Int32Array => "Int32Array",
JSType::Uint32Array => "Uint32Array",
JSType::Float16Array => "Float16Array",
JSType::Float32Array => "Float32Array",
JSType::Float64Array => "Float64Array",
JSType::BigInt64Array => "BigInt64Array",
JSType::BigUint64Array => "BigUint64Array",
JSType::DataView => "DataView",
_ => "TypedArray",
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/runtime/api/bun/spawn/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@ pub enum ToSpawnOptsError {
}

impl ToSpawnOptsError {
pub fn to_str(&self) -> &'static [u8] {
pub const fn to_str(&self) -> &'static str {
match self {
Self::StdinUsedAsOut => b"Stdin cannot be used for stdout or stderr",
Self::OutUsedAsStdin => b"Stdout and stderr cannot be used for stdin",
Self::BlobUsedAsOut => b"Blobs are immutable, and cannot be used for stdout/stderr",
Self::StdinUsedAsOut => "Stdin cannot be used for stdout or stderr",
Self::OutUsedAsStdin => "Stdout and stderr cannot be used for stdin",
Self::BlobUsedAsOut => "Blobs are immutable, and cannot be used for stdout/stderr",
Self::UvPipe(_) => panic!("TODO"),
}
}

pub fn throw_js(&self, global: &JSGlobalObject) -> jsc::JsError {
global.throw(format_args!("{}", bstr::BStr::new(self.to_str())))
global.throw(format_args!("{}", self.to_str()))
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/runtime/cli/create/SourceFileProjectGenerator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -984,11 +984,11 @@ impl Tag {
}
}

pub fn label(self) -> &'static [u8] {
pub const fn label(self) -> &'static str {
match self {
Tag::ReactTailwindSpa => b"React + Tailwind",
Tag::ReactSpa => b"React",
Tag::ReactShadcnSpa => b"React + shadcn/ui + Tailwind",
Tag::ReactTailwindSpa => "React + Tailwind",
Tag::ReactSpa => "React",
Tag::ReactShadcnSpa => "React + shadcn/ui + Tailwind",
}
}

Expand Down Expand Up @@ -1051,7 +1051,7 @@ impl Logger {
\x20 <green><b>bun run build<r>\n\
\n\
<blue>Happy bunning! 🐇<r>",
bstr::BStr::new(self.template.label())
self.template.label()
));
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/runtime/cli/init_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,7 @@ impl Template {
bump: &bun_alloc::Arena,
) -> Result<(), Error> {
type Rope = bun_ast::E::Rope;
fields.name = self.name().to_vec();
fields.name = self.name().as_bytes().to_vec();
// PORT NOTE: Zig `alloc.create(Rope)` against the default allocator and
// never frees; allocate in the process-lifetime CLI arena instead.
let key: &mut Rope = crate::cli::cli_arena().alloc(Rope {
Expand Down Expand Up @@ -1489,13 +1489,13 @@ impl Template {
}
}

pub fn name(self) -> &'static [u8] {
pub const fn name(self) -> &'static str {
match self {
Template::Blank => b"bun-blank-template",
Template::TypescriptLibrary => b"bun-typescript-library-template",
Template::ReactBlank => b"bun-react-template",
Template::ReactTailwind => b"bun-react-tailwind-template",
Template::ReactTailwindShadcn => b"bun-react-tailwind-shadcn-template",
Template::Blank => "bun-blank-template",
Template::TypescriptLibrary => "bun-typescript-library-template",
Template::ReactBlank => "bun-react-template",
Template::ReactTailwind => "bun-react-tailwind-template",
Template::ReactTailwindShadcn => "bun-react-tailwind-shadcn-template",
}
}

Expand Down Expand Up @@ -1740,7 +1740,7 @@ impl Template {
b"README.md",
contents,
&[
(b"name", self.name()),
(b"name", self.name().as_bytes()),
(b"bunVersion", Environment::VERSION_STRING.as_bytes()),
],
)
Expand Down
60 changes: 30 additions & 30 deletions src/runtime/ffi/abi_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ pub static ABI_TYPE_LABEL: phf::Map<&'static [u8], ABIType> = phf::phf_map! {

struct AbiRow {
/// C type name for return/decl position (`typename_label`).
c_type: &'static [u8],
c_type: &'static str,
/// C type name for parameter position (`param_typename_label`). Differs
/// from `c_type` only for Uint32T (int32_t — see ffi.ts) and Buffer.
c_param_type: &'static [u8],
c_param_type: &'static str,
/// `(T)` cast prefix emitted by `ToCFormatter` when `exact` is set. Empty
/// when no cast is wanted (Buffer) or the row is unreachable (Void/Napi*).
to_c_cast: &'static str,
Expand All @@ -146,42 +146,42 @@ struct AbiRow {
#[rustfmt::skip]
static ABI_TABLE: [AbiRow; 21] = {
const fn r(
c_type: &'static [u8],
c_param_type: &'static [u8],
c_type: &'static str,
c_param_type: &'static str,
to_c_cast: &'static str,
to_c_macro: Option<&'static str>,
to_js: Option<(&'static str, &'static str)>,
) -> AbiRow {
AbiRow { c_type, c_param_type, to_c_cast, to_c_macro, to_js }
}
[
/* Char */ r(b"char", b"char", "(char)", Some("JSVALUE_TO_INT32("), Some(("INT32_TO_JSVALUE((int32_t)", ")"))),
/* Int8T */ r(b"int8_t", b"int8_t", "(int8_t)", Some("JSVALUE_TO_INT32("), Some(("INT32_TO_JSVALUE((int32_t)", ")"))),
/* Uint8T */ r(b"uint8_t", b"uint8_t", "(uint8_t)", Some("JSVALUE_TO_INT32("), Some(("INT32_TO_JSVALUE((int32_t)", ")"))),
/* Int16T */ r(b"int16_t", b"int16_t", "(int16_t)", Some("JSVALUE_TO_INT32("), Some(("INT32_TO_JSVALUE((int32_t)", ")"))),
/* Uint16T */ r(b"uint16_t", b"uint16_t", "(uint16_t)", Some("JSVALUE_TO_INT32("), Some(("INT32_TO_JSVALUE((int32_t)", ")"))),
/* Int32T */ r(b"int32_t", b"int32_t", "(int32_t)", Some("JSVALUE_TO_INT32("), Some(("INT32_TO_JSVALUE((int32_t)", ")"))),
/* Uint32T */ r(b"uint32_t", b"int32_t", "(uint32_t)", Some("JSVALUE_TO_INT32("), Some(("UINT32_TO_JSVALUE(", ")"))),
/* Int64T */ r(b"int64_t", b"int64_t", "(int64_t)", Some("JSVALUE_TO_INT64("), Some(("INT64_TO_JSVALUE_SLOW(JS_GLOBAL_OBJECT, ", ")"))),
/* Uint64T */ r(b"uint64_t", b"uint64_t", "(uint64_t)", Some("JSVALUE_TO_UINT64("), Some(("UINT64_TO_JSVALUE_SLOW(JS_GLOBAL_OBJECT, ", ")"))),
/* Double */ r(b"double", b"double", "(double)", Some("JSVALUE_TO_DOUBLE("), Some(("DOUBLE_TO_JSVALUE(", ")"))),
/* Float */ r(b"float", b"float", "(float)", Some("JSVALUE_TO_FLOAT("), Some(("FLOAT_TO_JSVALUE(", ")"))),
/* Bool */ r(b"bool", b"bool", "(bool)", Some("JSVALUE_TO_BOOL("), Some(("BOOLEAN_TO_JSVALUE(", ")"))),
/* Ptr */ r(b"void*", b"void*", "(void*)", Some("JSVALUE_TO_PTR("), Some(("PTR_TO_JSVALUE(", ")"))),
/* Void */ r(b"void", b"void", "", None, None),
/* CString */ r(b"void*", b"void*", "(void*)", Some("JSVALUE_TO_PTR("), Some(("PTR_TO_JSVALUE(", ")"))),
/* I64Fast */ r(b"int64_t", b"int64_t", "(int64_t)", Some("JSVALUE_TO_INT64("), Some(("INT64_TO_JSVALUE(JS_GLOBAL_OBJECT, (int64_t)", ")"))),
/* U64Fast */ r(b"uint64_t", b"uint64_t", "(uint64_t)", Some("JSVALUE_TO_UINT64("), Some(("UINT64_TO_JSVALUE(JS_GLOBAL_OBJECT, ", ")"))),
/* Function */ r(b"void*", b"void*", "(void*)", Some("JSVALUE_TO_PTR("), Some(("PTR_TO_JSVALUE(", ")"))),
/* NapiEnv */ r(b"napi_env", b"napi_env", "", None, None),
/* NapiValue */ r(b"napi_value", b"napi_value", "", None, Some(("((EncodedJSValue) {.asNapiValue = ", " } )"))),
/* Buffer */ r(b"void*", b"buffer", "", Some("JSVALUE_TO_TYPED_ARRAY_VECTOR("), None),
/* Char */ r("char", "char", "(char)", Some("JSVALUE_TO_INT32("), Some(("INT32_TO_JSVALUE((int32_t)", ")"))),
/* Int8T */ r("int8_t", "int8_t", "(int8_t)", Some("JSVALUE_TO_INT32("), Some(("INT32_TO_JSVALUE((int32_t)", ")"))),
/* Uint8T */ r("uint8_t", "uint8_t", "(uint8_t)", Some("JSVALUE_TO_INT32("), Some(("INT32_TO_JSVALUE((int32_t)", ")"))),
/* Int16T */ r("int16_t", "int16_t", "(int16_t)", Some("JSVALUE_TO_INT32("), Some(("INT32_TO_JSVALUE((int32_t)", ")"))),
/* Uint16T */ r("uint16_t", "uint16_t", "(uint16_t)", Some("JSVALUE_TO_INT32("), Some(("INT32_TO_JSVALUE((int32_t)", ")"))),
/* Int32T */ r("int32_t", "int32_t", "(int32_t)", Some("JSVALUE_TO_INT32("), Some(("INT32_TO_JSVALUE((int32_t)", ")"))),
/* Uint32T */ r("uint32_t", "int32_t", "(uint32_t)", Some("JSVALUE_TO_INT32("), Some(("UINT32_TO_JSVALUE(", ")"))),
/* Int64T */ r("int64_t", "int64_t", "(int64_t)", Some("JSVALUE_TO_INT64("), Some(("INT64_TO_JSVALUE_SLOW(JS_GLOBAL_OBJECT, ", ")"))),
/* Uint64T */ r("uint64_t", "uint64_t", "(uint64_t)", Some("JSVALUE_TO_UINT64("), Some(("UINT64_TO_JSVALUE_SLOW(JS_GLOBAL_OBJECT, ", ")"))),
/* Double */ r("double", "double", "(double)", Some("JSVALUE_TO_DOUBLE("), Some(("DOUBLE_TO_JSVALUE(", ")"))),
/* Float */ r("float", "float", "(float)", Some("JSVALUE_TO_FLOAT("), Some(("FLOAT_TO_JSVALUE(", ")"))),
/* Bool */ r("bool", "bool", "(bool)", Some("JSVALUE_TO_BOOL("), Some(("BOOLEAN_TO_JSVALUE(", ")"))),
/* Ptr */ r("void*", "void*", "(void*)", Some("JSVALUE_TO_PTR("), Some(("PTR_TO_JSVALUE(", ")"))),
/* Void */ r("void", "void", "", None, None),
/* CString */ r("void*", "void*", "(void*)", Some("JSVALUE_TO_PTR("), Some(("PTR_TO_JSVALUE(", ")"))),
/* I64Fast */ r("int64_t", "int64_t", "(int64_t)", Some("JSVALUE_TO_INT64("), Some(("INT64_TO_JSVALUE(JS_GLOBAL_OBJECT, (int64_t)", ")"))),
/* U64Fast */ r("uint64_t", "uint64_t", "(uint64_t)", Some("JSVALUE_TO_UINT64("), Some(("UINT64_TO_JSVALUE(JS_GLOBAL_OBJECT, ", ")"))),
/* Function */ r("void*", "void*", "(void*)", Some("JSVALUE_TO_PTR("), Some(("PTR_TO_JSVALUE(", ")"))),
/* NapiEnv */ r("napi_env", "napi_env", "", None, None),
/* NapiValue */ r("napi_value", "napi_value", "", None, Some(("((EncodedJSValue) {.asNapiValue = ", " } )"))),
/* Buffer */ r("void*", "buffer", "", Some("JSVALUE_TO_TYPED_ARRAY_VECTOR("), None),
]
};

impl ABIType {
#[inline]
fn row(self) -> &'static AbiRow {
const fn row(self) -> &'static AbiRow {
&ABI_TABLE[self as usize]
}
}
Expand Down Expand Up @@ -267,20 +267,20 @@ impl ABIType {
}

pub fn typename(self, writer: &mut impl std::io::Write) -> Result<(), bun_core::Error> {
writer.write_all(self.typename_label())?;
writer.write_all(self.typename_label().as_bytes())?;
Ok(())
}

pub fn typename_label(self) -> &'static [u8] {
pub const fn typename_label(self) -> &'static str {
self.row().c_type
}

pub fn param_typename(self, writer: &mut impl std::io::Write) -> Result<(), bun_core::Error> {
writer.write_all(self.typename_label())?;
writer.write_all(self.typename_label().as_bytes())?;
Ok(())
}
Comment on lines 278 to 281

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Bug: param_typename calls wrong method — will emit incorrect type for Uint32T and Buffer.

This calls typename_label() instead of param_typename_label(). For variants where c_type differs from c_param_type (e.g., Uint32T: "uint32_t" vs "int32_t", Buffer: "void*" vs "buffer"), this produces incorrect C output.

🐛 Proposed fix
     pub fn param_typename(self, writer: &mut impl std::io::Write) -> Result<(), bun_core::Error> {
-        writer.write_all(self.typename_label().as_bytes())?;
+        writer.write_all(self.param_typename_label().as_bytes())?;
         Ok(())
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/runtime/ffi/abi_type.rs` around lines 278 - 281, The param_typename
method is emitting the wrong label by calling typename_label(); update
param_typename to call param_typename_label() instead so it writes the correct C
parameter type for variants like Uint32T and Buffer—locate the
param_typename(&self, writer: &mut impl std::io::Write) -> Result<(),
bun_core::Error> implementation and replace the call to self.typename_label()
with self.param_typename_label() (keeping the writer.write_all(...)? and Ok(())
behavior).


pub fn param_typename_label(self) -> &'static [u8] {
pub const fn param_typename_label(self) -> &'static str {
self.row().c_param_type
}
}
Expand Down
Loading