boa: builtinfun.length undefined

I’m getting undefined when I do 'abc'.matchAll.length. This is incompatible with Chrome’s implementation (for example), where I get 1.

Testing with master with the following tests.js:

console.log('abc'.matchAll.length);

Here’s the output for cargo run:

$ cargo run
   Compiling Boa v0.5.0 (/data/boa)
    Finished dev [unoptimized + debuginfo] target(s) in 3.20s
     Running `target/debug/boa`
undefined
[src/bin/bin.rs:57] exec(&buffer) = "undefined"

Related to #193 and #206

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 22 (22 by maintainers)

Most upvoted comments

I think I found the error. The following code:

'abc'.matchAll

returns undefined and not the function object. Firefox console returns the function object instead. I will investigate further and try to find the cause

If you create a string with " or ', the builtins::string::create_constructor (aka String Constructor) is not used, and so the methods are not set. You can easily prove this, because this:

(new String("abc")).matchAll.length

returns the correct length. When a method is called from this string (this = the constant string “abc”), this string is first converted to an object by Interpreter::to_object, this to_object method then uses the string prototype which has all methods set etc, so the matchAll method is also a property in the object. However, there is another problem. If the object you want to get a field from is a function, the to_obj method returns an error. I’m not sure how best to fix the error. At the moment I can only offer the following Quick-Fix: Change this to this:

ExprDef::GetConstField(ref obj, ref field) => {
    let mut obj = self.run(obj)?;
    if obj.get_type() != "function"
        && (obj.get_type() != "object" || obj.get_type() != "symbol")
    {
        obj = self.to_object(&obj).expect("failed to convert to object");
    }
    Ok(obj.borrow().get_field_slice(field))
}

If one of the maintainers provide me with a solution that should be used I can implement it.