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

LibJS: Implement Intl.DisplayNames.prototype.resolvedOptions

This commit is contained in:
Timothy Flynn 2021-08-24 23:26:44 -04:00 committed by Linus Groh
parent 17bb652775
commit a061d874c9
4 changed files with 61 additions and 0 deletions

View file

@ -46,6 +46,7 @@ void DisplayNamesPrototype::initialize(GlobalObject& global_object)
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(vm.names.of, of, 1, attr);
define_native_function(vm.names.resolvedOptions, resolved_options, 0, attr);
}
// 12.4.3 Intl.DisplayNames.prototype.of ( code ), https://tc39.es/ecma402/#sec-Intl.DisplayNames.prototype.of
@ -99,4 +100,30 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::of)
return js_undefined();
}
// 12.4.4 Intl.DisplayNames.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-Intl.DisplayNames.prototype.resolvedOptions
JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::resolved_options)
{
// 1. Let displayNames be this value.
// 2. Perform ? RequireInternalSlot(displayNames, [[InitializedDisplayNames]]).
auto* display_names = typed_this(global_object);
if (!display_names)
return {};
// 3. Let options be ! OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(global_object, global_object.object_prototype());
// 4. For each row of Table 8, except the header row, in table order, do
// a. Let p be the Property value of the current row.
// b. Let v be the value of displayNames's internal slot whose name is the Internal Slot value of the current row.
// c. Assert: v is not undefined.
// d. Perform ! CreateDataPropertyOrThrow(options, p, v).
options->create_data_property_or_throw(vm.names.locale, js_string(vm, display_names->locale()));
options->create_data_property_or_throw(vm.names.style, js_string(vm, display_names->style_string()));
options->create_data_property_or_throw(vm.names.type, js_string(vm, display_names->type_string()));
options->create_data_property_or_throw(vm.names.fallback, js_string(vm, display_names->fallback_string()));
// 5. Return options.
return options;
}
}

View file

@ -20,6 +20,7 @@ public:
private:
JS_DECLARE_NATIVE_FUNCTION(of);
JS_DECLARE_NATIVE_FUNCTION(resolved_options);
};
}