Skip to content

Commit

Permalink
Throw a type error when a non-object is called (#561)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwd36 committed Jul 11, 2020
1 parent 6a721f9 commit ffe8b5f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion boa/src/exec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl Interpreter {
}
self.throw_type_error("not a function")
}
_ => Err(Value::undefined()),
_ => self.throw_type_error("not a function"),
}
}

Expand Down
35 changes: 35 additions & 0 deletions boa/src/exec/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1128,3 +1128,38 @@ fn check_this_binding_in_object_literal() {

assert_eq!(forward(&mut engine, init), "8");
}

#[test]
fn not_a_function() {
let realm = Realm::create();
let mut engine = Interpreter::new(realm);
let init = r#"
let a = {};
let b = true;
"#;
forward(&mut engine, init);
let scenario = r#"
try {
a();
} catch(e) {
e.message
}
"#;
assert_eq!(forward(&mut engine, scenario), "not a function");
let scenario = r#"
try {
a.a();
} catch(e) {
e.message
}
"#;
assert_eq!(forward(&mut engine, scenario), "not a function");
let scenario = r#"
try {
b();
} catch(e) {
e.message
}
"#;
assert_eq!(forward(&mut engine, scenario), "not a function");
}

0 comments on commit ffe8b5f

Please sign in to comment.