From 5927cdd9c5a4a9e4f7698fa4318b69b8da6241b2 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 3 Jul 2022 16:26:55 +0200 Subject: [PATCH] LibJS: Use u64 for the length parameter in Array::create() This doesn't matter per se as the value is immediately validated to be in the 0 to 2^32 - 1 range, but it avoids having to cast a number that potentially doesn't fit into a size_t into one at the call site. More often than not, array-like lengths are only validated to be <= 2^52 - 1, i.e. MAX_SAFE_INTEGER. This is fully backwards compatible with existing code as a size_t always fits into an u64, but an u64 might not always fit into a size_t. --- Userland/Libraries/LibJS/Runtime/Array.cpp | 2 +- Userland/Libraries/LibJS/Runtime/Array.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Array.cpp b/Userland/Libraries/LibJS/Runtime/Array.cpp index 0f893068f0..6d88ccf103 100644 --- a/Userland/Libraries/LibJS/Runtime/Array.cpp +++ b/Userland/Libraries/LibJS/Runtime/Array.cpp @@ -17,7 +17,7 @@ namespace JS { // 10.4.2.2 ArrayCreate ( length [ , proto ] ), https://tc39.es/ecma262/#sec-arraycreate -ThrowCompletionOr Array::create(GlobalObject& global_object, size_t length, Object* prototype) +ThrowCompletionOr Array::create(GlobalObject& global_object, u64 length, Object* prototype) { auto& vm = global_object.vm(); diff --git a/Userland/Libraries/LibJS/Runtime/Array.h b/Userland/Libraries/LibJS/Runtime/Array.h index a3d793d05d..7886ac3c83 100644 --- a/Userland/Libraries/LibJS/Runtime/Array.h +++ b/Userland/Libraries/LibJS/Runtime/Array.h @@ -21,7 +21,7 @@ class Array : public Object { JS_OBJECT(Array, Object); public: - static ThrowCompletionOr create(GlobalObject&, size_t length, Object* prototype = nullptr); + static ThrowCompletionOr create(GlobalObject&, u64 length, Object* prototype = nullptr); static Array* create_from(GlobalObject&, Vector const&); // Non-standard but equivalent to CreateArrayFromList. template