Browse Source

Fix and tests (#469)

pull/472/head
croraf 4 years ago committed by GitHub
parent
commit
ca80114c53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      boa/src/exec/field/mod.rs
  2. 38
      boa/src/exec/tests.rs

7
boa/src/exec/field/mod.rs

@ -19,7 +19,12 @@ impl Executable for GetConstField {
impl Executable for GetField {
fn run(&self, interpreter: &mut Interpreter) -> ResultValue {
let obj = self.obj().run(interpreter)?;
let mut obj = self.obj().run(interpreter)?;
if obj.get_type() != "object" || obj.get_type() != "symbol" {
obj = interpreter
.to_object(&obj)
.expect("failed to convert to object");
}
let field = self.field().run(interpreter)?;
Ok(obj.get_field(field.to_string()))

38
boa/src/exec/tests.rs

@ -1,5 +1,43 @@
use crate::{builtins::Value, exec, exec::Interpreter, forward, realm::Realm};
#[test]
fn property_accessor_member_expression_dot_notation_on_string_literal() {
let scenario = r#"
typeof 'asd'.matchAll;
"#;
assert_eq!(&exec(scenario), "function");
}
#[test]
fn property_accessor_member_expression_bracket_notation_on_string_literal() {
let scenario = r#"
typeof 'asd'['matchAll'];
"#;
assert_eq!(&exec(scenario), "function");
}
#[test]
fn property_accessor_member_expression_dot_notation_on_function() {
let scenario = r#"
function asd () {};
asd.name;
"#;
assert_eq!(&exec(scenario), "asd");
}
#[test]
fn property_accessor_member_expression_bracket_notation_on_function() {
let scenario = r#"
function asd () {};
asd['name'];
"#;
assert_eq!(&exec(scenario), "asd");
}
#[test]
fn empty_let_decl_undefined() {
let scenario = r#"

Loading…
Cancel
Save