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

[Merged by Bors] - Add limited console.trace implementation #1623

Closed
wants to merge 2 commits into from
Closed
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
26 changes: 21 additions & 5 deletions boa/src/builtins/console/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,25 @@ impl Console {
Ok(JsValue::undefined())
}

#[cfg(feature = "vm")]
fn get_stack_trace(context: &mut Context) -> Vec<String> {
let mut stack_trace: Vec<String> = vec![];
let mut prev_frame = context.vm.frame.as_ref();

while let Some(frame) = prev_frame {
stack_trace.push(frame.code.name.to_string());
prev_frame = frame.prev.as_ref();
}

stack_trace
}

#[cfg(not(feature = "vm"))]
fn get_stack_trace(_: &mut Context) -> Vec<String> {
// TODO: Implement stack trace retrieval when "vm" feature is not available
vec![]
Copy link
Contributor

Choose a reason for hiding this comment

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

Should leave a TODO comment here so that it is easy to spot

}

/// `console.trace(...data)`
///
/// Prints a stack trace with "trace" logLevel, optionally labelled by data.
Expand All @@ -316,11 +335,8 @@ impl Console {
context.console(),
);

/* TODO: get and print stack trace */
logger(
LogMessage::Log("Not implemented: <stack trace>".to_string()),
context.console(),
)
let stack_trace_dump = Self::get_stack_trace(context).join("\n");
logger(LogMessage::Log(stack_trace_dump), context.console())
}

Ok(JsValue::undefined())
Expand Down