Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 4 additions & 17 deletions reference-implementation/lib/abstract-ops/ecmascript.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';
const assert = require('assert');

const isFakeDetached = Symbol('is "detached" for our purposes');
const ArrayBufferPrototypeTransferToFixedLength = ArrayBuffer.prototype.transferToFixedLength;
const ArrayBufferPrototypeDetachedGetter = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'detached').get;

exports.typeIsObject = x => (typeof x === 'object' && x !== null) || typeof x === 'function';

Expand All @@ -15,31 +16,17 @@ exports.CopyDataBlockBytes = (dest, destOffset, src, srcOffset, n) => {
new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset);
};

// Not implemented correctly
exports.TransferArrayBuffer = O => {
assert(!exports.IsDetachedBuffer(O));
const transferredIshVersion = O.slice();

// This is specifically to fool tests that test "is transferred" by taking a non-zero-length
// ArrayBuffer and checking if its byteLength starts returning 0.
Object.defineProperty(O, 'byteLength', {
get() {
return 0;
}
});
O[isFakeDetached] = true;

return transferredIshVersion;
return ArrayBufferPrototypeTransferToFixedLength.call(O);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using transferToFixedLength() since we don't (yet) support resizable ArrayBuffers.

I think we can loosen that restriction, but we should do that in an actual spec change. 😉

};

// Not implemented correctly
exports.CanTransferArrayBuffer = O => {
return !exports.IsDetachedBuffer(O);
};

// Not implemented correctly
exports.IsDetachedBuffer = O => {
return isFakeDetached in O;
return ArrayBufferPrototypeDetachedGetter.call(O) === true;
};

exports.Call = (F, V, args = []) => {
Expand Down
6 changes: 4 additions & 2 deletions reference-implementation/lib/abstract-ops/readable-streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -1584,6 +1584,8 @@ function ReadableByteStreamControllerPullInto(controller, view, min, readIntoReq
assert(minimumFill >= elementSize && minimumFill <= view.byteLength);
assert(minimumFill % elementSize === 0);

const byteOffset = view.byteOffset;
const byteLength = view.byteLength;
Comment on lines +1587 to +1588
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reference implementation was doing steps 8 and 9 after calling TransferArrayBuffer, which meant that view.byteLength was already 0. We didn't notice this, because we weren't actually transferring before. 😛

Fortunately, all "real" implementations already do this correctly.

const ctor = view.constructor;

let buffer;
Expand All @@ -1597,8 +1599,8 @@ function ReadableByteStreamControllerPullInto(controller, view, min, readIntoReq
const pullIntoDescriptor = {
buffer,
bufferByteLength: buffer.byteLength,
byteOffset: view.byteOffset,
byteLength: view.byteLength,
byteOffset,
byteLength,
bytesFilled: 0,
minimumFill,
elementSize,
Expand Down
2 changes: 1 addition & 1 deletion reference-implementation/web-platform-tests