Skip to content

Commit

Permalink
feat: avoid SharedArrayBuffer until required
Browse files Browse the repository at this point in the history
  • Loading branch information
snyamathi committed Apr 21, 2021
1 parent 4b1c0c7 commit de16a49
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions support/types.js
Expand Up @@ -238,10 +238,21 @@ exports.isDataView = isDataView;
function isSharedArrayBufferToString(value) {
return ObjectToString(value) === '[object SharedArrayBuffer]';
}
isSharedArrayBufferToString.working = (
typeof SharedArrayBuffer !== 'undefined' &&
isSharedArrayBufferToString(new 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') {
return false;
Expand Down

0 comments on commit de16a49

Please sign in to comment.