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

BigInt-related API fixes and non-breaking changes #285

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mildsunrise
Copy link
Contributor

BigInt-related API fixes and (for now, only) non-breaking changes.

  • input conversions for BigInt:

    • all integer types (8, 16, 32, 64) now accept bigint and number

    • 64-bit integer types ([u]long, [u]int64, gtype) now convert the value to BigInt and then call [U]Int64Value()

      (the other integer types still convert to Number first, which means IIRC that if an out-of-range BigInt is passed, they'll get converted to trash rather than the low bits, as the user would expect. but it's better for performance and user can just & 0xFFFFFFFFn)

  • GType consistency (these are breaking, but very little used so I think a fix like this is justified):

    • GValueToV8 now converts GType to BigInt to be consistent
    • GTypes only support conversion from BigInt now
  • I've also annotated the places that should be changed to completely support BigInt, but would be a breaking change.

  • other non-BigInt related fixes:

    • add missing entries for [u]int64 in CanConvertV8ToGValue

@romgrk
Copy link
Owner

romgrk commented Apr 20, 2021

You can include the breaking changes here directly, I'll release 1.0 right after it's merged.

@mildsunrise
Copy link
Contributor Author

hmm I would wait a bit before the breaking release, just in case there are more breaking changes we haven't discovered yet? either way, +1

@romgrk
Copy link
Owner

romgrk commented Apr 20, 2021

The breaking changes need to land on master anyway, even if we wait before the release. You can add them here directly, it will be simpler.

@mildsunrise mildsunrise marked this pull request as ready for review April 21, 2021 11:55
@mildsunrise
Copy link
Contributor Author

Perfect, done. This seems to be working but I'll test it some more to make sure.

Copy link
Owner

@romgrk romgrk left a comment

Choose a reason for hiding this comment

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

One comment but the rest seems good :)

if (value->IsBigInt())
return value.As<v8::BigInt>()->Int64Value();
return Nan::To<int32_t>(value).ToChecked();
}
Copy link
Owner

Choose a reason for hiding this comment

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

This one feels a bit weird, with the name being ToInt32 but it returns an int64_t. Maybe it should return an int32_t?

@mildsunrise
Copy link
Contributor Author

(note to self: parts of this PR have been merged as #301 and #322... I should take those out and rebase)

side-effects:
 - g_value_info_get_value() returns an int64, but enums
   are still 32 bit, so we need to cast to Number
turns out ToBigInt() and ToNumber() doesn't perform conversion
but only 'implicit' conversion which is not useful. create
helpers to extract the numbers from V8 and use them everywhere
(except in enum, flags, unichar)
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.

None yet

2 participants