diff --git a/Libraries/LibJS/Runtime/Value.cpp b/Libraries/LibJS/Runtime/Value.cpp index 555dab57828..a01d563e9a0 100644 --- a/Libraries/LibJS/Runtime/Value.cpp +++ b/Libraries/LibJS/Runtime/Value.cpp @@ -953,42 +953,6 @@ ThrowCompletionOr Value::to_i32_slow_case(VM& vm) const return static_cast(int32bit); } -// 7.1.6 ToInt32 ( argument ), https://tc39.es/ecma262/#sec-toint32 -ThrowCompletionOr Value::to_i32(VM& vm) const -{ - if (is_int32()) - return as_i32(); - return to_i32_slow_case(vm); -} - -// 7.1.7 ToUint32 ( argument ), https://tc39.es/ecma262/#sec-touint32 -ThrowCompletionOr Value::to_u32(VM& vm) const -{ - // OPTIMIZATION: If this value is encoded as a positive i32, return it directly. - if (is_int32() && as_i32() >= 0) - return as_i32(); - - // 1. Let number be ? ToNumber(argument). - double number = TRY(to_number(vm)).as_double(); - - // 2. If number is not finite or number is either +0𝔽 or -0𝔽, return +0𝔽. - if (!isfinite(number) || number == 0) - return 0; - - // 3. Let int be the mathematical value whose sign is the sign of number and whose magnitude is floor(abs(ℝ(number))). - auto int_val = floor(fabs(number)); - if (signbit(number)) - int_val = -int_val; - - // 4. Let int32bit be int modulo 2^32. - auto int32bit = modulo(int_val, NumericLimits::max() + 1.0); - - // 5. Return 𝔽(int32bit). - // Cast to i64 here to ensure that the double --> u32 cast doesn't invoke undefined behavior - // Otherwise, negative numbers cause a UBSAN warning. - return static_cast(static_cast(int32bit)); -} - // 7.1.8 ToInt16 ( argument ), https://tc39.es/ecma262/#sec-toint16 ThrowCompletionOr Value::to_i16(VM& vm) const { diff --git a/Libraries/LibJS/Runtime/ValueInlines.h b/Libraries/LibJS/Runtime/ValueInlines.h index 94d96701596..effa7f75eca 100644 --- a/Libraries/LibJS/Runtime/ValueInlines.h +++ b/Libraries/LibJS/Runtime/ValueInlines.h @@ -48,4 +48,19 @@ inline ThrowCompletionOr Value::to_primitive(VM& vm, PreferredType prefer return to_primitive_slow_case(vm, preferred_type); } +// 7.1.6 ToInt32 ( argument ), https://tc39.es/ecma262/#sec-toint32 +inline ThrowCompletionOr Value::to_i32(VM& vm) const +{ + if (is_int32()) + return as_i32(); + + return to_i32_slow_case(vm); +} + +// 7.1.7 ToUint32 ( argument ), https://tc39.es/ecma262/#sec-touint32 +inline ThrowCompletionOr Value::to_u32(VM& vm) const +{ + return static_cast(TRY(to_i32(vm))); +} + } diff --git a/Libraries/LibWeb/Bindings/ImageConstructor.cpp b/Libraries/LibWeb/Bindings/ImageConstructor.cpp index 91449b8435c..8111de81942 100644 --- a/Libraries/LibWeb/Bindings/ImageConstructor.cpp +++ b/Libraries/LibWeb/Bindings/ImageConstructor.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include diff --git a/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp b/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp index 9ac38d71952..a97eff14290 100644 --- a/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp +++ b/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include diff --git a/Libraries/LibWeb/Crypto/SubtleCrypto.cpp b/Libraries/LibWeb/Crypto/SubtleCrypto.cpp index a5ac5afb87f..4fb748f40ff 100644 --- a/Libraries/LibWeb/Crypto/SubtleCrypto.cpp +++ b/Libraries/LibWeb/Crypto/SubtleCrypto.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include diff --git a/Libraries/LibWeb/DOM/NodeIterator.cpp b/Libraries/LibWeb/DOM/NodeIterator.cpp index 61f32451afd..a4f8def926b 100644 --- a/Libraries/LibWeb/DOM/NodeIterator.cpp +++ b/Libraries/LibWeb/DOM/NodeIterator.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include diff --git a/Libraries/LibWeb/DOM/TreeWalker.cpp b/Libraries/LibWeb/DOM/TreeWalker.cpp index e2c6961a447..aeea0ae6f4e 100644 --- a/Libraries/LibWeb/DOM/TreeWalker.cpp +++ b/Libraries/LibWeb/DOM/TreeWalker.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include diff --git a/Libraries/LibWeb/WebAssembly/WebAssembly.cpp b/Libraries/LibWeb/WebAssembly/WebAssembly.cpp index 89613052c6b..50eb5262e39 100644 --- a/Libraries/LibWeb/WebAssembly/WebAssembly.cpp +++ b/Libraries/LibWeb/WebAssembly/WebAssembly.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include diff --git a/Tests/LibWasm/test-wasm.cpp b/Tests/LibWasm/test-wasm.cpp index 037b56c3b63..39171d6d005 100644 --- a/Tests/LibWasm/test-wasm.cpp +++ b/Tests/LibWasm/test-wasm.cpp @@ -5,6 +5,7 @@ */ #include +#include #include #include #include