mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 10:37:42 +00:00
LibJS: Change GetOption AO to accept the options as a concrete Object
This was being verified at runtime anyways, so let the compiler ensure it. This also matches the GetOption AO in Temporal now.
This commit is contained in:
parent
ada56981dc
commit
4411e16798
6 changed files with 53 additions and 55 deletions
|
@ -582,7 +582,7 @@ Array* supported_locales(GlobalObject& global_object, Vector<String> const& requ
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
// 2. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
|
// 2. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
|
||||||
auto matcher = get_option(global_object, options_object, vm.names.localeMatcher, Value::Type::String, { "lookup"sv, "best fit"sv }, "best fit"sv);
|
auto matcher = get_option(global_object, *options_object, vm.names.localeMatcher, Value::Type::String, { "lookup"sv, "best fit"sv }, "best fit"sv);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -617,15 +617,13 @@ Object* coerce_options_to_object(GlobalObject& global_object, Value options)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 9.2.13 GetOption ( options, property, type, values, fallback ), https://tc39.es/ecma402/#sec-getoption
|
// 9.2.13 GetOption ( options, property, type, values, fallback ), https://tc39.es/ecma402/#sec-getoption
|
||||||
Value get_option(GlobalObject& global_object, Value options, PropertyName const& property, Value::Type type, Vector<StringView> const& values, Fallback fallback)
|
Value get_option(GlobalObject& global_object, Object const& options, PropertyName const& property, Value::Type type, Vector<StringView> const& values, Fallback fallback)
|
||||||
{
|
{
|
||||||
auto& vm = global_object.vm();
|
auto& vm = global_object.vm();
|
||||||
|
|
||||||
// 1. Assert: Type(options) is Object.
|
// 1. Assert: Type(options) is Object.
|
||||||
VERIFY(options.is_object());
|
|
||||||
|
|
||||||
// 2. Let value be ? Get(options, property).
|
// 2. Let value be ? Get(options, property).
|
||||||
auto value = options.get(global_object, property);
|
auto value = options.get(property);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ Vector<String> lookup_supported_locales(Vector<String> const& requested_locales)
|
||||||
Vector<String> best_fit_supported_locales(Vector<String> const& requested_locales);
|
Vector<String> best_fit_supported_locales(Vector<String> const& requested_locales);
|
||||||
Array* supported_locales(GlobalObject&, Vector<String> const& requested_locales, Value options);
|
Array* supported_locales(GlobalObject&, Vector<String> const& requested_locales, Value options);
|
||||||
Object* coerce_options_to_object(GlobalObject& global_object, Value options);
|
Object* coerce_options_to_object(GlobalObject& global_object, Value options);
|
||||||
Value get_option(GlobalObject& global_object, Value options, PropertyName const& property, Value::Type type, Vector<StringView> const& values, Fallback fallback);
|
Value get_option(GlobalObject& global_object, Object const& options, PropertyName const& property, Value::Type type, Vector<StringView> const& values, Fallback fallback);
|
||||||
Optional<int> default_number_option(GlobalObject& global_object, Value value, int minimum, int maximum, Optional<int> fallback);
|
Optional<int> default_number_option(GlobalObject& global_object, Value value, int minimum, int maximum, Optional<int> fallback);
|
||||||
Optional<int> get_number_option(GlobalObject& global_object, Object& options, PropertyName const& property, int minimum, int maximum, Optional<int> fallback);
|
Optional<int> get_number_option(GlobalObject& global_object, Object& options, PropertyName const& property, int minimum, int maximum, Optional<int> fallback);
|
||||||
Vector<PatternPartition> partition_pattern(StringView pattern);
|
Vector<PatternPartition> partition_pattern(StringView pattern);
|
||||||
|
|
|
@ -50,8 +50,8 @@ Value DisplayNamesConstructor::construct(FunctionObject& new_target)
|
||||||
auto& vm = this->vm();
|
auto& vm = this->vm();
|
||||||
auto& global_object = this->global_object();
|
auto& global_object = this->global_object();
|
||||||
|
|
||||||
auto locales = vm.argument(0);
|
auto locale_value = vm.argument(0);
|
||||||
auto options = vm.argument(1);
|
auto options_value = vm.argument(1);
|
||||||
|
|
||||||
// 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNames.prototype%", « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »).
|
// 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNames.prototype%", « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »).
|
||||||
auto* display_names = ordinary_create_from_constructor<DisplayNames>(global_object, new_target, &GlobalObject::intl_display_names_prototype);
|
auto* display_names = ordinary_create_from_constructor<DisplayNames>(global_object, new_target, &GlobalObject::intl_display_names_prototype);
|
||||||
|
@ -59,18 +59,18 @@ Value DisplayNamesConstructor::construct(FunctionObject& new_target)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
// 3. Let requestedLocales be ? CanonicalizeLocaleList(locales).
|
// 3. Let requestedLocales be ? CanonicalizeLocaleList(locales).
|
||||||
auto requested_locales = canonicalize_locale_list(global_object, locales);
|
auto requested_locales = canonicalize_locale_list(global_object, locale_value);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
// 4. If options is undefined, throw a TypeError exception.
|
// 4. If options is undefined, throw a TypeError exception.
|
||||||
if (options.is_undefined()) {
|
if (options_value.is_undefined()) {
|
||||||
vm.throw_exception<TypeError>(global_object, ErrorType::IsUndefined, "options"sv);
|
vm.throw_exception<TypeError>(global_object, ErrorType::IsUndefined, "options"sv);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. Set options to ? GetOptionsObject(options).
|
// 5. Set options to ? GetOptionsObject(options).
|
||||||
options = Temporal::get_options_object(global_object, options);
|
auto* options = Temporal::get_options_object(global_object, options_value);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ Value DisplayNamesConstructor::construct(FunctionObject& new_target)
|
||||||
// 7. Let localeData be %DisplayNames%.[[LocaleData]].
|
// 7. Let localeData be %DisplayNames%.[[LocaleData]].
|
||||||
|
|
||||||
// 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
|
// 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
|
||||||
auto matcher = get_option(global_object, options, vm.names.localeMatcher, Value::Type::String, { "lookup"sv, "best fit"sv }, "best fit"sv);
|
auto matcher = get_option(global_object, *options, vm.names.localeMatcher, Value::Type::String, { "lookup"sv, "best fit"sv }, "best fit"sv);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ Value DisplayNamesConstructor::construct(FunctionObject& new_target)
|
||||||
auto result = resolve_locale(requested_locales, opt, {});
|
auto result = resolve_locale(requested_locales, opt, {});
|
||||||
|
|
||||||
// 11. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long").
|
// 11. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long").
|
||||||
auto style = get_option(global_object, options, vm.names.style, Value::Type::String, { "narrow"sv, "short"sv, "long"sv }, "long"sv);
|
auto style = get_option(global_object, *options, vm.names.style, Value::Type::String, { "narrow"sv, "short"sv, "long"sv }, "long"sv);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ Value DisplayNamesConstructor::construct(FunctionObject& new_target)
|
||||||
display_names->set_style(style.as_string().string());
|
display_names->set_style(style.as_string().string());
|
||||||
|
|
||||||
// 13. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined).
|
// 13. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined).
|
||||||
auto type = get_option(global_object, options, vm.names.type, Value::Type::String, { "language"sv, "region"sv, "script"sv, "currency"sv }, Empty {});
|
auto type = get_option(global_object, *options, vm.names.type, Value::Type::String, { "language"sv, "region"sv, "script"sv, "currency"sv }, Empty {});
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ Value DisplayNamesConstructor::construct(FunctionObject& new_target)
|
||||||
display_names->set_type(type.as_string().string());
|
display_names->set_type(type.as_string().string());
|
||||||
|
|
||||||
// 16. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code").
|
// 16. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code").
|
||||||
auto fallback = get_option(global_object, options, vm.names.fallback, Value::Type::String, { "code"sv, "none"sv }, "code"sv);
|
auto fallback = get_option(global_object, *options, vm.names.fallback, Value::Type::String, { "code"sv, "none"sv }, "code"sv);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
|
|
@ -49,8 +49,8 @@ Value ListFormatConstructor::construct(FunctionObject& new_target)
|
||||||
auto& vm = this->vm();
|
auto& vm = this->vm();
|
||||||
auto& global_object = this->global_object();
|
auto& global_object = this->global_object();
|
||||||
|
|
||||||
auto locales = vm.argument(0);
|
auto locale_value = vm.argument(0);
|
||||||
auto options = vm.argument(1);
|
auto options_value = vm.argument(1);
|
||||||
|
|
||||||
// 2. Let listFormat be ? OrdinaryCreateFromConstructor(NewTarget, "%ListFormat.prototype%", « [[InitializedListFormat]], [[Locale]], [[Type]], [[Style]], [[Templates]] »).
|
// 2. Let listFormat be ? OrdinaryCreateFromConstructor(NewTarget, "%ListFormat.prototype%", « [[InitializedListFormat]], [[Locale]], [[Type]], [[Style]], [[Templates]] »).
|
||||||
auto* list_format = ordinary_create_from_constructor<ListFormat>(global_object, new_target, &GlobalObject::intl_list_format_prototype);
|
auto* list_format = ordinary_create_from_constructor<ListFormat>(global_object, new_target, &GlobalObject::intl_list_format_prototype);
|
||||||
|
@ -58,12 +58,12 @@ Value ListFormatConstructor::construct(FunctionObject& new_target)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
// 3. Let requestedLocales be ? CanonicalizeLocaleList(locales).
|
// 3. Let requestedLocales be ? CanonicalizeLocaleList(locales).
|
||||||
auto requested_locales = canonicalize_locale_list(global_object, locales);
|
auto requested_locales = canonicalize_locale_list(global_object, locale_value);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
// 4. Set options to ? GetOptionsObject(options).
|
// 4. Set options to ? GetOptionsObject(options).
|
||||||
options = Temporal::get_options_object(global_object, options);
|
auto* options = Temporal::get_options_object(global_object, options_value);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ Value ListFormatConstructor::construct(FunctionObject& new_target)
|
||||||
LocaleOptions opt {};
|
LocaleOptions opt {};
|
||||||
|
|
||||||
// 6. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
|
// 6. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
|
||||||
auto matcher = get_option(global_object, options, vm.names.localeMatcher, Value::Type::String, { "lookup"sv, "best fit"sv }, "best fit"sv);
|
auto matcher = get_option(global_object, *options, vm.names.localeMatcher, Value::Type::String, { "lookup"sv, "best fit"sv }, "best fit"sv);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ Value ListFormatConstructor::construct(FunctionObject& new_target)
|
||||||
list_format->set_locale(move(result.locale));
|
list_format->set_locale(move(result.locale));
|
||||||
|
|
||||||
// 11. Let type be ? GetOption(options, "type", "string", « "conjunction", "disjunction", "unit" », "conjunction").
|
// 11. Let type be ? GetOption(options, "type", "string", « "conjunction", "disjunction", "unit" », "conjunction").
|
||||||
auto type = get_option(global_object, options, vm.names.type, Value::Type::String, { "conjunction"sv, "disjunction"sv, "unit"sv }, "conjunction"sv);
|
auto type = get_option(global_object, *options, vm.names.type, Value::Type::String, { "conjunction"sv, "disjunction"sv, "unit"sv }, "conjunction"sv);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ Value ListFormatConstructor::construct(FunctionObject& new_target)
|
||||||
list_format->set_type(type.as_string().string());
|
list_format->set_type(type.as_string().string());
|
||||||
|
|
||||||
// 13. Let style be ? GetOption(options, "style", "string", « "long", "short", "narrow" », "long").
|
// 13. Let style be ? GetOption(options, "style", "string", « "long", "short", "narrow" », "long").
|
||||||
auto style = get_option(global_object, options, vm.names.style, Value::Type::String, { "long"sv, "short"sv, "narrow"sv }, "long"sv);
|
auto style = get_option(global_object, *options, vm.names.style, Value::Type::String, { "long"sv, "short"sv, "narrow"sv }, "long"sv);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ static Optional<String> get_string_option(GlobalObject& global_object, Object co
|
||||||
{
|
{
|
||||||
auto& vm = global_object.vm();
|
auto& vm = global_object.vm();
|
||||||
|
|
||||||
auto option = get_option(global_object, &options, property, Value::Type::String, values, Empty {});
|
auto option = get_option(global_object, options, property, Value::Type::String, values, Empty {});
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
if (option.is_undefined())
|
if (option.is_undefined())
|
||||||
|
@ -274,8 +274,8 @@ Value LocaleConstructor::construct(FunctionObject& new_target)
|
||||||
auto& vm = this->vm();
|
auto& vm = this->vm();
|
||||||
auto& global_object = this->global_object();
|
auto& global_object = this->global_object();
|
||||||
|
|
||||||
auto tag = vm.argument(0);
|
auto tag_value = vm.argument(0);
|
||||||
auto options = vm.argument(1);
|
auto options_value = vm.argument(1);
|
||||||
|
|
||||||
// 2. Let relevantExtensionKeys be %Locale%.[[RelevantExtensionKeys]].
|
// 2. Let relevantExtensionKeys be %Locale%.[[RelevantExtensionKeys]].
|
||||||
auto const& relevant_extension_keys = locale_relevant_extension_keys();
|
auto const& relevant_extension_keys = locale_relevant_extension_keys();
|
||||||
|
@ -292,32 +292,32 @@ Value LocaleConstructor::construct(FunctionObject& new_target)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
// 7. If Type(tag) is not String or Object, throw a TypeError exception.
|
// 7. If Type(tag) is not String or Object, throw a TypeError exception.
|
||||||
if (!tag.is_string() && !tag.is_object()) {
|
if (!tag_value.is_string() && !tag_value.is_object()) {
|
||||||
vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOrString, "tag"sv);
|
vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOrString, "tag"sv);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8. If Type(tag) is Object and tag has an [[InitializedLocale]] internal slot, then
|
// 8. If Type(tag) is Object and tag has an [[InitializedLocale]] internal slot, then
|
||||||
if (tag.is_object() && is<Locale>(tag.as_object())) {
|
if (tag_value.is_object() && is<Locale>(tag_value.as_object())) {
|
||||||
// a. Let tag be tag.[[Locale]].
|
// a. Let tag be tag.[[Locale]].
|
||||||
auto const& tag_object = static_cast<Locale const&>(tag.as_object());
|
auto const& tag_object = static_cast<Locale const&>(tag_value.as_object());
|
||||||
tag = js_string(vm, tag_object.locale());
|
tag_value = js_string(vm, tag_object.locale());
|
||||||
}
|
}
|
||||||
// 9. Else,
|
// 9. Else,
|
||||||
else {
|
else {
|
||||||
// a. Let tag be ? ToString(tag).
|
// a. Let tag be ? ToString(tag).
|
||||||
tag = tag.to_primitive_string(global_object);
|
tag_value = tag_value.to_primitive_string(global_object);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 10. Set options to ? CoerceOptionsToObject(options).
|
// 10. Set options to ? CoerceOptionsToObject(options).
|
||||||
options = coerce_options_to_object(global_object, options);
|
auto* options = coerce_options_to_object(global_object, options_value);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
// 11. Set tag to ? ApplyOptionsToTag(tag, options).
|
// 11. Set tag to ? ApplyOptionsToTag(tag, options).
|
||||||
auto canonicalized_tag = apply_options_to_tag(global_object, tag.as_string().string(), options.as_object());
|
auto canonicalized_tag = apply_options_to_tag(global_object, tag_value.as_string().string(), *options);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -328,7 +328,7 @@ Value LocaleConstructor::construct(FunctionObject& new_target)
|
||||||
// 14. If calendar is not undefined, then
|
// 14. If calendar is not undefined, then
|
||||||
// a. If calendar does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception.
|
// a. If calendar does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception.
|
||||||
// 15. Set opt.[[ca]] to calendar.
|
// 15. Set opt.[[ca]] to calendar.
|
||||||
opt.ca = get_string_option(global_object, options.as_object(), vm.names.calendar, Unicode::is_type_identifier);
|
opt.ca = get_string_option(global_object, *options, vm.names.calendar, Unicode::is_type_identifier);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -336,24 +336,24 @@ Value LocaleConstructor::construct(FunctionObject& new_target)
|
||||||
// 17. If collation is not undefined, then
|
// 17. If collation is not undefined, then
|
||||||
// a. If collation does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception.
|
// a. If collation does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception.
|
||||||
// 18. Set opt.[[co]] to collation.
|
// 18. Set opt.[[co]] to collation.
|
||||||
opt.co = get_string_option(global_object, options.as_object(), vm.names.collation, Unicode::is_type_identifier);
|
opt.co = get_string_option(global_object, *options, vm.names.collation, Unicode::is_type_identifier);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
// 19. Let hc be ? GetOption(options, "hourCycle", "string", « "h11", "h12", "h23", "h24" », undefined).
|
// 19. Let hc be ? GetOption(options, "hourCycle", "string", « "h11", "h12", "h23", "h24" », undefined).
|
||||||
// 20. Set opt.[[hc]] to hc.
|
// 20. Set opt.[[hc]] to hc.
|
||||||
opt.hc = get_string_option(global_object, options.as_object(), vm.names.hourCycle, nullptr, { "h11"sv, "h12"sv, "h23"sv, "h24"sv });
|
opt.hc = get_string_option(global_object, *options, vm.names.hourCycle, nullptr, { "h11"sv, "h12"sv, "h23"sv, "h24"sv });
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
// 21. Let kf be ? GetOption(options, "caseFirst", "string", « "upper", "lower", "false" », undefined).
|
// 21. Let kf be ? GetOption(options, "caseFirst", "string", « "upper", "lower", "false" », undefined).
|
||||||
// 22. Set opt.[[kf]] to kf.
|
// 22. Set opt.[[kf]] to kf.
|
||||||
opt.kf = get_string_option(global_object, options.as_object(), vm.names.caseFirst, nullptr, { "upper"sv, "lower"sv, "false"sv });
|
opt.kf = get_string_option(global_object, *options, vm.names.caseFirst, nullptr, { "upper"sv, "lower"sv, "false"sv });
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
// 23. Let kn be ? GetOption(options, "numeric", "boolean", undefined, undefined).
|
// 23. Let kn be ? GetOption(options, "numeric", "boolean", undefined, undefined).
|
||||||
auto kn = get_option(global_object, options, vm.names.numeric, Value::Type::Boolean, {}, Empty {});
|
auto kn = get_option(global_object, *options, vm.names.numeric, Value::Type::Boolean, {}, Empty {});
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -366,7 +366,7 @@ Value LocaleConstructor::construct(FunctionObject& new_target)
|
||||||
// 27. If numberingSystem is not undefined, then
|
// 27. If numberingSystem is not undefined, then
|
||||||
// a. If numberingSystem does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception.
|
// a. If numberingSystem does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception.
|
||||||
// 28. Set opt.[[nu]] to numberingSystem.
|
// 28. Set opt.[[nu]] to numberingSystem.
|
||||||
opt.nu = get_string_option(global_object, options.as_object(), vm.names.numberingSystem, Unicode::is_type_identifier);
|
opt.nu = get_string_option(global_object, *options, vm.names.numberingSystem, Unicode::is_type_identifier);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
|
|
@ -155,7 +155,7 @@ static void set_number_format_unit_options(GlobalObject& global_object, NumberFo
|
||||||
// 2. Assert: Type(options) is Object.
|
// 2. Assert: Type(options) is Object.
|
||||||
|
|
||||||
// 3. Let style be ? GetOption(options, "style", "string", « "decimal", "percent", "currency", "unit" », "decimal").
|
// 3. Let style be ? GetOption(options, "style", "string", « "decimal", "percent", "currency", "unit" », "decimal").
|
||||||
auto style = get_option(global_object, &options, vm.names.style, Value::Type::String, { "decimal"sv, "percent"sv, "currency"sv, "unit"sv }, "decimal"sv);
|
auto style = get_option(global_object, options, vm.names.style, Value::Type::String, { "decimal"sv, "percent"sv, "currency"sv, "unit"sv }, "decimal"sv);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -163,7 +163,7 @@ static void set_number_format_unit_options(GlobalObject& global_object, NumberFo
|
||||||
intl_object.set_style(style.as_string().string());
|
intl_object.set_style(style.as_string().string());
|
||||||
|
|
||||||
// 5. Let currency be ? GetOption(options, "currency", "string", undefined, undefined).
|
// 5. Let currency be ? GetOption(options, "currency", "string", undefined, undefined).
|
||||||
auto currency = get_option(global_object, &options, vm.names.currency, Value::Type::String, {}, Empty {});
|
auto currency = get_option(global_object, options, vm.names.currency, Value::Type::String, {}, Empty {});
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -183,17 +183,17 @@ static void set_number_format_unit_options(GlobalObject& global_object, NumberFo
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8. Let currencyDisplay be ? GetOption(options, "currencyDisplay", "string", « "code", "symbol", "narrowSymbol", "name" », "symbol").
|
// 8. Let currencyDisplay be ? GetOption(options, "currencyDisplay", "string", « "code", "symbol", "narrowSymbol", "name" », "symbol").
|
||||||
auto currency_display = get_option(global_object, &options, vm.names.currencyDisplay, Value::Type::String, { "code"sv, "symbol"sv, "narrowSymbol"sv, "name"sv }, "symbol"sv);
|
auto currency_display = get_option(global_object, options, vm.names.currencyDisplay, Value::Type::String, { "code"sv, "symbol"sv, "narrowSymbol"sv, "name"sv }, "symbol"sv);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// 9. Let currencySign be ? GetOption(options, "currencySign", "string", « "standard", "accounting" », "standard").
|
// 9. Let currencySign be ? GetOption(options, "currencySign", "string", « "standard", "accounting" », "standard").
|
||||||
auto currency_sign = get_option(global_object, &options, vm.names.currencySign, Value::Type::String, { "standard"sv, "accounting"sv }, "standard"sv);
|
auto currency_sign = get_option(global_object, options, vm.names.currencySign, Value::Type::String, { "standard"sv, "accounting"sv }, "standard"sv);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// 10. Let unit be ? GetOption(options, "unit", "string", undefined, undefined).
|
// 10. Let unit be ? GetOption(options, "unit", "string", undefined, undefined).
|
||||||
auto unit = get_option(global_object, &options, vm.names.unit, Value::Type::String, {}, Empty {});
|
auto unit = get_option(global_object, options, vm.names.unit, Value::Type::String, {}, Empty {});
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ static void set_number_format_unit_options(GlobalObject& global_object, NumberFo
|
||||||
}
|
}
|
||||||
|
|
||||||
// 13. Let unitDisplay be ? GetOption(options, "unitDisplay", "string", « "short", "narrow", "long" », "short").
|
// 13. Let unitDisplay be ? GetOption(options, "unitDisplay", "string", « "short", "narrow", "long" », "short").
|
||||||
auto unit_display = get_option(global_object, &options, vm.names.unitDisplay, Value::Type::String, { "short"sv, "narrow"sv, "long"sv }, "short"sv);
|
auto unit_display = get_option(global_object, options, vm.names.unitDisplay, Value::Type::String, { "short"sv, "narrow"sv, "long"sv }, "short"sv);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -241,17 +241,17 @@ static void set_number_format_unit_options(GlobalObject& global_object, NumberFo
|
||||||
}
|
}
|
||||||
|
|
||||||
// 15.1.2 InitializeNumberFormat ( numberFormat, locales, options ), https://tc39.es/ecma402/#sec-initializenumberformat
|
// 15.1.2 InitializeNumberFormat ( numberFormat, locales, options ), https://tc39.es/ecma402/#sec-initializenumberformat
|
||||||
static NumberFormat* initialize_number_format(GlobalObject& global_object, NumberFormat& number_format, Value locales, Value options)
|
static NumberFormat* initialize_number_format(GlobalObject& global_object, NumberFormat& number_format, Value locales_value, Value options_value)
|
||||||
{
|
{
|
||||||
auto& vm = global_object.vm();
|
auto& vm = global_object.vm();
|
||||||
|
|
||||||
// 1. Let requestedLocales be ? CanonicalizeLocaleList(locales).
|
// 1. Let requestedLocales be ? CanonicalizeLocaleList(locales).
|
||||||
auto requested_locales = canonicalize_locale_list(global_object, locales);
|
auto requested_locales = canonicalize_locale_list(global_object, locales_value);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
// 2. Set options to ? CoerceOptionsToObject(options).
|
// 2. Set options to ? CoerceOptionsToObject(options).
|
||||||
options = coerce_options_to_object(global_object, options);
|
auto* options = coerce_options_to_object(global_object, options_value);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ static NumberFormat* initialize_number_format(GlobalObject& global_object, Numbe
|
||||||
LocaleOptions opt {};
|
LocaleOptions opt {};
|
||||||
|
|
||||||
// 4. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
|
// 4. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
|
||||||
auto matcher = get_option(global_object, options, vm.names.localeMatcher, Value::Type::String, { "lookup"sv, "best fit"sv }, "best fit"sv);
|
auto matcher = get_option(global_object, *options, vm.names.localeMatcher, Value::Type::String, { "lookup"sv, "best fit"sv }, "best fit"sv);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -267,7 +267,7 @@ static NumberFormat* initialize_number_format(GlobalObject& global_object, Numbe
|
||||||
opt.locale_matcher = matcher;
|
opt.locale_matcher = matcher;
|
||||||
|
|
||||||
// 6. Let numberingSystem be ? GetOption(options, "numberingSystem", "string", undefined, undefined).
|
// 6. Let numberingSystem be ? GetOption(options, "numberingSystem", "string", undefined, undefined).
|
||||||
auto numbering_system = get_option(global_object, options, vm.names.numberingSystem, Value::Type::String, {}, Empty {});
|
auto numbering_system = get_option(global_object, *options, vm.names.numberingSystem, Value::Type::String, {}, Empty {});
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -297,7 +297,7 @@ static NumberFormat* initialize_number_format(GlobalObject& global_object, Numbe
|
||||||
number_format.set_numbering_system(result.nu.release_value());
|
number_format.set_numbering_system(result.nu.release_value());
|
||||||
|
|
||||||
// 14. Perform ? SetNumberFormatUnitOptions(numberFormat, options).
|
// 14. Perform ? SetNumberFormatUnitOptions(numberFormat, options).
|
||||||
set_number_format_unit_options(global_object, number_format, options.as_object());
|
set_number_format_unit_options(global_object, number_format, *options);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -334,7 +334,7 @@ static NumberFormat* initialize_number_format(GlobalObject& global_object, Numbe
|
||||||
}
|
}
|
||||||
|
|
||||||
// 18. Let notation be ? GetOption(options, "notation", "string", « "standard", "scientific", "engineering", "compact" », "standard").
|
// 18. Let notation be ? GetOption(options, "notation", "string", « "standard", "scientific", "engineering", "compact" », "standard").
|
||||||
auto notation = get_option(global_object, options, vm.names.notation, Value::Type::String, { "standard"sv, "scientific"sv, "engineering"sv, "compact"sv }, "standard"sv);
|
auto notation = get_option(global_object, *options, vm.names.notation, Value::Type::String, { "standard"sv, "scientific"sv, "engineering"sv, "compact"sv }, "standard"sv);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -342,12 +342,12 @@ static NumberFormat* initialize_number_format(GlobalObject& global_object, Numbe
|
||||||
number_format.set_notation(notation.as_string().string());
|
number_format.set_notation(notation.as_string().string());
|
||||||
|
|
||||||
// 20. Perform ? SetNumberFormatDigitOptions(numberFormat, options, mnfdDefault, mxfdDefault, notation).
|
// 20. Perform ? SetNumberFormatDigitOptions(numberFormat, options, mnfdDefault, mxfdDefault, notation).
|
||||||
set_number_format_digit_options(global_object, number_format, options.as_object(), default_min_fraction_digits, default_max_fraction_digits, number_format.notation());
|
set_number_format_digit_options(global_object, number_format, *options, default_min_fraction_digits, default_max_fraction_digits, number_format.notation());
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
// 21. Let compactDisplay be ? GetOption(options, "compactDisplay", "string", « "short", "long" », "short").
|
// 21. Let compactDisplay be ? GetOption(options, "compactDisplay", "string", « "short", "long" », "short").
|
||||||
auto compact_display = get_option(global_object, options, vm.names.compactDisplay, Value::Type::String, { "short"sv, "long"sv }, "short"sv);
|
auto compact_display = get_option(global_object, *options, vm.names.compactDisplay, Value::Type::String, { "short"sv, "long"sv }, "short"sv);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -358,7 +358,7 @@ static NumberFormat* initialize_number_format(GlobalObject& global_object, Numbe
|
||||||
}
|
}
|
||||||
|
|
||||||
// 23. Let useGrouping be ? GetOption(options, "useGrouping", "boolean", undefined, true).
|
// 23. Let useGrouping be ? GetOption(options, "useGrouping", "boolean", undefined, true).
|
||||||
auto use_grouping = get_option(global_object, options, vm.names.useGrouping, Value::Type::Boolean, {}, true);
|
auto use_grouping = get_option(global_object, *options, vm.names.useGrouping, Value::Type::Boolean, {}, true);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -366,7 +366,7 @@ static NumberFormat* initialize_number_format(GlobalObject& global_object, Numbe
|
||||||
number_format.set_use_grouping(use_grouping.as_bool());
|
number_format.set_use_grouping(use_grouping.as_bool());
|
||||||
|
|
||||||
// 25. Let signDisplay be ? GetOption(options, "signDisplay", "string", « "auto", "never", "always", "exceptZero" », "auto").
|
// 25. Let signDisplay be ? GetOption(options, "signDisplay", "string", « "auto", "never", "always", "exceptZero" », "auto").
|
||||||
auto sign_display = get_option(global_object, options, vm.names.signDisplay, Value::Type::String, { "auto"sv, "never"sv, "always"sv, "exceptZero"sv }, "auto"sv);
|
auto sign_display = get_option(global_object, *options, vm.names.signDisplay, Value::Type::String, { "auto"sv, "never"sv, "always"sv, "exceptZero"sv }, "auto"sv);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue