Bug 1210330 - TCPSocket data event should be an ArrayBuffer in non-e10s case too. r=jdm

The conversion to WebIDL introduced a minor regression where the "data" event
carried a Uint8Array payload instead of an ArrayBuffer. This patch corrects
the type and introduces a fix.
This commit is contained in:
Andrew Sutherland 2015-10-14 14:05:36 -04:00
parent 8ff287ea02
commit dd110fee88
4 changed files with 22 additions and 2 deletions

View File

@ -1040,7 +1040,7 @@ TCPSocket::OnDataAvailable(nsIRequest* aRequest, nsISupports* aContext, nsIInput
JSContext* cx = api.cx();
JS::Rooted<JS::Value> value(cx);
if (!ToJSValue(cx, TypedArrayCreator<Uint8Array>(buffer), &value)) {
if (!ToJSValue(cx, TypedArrayCreator<ArrayBuffer>(buffer), &value)) {
return NS_ERROR_FAILURE;
}
FireDataEvent(cx, NS_LITERAL_STRING("data"), value);

View File

@ -1,4 +1,6 @@
this.EXPORTED_SYMBOLS = ['createSocket', 'createServer', 'enablePrefsAndPermissions'];
this.EXPORTED_SYMBOLS = [
'createSocket', 'createServer', 'enablePrefsAndPermissions',
'socketCompartmentInstanceOfArrayBuffer'];
this.createSocket = function(host, port, options) {
return new TCPSocket(host, port, options);
@ -11,3 +13,8 @@ this.createServer = function(port, options, backlog) {
this.enablePrefsAndPermissions = function() {
return false;
}
// See test_tcpsocket_client_and_server_basics.html's version for rationale.
this.socketCompartmentInstanceOfArrayBuffer = function(obj) {
return obj instanceof ArrayBuffer;
}

View File

@ -25,6 +25,17 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1084245
function enablePrefsAndPermissions() {
return true;
}
// In the JSM case, ArrayBuffers will be created in the compartment of the
// JSM with different globals than the
// test_tcpsocket_client_and_server_basics.js test logic sees, so we (and
// tcpsocket_test.jsm) need to do something. To avoid complexity relating
// to wrappers and the varying nuances of the module scope and global scope
// in JSM's (they differ on B2G), we hardcode ArrayBuffer rather than taking
// a string that we look up, etc.
function socketCompartmentInstanceOfArrayBuffer(obj) {
return obj instanceof ArrayBuffer;
}
</script>
<script type="application/javascript;version=1.7" src="test_tcpsocket_client_and_server_basics.js"></script>
</head>

View File

@ -55,6 +55,8 @@ function listenForEventsOnSocket(socket, socketType) {
socket.ondata = function(event) {
dump('(' + socketType + ' event: ' + event.type + ' length: ' +
event.data.byteLength + ')\n');
ok(socketCompartmentInstanceOfArrayBuffer(event.data),
'payload is ArrayBuffer');
var arr = new Uint8Array(event.data);
if (receivedData === null) {
receivedData = arr;