From 28464c988b4b213527780f6643ca881a3f13d1dc Mon Sep 17 00:00:00 2001 From: Jeff Walden Date: Sat, 3 Oct 2020 10:11:42 +0000 Subject: [PATCH] Bug 1663365 - Move Intl extras functionality (Mozilla extensions, standardized-but-not-stable/shippable-yet) to namespace JS, improve comments, and make various styling tweaks. r=jandem Differential Revision: https://phabricator.services.mozilla.com/D92167 --- js/src/builtin/intl/DateTimeFormat.cpp | 2 +- js/src/builtin/intl/DisplayNames.cpp | 4 +- js/src/jsfriendapi.cpp | 6 +- js/src/jsfriendapi.h | 76 ++++++++++++-------- js/src/shell/js.cpp | 4 +- toolkit/components/mozintl/MozIntlHelper.cpp | 2 +- 6 files changed, 57 insertions(+), 37 deletions(-) diff --git a/js/src/builtin/intl/DateTimeFormat.cpp b/js/src/builtin/intl/DateTimeFormat.cpp index b3b72229ac97..820fbb4a0ade 100644 --- a/js/src/builtin/intl/DateTimeFormat.cpp +++ b/js/src/builtin/intl/DateTimeFormat.cpp @@ -209,7 +209,7 @@ void js::DateTimeFormatObject::finalize(JSFreeOp* fop, JSObject* obj) { } } -bool js::AddMozDateTimeFormatConstructor(JSContext* cx, +bool JS::AddMozDateTimeFormatConstructor(JSContext* cx, JS::Handle intl) { RootedObject ctor( cx, GlobalObject::createConstructor(cx, MozDateTimeFormat, diff --git a/js/src/builtin/intl/DisplayNames.cpp b/js/src/builtin/intl/DisplayNames.cpp index 63469869759a..42b8e32cb47f 100644 --- a/js/src/builtin/intl/DisplayNames.cpp +++ b/js/src/builtin/intl/DisplayNames.cpp @@ -223,7 +223,7 @@ void js::DisplayNamesObject::finalize(JSFreeOp* fop, JSObject* obj) { } } -bool js::AddDisplayNamesConstructor(JSContext* cx, HandleObject intl) { +bool JS::AddDisplayNamesConstructor(JSContext* cx, HandleObject intl) { JSObject* ctor = GlobalObject::getOrCreateConstructor(cx, JSProto_DisplayNames); if (!ctor) { @@ -234,7 +234,7 @@ bool js::AddDisplayNamesConstructor(JSContext* cx, HandleObject intl) { return DefineDataProperty(cx, intl, cx->names().DisplayNames, ctorValue, 0); } -bool js::AddMozDisplayNamesConstructor(JSContext* cx, HandleObject intl) { +bool JS::AddMozDisplayNamesConstructor(JSContext* cx, HandleObject intl) { RootedObject ctor(cx, GlobalObject::createConstructor( cx, MozDisplayNames, cx->names().DisplayNames, 2)); if (!ctor) { diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp index 427325354dc8..d8a0cac39e89 100644 --- a/js/src/jsfriendapi.cpp +++ b/js/src/jsfriendapi.cpp @@ -867,15 +867,15 @@ static bool IntlNotEnabled(JSContext* cx) { return false; } -bool js::AddMozDateTimeFormatConstructor(JSContext* cx, JS::HandleObject intl) { +bool JS::AddMozDateTimeFormatConstructor(JSContext* cx, JS::HandleObject intl) { return IntlNotEnabled(cx); } -bool js::AddMozDisplayNamesConstructor(JSContext* cx, JS::HandleObject intl) { +bool JS::AddMozDisplayNamesConstructor(JSContext* cx, JS::HandleObject intl) { return IntlNotEnabled(cx); } -bool js::AddDisplayNamesConstructor(JSContext* cx, JS::HandleObject intl) { +bool JS::AddDisplayNamesConstructor(JSContext* cx, JS::HandleObject intl) { return IntlNotEnabled(cx); } diff --git a/js/src/jsfriendapi.h b/js/src/jsfriendapi.h index 992c89db29a3..3faecbd8f541 100644 --- a/js/src/jsfriendapi.h +++ b/js/src/jsfriendapi.h @@ -852,36 +852,56 @@ extern JS_FRIEND_API bool ReportIsNotFunction(JSContext* cx, JS::HandleValue v); extern JS_FRIEND_API JSObject* ConvertArgsToArray(JSContext* cx, const JS::CallArgs& args); -// Create and add the Intl.MozDateTimeFormat constructor function to the -// provided object. -// If JS was built without JS_HAS_INTL_API, this function will throw an -// exception. -// -// This custom date/time formatter constructor gives users the ability -// to specify a custom format pattern. This pattern is passed *directly* -// to ICU with NO SYNTAX PARSING OR VALIDATION WHATSOEVER. ICU appears to -// have a a modicum of testing of this, and it won't fall over completely -// if passed bad input. But the current behavior is entirely under-specified -// and emphatically not shippable on the web, and it *must* be fixed before -// this functionality can be exposed in the real world. (There are also some -// questions about whether the format exposed here is the *right* one to -// standardize, that will also need to be resolved to ship this.) -extern bool AddMozDateTimeFormatConstructor(JSContext* cx, - JS::Handle intl); +} // namespace js -// Create and add the Intl.MozDisplayNames constructor function to the -// provided object. -// If JS was built without JS_HAS_INTL_API, this function will throw an -// exception. -extern bool AddMozDisplayNamesConstructor(JSContext* cx, - JS::Handle intl); +namespace JS { -// Create and add the Intl.DisplayNames constructor function to the provided -// object. -// If JS was built without JS_HAS_INTL_API, this function will throw an -// exception. -extern bool AddDisplayNamesConstructor(JSContext* cx, - JS::Handle intl); +/** + * Create and add the Intl.MozDateTimeFormat constructor function to the + * provided object. + * + * This custom date/time formatter constructor gives users the ability to + * specify a custom format pattern. This pattern is passed *directly* to ICU + * with NO SYNTAX PARSING OR VALIDATION WHATSOEVER. ICU appears to have a + * modicum of testing of this, and it won't fall over completely if passed bad + * input. But the current behavior is entirely under-specified and emphatically + * not shippable on the web, and it *must* be fixed before this functionality + * can be exposed in the real world. (There are also some questions about + * whether the format exposed here is the *right* one to standardize, that will + * also need to be resolved to ship this.) + * + * If JS was built without JS_HAS_INTL_API, this function will throw an + * exception. + */ +extern JS_FRIEND_API bool AddMozDateTimeFormatConstructor( + JSContext* cx, Handle intl); + +/** + * Create and add the Intl.MozDisplayNames constructor function to the + * provided object. This constructor acts like the standard |Intl.DisplayNames| + * but accepts certain additional syntax that isn't standardized to the point of + * being shippable. + * + * If JS was built without JS_HAS_INTL_API, this function will throw an + * exception. + */ +extern JS_FRIEND_API bool AddMozDisplayNamesConstructor(JSContext* cx, + Handle intl); + +/** + * Create and add the Intl.DisplayNames constructor function to the provided + * object, implementing standardized behavior (that isn't yet shippable because + * we're not *quite* comfortable with the spec's progress yet). + * + * If JS was built without JS_HAS_INTL_API, this function will throw an + * exception. + */ +extern JS_FRIEND_API bool AddDisplayNamesConstructor(JSContext* cx, + Handle intl); + +} // namespace JS + +namespace js { class MOZ_STACK_CLASS JS_FRIEND_API AutoAssertNoContentJS { public: diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index 9ffd4ea8670d..0a9aa3b0cb85 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -1320,11 +1320,11 @@ static bool AddIntlExtras(JSContext* cx, unsigned argc, Value* vp) { return false; } - if (!js::AddMozDateTimeFormatConstructor(cx, intl)) { + if (!JS::AddMozDateTimeFormatConstructor(cx, intl)) { return false; } - if (!js::AddMozDisplayNamesConstructor(cx, intl)) { + if (!JS::AddMozDisplayNamesConstructor(cx, intl)) { return false; } diff --git a/toolkit/components/mozintl/MozIntlHelper.cpp b/toolkit/components/mozintl/MozIntlHelper.cpp index 476d0e58a1a7..20d43283eb08 100644 --- a/toolkit/components/mozintl/MozIntlHelper.cpp +++ b/toolkit/components/mozintl/MozIntlHelper.cpp @@ -72,7 +72,7 @@ MozIntlHelper::AddDateTimeFormatConstructor(JS::Handle val, JSAutoRealm ar(cx, realIntlObj); - if (!js::AddMozDateTimeFormatConstructor(cx, realIntlObj)) { + if (!JS::AddMozDateTimeFormatConstructor(cx, realIntlObj)) { return NS_ERROR_FAILURE; }