Skip to content

Commit

Permalink
Merge ea2a3b7 into bbd7dd2
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat authored Jul 22, 2020
2 parents bbd7dd2 + ea2a3b7 commit b656f0c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
12 changes: 11 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions boa/src/builtins/value/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ pub(crate) fn display_obj(v: &Value, print_internals: bool) -> String {
// in-memory address in this set
let mut encounters = HashSet::new();

if let Value::Object(object) = v {
if object.borrow().is_error() {
let name = v.get_field("name");
let message = v.get_field("message");
return format!("{}: {}", name, message);
}
}

fn display_obj_internal(
data: &Value,
encounters: &mut HashSet<usize>,
Expand Down
1 change: 1 addition & 0 deletions boa_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Boa = { path = "../boa", features = ["serde"] }
rustyline = "6.2.0"
structopt = "0.3.15"
serde_json = "1.0.56"
ansi_term = "0.12.1"

[target.x86_64-unknown-linux-gnu.dependencies]
jemallocator = "0.3.2"
Expand Down
15 changes: 13 additions & 2 deletions boa_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
clippy::as_conversions
)]

use ansi_term::{Colour as Color, Style};
use boa::{
exec::Interpreter,
forward_val,
Expand Down Expand Up @@ -208,8 +209,14 @@ pub fn main() -> Result<(), std::io::Error> {
let mut editor = Editor::<()>::with_config(config);
let _ = editor.load_history(CLI_HISTORY);

let readline = Style::default()
.bold()
.fg(Color::Cyan)
.paint("> ")
.to_string();

loop {
match editor.readline("> ") {
match editor.readline(&readline) {
Ok(line) if line == ".exit" => break,
Err(ReadlineError::Interrupted) | Err(ReadlineError::Eof) => break,

Expand All @@ -223,7 +230,11 @@ pub fn main() -> Result<(), std::io::Error> {
} else {
match forward_val(&mut engine, line.trim_end()) {
Ok(v) => println!("{}", v),
Err(v) => eprintln!("{}", v),
Err(v) => eprintln!(
"{}: {}",
Color::Red.paint("Uncaught"),
Color::Red.paint(&v.to_string())
),
}
}
}
Expand Down

0 comments on commit b656f0c

Please sign in to comment.