/* * Copyright (c) 2022, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include namespace JS::Intl { // 17.2 The Intl.RelativeTimeFormat Constructor, https://tc39.es/ecma402/#sec-intl-relativetimeformat-constructor RelativeTimeFormatConstructor::RelativeTimeFormatConstructor(GlobalObject& global_object) : NativeFunction(vm().names.RelativeTimeFormat.as_string(), *global_object.function_prototype()) { } void RelativeTimeFormatConstructor::initialize(GlobalObject& global_object) { NativeFunction::initialize(global_object); auto& vm = this->vm(); // 17.3.1 Intl.RelativeTimeFormat.prototype, https://tc39.es/ecma402/#sec-Intl.RelativeTimeFormat.prototype define_direct_property(vm.names.prototype, global_object.intl_relative_time_format_prototype(), 0); define_direct_property(vm.names.length, Value(0), Attribute::Configurable); } // 17.2.1 Intl.RelativeTimeFormat ( [ locales [ , options ] ] ), https://tc39.es/ecma402/#sec-Intl.RelativeTimeFormat ThrowCompletionOr RelativeTimeFormatConstructor::call() { // 1. If NewTarget is undefined, throw a TypeError exception. return vm().throw_completion(global_object(), ErrorType::ConstructorWithoutNew, "Intl.RelativeTimeFormat"); } // 17.2.1 Intl.RelativeTimeFormat ( [ locales [ , options ] ] ), https://tc39.es/ecma402/#sec-Intl.RelativeTimeFormat ThrowCompletionOr RelativeTimeFormatConstructor::construct(FunctionObject& new_target) { auto& global_object = this->global_object(); // 2. Let relativeTimeFormat be ? OrdinaryCreateFromConstructor(NewTarget, "%RelativeTimeFormat.prototype%", « [[InitializedRelativeTimeFormat]], [[Locale]], [[DataLocale]], [[Style]], [[Numeric]], [[NumberFormat]], [[NumberingSystem]], [[PluralRules]] »). auto* relative_time_format = TRY(ordinary_create_from_constructor(global_object, new_target, &GlobalObject::intl_relative_time_format_prototype)); // 3. Return ? InitializeRelativeTimeFormat(relativeTimeFormat, locales, options). return relative_time_format; } }