1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:07:45 +00:00

LibJS: Add content type check to IntegerIndexedElementSet()

Resolves a FIXME.
This commit is contained in:
Linus Groh 2021-06-27 20:59:20 +01:00
parent e08702a235
commit d3fc8652c7

View file

@ -63,9 +63,19 @@ public:
// NOTE: In error cases, the function will return as if it succeeded.
virtual bool put_by_index(u32 property_index, Value value) override
{
// FIXME: If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value).
// Otherwise, let numValue be ? ToNumber(value).
// (set_value currently takes value by itself)
auto& vm = this->vm();
auto& global_object = this->global_object();
Value num_value;
if (content_type() == TypedArrayBase::ContentType::BigInt) {
num_value = value.to_bigint(global_object);
if (vm.exception())
return {};
} else {
num_value = value.to_number(global_object);
if (vm.exception())
return {};
}
if (!is_valid_integer_index(property_index))
return true;
@ -82,7 +92,7 @@ public:
return true;
}
viewed_array_buffer()->template set_value<T>(indexed_position.value(), value, true, ArrayBuffer::Order::Unordered);
viewed_array_buffer()->template set_value<T>(indexed_position.value(), num_value, true, ArrayBuffer::Order::Unordered);
return true;
}