1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:07:35 +00:00

LibWeb/WebIDL: Implement ConvertToInt and IntegerPart AOs

These are used when converting JS::Values to integers in IDL, as opposed
to our current AD-HOC solution.
This commit is contained in:
Shannon Booth 2023-12-27 21:00:56 +13:00 committed by Andreas Kling
parent f1f369b6c6
commit 11371acfaf
3 changed files with 132 additions and 0 deletions

View file

@ -1,6 +1,7 @@
/*
* Copyright (c) 2021-2023, Luke Wilde <lukew@serenityos.org>
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2023, Shannon Booth <shannon@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -63,4 +64,21 @@ JS::Completion construct(WebIDL::CallbackType& callback, Args&&... args)
JS::ThrowCompletionOr<bool> is_named_property_exposed_on_object(Variant<Bindings::LegacyPlatformObject const*, HTML::Window*> const& variant, JS::PropertyKey const& property_key);
// https://webidl.spec.whatwg.org/#abstract-opdef-integerpart
double integer_part(double n);
enum class EnforceRange {
Yes,
No,
};
enum class Clamp {
Yes,
No,
};
// https://webidl.spec.whatwg.org/#abstract-opdef-converttoint
template<Integral T>
JS::ThrowCompletionOr<T> convert_to_int(JS::VM& vm, JS::Value, EnforceRange enforce_range = EnforceRange::No, Clamp clamp = Clamp::No);
}