summaryrefslogtreecommitdiff
path: root/js/src/builtin/intl/CommonFunctions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/builtin/intl/CommonFunctions.cpp')
-rw-r--r--js/src/builtin/intl/CommonFunctions.cpp91
1 files changed, 34 insertions, 57 deletions
diff --git a/js/src/builtin/intl/CommonFunctions.cpp b/js/src/builtin/intl/CommonFunctions.cpp
index 1de598bd9a..1013d12e0e 100644
--- a/js/src/builtin/intl/CommonFunctions.cpp
+++ b/js/src/builtin/intl/CommonFunctions.cpp
@@ -20,25 +20,9 @@
#include "jsobjinlines.h"
bool
-js::intl::CreateDefaultOptions(JSContext* cx, MutableHandleValue defaultOptions)
-{
- RootedObject options(cx, NewObjectWithGivenProto<PlainObject>(cx, nullptr));
- if (!options)
- return false;
- defaultOptions.setObject(*options);
- return true;
-}
-
-bool
js::intl::InitializeObject(JSContext* cx, HandleObject obj, Handle<PropertyName*> initializer,
HandleValue locales, HandleValue options)
{
- RootedValue initializerValue(cx);
- if (!GlobalObject::getIntrinsicValue(cx, cx->global(), initializer, &initializerValue))
- return false;
- MOZ_ASSERT(initializerValue.isObject());
- MOZ_ASSERT(initializerValue.toObject().is<JSFunction>());
-
FixedInvokeArgs<3> args(cx);
args[0].setObject(*obj);
@@ -47,7 +31,33 @@ js::intl::InitializeObject(JSContext* cx, HandleObject obj, Handle<PropertyName*
RootedValue thisv(cx, NullValue());
RootedValue ignored(cx);
- return js::Call(cx, initializerValue, thisv, args, &ignored);
+ if (!js::CallSelfHostedFunction(cx, initializer, thisv, args, &ignored))
+ return false;
+
+ MOZ_ASSERT(ignored.isUndefined(),
+ "Unexpected return value from non-legacy Intl object initializer");
+ return true;
+}
+
+bool
+js::intl::LegacyIntlInitialize(JSContext* cx, HandleObject obj, Handle<PropertyName*> initializer,
+ HandleValue thisValue, HandleValue locales, HandleValue options,
+ DateTimeFormatOptions dtfOptions, MutableHandleValue result)
+{
+ FixedInvokeArgs<5> args(cx);
+
+ args[0].setObject(*obj);
+ args[1].set(thisValue);
+ args[2].set(locales);
+ args[3].set(options);
+ args[4].setBoolean(dtfOptions == DateTimeFormatOptions::EnableMozExtensions);
+
+ RootedValue thisv(cx, NullValue());
+ if (!js::CallSelfHostedFunction(cx, initializer, thisv, args, result))
+ return false;
+
+ MOZ_ASSERT(result.isObject(), "Legacy Intl object initializer must return an object");
+ return true;
}
/**
@@ -56,21 +66,12 @@ js::intl::InitializeObject(JSContext* cx, HandleObject obj, Handle<PropertyName*
JSObject*
js::intl::GetInternalsObject(JSContext* cx, HandleObject obj)
{
- RootedValue getInternalsValue(cx);
- if (!GlobalObject::getIntrinsicValue(cx, cx->global(), cx->names().getInternals,
- &getInternalsValue))
- {
- return nullptr;
- }
- MOZ_ASSERT(getInternalsValue.isObject());
- MOZ_ASSERT(getInternalsValue.toObject().is<JSFunction>());
-
FixedInvokeArgs<1> args(cx);
args[0].setObject(*obj);
RootedValue v(cx, NullValue());
- if (!js::Call(cx, getInternalsValue, v, args, &v))
+ if (!js::CallSelfHostedFunction(cx, cx->names().getInternals, v, args, &v))
return nullptr;
return &v.toObject();
@@ -82,34 +83,10 @@ js::intl::ReportInternalError(JSContext* cx)
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_INTERNAL_INTL_ERROR);
}
-bool
-js::intl::GetAvailableLocales(JSContext* cx, CountAvailable countAvailable,
- GetAvailable getAvailable, MutableHandleValue result)
-{
- RootedObject locales(cx, NewObjectWithGivenProto<PlainObject>(cx, nullptr));
- if (!locales)
- return false;
+const js::intl::OldStyleLanguageTagMapping
+ js::intl::oldStyleLanguageTagMappings[] = {
+ {"pa-PK", "pa-Arab-PK"}, {"zh-CN", "zh-Hans-CN"},
+ {"zh-HK", "zh-Hant-HK"}, {"zh-SG", "zh-Hans-SG"},
+ {"zh-TW", "zh-Hant-TW"},
+};
- uint32_t count = countAvailable();
- RootedValue t(cx, BooleanValue(true));
- for (uint32_t i = 0; i < count; i++) {
- const char* locale = getAvailable(i);
- auto lang = DuplicateString(cx, locale);
- if (!lang)
- return false;
- char* p;
- while ((p = strchr(lang.get(), '_')))
- *p = '-';
- RootedAtom a(cx, Atomize(cx, lang.get(), strlen(lang.get())));
- if (!a)
- return false;
- if (!DefineProperty(cx, locales, a->asPropertyName(), t, nullptr, nullptr,
- JSPROP_ENUMERATE))
- {
- return false;
- }
- }
-
- result.setObject(*locales);
- return true;
-}