1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use super::{Executable, Interpreter};
use crate::{
    builtins::value::{ResultValue, Type},
    syntax::ast::node::{GetConstField, GetField},
};

impl Executable for GetConstField {
    fn run(&self, interpreter: &mut Interpreter) -> ResultValue {
        let mut obj = self.obj().run(interpreter)?;
        if obj.get_type() != Type::Object || obj.get_type() != Type::Symbol {
            obj = interpreter.to_object(&obj)?;
        }

        Ok(obj.get_field(self.field()))
    }
}

impl Executable for GetField {
    fn run(&self, interpreter: &mut Interpreter) -> ResultValue {
        let mut obj = self.obj().run(interpreter)?;
        if obj.get_type() != Type::Object || obj.get_type() != Type::Symbol {
            obj = interpreter.to_object(&obj)?;
        }
        let field = self.field().run(interpreter)?;

        Ok(obj.get_field(field.to_string()))
    }
}