Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions src/jsc/ResolvedSource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct ResolvedSource {
pub already_bundled: bool,

// -- Bytecode cache fields --
pub bytecode_cache: *mut u8,
pub bytecode_cache: *const u8,
pub bytecode_cache_size: usize,
pub module_info: *mut c_void,
/// The file path used as the source origin for bytecode cache validation.
Expand All @@ -66,7 +66,7 @@ impl Default for ResolvedSource {
tag: Tag::Javascript,
source_code_needs_deref: true,
already_bundled: false,
bytecode_cache: core::ptr::null_mut(),
bytecode_cache: core::ptr::null(),
bytecode_cache_size: 0,
module_info: core::ptr::null_mut(),
bytecode_origin_path: BunString::empty(),
Expand Down
9 changes: 6 additions & 3 deletions src/jsc/RuntimeTranspilerStore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,12 +1026,15 @@ impl TranspilerJob {
AlreadyBundled::Bytecode(bytes) | AlreadyBundled::BytecodeCjs(bytes) => {
let len = bytes.len();
if len == 0 {
(ptr::null_mut(), 0)
(ptr::null(), 0)
} else {
(bun_core::heap::into_raw(bytes).cast::<u8>(), len)
(
bun_core::heap::into_raw(bytes).cast::<u8>().cast_const(),
len,
)
}
}
_ => (ptr::null_mut(), 0),
_ => (ptr::null(), 0),
};
self.resolved_source = OwnedResolvedSource::from(ResolvedSource {
source_code: String::clone_latin1(&parse_result.source.contents),
Expand Down
4 changes: 3 additions & 1 deletion src/jsc/bindings/ZigSourceProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ Ref<SourceProvider> SourceProvider::create(

auto origin = getSourceOrigin();

Ref<JSC::CachedBytecode> bytecode = JSC::CachedBytecode::create(std::span<uint8_t>(resolvedSource.bytecode_cache, resolvedSource.bytecode_cache_size), destructor, {});
// CachedBytecode::create takes span<uint8_t> but JSC only ever reads it
// (span() returns span<const uint8_t>; Decoder caches into a side map).
Ref<JSC::CachedBytecode> bytecode = JSC::CachedBytecode::create(std::span<uint8_t>(const_cast<uint8_t*>(resolvedSource.bytecode_cache), resolvedSource.bytecode_cache_size), destructor, {});
auto provider = adoptRef(*new SourceProvider(
globalObject->bunVM(),
resolvedSource,
Expand Down
2 changes: 1 addition & 1 deletion src/jsc/bindings/headers-handwritten.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ typedef struct ResolvedSource {
bool needsDeref;
bool already_bundled;
// -- Bytecode cache fields --
uint8_t* bytecode_cache;
const uint8_t* bytecode_cache;
size_t bytecode_cache_size;
void* module_info;
// File path used as source origin for bytecode cache validation.
Expand Down
15 changes: 9 additions & 6 deletions src/runtime/jsc_hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2750,13 +2750,16 @@ fn transpile_source_code_inner(
AlreadyBundled::Bytecode(bytes) | AlreadyBundled::BytecodeCjs(bytes) => {
let len = bytes.len();
if len == 0 {
(core::ptr::null_mut(), 0)
(core::ptr::null(), 0)
} else {
// C++ side becomes the owner.
(bun_core::heap::into_raw(bytes).cast::<u8>(), len)
(
bun_core::heap::into_raw(bytes).cast::<u8>().cast_const(),
len,
)
}
}
_ => (core::ptr::null_mut(), 0),
_ => (core::ptr::null(), 0),
};
return Ok(OwnedResolvedSource::from(ResolvedSource {
source_code: bun_core::String::clone_latin1(&source.contents),
Expand Down Expand Up @@ -3768,14 +3771,14 @@ export default db;
},
source_code_needs_deref: false,
bytecode_cache: if bytecode_len > 0 {
file.bytecode.cast::<u8>()
file.bytecode.as_ptr()
} else {
core::ptr::null_mut()
core::ptr::null()
},
bytecode_cache_size: bytecode_len,
module_info: if module_info_len > 0 {
bun_bundler::analyze_transpiled_module::ModuleInfoDeserialized
::create_from_cached_record(&*file.module_info)
::create_from_cached_record(file.module_info)
.map(bun_core::heap::into_raw)
.unwrap_or(core::ptr::null_mut())
.cast::<c_void>()
Expand Down
Loading
Loading