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

compat: Buffer: allow optional positional arguments to be undefined #4911

Merged
merged 2 commits into from
Oct 3, 2023
Merged

compat: Buffer: allow optional positional arguments to be undefined #4911

merged 2 commits into from
Oct 3, 2023

Conversation

kitsuned
Copy link
Contributor

What does this PR do?

SSIA.
Fixes Buffer.prototype.copy() and Buffer.prototype.compare() in the following cases:

Buffer.prototype.copy()
Welcome to Node.js v18.17.1.
Type ".help" for more information.
> Buffer.alloc(0).copy(Buffer.alloc(0), undefined)
0
Welcome to Bun v1.0.0
Type ".help" for more information.
> Buffer.alloc(0).copy(Buffer.alloc(0), undefined)
1 | "use strict";void 0;Buffer.alloc(0).copy(Buffer.alloc(0), undefined);
                       ^
TypeError: Expected number
Buffer.prototype.compare()
Welcome to Node.js v18.17.1.
Type ".help" for more information.
> Buffer.alloc(0).compare(Buffer.alloc(0), undefined)
0
Welcome to Bun v1.0.0
Type ".help" for more information.
> Buffer.alloc(0).compare(Buffer.alloc(0), undefined)
1 | "use strict";void 0;Buffer.alloc(0).compare(Buffer.alloc(0), undefined);
                       ^
TypeError: Expected number

@Jarred-Sumner
Copy link
Collaborator

thank you for this

later we should do a helper for argumentCount() that is "last non-undefined argument", since it's really easy to make a mistake like this in native code

@kitsuned
Copy link
Contributor Author

kitsuned commented Oct 3, 2023

hey, @Jarred-Sumner! any updates on this?

fyi quite popular tar-stream package is broken due to Buffer handling in b4a dependency.
the PR addresses this issue.

@Jarred-Sumner Jarred-Sumner merged commit aa8ccce into oven-sh:main Oct 3, 2023
14 of 19 checks passed
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.

2 participants