Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid SharedArrayBuffer until required #59

Merged
merged 3 commits into from
May 3, 2021
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