Browse Source

[FunctionDeclaration - execution] evaluate declaration into undefined not function (#473)

pull/489/head
croraf 4 years ago committed by GitHub
parent
commit
c42fcf12a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      boa/src/builtins/value/tests.rs
  2. 4
      boa/src/exec/declaration/mod.rs
  3. 29
      boa/src/exec/tests.rs

2
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(),

4
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())
}
}

29
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#"

Loading…
Cancel
Save