Skip to content

Commit

Permalink
Bug 1718134 [wpt PR 29488] - Streams: read with fixed endianness, a=t…
Browse files Browse the repository at this point in the history
…estonly

Automatic update from web-platform-tests
Streams: read with fixed endianness

In some tests for readable byte streams, we pass a Uint16Array to
reader.read(view), then write into it as a Uint8Array and finally read
the results back as a Uint16Array. However, Uint16Array uses the
platform byte order, whereas these tests assume that it's always in
little-endian order.

Node.js has also started implementing the Streams API
(nodejs/node#39062), and they also run on big-endian platforms. To
support this, the tests must be independent of the platform byte
order. Use a DataView to achieve this.
--

wpt-commits: afcacf21caaf9d0efd6601833077e04af9b4dee1
wpt-pr: 29488
  • Loading branch information
MattiasBuelens authored and moz-wptsync-bot committed Jun 26, 2021
1 parent 9423479 commit f1dec82
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,8 @@ promise_test(() => {
assert_equals(view.byteOffset, 0, 'byteOffset');
assert_equals(view.byteLength, 2, 'byteLength');

assert_equals(view[0], 0x0201);
const dataView = new DataView(view.buffer, view.byteOffset, view.byteLength);
assert_equals(dataView.getUint16(0), 0x0102);

return reader.read(new Uint8Array(1));
}).then(result => {
Expand Down Expand Up @@ -1138,7 +1139,7 @@ promise_test(() => {

assert_equals(pullCount, 1, '1 pull() should have been made in response to partial fill by enqueue()');
assert_not_equals(byobRequest, null, 'byobRequest should not be null');
assert_equals(viewInfos[0].byteLength, 2, 'byteLength before enqueue() shouild be 2');
assert_equals(viewInfos[0].byteLength, 2, 'byteLength before enqueue() should be 2');
assert_equals(viewInfos[1].byteLength, 1, 'byteLength after enqueue() should be 1');

reader.cancel();
Expand Down Expand Up @@ -1326,7 +1327,9 @@ promise_test(() => {
const view = result.value;
assert_equals(view.byteOffset, 0);
assert_equals(view.byteLength, 2);
assert_equals(view[0], 0xaaff);

const dataView = new DataView(view.buffer, view.byteOffset, view.byteLength);
assert_equals(dataView.getUint16(0), 0xffaa);

assert_equals(viewInfo.constructor, Uint8Array, 'view.constructor should be Uint8Array');
assert_equals(viewInfo.bufferByteLength, 2, 'view.buffer.byteLength should be 2');
Expand Down Expand Up @@ -1381,7 +1384,9 @@ promise_test(() => {
assert_equals(view.buffer.byteLength, 4, 'buffer.byteLength');
assert_equals(view.byteOffset, 0, 'byteOffset');
assert_equals(view.byteLength, 2, 'byteLength');
assert_equals(view[0], 0x0001, 'Contents are set');

const dataView = new DataView(view.buffer, view.byteOffset, view.byteLength);
assert_equals(dataView.getUint16(0), 0x0100, 'contents are set');

const p = reader.read(new Uint16Array(1));

Expand All @@ -1395,7 +1400,9 @@ promise_test(() => {
assert_equals(view.buffer.byteLength, 2, 'buffer.byteLength');
assert_equals(view.byteOffset, 0, 'byteOffset');
assert_equals(view.byteLength, 2, 'byteLength');
assert_equals(view[0], 0x0302, 'Contents are set');

const dataView = new DataView(view.buffer, view.byteOffset, view.byteLength);
assert_equals(dataView.getUint16(0), 0x0203, 'contents are set');

assert_not_equals(byobRequest, null, 'byobRequest must not be null');
assert_equals(viewInfo.constructor, Uint8Array, 'view.constructor should be Uint8Array');
Expand Down

0 comments on commit f1dec82

Please sign in to comment.