mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-06 16:19:23 +00:00
Everywhere: Hoist the Libraries folder to the top-level
This commit is contained in:
parent
950e819ee7
commit
93712b24bf
Notes:
github-actions[bot]
2024-11-10 11:51:52 +00:00
Author: https://github.com/trflynn89
Commit: 93712b24bf
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2256
Reviewed-by: https://github.com/sideshowbarker
4547 changed files with 104 additions and 113 deletions
59
Libraries/LibJS/Runtime/Intl/NumberFormatFunction.cpp
Normal file
59
Libraries/LibJS/Runtime/Intl/NumberFormatFunction.cpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2024, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibJS/Runtime/Intl/NumberFormat.h>
|
||||
#include <LibJS/Runtime/Intl/NumberFormatFunction.h>
|
||||
|
||||
namespace JS::Intl {
|
||||
|
||||
JS_DEFINE_ALLOCATOR(NumberFormatFunction);
|
||||
|
||||
// 15.5.2 Number Format Functions, https://tc39.es/ecma402/#sec-number-format-functions
|
||||
NonnullGCPtr<NumberFormatFunction> NumberFormatFunction::create(Realm& realm, NumberFormat& number_format)
|
||||
{
|
||||
return realm.heap().allocate<NumberFormatFunction>(realm, number_format, realm.intrinsics().function_prototype());
|
||||
}
|
||||
|
||||
NumberFormatFunction::NumberFormatFunction(NumberFormat& number_format, Object& prototype)
|
||||
: NativeFunction(prototype)
|
||||
, m_number_format(number_format)
|
||||
{
|
||||
}
|
||||
|
||||
void NumberFormatFunction::initialize(Realm& realm)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
|
||||
Base::initialize(realm);
|
||||
define_direct_property(vm.names.length, Value(1), Attribute::Configurable);
|
||||
define_direct_property(vm.names.name, PrimitiveString::create(vm, String {}), Attribute::Configurable);
|
||||
}
|
||||
|
||||
ThrowCompletionOr<Value> NumberFormatFunction::call()
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
|
||||
// 1. Let nf be F.[[NumberFormat]].
|
||||
// 2. Assert: Type(nf) is Object and nf has an [[InitializedNumberFormat]] internal slot.
|
||||
// 3. If value is not provided, let value be undefined.
|
||||
auto value = vm.argument(0);
|
||||
|
||||
// 4. Let x be ? ToIntlMathematicalValue(value).
|
||||
auto mathematical_value = TRY(to_intl_mathematical_value(vm, value));
|
||||
|
||||
// 5. Return ? FormatNumeric(nf, x).
|
||||
auto formatted = format_numeric(m_number_format, move(mathematical_value));
|
||||
return PrimitiveString::create(vm, move(formatted));
|
||||
}
|
||||
|
||||
void NumberFormatFunction::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_number_format);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue