Skip to content

websocket.send(null) causes Servo to panic #7858

Closed

Description

@jdm

We call unwrap on the argument passed to WebSocket::Send which is an Option<String>, but that brings Servo down if the argument is null in JavaScript which corresponds to None in Rust. We should use unwrap_or_else and create an empty string instead.

Code: components/script/dom/websocket.rs

Activity

  1. added
    A-content/dom
    E-less-complex
    I-panic
    on Oct 5, 2015
  2. jimberlage commented on Oct 5, 2015

    @jimberlage
    Contributor

    I'd like to take this on, if that's cool.

  3. jdm commented on Oct 5, 2015

    @jdm
    MemberAuthor

    Please do!

  4. added
    C-assigned
    on Oct 5, 2015
  5. nox commented on Oct 6, 2015

    @nox
    Contributor

    @jdm Why is null converted to None for an optional argument though? Isn't null not the same thing as a missing argument? Shouldn't thus the null value be converted to an empty string in codegen directly?

  6. jdm commented on Oct 6, 2015

    @jdm
    MemberAuthor

    My reading of the WebIDL spec suggests that for methods with optional arguments with no default value, an undefined value is converted to a "missing" value, which I presume is equivalent to None for Servo's implementation.

  7. jdm commented on Oct 6, 2015

    @jdm
    MemberAuthor

    @jimberlage Want to test what happens without your change in #7885 when passing either null or undefined to the send method? I suggest modifying an existing test in tests/wpt/web-platform-tests/websockets/ for quick experimentation, then running with ./mach test-wpt path/to/test.html.

  8. Ms2ger commented on Oct 6, 2015

    @Ms2ger
    Contributor

    The spec says

      void send(USVString data);
      void send(Blob data);
      void send(ArrayBuffer data);
      void send(ArrayBufferView data);
    

    so the argument should not be optional or nullable, which means null should be mapped to the string "null", and undefined to the string "undefined".

    Fixing this should make some tests in html/dom/interfaces.html and websockets/interfaces.html, as well as websockets/interfaces/WebSocket/send/001.html, pass.

  9. jdm commented on Oct 6, 2015

    @jdm
    MemberAuthor

    Huh, I feel a bit silly now. Want to get rid of the optional in WebSocket.webidl, @jimberlage ?

  10. jimberlage commented on Oct 6, 2015

    @jimberlage
    Contributor

    Sure thing.

  11. added 2 commits that reference this issue on Oct 8, 2015
    c0030ad
    0ffd2f6
  12. added a commit that references this issue on Oct 9, 2015
    8c81d9a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-content/domC-assignedE-less-complexI-panic

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions