1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:37:44 +00:00

LibJS: Extract named vm variables in ArrayBufferPrototype::slice

This commit is contained in:
Shannon Booth 2023-07-01 22:33:12 +12:00 committed by Linus Groh
parent 3781948f0c
commit e7435d68b0

View file

@ -41,6 +41,9 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayBufferPrototype::slice)
{ {
auto& realm = *vm.current_realm(); auto& realm = *vm.current_realm();
auto start = vm.argument(0);
auto end = vm.argument(1);
// 1. Let O be the this value. // 1. Let O be the this value.
// 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). // 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
auto array_buffer_object = TRY(typed_this_value(vm)); auto array_buffer_object = TRY(typed_this_value(vm));
@ -56,7 +59,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayBufferPrototype::slice)
auto length = array_buffer_object->byte_length(); auto length = array_buffer_object->byte_length();
// 6. Let relativeStart be ? ToIntegerOrInfinity(start). // 6. Let relativeStart be ? ToIntegerOrInfinity(start).
auto relative_start = TRY(vm.argument(0).to_integer_or_infinity(vm)); auto relative_start = TRY(start.to_integer_or_infinity(vm));
double first; double first;
// 7. If relativeStart is -∞, let first be 0. // 7. If relativeStart is -∞, let first be 0.
@ -70,7 +73,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayBufferPrototype::slice)
first = min(relative_start, (double)length); first = min(relative_start, (double)length);
// 10. If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToIntegerOrInfinity(end). // 10. If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToIntegerOrInfinity(end).
auto relative_end = vm.argument(1).is_undefined() ? length : TRY(vm.argument(1).to_integer_or_infinity(vm)); auto relative_end = end.is_undefined() ? length : TRY(end.to_integer_or_infinity(vm));
double final; double final;
// 11. If relativeEnd is -∞, let final be 0. // 11. If relativeEnd is -∞, let final be 0.