Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse runtime when compiling source code to bytecode #781

Merged
merged 5 commits into from
Oct 21, 2024
Merged
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
16 changes: 14 additions & 2 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,20 @@ pub extern "C" fn initialize_runtime() {
/// * `js_src_ptr` must reference a valid array of unsigned bytes of `js_src_len` length
#[export_name = "compile_src"]
pub unsafe extern "C" fn compile_src(js_src_ptr: *const u8, js_src_len: usize) -> *const u32 {
// Use fresh runtime to avoid depending on Wizened runtime
let runtime = runtime::new(Config::default()).unwrap();
// Use initialized runtime when compiling because certain runtime
// configurations can cause different bytecode to be emitted.
//
// For example, given the following JS:
// ```
// function foo() {
// "use math"
// 1234 % 32
// }
// ```
//
// Setting `config.bignum_extension` to `true` will produce different
// bytecode than if it were set to `false`.
let runtime = unsafe { RUNTIME.get().unwrap() };
Copy link
Member

Choose a reason for hiding this comment

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

Could you add some docs that include your comment?

let js_src = str::from_utf8(slice::from_raw_parts(js_src_ptr, js_src_len)).unwrap();

let bytecode = runtime
Expand Down
Loading