Browse Source

fixed length

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

5
src/lib/js/value.rs

@ -159,12 +159,13 @@ impl ValueData {
/// Resolve the property in the object /// Resolve the property in the object
/// Returns a copy of the Property /// Returns a copy of the Property
pub fn get_prop(&self, field: String) -> Option<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 // 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 // TODO: Move this to a better place
if self.is_string() && field == "length" {
if let ValueData::String(ref s) = *self { if let ValueData::String(ref s) = *self {
return Some(Property::new(to_value(s.len() as f64))) return Some(Property::new(to_value(s.len() as f64)))
} }
}
let obj: ObjectData = match *self { let obj: ObjectData = match *self {
ValueData::Object(ref obj) => { ValueData::Object(ref obj) => {

4
tests/js/test.js

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