Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: remove getter, store copy of SAB
  • Loading branch information
snyamathi committed Apr 21, 2021
commit 62f00fd96de23ba82685b819f7ecfb20b94a9bc6
25 changes: 8 additions & 17 deletions support/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,32 +235,23 @@ function isDataView(value) {
}
exports.isDataView = isDataView;

// Store a copy of SharedArrayBuffer in case it's deleted elsewhere
var SharedArrayBufferCopy = SharedArrayBuffer;
function isSharedArrayBufferToString(value) {
return ObjectToString(value) === '[object SharedArrayBuffer]';
}
// Avoid invoking SharedArrayBuffer constructor until required, then memoize
Object.defineProperty(isSharedArrayBufferToString, 'working', {
get: (function() {
var isWorking;
return function () {
if (isWorking === undefined) {
isWorking = (
typeof SharedArrayBuffer !== 'undefined' &&
isSharedArrayBufferToString(new SharedArrayBuffer())
)
}
return isWorking;
}
})()
});
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