Browse Source

Change default return type from null to undefined (#643)

* Change default return type from null to undefined

* Change default return value of block

* Add link to spec

* Add tests
pull/645/head
54k1 4 years ago committed by GitHub
parent
commit
2d1dabb554
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      boa/src/exec/block/mod.rs
  2. 5
      boa/src/exec/statement_list.rs
  3. 12
      boa/src/exec/tests.rs

4
boa/src/exec/block/mod.rs

@ -16,7 +16,9 @@ impl Executable for Block {
)));
}
let mut obj = Value::null();
// https://tc39.es/ecma262/#sec-block-runtime-semantics-evaluation
// The return value is uninitialized, which means it defaults to Value::Undefined
let mut obj = Value::default();
for statement in self.statements() {
obj = statement.run(interpreter)?;

5
boa/src/exec/statement_list.rs

@ -6,7 +6,10 @@ use crate::{builtins::value::Value, syntax::ast::node::StatementList, BoaProfile
impl Executable for StatementList {
fn run(&self, interpreter: &mut Interpreter) -> Result<Value> {
let _timer = BoaProfiler::global().start_event("StatementList", "exec");
let mut obj = Value::null();
// https://tc39.es/ecma262/#sec-block-runtime-semantics-evaluation
// The return value is uninitialized, which means it defaults to Value::Undefined
let mut obj = Value::default();
interpreter.set_current_state(InterpreterState::Executing);
for (i, item) in self.statements().iter().enumerate() {
let val = item.run(interpreter)?;

12
boa/src/exec/tests.rs

@ -15,6 +15,12 @@ fn function_declaration_returns_undefined() {
assert_eq!(&exec(scenario), "undefined");
}
#[test]
fn empty_function_returns_undefined() {
let scenario = "(function () {}) ()";
assert_eq!(&exec(scenario), "undefined");
}
#[test]
fn property_accessor_member_expression_dot_notation_on_string_literal() {
let scenario = r#"
@ -1205,3 +1211,9 @@ fn comma_operator() {
"#;
assert_eq!(&exec(scenario), "2");
}
#[test]
fn test_result_of_empty_block() {
let scenario = "{}";
assert_eq!(&exec(scenario), "undefined");
}

Loading…
Cancel
Save