mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:47:37 +00:00
LibJS: Implement Intl.Locale.prototype.numeric
This commit is contained in:
parent
d7825f3680
commit
bdf36575c8
3 changed files with 31 additions and 0 deletions
|
@ -52,6 +52,7 @@ void LocalePrototype::initialize(GlobalObject& global_object)
|
||||||
define_native_accessor(vm.names.collation, collation, {}, Attribute::Configurable);
|
define_native_accessor(vm.names.collation, collation, {}, Attribute::Configurable);
|
||||||
define_native_accessor(vm.names.hourCycle, hour_cycle, {}, Attribute::Configurable);
|
define_native_accessor(vm.names.hourCycle, hour_cycle, {}, Attribute::Configurable);
|
||||||
define_native_accessor(vm.names.numberingSystem, numbering_system, {}, Attribute::Configurable);
|
define_native_accessor(vm.names.numberingSystem, numbering_system, {}, Attribute::Configurable);
|
||||||
|
define_native_accessor(vm.names.numeric, numeric, {}, Attribute::Configurable);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 14.3.5 Intl.Locale.prototype.toString ( ), https://tc39.es/ecma402/#sec-Intl.Locale.prototype.toString
|
// 14.3.5 Intl.Locale.prototype.toString ( ), https://tc39.es/ecma402/#sec-Intl.Locale.prototype.toString
|
||||||
|
@ -109,4 +110,17 @@ JS_DEFINE_NATIVE_GETTER(LocalePrototype::base_name)
|
||||||
JS_ENUMERATE_LOCALE_KEYWORD_PROPERTIES
|
JS_ENUMERATE_LOCALE_KEYWORD_PROPERTIES
|
||||||
#undef __JS_ENUMERATE
|
#undef __JS_ENUMERATE
|
||||||
|
|
||||||
|
// 14.3.11 get Intl.Locale.prototype.numeric, https://tc39.es/ecma402/#sec-Intl.Locale.prototype.numeric
|
||||||
|
JS_DEFINE_NATIVE_GETTER(LocalePrototype::numeric)
|
||||||
|
{
|
||||||
|
// 1. Let loc be the this value.
|
||||||
|
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
|
||||||
|
auto* locale_object = typed_this(global_object);
|
||||||
|
if (!locale_object)
|
||||||
|
return {};
|
||||||
|
|
||||||
|
// 3. Return loc.[[Numeric]].
|
||||||
|
return Value(locale_object->numeric());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ private:
|
||||||
JS_DECLARE_NATIVE_GETTER(collation);
|
JS_DECLARE_NATIVE_GETTER(collation);
|
||||||
JS_DECLARE_NATIVE_GETTER(hour_cycle);
|
JS_DECLARE_NATIVE_GETTER(hour_cycle);
|
||||||
JS_DECLARE_NATIVE_GETTER(numbering_system);
|
JS_DECLARE_NATIVE_GETTER(numbering_system);
|
||||||
|
JS_DECLARE_NATIVE_GETTER(numeric);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
describe("errors", () => {
|
||||||
|
test("called on non-Locale object", () => {
|
||||||
|
expect(() => {
|
||||||
|
Intl.Locale.prototype.numeric;
|
||||||
|
}).toThrowWithMessage(TypeError, "Not a Intl.Locale object");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("normal behavior", () => {
|
||||||
|
test("basic functionality", () => {
|
||||||
|
expect(new Intl.Locale("en").numeric).toBeFalse();
|
||||||
|
expect(new Intl.Locale("en-u-kn-true").numeric).toBeTrue();
|
||||||
|
expect(new Intl.Locale("en", { numeric: false }).numeric).toBeFalse();
|
||||||
|
expect(new Intl.Locale("en-u-kn-false", { numeric: true }).numeric).toBeTrue();
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue