Skip to content
Open
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
7 changes: 4 additions & 3 deletions src/bundler/transpiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ pub(crate) fn resolver_bundle_options_subset(
}

impl<'a> Transpiler<'a> {
/// Called by [`init_runtime_state`](../runtime/jsc_hooks.rs)
/// Called by [`bun_runtime_init_runtime_state`](../runtime/jsc_hooks.rs)
/// to write `vm.transpiler`. Builds on:
/// * [`options::BundleOptions::from_api`] — `bun_bundler::options`
/// * [`Resolver::init1`] — `bun_resolver`
Expand All @@ -1177,8 +1177,9 @@ impl<'a> Transpiler<'a> {
/// In-place sibling of [`Self::init`]: builds the `Transpiler` directly into
/// `dst` rather than returning it by value, so callers that already own its
/// final storage — most importantly `VirtualMachine.transpiler`, written by
/// [`init_runtime_state`](../runtime/jsc_hooks.rs) once per VM — avoid the
/// multi-KB `stack temporary → return slot → final home` double `memcpy`.
/// [`bun_runtime_init_runtime_state`](../runtime/jsc_hooks.rs) once per VM —
/// avoid the multi-KB `stack temporary → return slot → final home` double
/// `memcpy`.
///
/// On `Ok(())`, every field of `dst` is initialised. On `Err`, `dst` is
/// untouched (all fallible work happens before the first field write), so the
Expand Down
11 changes: 6 additions & 5 deletions src/http_jsc/websocket_client/WebSocketUpgradeClient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,9 @@ impl<const SSL: bool> HTTPClient<SSL> {
// §Dispatch (cycle-break): `RareData.defaultClientSslCtx()` and
// `RareData.sslCtxCache().getOrCreateOpts()` reach
// `RuntimeState.ssl_ctx_cache` (high-tier `bun_runtime`); routed
// through `RuntimeHooks` so this crate stays below `bun_runtime`.
// through the `bun_runtime_*` link-time externs so this crate stays
// below `bun_runtime`.
let secure_ptr: Option<*mut uws::SslCtx> = if SSL {
let hooks =
bun_jsc::virtual_machine::runtime_hooks().expect("RuntimeHooks not installed");
'brk: {
if let Some(config) = &client_ref.ssl_config {
if config.requires_custom_request_ctx {
Expand All @@ -424,7 +423,7 @@ impl<const SSL: bool> HTTPClient<SSL> {
// SAFETY: `vm_ptr` is the live per-thread VM (caller
// contract); JS thread.
let ctx = unsafe {
(hooks.ssl_ctx_cache_get_or_create)(
bun_jsc::virtual_machine::bun_runtime_ssl_ctx_cache_get_or_create(
vm_ptr,
&config.as_usockets_for_client_verification(),
&mut err,
Expand All @@ -450,7 +449,9 @@ impl<const SSL: bool> HTTPClient<SSL> {
}
}
// SAFETY: `vm_ptr` is the live per-thread VM; JS thread.
Some(unsafe { (hooks.default_client_ssl_ctx)(vm_ptr) })
Some(unsafe {
bun_jsc::virtual_machine::bun_runtime_default_client_ssl_ctx(vm_ptr)
})
}
} else {
None
Expand Down
11 changes: 6 additions & 5 deletions src/js_parser_jsc/Macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use bun_resolver::package_json::{
use crate::expr_jsc::ExprJsc;
use bun_jsc::js_property_iterator::JSPropertyIteratorOptions;
use bun_jsc::virtual_machine::{
InitOptions as VirtualMachineInitOptions, MacroModeGuard, VirtualMachine, runtime_hooks,
InitOptions as VirtualMachineInitOptions, MacroModeGuard, VirtualMachine,
bun_runtime_body_mixin_get_blob,
};
#[allow(deprecated)]
use bun_jsc::{
Expand Down Expand Up @@ -418,7 +419,7 @@ impl Macro {
// The resolver's forward-decl `BundleOptions` does not carry
// `transform_options` (the canonical owner is the bundler's
// `BundleOptions<'a>`), and
// `RuntimeHooks::init_runtime_state` builds the macro VM's
// `bun_runtime_init_runtime_state` builds the macro VM's
// transpiler from a fresh `TransformOptions` value rather than
// borrowing the caller's, so there is nothing to mutate-and-restore
// on `resolver.opts` here. `log`/`env_loader` *are* threaded so the
Expand Down Expand Up @@ -663,11 +664,11 @@ impl<'a> Run<'a> {
// LAYERING: `Response`/`Request` (and their `BodyMixin::
// get_blob_without_call_frame`) live in `bun_runtime::
// webcore`, which depends on this crate. The downcast +
// body-extract is dispatched through `RuntimeHooks` (the
// body-extract is dispatched through the
// `bun_runtime_body_mixin_get_blob` link-time extern (the
// established §Dispatch cycle-break) so the data shapes
// stay in the high tier.
let hooks = runtime_hooks().expect("RuntimeHooks not installed");
if let Some(body_blob) = (hooks.body_mixin_get_blob)(value, self.global)? {
if let Some(body_blob) = bun_runtime_body_mixin_get_blob(value, self.global)? {
return self.run(body_blob);
} else if let Some(resp) = value.as_::<WebCore::Blob>() {
blob_ = Some(resp);
Expand Down
2 changes: 1 addition & 1 deletion src/jsc/AbortSignal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ impl AbortReason {
//
// LAYERING: `EventLoopTimer` + `TimerFlags` live in `bun_event_loop` (lower
// tier). The per-VM timer heap (`Timer::All`) lives in `bun_runtime` (higher
// tier) and is reached through `RuntimeHooks::{timer_insert,timer_remove}` —
// tier) and is reached through `bun_runtime_timer_{insert,remove}` —
// see `VirtualMachine::timer_insert/remove`. C++ only ever sees `*mut Timeout`
// as an opaque token round-tripped through `create`/`run`/`deinit`, so the
// concrete layout is private to Rust; `repr(C)` is here so `offset_of!` is
Expand Down
39 changes: 18 additions & 21 deletions src/jsc/ConsoleObject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,12 +506,10 @@ fn message_with_type_and_level_(
let writer: &mut dyn bun_io::Write = raw_writer;

// LAYERING: `Jest::runner()` lives in `bun_runtime::test_runner` (forward
// dep on the high tier). Dispatch through `RuntimeHooks` instead — the
// high-tier hook checks `Jest.runner` and calls `onBeforePrint()`; no-op
// when `bun test` isn't running or hooks aren't installed.
if let Some(hooks) = crate::virtual_machine::runtime_hooks() {
(hooks.console_on_before_print)();
}
// dep on the high tier). Dispatch through the link-time extern instead —
// the high-tier body checks `Jest.runner` and calls `onBeforePrint()`;
// no-op when `bun test` isn't running.
crate::virtual_machine::bun_runtime_console_on_before_print();

let mut print_length = len;
// Get console depth from CLI options or bunfig, fallback to default.
Expand Down Expand Up @@ -4689,21 +4687,20 @@ pub mod formatter {
// `Response`/`Request`/`Blob`/`S3Client`/`Archive`/`BuildArtifact`/
// `FetchHeaders`/`TimeoutObject`/`ImmediateObject`/`BuildMessage`/
// `ResolveMessage`/Jest asymmetric matchers — all of which live in
// `bun_runtime` (forward-dep). Dispatch through `RuntimeHooks` so
// the high tier owns the downcasts. Hook returns `true` when it
// formatted `value`; otherwise we fall through to the generic
// object printer below.
if let Some(hooks) = crate::virtual_machine::runtime_hooks() {
// The hook only ever
// seeds a `ZigString` that `get_class_name` immediately
// overwrites with JSC-owned bytes, so a shared zero buffer is
// sufficient and keeps 512B off every recursive frame.
static NAME_BUF: [u8; 512] = [0; 512];
let handled =
(hooks.console_print_runtime_object)(self, writer_, value, &NAME_BUF, C)?;
if handled {
return Ok(());
}
// `bun_runtime` (forward-dep). Dispatch through the link-time
// extern so the high tier owns the downcasts. It returns `true`
// when it formatted `value`; otherwise we fall through to the
// generic object printer below.
//
// The hook only ever
// seeds a `ZigString` that `get_class_name` immediately
// overwrites with JSC-owned bytes, so a shared zero buffer is
// sufficient and keeps 512B off every recursive frame.
static NAME_BUF: [u8; 512] = [0; 512];
if crate::virtual_machine::bun_runtime_console_print_runtime_object(
self, writer_, value, &NAME_BUF, C,
)? {
return Ok(());
}

// `DOMFormData` is a C++-backed WebCore type — no `JsClass` derive,
Expand Down
18 changes: 8 additions & 10 deletions src/jsc/Debugger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! compiles against the `bun_jsc` crate's available dependency set.
//! `retroactively_report_discovered_tests` reaches into the `bun:test` runner
//! (`bun_runtime::test_runner`) — a forward-dep cycle — so it dispatches
//! through [`RuntimeHooks::retroactively_report_discovered_tests`].
//! through [`bun_runtime_retroactively_report_discovered_tests`].

use core::cell::Cell;
use core::ffi::{c_int, c_void};
Expand All @@ -15,7 +15,7 @@ use bun_core::String as BunString;
use bun_io::KeepAlive;
use bun_io::posix_event_loop::{AllocatorType, get_vm_ctx};

use crate::virtual_machine::{VirtualMachine, runtime_hooks};
use crate::virtual_machine::{VirtualMachine, bun_runtime_retroactively_report_discovered_tests};
use crate::{self as jsc, CallFrame, JSGlobalObject, ZigException};

bun_core::declare_scope!(debugger, visible);
Expand Down Expand Up @@ -415,7 +415,7 @@ impl Debugger {
pub fn start_js_debugger_thread(other_vm: *mut VirtualMachine) {
// The global allocator is mimalloc and `InitOptions` does not carry
// `allocator`/`env_loader` (those are wired by
// `RuntimeHooks::init_runtime_state`).
// `bun_runtime_init_runtime_state`).
bun_core::Output::Source::configure_named_thread(bun_core::zstr!("Debugger"));
bun_core::scoped_log!(debugger, "startJSDebuggerThread");
jsc::mark_binding();
Expand Down Expand Up @@ -795,13 +795,11 @@ pub fn test_reporter_agent_enable(agent: *mut TestReporterHandle) {
//
// LAYERING: `retroactivelyReportDiscoveredTests` reaches into
// the test runner (`bun_test.DescribeScope`), which lives in `bun_runtime::test_runner`
// — a forward-dep cycle. Dispatched through [`RuntimeHooks`].
if let Some(hooks) = runtime_hooks() {
// SAFETY: `handle` is the live C++ agent just stored above.
unsafe {
(hooks.retroactively_report_discovered_tests)(dbg.test_reporter_agent.handle)
};
}
// — a forward-dep cycle. Dispatched through the link-time extern.
// SAFETY: `handle` is the live C++ agent just stored above.
unsafe {
bun_runtime_retroactively_report_discovered_tests(dbg.test_reporter_agent.handle)
};
}
}

Expand Down
Loading
Loading