Skip to content
Merged
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
14 changes: 8 additions & 6 deletions support/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,21 +235,23 @@ function isDataView(value) {
}
exports.isDataView = isDataView;

// Store a copy of SharedArrayBuffer in case it's deleted elsewhere
var SharedArrayBufferCopy = typeof SharedArrayBuffer !== 'undefined' ? SharedArrayBuffer : undefined;
function isSharedArrayBufferToString(value) {
return ObjectToString(value) === '[object SharedArrayBuffer]';
}
isSharedArrayBufferToString.working = (
typeof SharedArrayBuffer !== 'undefined' &&
isSharedArrayBufferToString(new SharedArrayBuffer())
);
function isSharedArrayBuffer(value) {
if (typeof SharedArrayBuffer === 'undefined') {
if (typeof SharedArrayBufferCopy === 'undefined') {
Copy link
Contributor Author

@snyamathi snyamathi Apr 21, 2021

Choose a reason for hiding this comment

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

So after this change, we would check calls at some later time against the copy of SharedArrayBuffer which existed initially. Even if someone deleted SharedArrayBuffer we would still return correctly for any buffers created before SharedArrayBuffer was deleted.

.. it does look ugly though 😛

return false;
}

if (typeof isSharedArrayBufferToString.working === 'undefined') {
isSharedArrayBufferToString.working = isSharedArrayBufferToString(new SharedArrayBufferCopy());
}

return isSharedArrayBufferToString.working
? isSharedArrayBufferToString(value)
: value instanceof SharedArrayBuffer;
: value instanceof SharedArrayBufferCopy;
}
exports.isSharedArrayBuffer = isSharedArrayBuffer;

Expand Down