From 6a1b081efd4a6ccf2f32740f48832fe13d832c1b Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Wed, 28 Nov 2018 22:54:01 +0000 Subject: [PATCH] fixed length --- src/lib/js/value.rs | 9 +++++---- tests/js/test.js | 4 +++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/lib/js/value.rs b/src/lib/js/value.rs index 7e38969e38..28aa50637d 100644 --- a/src/lib/js/value.rs +++ b/src/lib/js/value.rs @@ -159,11 +159,12 @@ impl ValueData { /// Resolve the property in the object /// Returns a copy of the Property pub fn get_prop(&self, field: String) -> Option { - // handle length // Spidermonkey has its own GetLengthProperty: https://searchfox.org/mozilla-central/source/js/src/vm/Interpreter-inl.h#154 - // TODO: Maybe we need a GetLengthProperty for value types - if let ValueData::String(ref s) = *self { - return Some(Property::new(to_value(s.len() as f64))) + // TODO: Move this to a better place + if self.is_string() && field == "length" { + if let ValueData::String(ref s) = *self { + return Some(Property::new(to_value(s.len() as f64))) + } } let obj: ObjectData = match *self { diff --git a/tests/js/test.js b/tests/js/test.js index 7e56815e02..7ee5d1c90b 100644 --- a/tests/js/test.js +++ b/tests/js/test.js @@ -1,2 +1,4 @@ -var a = 'jabra888'; +var a = 'jabrjjja888'; +a.length; +a = "jase"; a.length; \ No newline at end of file