/src/serenity/Userland/Libraries/LibJS/Runtime/ValueInlines.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2023, Andreas Kling <kling@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <LibJS/Runtime/Completion.h> |
10 | | #include <LibJS/Runtime/Value.h> |
11 | | |
12 | | namespace JS { |
13 | | |
14 | | inline bool Value::to_boolean() const |
15 | 8 | { |
16 | | // OPTIMIZATION: Fast path for when this value is already a boolean. |
17 | 8 | if (is_boolean()) |
18 | 8 | return as_bool(); |
19 | | |
20 | 0 | return to_boolean_slow_case(); |
21 | 8 | } |
22 | | |
23 | | inline ThrowCompletionOr<Value> Value::to_number(VM& vm) const |
24 | 5 | { |
25 | | // OPTIMIZATION: Fast path for when this value is already a number. |
26 | 5 | if (is_number()) |
27 | 5 | return *this; |
28 | | |
29 | 0 | return to_number_slow_case(vm); |
30 | 5 | } |
31 | | |
32 | | inline ThrowCompletionOr<Value> Value::to_numeric(VM& vm) const |
33 | 0 | { |
34 | | // OPTIMIZATION: Fast path for when this value is already a number. |
35 | 0 | if (is_number()) |
36 | 0 | return *this; |
37 | | |
38 | 0 | return to_numeric_slow_case(vm); |
39 | 0 | } |
40 | | |
41 | | inline ThrowCompletionOr<Value> Value::to_primitive(VM& vm, PreferredType preferred_type) const |
42 | 2 | { |
43 | 2 | if (!is_object()) |
44 | 1 | return *this; |
45 | 1 | return to_primitive_slow_case(vm, preferred_type); |
46 | 2 | } |
47 | | |
48 | | } |