The W3C Candidate Recommendation 08 December 2011 says we should throw an exception if text with unpaired surrogates is passed to send(). The latest editor's draft has changed that to say that we should convert the incoming argument to Unicode if it's not already (I'm an ignoramus about Unicode: apparently this involves inserting replacement characters). Not sure when we should ship a fix: now, or wait until the Editor's draft becomes another W3C recommendation?
Consensus in the working group was to take this change (though it came down to a close vote if we should make the change now or wait until v2 of the protocol). So I feel pretty confident that this change will stick, so I see no reason to wait.
Created attachment 638996 [details] [diff] [review] v1 fix Why do I ever think little things like this will take "just 15 minutes"? Anyway: here's what seems to be a working fix. It turns out that the existing, custom conversion code (nsWebSocket::ConvertTextToUTF8) doesn't insert replacement characters correctly (instead of replacing with '0xef 0xbf 0xbd', aka '\ufffd', it replaced with '0xed 0xa0 0x80'. Which seems odd, because the code explicitly tells the converter to use UTF_8_REPLACEMENT_CHAR. But I didn't spent too much time worrying about it, because it seems like we're fine just using CopyUTF16toUTF8(), which is what we're already using everywhere else in the logic.