Browse Source

TypeError when to_object is passed null or undefined (#518)

Co-authored-by: HalidOdat <halidodat@gmail.com>
pull/523/head
Ryan Fickenscher 4 years ago committed by GitHub
parent
commit
24418e7520
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      boa/src/exec/mod.rs
  2. 12
      boa/src/exec/tests.rs

4
boa/src/exec/mod.rs

@ -425,7 +425,9 @@ impl Interpreter {
#[allow(clippy::wrong_self_convention)] #[allow(clippy::wrong_self_convention)]
pub(crate) fn to_object(&mut self, value: &Value) -> ResultValue { pub(crate) fn to_object(&mut self, value: &Value) -> ResultValue {
match value { match value {
Value::Undefined | Value::Null => Err(Value::undefined()), Value::Undefined | Value::Null => {
self.throw_type_error("cannot convert 'null' or 'undefined' to object")
}
Value::Boolean(boolean) => { Value::Boolean(boolean) => {
let proto = self let proto = self
.realm .realm

12
boa/src/exec/tests.rs

@ -927,3 +927,15 @@ fn calling_function_with_unspecified_arguments() {
assert_eq!(forward(&mut engine, scenario), "undefined"); assert_eq!(forward(&mut engine, scenario), "undefined");
} }
#[test]
fn to_object() {
let realm = Realm::create();
let mut engine = Interpreter::new(realm);
assert!(engine
.to_object(&Value::undefined())
.unwrap_err()
.is_object());
assert!(engine.to_object(&Value::null()).unwrap_err().is_object());
}

Loading…
Cancel
Save