summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoshiya Hinosawa <stibium121@gmail.com>2023-02-26 11:23:53 +0900
committerGitHub <noreply@github.com>2023-02-26 11:23:53 +0900
commit3187e4e909c734da1f1d35488315e9eb6c76d9cb (patch)
tree0987172b833f24845fc55987cc27a72a2795bb9f
parentda5b5d4688f03e578565966b1c0634a187f7729d (diff)
fix(ext/node): util.types.isSharedArrayBuffer (#17836)
-rw-r--r--cli/tests/node_compat/config.json2
-rw-r--r--ext/node/polyfills/internal_binding/types.ts16
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);