Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
8 changes: 3 additions & 5 deletions src/ast/transpiler_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,23 @@ bun_dispatch::link_interface! {
pub TranspilerCacheImpl[Jsc] {
fn get(source: &Source, parser_options: NonNull<()>, used_jsx: bool) -> bool;
fn put(output_code: &[u8], sourcemap: &[u8], esm_record: &[u8]);
fn is_disabled() -> bool;
}
}

impl RuntimeTranspilerCache {
/// Build the dispatch handle for the set-once `r#impl` slot.
///
/// Centralises the raw-pointer obligation so the three public entry
/// Centralises the raw-pointer obligation so the two public entry
/// points below stay safe.
/// `this` is always derived from a live `&self` / `&mut self` in those
/// `this` is always derived from a live `&mut self` in those
/// callers and the returned `Copy` handle is consumed immediately, so
/// the `link_interface!` liveness contract (owner valid for every
/// dispatch through the handle) is upheld.
#[inline]
fn handle(kind: TranspilerCacheImplKind, this: *mut Self) -> TranspilerCacheImpl {
// SAFETY: `this` is non-null, aligned, and live for the immediate
// dispatch at every call site (`get`/`put`: `&mut self`-derived with
// write provenance; `is_disabled`: `&self`-derived, impl ignores
// `this`). See `link_interface!` `new()` contract.
// write provenance). See `link_interface!` `new()` contract.
unsafe { TranspilerCacheImpl::new(kind, this) }
}

Expand Down
9 changes: 3 additions & 6 deletions src/bun_alloc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,9 +1033,9 @@ impl WTFStringImplStruct {
}
/// Inline port of `WTF::StringImpl::ref()` (StringImpl.h:1181).
///
/// Cross-language LTO does not inline the `Bun__WTFStringImpl__ref` C++
/// shim into Rust callers (2151 out-of-line `callq` sites in the release
/// binary), so the one-instruction body is reimplemented here.
/// Cross-language LTO did not inline a C++ shim for this into Rust
/// callers (2151 out-of-line `callq` sites in the release binary), so the
/// one-instruction body is reimplemented here.
Comment thread
robobun marked this conversation as resolved.
Outdated
/// `Relaxed` matches WebKit's
/// `m_refCount.fetch_add(s_refCountIncrement, std::memory_order_relaxed)`.
#[inline]
Expand Down Expand Up @@ -1136,9 +1136,6 @@ unsafe extern "C" {
// `destroy` path crosses FFI. `*const` + `unsafe`: it frees the
// allocation backing the pointer.
pub fn Bun__WTFStringImpl__destroy(this: *const WTFStringImplStruct);
// Rust no longer calls these.
pub safe fn Bun__WTFStringImpl__ref(this: &WTFStringImplStruct);
pub fn Bun__WTFStringImpl__deref(this: *const WTFStringImplStruct);
safe fn WTFStringImpl__isThreadSafe(this: &WTFStringImplStruct) -> bool;
safe fn Bun__WTFStringImpl__ensureHash(this: &WTFStringImplStruct);
}
Expand Down
4 changes: 0 additions & 4 deletions src/bun_core/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,6 @@ impl OutputSink {
bun_dispatch::link_interface! {
pub ErrnoNames[Sys] {
fn name(errno: i32) -> Option<&'static str>;
fn max_dense() -> u32;
// Raw Win32 `GetLastError()` code → `SystemErrno` tag name.
// Always `None` on non-Windows.
fn win32_name(code: u32) -> Option<&'static str>;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/bun_core/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1707,8 +1707,8 @@ pub enum ZigStringSlice {
Owned(Vec<u8>),
/// Backed by a WTFStringImpl ref; Drop derefs it. Stored as raw ptr to
/// avoid wtf-module cycle; `wtf::to_latin1_slice` constructs this.
/// `*const` because we only ever hand it back to `Bun__WTFStringImpl__deref`
/// (which takes `*const`); refcount mutation happens on the C++ side.
/// `*const` because Drop only calls `deref()` on it; the refcount itself
/// is interior-mutable.
Comment thread
robobun marked this conversation as resolved.
Outdated
WTF {
string_impl: *const wtf::WTFStringImplStruct,
bytes: RawSlice<u8>,
Expand Down
2 changes: 0 additions & 2 deletions src/bun_core/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5311,8 +5311,6 @@ pub mod perf {
unsafe extern "C" {
/// No preconditions; returns 0/1 based on tracefs availability.
pub safe fn Bun__linux_trace_init() -> core::ffi::c_int;
/// No preconditions.
pub safe fn Bun__linux_trace_close();
pub fn Bun__linux_trace_emit(
event_name: *const core::ffi::c_char,
duration_ns: i64,
Expand Down
9 changes: 0 additions & 9 deletions src/codegen/generate-jssink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ function header() {
void finishCreation(JSC::VM&);
};

JSC_DECLARE_CUSTOM_GETTER(function${name}__getter);

`;
}

Expand Down Expand Up @@ -368,13 +366,6 @@ JSC_DEFINE_HOST_FUNCTION(${name}__unref, (JSC::JSGlobalObject * lexicalGlobalObj

}

JSC_DEFINE_CUSTOM_GETTER(function${name}__getter, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName))
{
Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);

return JSC::JSValue::encode(globalObject->${name}());
}

size_t ${className}::estimatedSize(JSCell* cell, JSC::VM& vm) {
return Base::estimatedSize(cell, vm) + ${className}::memoryCost(uncheckedDowncast<${className}>(cell)->wrapped());
}
Expand Down
63 changes: 14 additions & 49 deletions src/errno/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,41 +375,11 @@ fn system_errno_name(errno: i32) -> Option<&'static str> {
}
}

/// Length of the dense `0..MAX` prefix of `SystemErrno` (on Windows, the
/// dense head before the sparse UV_* range). Exposed so bun_core can pre-seed its
/// interned `ERRNO_MAP` without a second hand-written per-OS length table.
#[inline]
const fn system_errno_max_dense() -> u32 {
SystemErrno::MAX as u32
}

/// Raw Win32 `GetLastError()` code → `SystemErrno` tag name, via the
/// `Win32Error` mapping table. Restores `error.code` fidelity (ENOENT,
/// EACCES, ...) for `?`-propagated `std::io::Error`s on Windows. Exists on all
/// platforms because the `ErrnoNames` link-interface is platform-independent;
/// always `None` off Windows.
#[inline]
fn win32_errno_name(code: u32) -> Option<&'static str> {
#[cfg(windows)]
{
let code = u16::try_from(code).ok()?;
SystemErrno::init_win32_error(windows_errno::Win32Error::from_raw(code))
.map(<&'static str>::from)
}
#[cfg(not(windows))]
{
let _ = code;
None
}
}

// Wire the above into bun_core's `ErrnoNames` hook. `()` owner — pure
// stateless functions; the handle is the const `ErrnoNames::SYS`.
// stateless function; the handle is the const `ErrnoNames::SYS`.
bun_core::link_impl_ErrnoNames! {
Sys for () => |_this| {
name(errno) => system_errno_name(errno),
max_dense() => system_errno_max_dense(),
win32_name(code) => win32_errno_name(code),
}
}

Expand Down Expand Up @@ -450,7 +420,7 @@ mod errno_name_tests {
fn errno_table_full_range() {
// Slot 0 is the SUCCESS hole.
assert_eq!(system_errno_name(0), None);
let max = system_errno_max_dense();
let max = SystemErrno::MAX as u32;
for i in 1..max {
let name = system_errno_name(i as i32).expect("dense slot");
assert_eq!(
Expand Down Expand Up @@ -482,25 +452,20 @@ mod errno_name_tests {
assert_eq!(system_errno_name(97), Some("EINTEGRITY"));
}

/// `win32_errno_name` translation contract: known `GetLastError()` codes
/// map to POSIX names on Windows, unmapped/out-of-range codes are `None`,
/// and the helper is a constant `None` off Windows.
/// Known `GetLastError()` codes map to POSIX names; unmapped codes are
/// `None`.
Comment thread
robobun marked this conversation as resolved.
Outdated
#[cfg(windows)]
#[test]
fn win32_errno_names() {
#[cfg(windows)]
{
// ERROR_FILE_NOT_FOUND / ERROR_ACCESS_DENIED.
assert_eq!(win32_errno_name(2), Some("ENOENT"));
assert_eq!(win32_errno_name(5), Some("EPERM"));
// Unmapped Win32 code and the `u16::try_from` overflow fallback.
assert_eq!(win32_errno_name(0), None);
assert_eq!(win32_errno_name(u32::MAX), None);
}
#[cfg(not(windows))]
{
assert_eq!(win32_errno_name(2), None);
assert_eq!(win32_errno_name(u32::MAX), None);
}
let name = |code: u16| {
SystemErrno::init_win32_error(windows_errno::Win32Error::from_raw(code))
.map(<&'static str>::from)
};
// ERROR_FILE_NOT_FOUND / ERROR_ACCESS_DENIED.
assert_eq!(name(2), Some("ENOENT"));
assert_eq!(name(5), Some("EPERM"));
assert_eq!(name(0), None);
assert_eq!(name(u16::MAX), None);
}

#[test]
Expand Down
4 changes: 4 additions & 0 deletions src/errno/windows_errno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,10 @@ impl SystemErrnoInit for Win32Error {
}

impl SystemErrno {
/// Length of the dense head of the enum (the sparse `UV_*` range follows).
/// Only the exhaustive round-trip test iterates it; runtime code on Windows
/// validates tags through the `init_*` constructors instead.
Comment thread
robobun marked this conversation as resolved.
Outdated
#[cfg(test)]
pub(crate) const MAX: usize = 138;

/// Windows' libuv-mapped errno set spells this `ENOTSUP`; alias the POSIX
Expand Down
5 changes: 0 additions & 5 deletions src/event_loop/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,12 @@ pub use any_event_loop::{
bun_dispatch::link_interface! {
pub JsEventLoop[Jsc] {
fn iteration_number() -> u64;
fn file_polls() -> *mut bun_io::file_poll::Store;
fn put_file_poll(poll: *mut bun_io::FilePoll, was_ever_registered: bool);
fn uws_loop() -> *mut bun_uws::Loop;
fn pipe_read_buffer() -> *mut [u8];
fn tick();
fn auto_tick();
fn auto_tick_active();
fn global_object() -> *mut ();
fn bun_vm() -> *mut ();
fn stdout() -> *mut ();
fn stderr() -> *mut ();
fn enter();
fn exit();
fn enqueue_task(task: Task);
Expand Down
46 changes: 1 addition & 45 deletions src/http_jsc/websocket_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use bun_collections::linear_fifo::DynamicBuffer;
use bun_core::{ZigString, strings};
use bun_http::websocket::{Opcode, WebsocketHeader};
use bun_io::KeepAlive;
use bun_jsc::{self as jsc, GlobalRef, JSGlobalObject, JSValue};
use bun_jsc::{self as jsc, GlobalRef, JSGlobalObject};
use bun_ptr::{AsCtxPtr, ThisPtr};
use bun_uws::{self as uws, NewSocketHandler, SslCtx, us_bun_verify_error_t};
use bun_uws_sys::us_socket_t;
Expand Down Expand Up @@ -1357,43 +1357,6 @@ impl<const SSL: bool> WebSocket<SSL> {
!tcp.is_closed() && !tcp.is_shutdown()
}

// `extern "C"` entrypoint; `this_ptr` is non-null by C++ contract (see SAFETY comments below).
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub(crate) extern "C" fn write_blob(this_ptr: *mut Self, blob_value: JSValue, op: u8) {
// See write_binary_data() — tunnel.write() can re-enter fail().
// SAFETY: called from C++ with a valid `heap::alloc` pointer; ScopedRef
// bumps the intrusive refcount and derefs on Drop (after `this`'s last
// use, since `this` is declared after the guard).
let _guard = unsafe { bun_ptr::ScopedRef::new(this_ptr) };
// SAFETY: called from C++ with a valid pointer; guarded above.
let this = unsafe { &*this_ptr };

if !this.has_tcp() || op > 0xF {
this.dispatch_abrupt_close(ErrorCode::Ended);
return;
}

// Cast the JSValue to a Blob.
// `bun_jsc::webcore::Blob` is an opaque C-ABI shim (real
// layout lives in `bun_runtime::webcore::Blob`, a higher-tier crate).
// `from_js`/`shared_view` trampoline through extern fns to avoid the
// dep cycle — see `bun_jsc::webcore::Blob` impl block.
let Some(blob) = blob_value.as_::<bun_jsc::webcore::Blob>() else {
this.dispatch_abrupt_close(ErrorCode::Ended);
return;
};
let opcode = Opcode::from_raw(op);
// SAFETY: `as_` returned a live `*mut Blob` owned by the JS heap;
// the JSValue is rooted by the caller for the duration of this call.
let data = unsafe { (*blob).shared_view() };
if data.is_empty() {
let _ = this.send_data(Copy::Bytes(&[]), !this.has_backpressure(), opcode);
return;
}

this.send_frame(Copy::Bytes(data), data.len(), opcode);
}

// `extern "C"` entrypoint; pointers are valid by C++ contract (see SAFETY comments below).
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub(crate) extern "C" fn write_string(this_ptr: *mut Self, str_: *const ZigString, op: u8) {
Expand Down Expand Up @@ -1854,7 +1817,6 @@ macro_rules! export_websocket_client {
init_with_tunnel = $init_with_tunnel:ident,
memory_cost = $memory_cost:ident,
write_binary_data = $write_binary_data:ident,
write_blob = $write_blob:ident,
write_string = $write_string:ident $(,)?
) => {
#[unsafe(no_mangle)]
Expand Down Expand Up @@ -1925,10 +1887,6 @@ macro_rules! export_websocket_client {
WebSocket::<$ssl>::write_binary_data(this, ptr, len, op)
}
#[unsafe(no_mangle)]
pub extern "C" fn $write_blob(this: *mut WebSocket<$ssl>, blob_value: JSValue, op: u8) {
WebSocket::<$ssl>::write_blob(this, blob_value, op)
}
#[unsafe(no_mangle)]
pub extern "C" fn $write_string(
this: *mut WebSocket<$ssl>,
str_: *const ZigString,
Expand All @@ -1949,7 +1907,6 @@ export_websocket_client!(
init_with_tunnel = Bun__WebSocketClient__initWithTunnel,
memory_cost = Bun__WebSocketClient__memoryCost,
write_binary_data = Bun__WebSocketClient__writeBinaryData,
write_blob = Bun__WebSocketClient__writeBlob,
write_string = Bun__WebSocketClient__writeString,
);
export_websocket_client!(
Expand All @@ -1962,7 +1919,6 @@ export_websocket_client!(
init_with_tunnel = Bun__WebSocketClientTLS__initWithTunnel,
memory_cost = Bun__WebSocketClientTLS__memoryCost,
write_binary_data = Bun__WebSocketClientTLS__writeBinaryData,
write_blob = Bun__WebSocketClientTLS__writeBlob,
write_string = Bun__WebSocketClientTLS__writeString,
);

Expand Down
10 changes: 2 additions & 8 deletions src/js/internal/repl/node-inspect.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Shim for Node's `internal/util/inspect` as consumed by the ported
// node:repl / internal/readline stack. getStringWidth/stripVTControlCharacters
// go straight to the native bindings so `require("node:readline")` does not
// pull in the 99 KB internal/util/inspect; inspect/format load it lazily on
// first access (REPL output / completion rendering).
// pull in the 99 KB internal/util/inspect; inspect loads it lazily on first
// access (REPL output / completion rendering).
Comment thread
robobun marked this conversation as resolved.

const stripANSI = Bun.stripANSI;
const nativeStringWidth = $newCppFunction("stringWidth.cpp", "jsFunctionBunStringWidth", 1);
Expand Down Expand Up @@ -31,10 +31,4 @@ export default {
get inspect() {
return load().inspect;
},
get format() {
return load().format;
},
get formatWithOptions() {
return load().formatWithOptions;
},
};
Comment thread
claude[bot] marked this conversation as resolved.
11 changes: 0 additions & 11 deletions src/js/internal/repl/node-shims.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,6 @@ const BuiltinModule = {
// Bare names; completion.js prefixes them with "node:" itself.
return ["test"];
},
exists(id) {
return Module.isBuiltin(id);
},
canBeRequiredByUsers(id) {
return Module.isBuiltin(id);
},
canBeRequiredWithoutScheme(id) {
return Module.isBuiltin(id) && Module.isBuiltin("node:" + id);
},
};

// ---- internal/modules/esm/get_format ----------------------------------------------
Expand Down Expand Up @@ -388,8 +379,6 @@ export default {
// internalBinding('util')
constants: {
ALL_PROPERTIES,
ONLY_ENUMERABLE,
SKIP_STRINGS,
SKIP_SYMBOLS,
},
getOwnNonIndexProperties,
Expand Down
Loading
Loading