From 0a46bdbe04dbd0a6191fae6258843421d44f2703 Mon Sep 17 00:00:00 2001 From: KrisChambers Date: Sun, 14 Jul 2019 12:23:42 -0500 Subject: [PATCH] Is property key implementation (#72) (#79) * Implemented Property::is_property_key static function. * Fixed rust formating. --- src/lib/js/object.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/lib/js/object.rs b/src/lib/js/object.rs index de44c78063..ebe5d3b232 100644 --- a/src/lib/js/object.rs +++ b/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)); + } +}