diff options
author | Linus Groh <mail@linusgroh.de> | 2022-07-03 16:26:55 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-07-04 10:10:11 +0200 |
commit | 5927cdd9c5a4a9e4f7698fa4318b69b8da6241b2 (patch) | |
tree | 8c92b5a526e4f649e4992a3e65ef72dd5f5dee54 | |
parent | 65eb1ee67a45384b4d4276444779bece9677cd66 (diff) | |
download | serenity-5927cdd9c5a4a9e4f7698fa4318b69b8da6241b2.zip |
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.
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Array.cpp | 2 | ||||
-rw-r--r-- | 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*> Array::create(GlobalObject& global_object, size_t length, Object* prototype) +ThrowCompletionOr<Array*> 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<Array*> create(GlobalObject&, size_t length, Object* prototype = nullptr); + static ThrowCompletionOr<Array*> create(GlobalObject&, u64 length, Object* prototype = nullptr); static Array* create_from(GlobalObject&, Vector<Value> const&); // Non-standard but equivalent to CreateArrayFromList. template<typename T> |