Browse Source

Throw a type error when a non-object is called (#561)

pull/563/head
joshwd36 4 years ago committed by GitHub
parent
commit
ffe8b5f337
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      boa/src/exec/mod.rs
  2. 35
      boa/src/exec/tests.rs

2
boa/src/exec/mod.rs

@ -173,7 +173,7 @@ impl Interpreter {
} }
self.throw_type_error("not a function") self.throw_type_error("not a function")
} }
_ => Err(Value::undefined()), _ => self.throw_type_error("not a function"),
} }
} }

35
boa/src/exec/tests.rs

@ -1128,3 +1128,38 @@ fn check_this_binding_in_object_literal() {
assert_eq!(forward(&mut engine, init), "8"); 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");
}

Loading…
Cancel
Save