Browse Source

Fix undefined constant expression evaluation (#645)

pull/650/head
Jonathan Dickinson 4 years ago committed by GitHub
parent
commit
13f73749c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      boa/src/exec/mod.rs
  2. 16
      boa/src/exec/tests.rs

4
boa/src/exec/mod.rs

@ -385,6 +385,7 @@ impl Executable for Node {
Node::Const(Const::Num(num)) => Ok(Value::rational(num)), Node::Const(Const::Num(num)) => Ok(Value::rational(num)),
Node::Const(Const::Int(num)) => Ok(Value::integer(num)), Node::Const(Const::Int(num)) => Ok(Value::integer(num)),
Node::Const(Const::BigInt(ref num)) => Ok(Value::from(num.clone())), Node::Const(Const::BigInt(ref num)) => Ok(Value::from(num.clone())),
Node::Const(Const::Undefined) => Ok(Value::Undefined),
// we can't move String from Const into value, because const is a garbage collected value // we can't move String from Const into value, because const is a garbage collected value
// Which means Drop() get's called on Const, but str will be gone at that point. // Which means Drop() get's called on Const, but str will be gone at that point.
// Do Const values need to be garbage collected? We no longer need them once we've generated Values // Do Const values need to be garbage collected? We no longer need them once we've generated Values
@ -423,7 +424,8 @@ impl Executable for Node {
} }
Node::Try(ref try_node) => try_node.run(interpreter), Node::Try(ref try_node) => try_node.run(interpreter),
Node::Break(ref break_node) => break_node.run(interpreter), Node::Break(ref break_node) => break_node.run(interpreter),
ref i => unimplemented!("{:?}", i), Node::ConditionalOp(_) => unimplemented!("ConditionalOp"),
Node::Continue(_) => unimplemented!("Continue"),
} }
} }
} }

16
boa/src/exec/tests.rs

@ -770,7 +770,9 @@ mod in_operator {
let bar_obj = bar_val.as_object().unwrap(); let bar_obj = bar_val.as_object().unwrap();
let foo_val = forward_val(&mut engine, "Foo").unwrap(); let foo_val = forward_val(&mut engine, "Foo").unwrap();
let foo_obj = foo_val.as_object().unwrap(); let foo_obj = foo_val.as_object().unwrap();
assert!(bar_obj.prototype().strict_equals(&foo_obj.get_field("prototype").unwrap())); assert!(bar_obj
.prototype()
.strict_equals(&foo_obj.get_field("prototype").unwrap()));
} }
} }
@ -1220,3 +1222,15 @@ fn test_result_of_empty_block() {
let scenario = "{}"; let scenario = "{}";
assert_eq!(&exec(scenario), "undefined"); assert_eq!(&exec(scenario), "undefined");
} }
#[test]
fn test_undefined_constant() {
let scenario = "undefined";
assert_eq!(&exec(scenario), "undefined");
}
#[test]
fn test_undefined_type() {
let scenario = "typeof undefined";
assert_eq!(&exec(scenario), "\"undefined\"");
}

Loading…
Cancel
Save