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

feat: support no_std #250

Merged
merged 7 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
check
  • Loading branch information
stevencartavia committed Jan 4, 2025
commit 17e23bacfa9e14c2d2dc4493d0200a2c82bf8813
14 changes: 10 additions & 4 deletions src/tracing/js/bindings.rs
Copy link
Member

@DaniPopes DaniPopes Jan 4, 2025

Choose a reason for hiding this comment

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

Please leave JS unchanged, it can never support no_std. It may look like it works because tests pass but that's because you're running on a target that has std, and it is used by dependencies regardless of the no_std status of this crate.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ use crate::tracing::{
types::CallKind,
TransactionContext,
};
use alloc::{
boxed::Box,
format,
rc::Rc,
string::{String, ToString},
};
use alloy_primitives::{Address, Bytes, B256, U256};
use boa_engine::{
js_string,
Expand All @@ -16,6 +22,7 @@ use boa_engine::{
Context, JsArgs, JsError, JsNativeError, JsObject, JsResult, JsValue,
};
use boa_gc::{empty_trace, Finalize, Trace};
use core::cell::RefCell;
use revm::{
interpreter::{
opcode::{PUSH0, PUSH32},
Expand All @@ -24,7 +31,6 @@ use revm::{
primitives::{AccountInfo, Bytecode, EvmState, KECCAK_EMPTY},
DatabaseRef,
};
use std::{cell::RefCell, rc::Rc};

/// A macro that creates a native function that returns via [JsValue::from]
macro_rules! js_value_getter {
Expand Down Expand Up @@ -99,7 +105,7 @@ impl<Val: 'static> GuardedNullableGc<Val> {

// SAFETY: guard enforces that the value is removed from the refcell before it is dropped.
#[allow(clippy::missing_transmute_annotations)]
let this = Self { inner: unsafe { std::mem::transmute(inner) } };
let this = Self { inner: unsafe { core::mem::transmute(inner) } };

(this, guard)
}
Expand Down Expand Up @@ -764,7 +770,7 @@ impl EvmDbRef {
// the guard.
let db = JsDb(db);
let js_db = unsafe {
std::mem::transmute::<
core::mem::transmute::<
Box<dyn DatabaseRef<Error = String> + '_>,
Box<dyn DatabaseRef<Error = String> + 'static>,
>(Box::new(db))
Expand Down Expand Up @@ -799,7 +805,7 @@ impl EvmDbRef {
let acc = self.read_basic(address, ctx)?;
let code_hash = acc.map(|acc| acc.code_hash).unwrap_or(KECCAK_EMPTY);
if code_hash == KECCAK_EMPTY {
return JsUint8Array::from_iter(std::iter::empty(), ctx);
return JsUint8Array::from_iter(core::iter::empty(), ctx);
}

let Some(Ok(bytecode)) = self.inner.db.0.with_inner(|db| db.code_by_hash_ref(code_hash))
Expand Down
3 changes: 2 additions & 1 deletion src/tracing/js/builtins.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Builtin functions

use alloc::borrow::Borrow;
use crate::alloc::string::ToString;
use alloc::{borrow::Borrow, format, vec::Vec};
use alloy_primitives::{hex, map::HashSet, Address, FixedBytes, B256, U256};
use boa_engine::{
builtins::{array_buffer::ArrayBuffer, typed_array::TypedArray},
Expand Down
19 changes: 12 additions & 7 deletions src/tracing/js/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
//! Javascript inspector

use crate::tracing::{
js::{
bindings::{
CallFrame, Contract, EvmDbRef, FrameResult, JsEvmContext, MemoryRef, StackRef, StepLog,
use crate::{
alloc::string::ToString,
tracing::{
js::{
bindings::{
CallFrame, Contract, EvmDbRef, FrameResult, JsEvmContext, MemoryRef, StackRef,
StepLog,
},
builtins::{register_builtins, to_serde_value, PrecompileList},
},
builtins::{register_builtins, to_serde_value, PrecompileList},
types::CallKind,
TransactionContext,
},
types::CallKind,
TransactionContext,
};
use alloc::{format, string::String, vec::Vec};
use alloy_primitives::{Address, Bytes, Log, U256};
pub use boa_engine::vm::RuntimeLimits;
use boa_engine::{js_string, Context, JsError, JsObject, JsResult, JsValue, Source};
Expand Down
Loading