1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 10:47:35 +00:00

LibJS: Add all of the DataView.prototype.get* methods

This commit is contained in:
Idan Horowitz 2021-06-14 01:57:15 +03:00 committed by Linus Groh
parent e4d267d4fb
commit c54b9a6920
6 changed files with 206 additions and 0 deletions

View file

@ -47,6 +47,19 @@ public:
static SignedBigInteger import_data(const StringView& data) { return import_data((const u8*)data.characters_without_null_termination(), data.length()); }
static SignedBigInteger import_data(const u8* ptr, size_t length);
static SignedBigInteger create_from(i64 value)
{
auto sign = false;
u64 unsigned_value;
if (value < 0) {
unsigned_value = static_cast<u64>(-(value + 1)) + 1;
sign = true;
} else {
unsigned_value = value;
}
return SignedBigInteger { UnsignedBigInteger::create_from(unsigned_value), sign };
}
size_t export_data(Bytes, bool remove_leading_zeros = false) const;
static SignedBigInteger from_base10(StringView str);

View file

@ -41,6 +41,16 @@ public:
return UnsignedBigInteger(ptr, length);
}
static UnsignedBigInteger create_from(u64 value)
{
VERIFY(sizeof(Word) == 4);
UnsignedBigInteger integer;
integer.m_words.resize(2);
integer.m_words[0] = static_cast<Word>(value & 0xFFFFFFFF);
integer.m_words[1] = static_cast<Word>((value >> 32) & 0xFFFFFFFF);
return integer;
}
size_t export_data(Bytes, bool remove_leading_zeros = false) const;
static UnsignedBigInteger from_base10(const String& str);