Skip to content

Commit

Permalink
cargo fmt and clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
nekevss committed Jan 20, 2024
1 parent 80d8ac0 commit 606f48e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
9 changes: 6 additions & 3 deletions cli/src/debug/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion core/engine/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 9 additions & 12 deletions core/engine/src/vm/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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() == "<main>" {
return TraceAction::BlockWithFullBytecode
return TraceAction::BlockWithFullBytecode;
}
TraceAction::Block
}
Expand Down Expand Up @@ -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
Expand All @@ -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<Box<dyn Tracer>>,
}
Expand All @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion ffi/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 606f48e

Please sign in to comment.