Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ext/node): util.types.isSharedArrayBuffer #17836

Merged
merged 2 commits into from
Feb 26, 2023

Conversation

kt3k
Copy link
Member

@kt3k kt3k commented Feb 21, 2023

part of #17779

This fixes node compat test case cli/tests/node_compat/test/parallel/test-util-types.js.

util.types.isSharedArrayBuffer was broken because SharedArrayBuffer is unavailable during snapshotting. This fixes it by avoiding caching _getSharedArrayBufferByteLength during snapshotting

} catch {
return false;
}
return value instanceof SharedArrayBuffer;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about the following code?

// https://tc39.es/ecma262/#sec-get-sharedarraybuffer.prototype.bytelength
let _getSharedArrayBufferByteLength;

export function isSharedArrayBuffer(
  value: unknown,
): value is SharedArrayBuffer {
  // TODO: add SharedArrayBuffer to primordials
  _getSharedArrayBufferByteLength ??= Object.getOwnPropertyDescriptor(
    SharedArrayBuffer.prototype,
    "byteLength",
  )!.get!;

  try {
    _getSharedArrayBufferByteLength.call(value);
    return true;
  } catch {
    return false;
  }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Updated the PR to use it

@kt3k kt3k requested a review from bartlomieju February 24, 2023 12:18
Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@kt3k kt3k merged commit 3187e4e into denoland:main Feb 26, 2023
@kt3k kt3k deleted the fix-node-compat-1 branch February 26, 2023 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants