diff --git a/boa/src/builtins/value/tests.rs b/boa/src/builtins/value/tests.rs index a13883f19d..03975069c0 100644 --- a/boa/src/builtins/value/tests.rs +++ b/boa/src/builtins/value/tests.rs @@ -128,7 +128,7 @@ fn get_types() { forward_val(&mut engine, "function foo() {console.log(\"foo\");}") .unwrap() .get_type(), - Type::Function + Type::Undefined ); assert_eq!( forward_val(&mut engine, "null").unwrap().get_type(), diff --git a/boa/src/exec/declaration/mod.rs b/boa/src/exec/declaration/mod.rs index 192a8a168f..37f199003a 100644 --- a/boa/src/exec/declaration/mod.rs +++ b/boa/src/exec/declaration/mod.rs @@ -35,9 +35,9 @@ impl Executable for FunctionDecl { interpreter .realm_mut() .environment - .initialize_binding(self.name(), val.clone()); + .initialize_binding(self.name(), val); - Ok(val) + Ok(Value::undefined()) } } diff --git a/boa/src/exec/tests.rs b/boa/src/exec/tests.rs index e12ffca31c..63e51bd075 100644 --- a/boa/src/exec/tests.rs +++ b/boa/src/exec/tests.rs @@ -1,5 +1,24 @@ use crate::{builtins::Value, exec, exec::Interpreter, forward, realm::Realm}; +#[test] +fn function_declaration_returns_undefined() { + let scenario = r#" + function abc() {} + "#; + + assert_eq!(&exec(scenario), "undefined"); +} + +#[test] +fn empty_var_decl_undefined() { + let scenario = r#" + let b; + b === undefined; + "#; + + assert_eq!(&exec(scenario), "true"); +} + #[test] fn property_accessor_member_expression_dot_notation_on_string_literal() { let scenario = r#" @@ -59,16 +78,6 @@ fn semicolon_expression_stop() { assert_eq!(&exec(scenario), "1"); } -#[test] -fn empty_var_decl_undefined() { - let scenario = r#" - let b; - b == undefined; - "#; - - assert_eq!(&exec(scenario), "true"); -} - #[test] fn object_field_set() { let scenario = r#"