mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-27 07:34:20 +00:00
Bug 996310 - nsIBinaryOutputStream should return number of bytes read. r=bsmedberg
This commit is contained in:
parent
cfd3e70677
commit
06e21291bb
@ -816,7 +816,7 @@ nsBinaryInputStream::ReadByteArray(uint32_t aLength, uint8_t** aResult)
|
||||
NS_IMETHODIMP
|
||||
nsBinaryInputStream::ReadArrayBuffer(uint32_t aLength,
|
||||
JS::Handle<JS::Value> aBuffer,
|
||||
JSContext* aCx)
|
||||
JSContext* aCx, uint32_t *rLength)
|
||||
{
|
||||
if (!aBuffer.isObject()) {
|
||||
return NS_ERROR_FAILURE;
|
||||
@ -831,14 +831,11 @@ nsBinaryInputStream::ReadArrayBuffer(uint32_t aLength,
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
uint32_t bytesRead;
|
||||
nsresult rv = Read(reinterpret_cast<char*>(data), aLength, &bytesRead);
|
||||
nsresult rv = Read(reinterpret_cast<char*>(data), aLength, rLength);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
if (bytesRead != aLength) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
* @See nsIBinaryOutputStream
|
||||
*/
|
||||
|
||||
[scriptable, uuid(42084755-fedc-4310-831c-4f43e7b42e20)]
|
||||
[scriptable, uuid(899b826b-2eb3-469c-8b31-4c29f5d341a6)]
|
||||
interface nsIBinaryInputStream : nsIInputStream {
|
||||
void setInputStream(in nsIInputStream aInputStream);
|
||||
|
||||
@ -76,10 +76,10 @@ interface nsIBinaryInputStream : nsIInputStream {
|
||||
* Note: passing view.buffer, where view is an ArrayBufferView of an
|
||||
* ArrayBuffer, is not valid unless view.byteOffset == 0.
|
||||
*
|
||||
* @throws NS_ERROR_FAILURE if it can't read aLength bytes
|
||||
* @return The number of bytes actually read into aArrayBuffer.
|
||||
*/
|
||||
[implicit_jscontext]
|
||||
void readArrayBuffer(in uint32_t aLength, in jsval aArrayBuffer);
|
||||
unsigned long readArrayBuffer(in uint32_t aLength, in jsval aArrayBuffer);
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
@ -32,6 +32,7 @@ function test_binary_streams() {
|
||||
const HelloArray = Array.map(HelloStr, function(c) {return c.charCodeAt(0)});
|
||||
var countObj = {};
|
||||
var msg = {};
|
||||
var buffer = ArrayBuffer(HelloArray.length);
|
||||
|
||||
// Test reading immediately after writing.
|
||||
os.writeBoolean(true);
|
||||
@ -72,6 +73,10 @@ function test_binary_streams() {
|
||||
do_check_eq(typeof msg, typeof HelloArray);
|
||||
do_check_eq(msg.toSource(), HelloArray.toSource());
|
||||
do_check_eq(is.available(), 0);
|
||||
os.writeByteArray(HelloArray, HelloArray.length);
|
||||
do_check_eq(is.readArrayBuffer(buffer.byteLength, buffer), HelloArray.length);
|
||||
do_check_eq([b for (b of Uint8Array(buffer))].toSource(), HelloArray.toSource());
|
||||
do_check_eq(is.available(), 0);
|
||||
|
||||
// Test writing in one big chunk.
|
||||
os.writeBoolean(true);
|
||||
|
Loading…
x
Reference in New Issue
Block a user