Issue #325 Part 14: Remove EXPOSE_INTL_API conditionals.

This commit is contained in:
wolfbeast 2018-05-04 21:47:32 +02:00 committed by Roy Tam
commit 8e9e42c7d8
17 changed files with 5 additions and 395 deletions

View file

@ -900,11 +900,7 @@ function ArrayToLocaleString(locales, options) {
if (firstElement === undefined || firstElement === null) {
R = "";
} else {
#if EXPOSE_INTL_API
R = ToString(callContentFunction(firstElement.toLocaleString, firstElement, locales, options));
#else
R = ToString(callContentFunction(firstElement.toLocaleString, firstElement));
#endif
}
// Step 3 (reordered).
@ -919,11 +915,7 @@ function ArrayToLocaleString(locales, options) {
// Steps 9.a, 9.c-e.
R += separator;
if (!(nextElement === undefined || nextElement === null)) {
#if EXPOSE_INTL_API
R += ToString(callContentFunction(nextElement.toLocaleString, nextElement, locales, options));
#else
R += ToString(callContentFunction(nextElement.toLocaleString, nextElement));
#endif
}
}

View file

@ -659,11 +659,7 @@ function String_static_localeCompare(str1, str2) {
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, "String.localeCompare");
var locales = arguments.length > 2 ? arguments[2] : undefined;
var options = arguments.length > 3 ? arguments[3] : undefined;
#if EXPOSE_INTL_API
return callFunction(String_localeCompare, str1, str2, locales, options);
#else
return callFunction(std_String_localeCompare, str1, str2, locales, options);
#endif
}
// ES6 draft 2014-04-27 B.2.3.3
@ -855,14 +851,12 @@ function String_static_toLocaleUpperCase(string) {
return callFunction(std_String_toLocaleUpperCase, string);
}
#if EXPOSE_INTL_API
function String_static_normalize(string) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'String.normalize');
var form = arguments.length > 1 ? arguments[1] : undefined;
return callFunction(std_String_normalize, string, form);
}
#endif
function String_static_concat(string, arg1) {
if (arguments.length < 1)

View file

@ -236,11 +236,7 @@ GetBuildConfiguration(JSContext* cx, unsigned argc, Value* vp)
if (!JS_SetProperty(cx, info, "binary-data", value))
return false;
#ifdef EXPOSE_INTL_API
value = BooleanValue(true);
#else
value = BooleanValue(false);
#endif
if (!JS_SetProperty(cx, info, "intl-api", value))
return false;

View file

@ -1232,11 +1232,7 @@ function TypedArrayToLocaleString(locales = undefined, options = undefined) {
// Steps 6-7.
// Omit the 'if' clause in step 6, since typed arrays can't have undefined
// or null elements.
#if EXPOSE_INTL_API
var R = ToString(callContentFunction(firstElement.toLocaleString, firstElement, locales, options));
#else
var R = ToString(callContentFunction(firstElement.toLocaleString, firstElement));
#endif
// Step 3 (reordered).
// We don't (yet?) implement locale-dependent separators.
@ -1258,11 +1254,7 @@ function TypedArrayToLocaleString(locales = undefined, options = undefined) {
// the error message. So despite bug 1079853, we can skip step 9.c.
// Step 9.d.
#if EXPOSE_INTL_API
R = ToString(callContentFunction(nextElement.toLocaleString, nextElement, locales, options));
#else
R = ToString(callContentFunction(nextElement.toLocaleString, nextElement));
#endif
// Step 9.e.
R = S + R;

View file

@ -5222,7 +5222,7 @@ JS_ResetDefaultLocale(JSContext* cx);
struct JSLocaleCallbacks {
JSLocaleToUpperCase localeToUpperCase;
JSLocaleToLowerCase localeToLowerCase;
JSLocaleCompare localeCompare; // not used #if EXPOSE_INTL_API
JSLocaleCompare localeCompare; // not used
JSLocaleToUnicode localeToUnicode;
};

View file

@ -2743,77 +2743,6 @@ ToLocaleFormatHelper(JSContext* cx, HandleObject obj, const char* format, Mutabl
return true;
}
#if !EXPOSE_INTL_API
/* ES5 15.9.5.5. */
MOZ_ALWAYS_INLINE bool
date_toLocaleString_impl(JSContext* cx, const CallArgs& args)
{
/*
* Use '%#c' for windows, because '%c' is backward-compatible and non-y2k
* with msvc; '%#c' requests that a full year be used in the result string.
*/
static const char format[] =
#if defined(_WIN32) && !defined(__MWERKS__)
"%#c"
#else
"%c"
#endif
;
Rooted<DateObject*> dateObj(cx, &args.thisv().toObject().as<DateObject>());
return ToLocaleFormatHelper(cx, dateObj, format, args.rval());
}
static bool
date_toLocaleString(JSContext* cx, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
return CallNonGenericMethod<IsDate, date_toLocaleString_impl>(cx, args);
}
/* ES5 15.9.5.6. */
MOZ_ALWAYS_INLINE bool
date_toLocaleDateString_impl(JSContext* cx, const CallArgs& args)
{
/*
* Use '%#x' for windows, because '%x' is backward-compatible and non-y2k
* with msvc; '%#x' requests that a full year be used in the result string.
*/
static const char format[] =
#if defined(_WIN32) && !defined(__MWERKS__)
"%#x"
#else
"%x"
#endif
;
Rooted<DateObject*> dateObj(cx, &args.thisv().toObject().as<DateObject>());
return ToLocaleFormatHelper(cx, dateObj, format, args.rval());
}
static bool
date_toLocaleDateString(JSContext* cx, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
return CallNonGenericMethod<IsDate, date_toLocaleDateString_impl>(cx, args);
}
/* ES5 15.9.5.7. */
MOZ_ALWAYS_INLINE bool
date_toLocaleTimeString_impl(JSContext* cx, const CallArgs& args)
{
Rooted<DateObject*> dateObj(cx, &args.thisv().toObject().as<DateObject>());
return ToLocaleFormatHelper(cx, dateObj, "%X", args.rval());
}
static bool
date_toLocaleTimeString(JSContext* cx, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
return CallNonGenericMethod<IsDate, date_toLocaleTimeString_impl>(cx, args);
}
#endif /* !EXPOSE_INTL_API */
MOZ_ALWAYS_INLINE bool
date_toLocaleFormat_impl(JSContext* cx, const CallArgs& args)
{
@ -3037,15 +2966,9 @@ static const JSFunctionSpec date_methods[] = {
JS_FN("setUTCMilliseconds", date_setUTCMilliseconds, 1,0),
JS_FN("toUTCString", date_toGMTString, 0,0),
JS_FN("toLocaleFormat", date_toLocaleFormat, 0,0),
#if EXPOSE_INTL_API
JS_SELF_HOSTED_FN(js_toLocaleString_str, "Date_toLocaleString", 0,0),
JS_SELF_HOSTED_FN("toLocaleDateString", "Date_toLocaleDateString", 0,0),
JS_SELF_HOSTED_FN("toLocaleTimeString", "Date_toLocaleTimeString", 0,0),
#else
JS_FN(js_toLocaleString_str, date_toLocaleString, 0,0),
JS_FN("toLocaleDateString", date_toLocaleDateString, 0,0),
JS_FN("toLocaleTimeString", date_toLocaleTimeString, 0,0),
#endif
JS_FN("toDateString", date_toDateString, 0,0),
JS_FN("toTimeString", date_toTimeString, 0,0),
JS_FN("toISOString", date_toISOString, 0,0),

View file

@ -724,141 +724,6 @@ js::num_toString(JSContext* cx, unsigned argc, Value* vp)
return CallNonGenericMethod<IsNumber, num_toString_impl>(cx, args);
}
#if !EXPOSE_INTL_API
MOZ_ALWAYS_INLINE bool
num_toLocaleString_impl(JSContext* cx, const CallArgs& args)
{
MOZ_ASSERT(IsNumber(args.thisv()));
double d = Extract(args.thisv());
RootedString str(cx, NumberToStringWithBase<CanGC>(cx, d, 10));
if (!str) {
JS_ReportOutOfMemory(cx);
return false;
}
/*
* Create the string, move back to bytes to make string twiddling
* a bit easier and so we can insert platform charset seperators.
*/
JSAutoByteString numBytes(cx, str);
if (!numBytes)
return false;
const char* num = numBytes.ptr();
if (!num)
return false;
/*
* Find the first non-integer value, whether it be a letter as in
* 'Infinity', a decimal point, or an 'e' from exponential notation.
*/
const char* nint = num;
if (*nint == '-')
nint++;
while (*nint >= '0' && *nint <= '9')
nint++;
int digits = nint - num;
const char* end = num + digits;
if (!digits) {
args.rval().setString(str);
return true;
}
JSRuntime* rt = cx->runtime();
size_t thousandsLength = strlen(rt->thousandsSeparator);
size_t decimalLength = strlen(rt->decimalSeparator);
/* Figure out how long resulting string will be. */
int buflen = strlen(num);
if (*nint == '.')
buflen += decimalLength - 1; /* -1 to account for existing '.' */
const char* numGrouping;
const char* tmpGroup;
numGrouping = tmpGroup = rt->numGrouping;
int remainder = digits;
if (*num == '-')
remainder--;
while (*tmpGroup != CHAR_MAX && *tmpGroup != '\0') {
if (*tmpGroup >= remainder)
break;
buflen += thousandsLength;
remainder -= *tmpGroup;
tmpGroup++;
}
int nrepeat;
if (*tmpGroup == '\0' && *numGrouping != '\0') {
nrepeat = (remainder - 1) / tmpGroup[-1];
buflen += thousandsLength * nrepeat;
remainder -= nrepeat * tmpGroup[-1];
} else {
nrepeat = 0;
}
tmpGroup--;
char* buf = cx->pod_malloc<char>(buflen + 1);
if (!buf)
return false;
char* tmpDest = buf;
const char* tmpSrc = num;
while (*tmpSrc == '-' || remainder--) {
MOZ_ASSERT(tmpDest - buf < buflen);
*tmpDest++ = *tmpSrc++;
}
while (tmpSrc < end) {
MOZ_ASSERT(tmpDest - buf + ptrdiff_t(thousandsLength) <= buflen);
strcpy(tmpDest, rt->thousandsSeparator);
tmpDest += thousandsLength;
MOZ_ASSERT(tmpDest - buf + *tmpGroup <= buflen);
js_memcpy(tmpDest, tmpSrc, *tmpGroup);
tmpDest += *tmpGroup;
tmpSrc += *tmpGroup;
if (--nrepeat < 0)
tmpGroup--;
}
if (*nint == '.') {
MOZ_ASSERT(tmpDest - buf + ptrdiff_t(decimalLength) <= buflen);
strcpy(tmpDest, rt->decimalSeparator);
tmpDest += decimalLength;
MOZ_ASSERT(tmpDest - buf + ptrdiff_t(strlen(nint + 1)) <= buflen);
strcpy(tmpDest, nint + 1);
} else {
MOZ_ASSERT(tmpDest - buf + ptrdiff_t(strlen(nint)) <= buflen);
strcpy(tmpDest, nint);
}
if (cx->runtime()->localeCallbacks && cx->runtime()->localeCallbacks->localeToUnicode) {
Rooted<Value> v(cx, StringValue(str));
bool ok = !!cx->runtime()->localeCallbacks->localeToUnicode(cx, buf, &v);
if (ok)
args.rval().set(v);
js_free(buf);
return ok;
}
str = NewStringCopyN<CanGC>(cx, buf, buflen);
js_free(buf);
if (!str)
return false;
args.rval().setString(str);
return true;
}
static bool
num_toLocaleString(JSContext* cx, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
return CallNonGenericMethod<IsNumber, num_toLocaleString_impl>(cx, args);
}
#endif /* !EXPOSE_INTL_API */
MOZ_ALWAYS_INLINE bool
num_valueOf_impl(JSContext* cx, const CallArgs& args)
{
@ -1075,11 +940,7 @@ static const JSFunctionSpec number_methods[] = {
JS_FN(js_toSource_str, num_toSource, 0, 0),
#endif
JS_FN(js_toString_str, num_toString, 1, 0),
#if EXPOSE_INTL_API
JS_SELF_HOSTED_FN(js_toLocaleString_str, "Number_toLocaleString", 0,0),
#else
JS_FN(js_toLocaleString_str, num_toLocaleString, 0,0),
#endif
JS_FN(js_valueOf_str, num_valueOf, 0, 0),
JS_FN("toFixed", num_toFixed, 1, 0),
JS_FN("toExponential", num_toExponential, 1, 0),
@ -1135,72 +996,11 @@ js::InitRuntimeNumberState(JSRuntime* rt)
{
FIX_FPU();
// XXX If EXPOSE_INTL_API becomes true all the time at some point,
// js::InitRuntimeNumberState is no longer fallible, and we should
// change its return type.
#if !EXPOSE_INTL_API
/* Copy locale-specific separators into the runtime strings. */
const char* thousandsSeparator;
const char* decimalPoint;
const char* grouping;
#ifdef HAVE_LOCALECONV
struct lconv* locale = localeconv();
thousandsSeparator = locale->thousands_sep;
decimalPoint = locale->decimal_point;
grouping = locale->grouping;
#else
thousandsSeparator = getenv("LOCALE_THOUSANDS_SEP");
decimalPoint = getenv("LOCALE_DECIMAL_POINT");
grouping = getenv("LOCALE_GROUPING");
#endif
if (!thousandsSeparator)
thousandsSeparator = "'";
if (!decimalPoint)
decimalPoint = ".";
if (!grouping)
grouping = "\3\0";
/*
* We use single malloc to get the memory for all separator and grouping
* strings.
*/
size_t thousandsSeparatorSize = strlen(thousandsSeparator) + 1;
size_t decimalPointSize = strlen(decimalPoint) + 1;
size_t groupingSize = strlen(grouping) + 1;
char* storage = js_pod_malloc<char>(thousandsSeparatorSize +
decimalPointSize +
groupingSize);
if (!storage)
return false;
js_memcpy(storage, thousandsSeparator, thousandsSeparatorSize);
rt->thousandsSeparator = storage;
storage += thousandsSeparatorSize;
js_memcpy(storage, decimalPoint, decimalPointSize);
rt->decimalSeparator = storage;
storage += decimalPointSize;
js_memcpy(storage, grouping, groupingSize);
rt->numGrouping = grouping;
#endif /* !EXPOSE_INTL_API */
// XXX EXPOSE_INTL_API has become true all the time, meaning this is
// no longer fallible, and we should change its return type.
return true;
}
#if !EXPOSE_INTL_API
void
js::FinishRuntimeNumberState(JSRuntime* rt)
{
/*
* The free also releases the memory for decimalSeparator and numGrouping
* strings.
*/
char* storage = const_cast<char*>(rt->thousandsSeparator);
js_free(storage);
}
#endif
JSObject*
js::InitNumberClass(JSContext* cx, HandleObject obj)
{

View file

@ -37,11 +37,6 @@ class StringBuffer;
extern MOZ_MUST_USE bool
InitRuntimeNumberState(JSRuntime* rt);
#if !EXPOSE_INTL_API
extern void
FinishRuntimeNumberState(JSRuntime* rt);
#endif
/* Initialize the Number class, returning its prototype object. */
extern JSObject*
InitNumberClass(JSContext* cx, HandleObject obj);

View file

@ -37,11 +37,7 @@
#define TYPED_ARRAY_CLASP(type) (&TypedArrayObject::classes[Scalar::type])
#define ERROR_CLASP(type) (&ErrorObject::classes[type])
#ifdef EXPOSE_INTL_API
#define IF_INTL(real,imaginary) real
#else
#define IF_INTL(real,imaginary) imaginary
#endif
#ifdef ENABLE_BINARYDATA
#define IF_BDATA(real,imaginary) real

View file

@ -897,38 +897,6 @@ js::str_toLocaleUpperCase(JSContext* cx, unsigned argc, Value* vp)
return ToUpperCaseHelper(cx, args);
}
#if !EXPOSE_INTL_API
bool
js::str_localeCompare(JSContext* cx, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
RootedString str(cx, ToStringForStringFunction(cx, args.thisv()));
if (!str)
return false;
RootedString thatStr(cx, ToString<CanGC>(cx, args.get(0)));
if (!thatStr)
return false;
if (cx->runtime()->localeCallbacks && cx->runtime()->localeCallbacks->localeCompare) {
RootedValue result(cx);
if (!cx->runtime()->localeCallbacks->localeCompare(cx, str, thatStr, &result))
return false;
args.rval().set(result);
return true;
}
int32_t result;
if (!CompareStrings(cx, str, thatStr, &result))
return false;
args.rval().setInt32(result);
return true;
}
#endif
#if EXPOSE_INTL_API
/* ES6 20140210 draft 21.1.3.12. */
bool
js::str_normalize(JSContext* cx, unsigned argc, Value* vp)
@ -1005,7 +973,6 @@ js::str_normalize(JSContext* cx, unsigned argc, Value* vp)
args.rval().setString(ns);
return true;
}
#endif
bool
js::str_charAt(JSContext* cx, unsigned argc, Value* vp)
@ -2597,15 +2564,9 @@ static const JSFunctionSpec string_methods[] = {
JS_FN("trimRight", str_trimRight, 0,0),
JS_FN("toLocaleLowerCase", str_toLocaleLowerCase, 0,0),
JS_FN("toLocaleUpperCase", str_toLocaleUpperCase, 0,0),
#if EXPOSE_INTL_API
JS_SELF_HOSTED_FN("localeCompare", "String_localeCompare", 1,0),
#else
JS_FN("localeCompare", str_localeCompare, 1,0),
#endif
JS_SELF_HOSTED_FN("repeat", "String_repeat", 1,0),
#if EXPOSE_INTL_API
JS_FN("normalize", str_normalize, 0,0),
#endif
/* Perl-ish methods (search is actually Python-esque). */
JS_SELF_HOSTED_FN("match", "String_match", 1,0),
@ -2916,9 +2877,7 @@ static const JSFunctionSpec string_static_methods[] = {
JS_SELF_HOSTED_FN("trimRight", "String_static_trimRight", 1,0),
JS_SELF_HOSTED_FN("toLocaleLowerCase","String_static_toLocaleLowerCase",1,0),
JS_SELF_HOSTED_FN("toLocaleUpperCase","String_static_toLocaleUpperCase",1,0),
#if EXPOSE_INTL_API
JS_SELF_HOSTED_FN("normalize", "String_static_normalize", 1,0),
#endif
JS_SELF_HOSTED_FN("concat", "String_static_concat", 2,0),
JS_SELF_HOSTED_FN("localeCompare", "String_static_localeCompare", 2,0),

View file

@ -378,13 +378,8 @@ str_toLocaleLowerCase(JSContext* cx, unsigned argc, Value* vp);
extern bool
str_toLocaleUpperCase(JSContext* cx, unsigned argc, Value* vp);
#if !EXPOSE_INTL_API
extern bool
str_localeCompare(JSContext* cx, unsigned argc, Value* vp);
#else
extern bool
str_normalize(JSContext* cx, unsigned argc, Value* vp);
#endif
extern bool
str_concat(JSContext* cx, unsigned argc, Value* vp);

View file

@ -17,9 +17,7 @@
#include "builtin/AtomicsObject.h"
#include "builtin/Eval.h"
#if EXPOSE_INTL_API
# include "builtin/Intl.h"
#endif
#include "builtin/Intl.h"
#include "builtin/MapObject.h"
#include "builtin/ModuleObject.h"
#include "builtin/Object.h"

View file

@ -111,12 +111,10 @@ JS::detail::InitWithFailureDiagnostic(bool isDebugBuild)
js::DateTimeInfo::init();
#if EXPOSE_INTL_API
UErrorCode err = U_ZERO_ERROR;
u_init(&err);
if (U_FAILURE(err))
return "u_init() failed";
#endif // EXPOSE_INTL_API
RETURN_IF_FAIL(js::CreateHelperThreadsState());
RETURN_IF_FAIL(FutexRuntime::initialize());
@ -169,9 +167,7 @@ JS_ShutDown(void)
// to do it only when PRMJ_Now is eventually called.
PRMJ_NowShutdown();
#if EXPOSE_INTL_API
u_cleanup();
#endif // EXPOSE_INTL_API
if (!JSRuntime::hasLiveRuntimes())
js::jit::ReleaseProcessExecutableMemory();
@ -186,11 +182,7 @@ JS_SetICUMemoryFunctions(JS_ICUAllocFn allocFn, JS_ICUReallocFn reallocFn, JS_IC
"must call JS_SetICUMemoryFunctions before any other JSAPI "
"operation (including JS_Init)");
#if EXPOSE_INTL_API
UErrorCode status = U_ZERO_ERROR;
u_setMemoryFunctions(/* context = */ nullptr, allocFn, reallocFn, freeFn, &status);
return U_SUCCESS(status);
#else
return true;
#endif
}

View file

@ -213,11 +213,6 @@ JSRuntime::JSRuntime(JSRuntime* parentRuntime)
warningReporter(nullptr),
buildIdOp(nullptr),
propertyRemovals(0),
#if !EXPOSE_INTL_API
thousandsSeparator(0),
decimalSeparator(0),
numGrouping(0),
#endif
keepAtoms_(0),
trustedPrincipals_(nullptr),
beingDestroyed_(false),
@ -425,10 +420,6 @@ JSRuntime::destroyRuntime()
*/
FreeScriptData(this, lock);
#if !EXPOSE_INTL_API
FinishRuntimeNumberState(this);
#endif
gc.finish();
atomsCompartment_ = nullptr;

View file

@ -978,13 +978,6 @@ struct JSRuntime : public JS::shadow::Runtime,
*/
uint32_t propertyRemovals;
#if !EXPOSE_INTL_API
/* Number localization, used by jsnum.cpp. */
const char* thousandsSeparator;
const char* decimalSeparator;
const char* numGrouping;
#endif
private:
mozilla::Maybe<js::SharedImmutableStringsCache> sharedImmutableStrings_;

View file

@ -2205,11 +2205,7 @@ static const JSFunctionSpec intrinsic_functions[] = {
JS_FN("std_String_trimRight", str_trimRight, 0,0),
JS_FN("std_String_toLocaleLowerCase", str_toLocaleLowerCase, 0,0),
JS_FN("std_String_toLocaleUpperCase", str_toLocaleUpperCase, 0,0),
#if !EXPOSE_INTL_API
JS_FN("std_String_localeCompare", str_localeCompare, 1,0),
#else
JS_FN("std_String_normalize", str_normalize, 0,0),
#endif
JS_FN("std_String_concat", str_concat, 1,0),
JS_FN("std_TypedArray_buffer", js::TypedArray_bufferGetter, 1,0),

View file

@ -172,9 +172,7 @@ extern nsresult nsStringInputStreamConstructor(nsISupports*, REFNSIID, void**);
#include "gfxPlatform.h"
#if EXPOSE_INTL_API
#include "unicode/putil.h"
#endif
using namespace mozilla;
using base::AtExitManager;
@ -692,7 +690,7 @@ NS_InitXPCOM2(nsIServiceManager** aResult,
memmove);
#endif
#if EXPOSE_INTL_API && defined(MOZ_ICU_DATA_ARCHIVE)
#if defined(MOZ_ICU_DATA_ARCHIVE)
nsCOMPtr<nsIFile> greDir;
nsDirectoryService::gService->Get(NS_GRE_DIR,
NS_GET_IID(nsIFile),