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

enhance INVALID_ARG_TYPE and cleanup some node:buffer error handling #14200

Merged
merged 4 commits into from
Oct 3, 2024

Conversation

nektro
Copy link
Contributor

@nektro nektro commented Sep 27, 2024

pulled out of #13757 to merge independently

wip: i expect having to update some test messages once this runs through the first time

@nektro nektro marked this pull request as ready for review September 27, 2024 07:29
throwNodeRangeError(lexicalGlobalObject, scope, "Invalid array length"_s);
else
throwTypeError(lexicalGlobalObject, scope, "Expected number"_s);
const unsigned U32_MAX = std::numeric_limits<unsigned>().max();
Copy link
Collaborator

Choose a reason for hiding this comment

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

constexpr

auto num = arg.asNumber();
if (num < 0 || std::isinf(num)) return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, name, 0, upperBound, arg);
double intpart;
if (std::modf(num, &intpart) != 0) return Bun::ERR::INVALID_ARG_TYPE(scope, lexicalGlobalObject, name, "integer"_s, arg);
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this supposed to truncate? if so std::trunc might fit better

@@ -1527,6 +1478,9 @@ static inline JSC::EncodedJSValue jsBufferToString(JSC::VM& vm, JSC::JSGlobalObj
if (UNLIKELY(length == 0)) {
RELEASE_AND_RETURN(scope, JSC::JSValue::encode(JSC::jsEmptyString(vm)));
}
if (length > WTF::String::MaxLength) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we have a different length constant for this?

RETURN_IF_EXCEPTION(scope, {});
}

if (!lengthValue.isUndefined()) {
end = parseIndex(lexicalGlobalObject, scope, lengthValue);
end = parseIndex(lexicalGlobalObject, scope, "end"_s, lengthValue, limit - start);
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice

@nektro nektro merged commit 13ca454 into main Oct 3, 2024
47 of 49 checks passed
@nektro nektro deleted the nektro-patch-58076 branch October 3, 2024 09:13
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