Browse Source

Is property key implementation (#72) (#79)

* Implemented Property::is_property_key static function.

* Fixed rust formating.
pull/80/head
KrisChambers 5 years ago committed by Jason Williams
parent
commit
0a46bdbe04
  1. 19
      src/lib/js/object.rs

19
src/lib/js/object.rs

@ -70,6 +70,11 @@ pub struct Property {
}
impl Property {
/// Checks if the provided Value can be used as a property key.
pub fn is_property_key(value: &Value) -> bool {
value.is_string() // || value.is_symbol() // Uncomment this when we are handeling symbols.
}
/// Make a new property with the given value
pub fn new(value: Value) -> Self {
Self {
@ -184,3 +189,17 @@ pub fn _create(global: &Value) -> Value {
pub fn init(global: &Value) {
global.set_field_slice("Object", _create(global));
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn is_property_key_test() {
let v = Value::new(ValueData::String(String::from("Boop")));
assert!(Property::is_property_key(&v));
let v = Value::new(ValueData::Boolean(true));
assert!(!Property::is_property_key(&v));
}
}

Loading…
Cancel
Save