Issue #1756 - Expose NumberFormat.formatToParts() to content.

This commit is contained in:
Moonchild 2021-03-31 14:45:56 +00:00 committed by roytam1
commit bdcb9cc504
4 changed files with 1 additions and 44 deletions

View file

@ -755,6 +755,7 @@ static const JSFunctionSpec numberFormat_static_methods[] = {
static const JSFunctionSpec numberFormat_methods[] = {
JS_SELF_HOSTED_FN("resolvedOptions", "Intl_NumberFormat_resolvedOptions", 0, 0),
JS_SELF_HOSTED_FN("formatToParts", "Intl_NumberFormat_formatToParts", 1, 0),
#if JS_HAS_TOSOURCE
JS_FN(js_toSource_str, numberFormat_toSource, 0, 0),
#endif
@ -905,24 +906,6 @@ CreateNumberFormatPrototype(JSContext* cx, HandleObject Intl, Handle<GlobalObjec
return nullptr;
}
#if defined(ICU_UNUM_HAS_FORMATDOUBLEFORFIELDS)
// If the still-experimental NumberFormat.prototype.formatToParts method is
// enabled, also add it.
if (cx->compartment()->creationOptions().experimentalNumberFormatFormatToPartsEnabled()) {
RootedValue ftp(cx);
HandlePropertyName name = cx->names().formatToParts;
if (!GlobalObject::getSelfHostedFunction(cx, cx->global(),
cx->names().NumberFormatFormatToParts,
name, 1, &ftp))
{
return nullptr;
}
if (!DefineProperty(cx, proto, cx->names().formatToParts, ftp, nullptr, nullptr, 0))
return nullptr;
}
#endif // defined(ICU_UNUM_HAS_FORMATDOUBLEFORFIELDS)
RootedValue options(cx);
if (!CreateDefaultOptions(cx, &options))
return nullptr;

View file

@ -2206,7 +2206,6 @@ class JS_PUBLIC_API(CompartmentCreationOptions)
mergeable_(false),
preserveJitCode_(false),
cloneSingletons_(false),
experimentalNumberFormatFormatToPartsEnabled_(false),
sharedMemoryAndAtomics_(false),
secureContext_(false)
{
@ -2271,23 +2270,6 @@ class JS_PUBLIC_API(CompartmentCreationOptions)
return *this;
}
// ECMA-402 is considering adding a "formatToParts" NumberFormat method,
// that exposes not just a formatted string but its subcomponents. The
// method, its semantics, and its name aren't finalized, so for now it's
// exposed *only* if requested.
//
// Until "formatToParts" is included in a final specification edition, it's
// subject to change or removal at any time. Do *not* rely on it in
// mission-critical code that can't be changed if ECMA-402 decides not to
// accept the method in its current form.
bool experimentalNumberFormatFormatToPartsEnabled() const {
return experimentalNumberFormatFormatToPartsEnabled_;
}
CompartmentCreationOptions& setExperimentalNumberFormatFormatToPartsEnabled(bool flag) {
experimentalNumberFormatFormatToPartsEnabled_ = flag;
return *this;
}
bool getSharedMemoryAndAtomicsEnabled() const;
CompartmentCreationOptions& setSharedMemoryAndAtomicsEnabled(bool flag);
@ -2312,7 +2294,6 @@ class JS_PUBLIC_API(CompartmentCreationOptions)
bool mergeable_;
bool preserveJitCode_;
bool cloneSingletons_;
bool experimentalNumberFormatFormatToPartsEnabled_;
bool sharedMemoryAndAtomics_;
bool secureContext_;
};

View file

@ -4684,11 +4684,6 @@ NewGlobal(JSContext* cx, unsigned argc, Value* vp)
if (v.isBoolean())
creationOptions.setCloneSingletons(v.toBoolean());
if (!JS_GetProperty(cx, opts, "experimentalNumberFormatFormatToPartsEnabled", &v))
return false;
if (v.isBoolean())
creationOptions.setExperimentalNumberFormatFormatToPartsEnabled(v.toBoolean());
if (!JS_GetProperty(cx, opts, "sameZoneAs", &v))
return false;
if (v.isObject())

View file

@ -142,7 +142,6 @@
macro(forceInterpreter, forceInterpreter, "forceInterpreter") \
macro(forEach, forEach, "forEach") \
macro(format, format, "format") \
macro(formatToParts, formatToParts, "formatToParts") \
macro(fraction, fraction, "fraction") \
macro(frame, frame, "frame") \
macro(from, from, "from") \
@ -253,7 +252,6 @@
macro(notes, notes, "notes") \
macro(NumberFormat, NumberFormat, "NumberFormat") \
macro(NumberFormatFormatGet, NumberFormatFormatGet, "Intl_NumberFormat_format_get") \
macro(NumberFormatFormatToParts, NumberFormatFormatToParts, "Intl_NumberFormat_formatToParts") \
macro(numeric, numeric, "numeric") \
macro(objectArguments, objectArguments, "[object Arguments]") \
macro(objectArray, objectArray, "[object Array]") \