From 3187e4e909c734da1f1d35488315e9eb6c76d9cb Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Sun, 26 Feb 2023 11:23:53 +0900 Subject: fix(ext/node): util.types.isSharedArrayBuffer (#17836) --- cli/tests/node_compat/config.json | 2 +- ext/node/polyfills/internal_binding/types.ts | 16 ++++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/cli/tests/node_compat/config.json b/cli/tests/node_compat/config.json index b133fe8b2..2f21e0d46 100644 --- a/cli/tests/node_compat/config.json +++ b/cli/tests/node_compat/config.json @@ -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", diff --git a/ext/node/polyfills/internal_binding/types.ts b/ext/node/polyfills/internal_binding/types.ts index 348d5553f..6b8b3d6e4 100644 --- a/ext/node/polyfills/internal_binding/types.ts +++ b/ext/node/polyfills/internal_binding/types.ts @@ -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( @@ -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); -- cgit v1.2.3