diff --git a/cli/src/debug/function.rs b/cli/src/debug/function.rs index ea97b61b665..9d932bd04a0 100644 --- a/cli/src/debug/function.rs +++ b/cli/src/debug/function.rs @@ -2,7 +2,10 @@ use boa_engine::{ builtins::function::OrdinaryFunction, js_string, object::ObjectInitializer, - vm::{flowgraph::{Direction, Graph}, trace::{Tracer, TraceAction}}, + vm::{ + flowgraph::{Direction, Graph}, + trace::{TraceAction, Tracer}, + }, Context, JsArgs, JsNativeError, JsObject, JsResult, JsValue, NativeFunction, }; @@ -130,9 +133,9 @@ impl Tracer for FunctionTracer { fn should_trace(&self, frame: &boa_engine::vm::CallFrame) -> TraceAction { if frame.code_block().traceable() { if frame.code_block().was_traced() { - return TraceAction::Block + return TraceAction::Block; } - return TraceAction::BlockWithBytecode + return TraceAction::BlockWithBytecode; } TraceAction::None } diff --git a/core/engine/src/vm/mod.rs b/core/engine/src/vm/mod.rs index 3ea63477f4c..bd7b21c34f9 100644 --- a/core/engine/src/vm/mod.rs +++ b/core/engine/src/vm/mod.rs @@ -389,7 +389,7 @@ impl Context { } #[cfg(feature = "trace")] - let result = if self.vm.trace.should_trace(&self.vm.frame()) { + let result = if self.vm.trace.should_trace(self.vm.frame()) { self.trace_execute_instruction(f) } else { self.execute_instruction(f) diff --git a/core/engine/src/vm/trace.rs b/core/engine/src/vm/trace.rs index 2b20159ec1b..20ba1e65313 100644 --- a/core/engine/src/vm/trace.rs +++ b/core/engine/src/vm/trace.rs @@ -3,7 +3,7 @@ use std::collections::VecDeque; use std::fmt; -use super::{Constant, Vm, CallFrame}; +use super::{CallFrame, Constant, Vm}; // TODO: Build out further, maybe provide more element visiblity and events/outputs /// The `Tracer` trait is a customizable trait that can be provided to `Boa` @@ -12,7 +12,7 @@ pub trait Tracer: fmt::Debug { /// Whether the current call frame should trace. fn should_trace(&self, frame: &CallFrame) -> TraceAction { if frame.code_block.name().to_std_string_escaped().as_str() == "
" { - return TraceAction::BlockWithFullBytecode + return TraceAction::BlockWithFullBytecode; } TraceAction::Block } @@ -60,14 +60,6 @@ impl Tracer for ActiveTracer { } } -impl Default for VmTrace { - fn default() -> Self { - Self { - tracers: Vec::default(), - } - } -} - /// `VmTrace` is a boa spcific structure for running Boa's Virtual Machine trace. /// /// It holds registered `Tracer` implementations and actions messages depending on @@ -77,6 +69,7 @@ impl Default for VmTrace { /// /// After the Global callframe is initially provided. It searches /// for all possible compiled output +#[derive(Default)] pub struct VmTrace { tracers: Vec>, } @@ -90,12 +83,16 @@ impl VmTrace { } /// Returns whether there is an active trace request. - pub fn should_trace(&self, frame: &CallFrame) -> bool { + #[must_use] + pub(crate) fn should_trace(&self, frame: &CallFrame) -> bool { self.trace_action(frame) != TraceAction::None } + /// Returns the folded `TraceAction` of the current `Tracer`s pub(crate) fn trace_action(&self, frame: &CallFrame) -> TraceAction { - (&self.tracers).into_iter().fold(TraceAction::None, |a, b| a.max(b.should_trace(frame))) + self.tracers + .iter() + .fold(TraceAction::None, |a, b| a.max(b.should_trace(frame))) } /// Sets the current `Tracer` of `VmTrace`. diff --git a/ffi/wasm/src/lib.rs b/ffi/wasm/src/lib.rs index c1a2a3ed8d3..d120d6723a7 100644 --- a/ffi/wasm/src/lib.rs +++ b/ffi/wasm/src/lib.rs @@ -9,8 +9,8 @@ use boa_engine::{vm::trace::Tracer, Context, Source}; use chrono as _; use getrandom as _; -use wasm_bindgen::prelude::*; use std::fmt; +use wasm_bindgen::prelude::*; #[wasm_bindgen(start)] fn main() {