From 40eab55e7d4e757d6b3fcf18d26db8c6c40bbc25 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Mon, 22 Mar 2021 22:56:47 +0100 Subject: [PATCH] LibJS: Remove as_size_t() Just like to_size_t() - which was already removed in f369229 - this is non-standard, use to_length() instead. One remaining use was removed, and I'm glad it's gone. :^) --- Userland/Applications/Spreadsheet/JSIntegration.cpp | 4 +++- Userland/Libraries/LibJS/Runtime/Value.cpp | 6 ------ Userland/Libraries/LibJS/Runtime/Value.h | 1 - 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/Userland/Applications/Spreadsheet/JSIntegration.cpp b/Userland/Applications/Spreadsheet/JSIntegration.cpp index b62c89298e..b62a5985e9 100644 --- a/Userland/Applications/Spreadsheet/JSIntegration.cpp +++ b/Userland/Applications/Spreadsheet/JSIntegration.cpp @@ -449,7 +449,9 @@ JS_DEFINE_NATIVE_FUNCTION(WorkbookObject::sheet) return JS::Value(&sheet.global_object()); } } else { - auto index = name_value.as_size_t(); + auto index = name_value.to_length(global_object); + if (vm.exception()) + return {}; if (index < workbook.sheets().size()) return JS::Value(&workbook.sheets()[index].global_object()); } diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp index c5467eb300..a31e760e37 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.cpp +++ b/Userland/Libraries/LibJS/Runtime/Value.cpp @@ -517,12 +517,6 @@ u32 Value::as_u32() const return min((double)as_i32(), MAX_U32); } -size_t Value::as_size_t() const -{ - VERIFY(as_double() >= 0); - return min((double)as_i32(), MAX_ARRAY_LIKE_INDEX); -} - double Value::to_double(GlobalObject& global_object) const { auto number = to_number(global_object); diff --git a/Userland/Libraries/LibJS/Runtime/Value.h b/Userland/Libraries/LibJS/Runtime/Value.h index fcd40cd226..d0e51bc2e1 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.h +++ b/Userland/Libraries/LibJS/Runtime/Value.h @@ -261,7 +261,6 @@ public: i32 as_i32() const; u32 as_u32() const; - size_t as_size_t() const; String to_string(GlobalObject&, bool legacy_null_to_empty_string = false) const; PrimitiveString* to_primitive_string(GlobalObject&);