1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-08 05:27:14 +09:00
ladybird/Libraries/LibJS/Runtime/ValueInlines.h
Andreas Kling fc111537bb LibJS: Move Value::to_i32() and to_u32() back out-of-line
While good on arm64, this appears to have angered the x86_64 benchmark
runner, so let's just put them back out-of-line.
2025-04-10 00:33:54 +02:00

51 lines
1.1 KiB
C++

/*
* Copyright (c) 2023, Andreas Kling <andreas@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/Value.h>
namespace JS {
inline bool Value::to_boolean() const
{
// OPTIMIZATION: Fast path for when this value is already a boolean.
if (is_boolean())
return as_bool();
if (is_int32())
return as_i32() != 0;
return to_boolean_slow_case();
}
inline ThrowCompletionOr<Value> Value::to_number(VM& vm) const
{
// OPTIMIZATION: Fast path for when this value is already a number.
if (is_number())
return *this;
return to_number_slow_case(vm);
}
inline ThrowCompletionOr<Value> Value::to_numeric(VM& vm) const
{
// OPTIMIZATION: Fast path for when this value is already a number.
if (is_number())
return *this;
return to_numeric_slow_case(vm);
}
inline ThrowCompletionOr<Value> Value::to_primitive(VM& vm, PreferredType preferred_type) const
{
if (!is_object())
return *this;
return to_primitive_slow_case(vm, preferred_type);
}
}