Browse Source

fixed length

pull/5/head
Jason Williams 6 years ago
parent
commit
6a1b081efd
  1. 9
      src/lib/js/value.rs
  2. 4
      tests/js/test.js

9
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<Property> {
// 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 {

4
tests/js/test.js

@ -1,2 +1,4 @@
var a = 'jabra888';
var a = 'jabrjjja888';
a.length;
a = "jase";
a.length;
Loading…
Cancel
Save