From 2598241e859854d24d715df4e782218c9189c864 Mon Sep 17 00:00:00 2001 From: Osman Turan Date: Mon, 4 Oct 2021 03:36:57 +0300 Subject: [PATCH 1/2] Add limited console.trace implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See: #307 --- boa/src/builtins/console/mod.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/boa/src/builtins/console/mod.rs b/boa/src/builtins/console/mod.rs index 06ba2cd9f1f..114d24d2dcb 100644 --- a/boa/src/builtins/console/mod.rs +++ b/boa/src/builtins/console/mod.rs @@ -299,6 +299,24 @@ impl Console { Ok(JsValue::undefined()) } + #[cfg(feature = "vm")] + fn get_stack_trace(context: &mut Context) -> Vec { + let mut stack_trace: Vec = 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 { + vec![] + } + /// `console.trace(...data)` /// /// Prints a stack trace with "trace" logLevel, optionally labelled by data. @@ -316,11 +334,8 @@ impl Console { context.console(), ); - /* TODO: get and print stack trace */ - logger( - LogMessage::Log("Not implemented: ".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()) From 47ce745fc35f7e177432eb40ef1c9d393b03873b Mon Sep 17 00:00:00 2001 From: Osman Turan Date: Tue, 26 Oct 2021 20:06:10 +0300 Subject: [PATCH 2/2] Add TODO comment for stack trace retrieval See: #307 --- boa/src/builtins/console/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/boa/src/builtins/console/mod.rs b/boa/src/builtins/console/mod.rs index 114d24d2dcb..ec08db5a48f 100644 --- a/boa/src/builtins/console/mod.rs +++ b/boa/src/builtins/console/mod.rs @@ -314,6 +314,7 @@ impl Console { #[cfg(not(feature = "vm"))] fn get_stack_trace(_: &mut Context) -> Vec { + // TODO: Implement stack trace retrieval when "vm" feature is not available vec![] }