Skip to content

Error in generated binding for variadic argument of type that needs rooting #8159

Closed

Description

@mbrubeck

The following WebIDL (where Touch is as defined in #7204):

partial interface Document {
      TouchList createTouchList(Touch... touches);
};

causes this compile error:

DocumentBinding.rs:2184:61: 2184:64 error: no method named `r` found for type `collections::vec::Vec<dom::bindings::js::Root<dom::touch::Touch>>` in the current scope
DocumentBinding.rs:2184     let result: Root<TouchList> = this.CreateTouchList(arg0.r());
                                                                                    ^~~

The generated trait method signature is:

    fn CreateTouchList(&self, touches: Vec<&Touch>) -> Root<TouchList>;

and the generated binding is:

unsafe extern fn createTouchList(cx: *mut JSContext, _obj: HandleObject, this: *const Document, args: *const JSJitMethodCallArgs) -> bool {
    let this = &*this;
    let args = &*args;
    let argc = args._base.argc_;
    let arg0: Vec<Root<Touch>> = if 0 < argc {
        let mut vector: Vec<Root<Touch>> = Vec::with_capacity((argc - 0) as usize);
        for variadicArg in 0..argc {
            let slot: Root<Touch> = if args.get(variadicArg).get().is_object() {
                match native_from_handlevalue(args.get(variadicArg)) {
                    Ok(val) => val,
                    Err(()) => {
                        throw_type_error(cx, "value does not implement interface Touch.");
                        return false;
                    }
                }
            } else {
                throw_type_error(cx, "Value is not an object.");
                return false;
            };
            vector.push(slot);
        }
        vector
    } else {
        Vec::new()
    };
    let result: Root<TouchList> = this.CreateTouchList(arg0.r());

    (result).to_jsval(cx, args.rval());
    return true;
}

Activity

  1. added
    A-content/bindings
    I-wrong
    on Oct 22, 2015
  2. Ms2ger commented on Oct 23, 2015

    @Ms2ger
    Contributor

    This is probably because CGPerSignatureCall.getArguments doesn't check whether the argument is variadic. I suspect adding that check would fix this (but note the duplicated code in CGProxySpecialOperation.getArguments).

  3. self-assigned this
    on Oct 23, 2015
  4. nox commented on Oct 25, 2015

    @nox
    Contributor

    I would rather make it pass &[&T] instead of just removing that .r() call, no?

  5. Ms2ger commented on Oct 25, 2015

    @Ms2ger
    Contributor

    I guess a Vec<Root<T>> is useless anyway. We could go either way.

  6. nox commented on Oct 25, 2015

    @nox
    Contributor

    Sounds like making the proper thing (&[&T]) is more complex than just removing the .r() call, for now.

  7. nox commented on Oct 25, 2015

    @nox
    Contributor

    Especially because I think the RootedVec::new() then needs to be moved outside the block that defines arg0, so that it doesn't end up moved.

  8. nox commented on Oct 25, 2015

    @nox
    Contributor

    So I managed to get the code to compile:

    unsafe extern fn passVariadicInterface(cx: *mut JSContext, _obj: HandleObject, this: *const TestBinding, args: *const JSJitMethodCallArgs) -> bool {
        let this = &*this;
        let args = &*args;
        let argc = args._base.argc_;
        let arg0: _ = if 0 < argc {
            let mut vector = RootedVec::new();
            *vector = Vec::with_capacity((argc - 0) as usize);
    
            for variadicArg in 0..argc {
                let slot: *const Blob = if args.get(variadicArg).get().is_object() {
                    match native_from_handlevalue(args.get(variadicArg)) {
                        Ok(val) => val,
                        Err(()) => {
                            throw_type_error(cx, "value does not implement interface Blob.");
                            return false;
                        }
                    }
                } else {
                    throw_type_error(cx, "Value is not an object.");
                    return false;
                };
                vector.push(JS::from_ref(&*slot));
            }
            vector
        } else {
            RootedVec::new()
        };
        let result: () = this.PassVariadicInterface(arg0.r());
    
        (result).to_jsval(cx, args.rval());
        return true;
    }

    But I'm pretty sure this will fail at runtime when the RootedVec is dropped. Will write a test.

  9. nox commented on Oct 25, 2015

    @nox
    Contributor

    Yes, this panics.

  10. added 2 commits that reference this issue on Oct 25, 2015
    502d542
    88bf688
  11. added 2 commits that reference this issue on Nov 11, 2015
    c765924
    acb13dc
  12. added a commit that references this issue on Nov 11, 2015
    f03a826
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-content/bindingsI-wrong

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions