Skip to content

Commit

Permalink
fix(ext/node): util.types.isSharedArrayBuffer (#17836)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k committed Mar 10, 2023
1 parent a07adc1 commit e5ff08d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cli/tests/node_compat/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@
"test-util-isDeepStrictEqual.js",
"test-util-promisify.js",
"test-util-types-exists.js",
"TODO:test-util-types.js",
"test-util-types.js",
"test-util.js",
"test-vm-static-this.js",
"test-webcrypto-sign-verify.js",
Expand Down
16 changes: 6 additions & 10 deletions ext/node/polyfills/internal_binding/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@ const _getArrayBufferByteLength = Object.getOwnPropertyDescriptor(
)!.get!;

// https://tc39.es/ecma262/#sec-get-sharedarraybuffer.prototype.bytelength
const _getSharedArrayBufferByteLength = globalThis.SharedArrayBuffer
? Object.getOwnPropertyDescriptor(
SharedArrayBuffer.prototype,
"byteLength",
)!.get!
: undefined;
let _getSharedArrayBufferByteLength;

// https://tc39.es/ecma262/#sec-get-%typedarray%.prototype-@@tostringtag
const _getTypedArrayToStringTag = Object.getOwnPropertyDescriptor(
Expand Down Expand Up @@ -285,10 +280,11 @@ export function isSetIterator(
export function isSharedArrayBuffer(
value: unknown,
): value is SharedArrayBuffer {
// SharedArrayBuffer is not available on this runtime
if (_getSharedArrayBufferByteLength === undefined) {
return false;
}
// TODO(kt3k): add SharedArrayBuffer to primordials
_getSharedArrayBufferByteLength ??= Object.getOwnPropertyDescriptor(
SharedArrayBuffer.prototype,
"byteLength",
)!.get!;

try {
_getSharedArrayBufferByteLength.call(value);
Expand Down

0 comments on commit e5ff08d

Please sign in to comment.