Skip to content

Commit

Permalink
Bug 1590907 - Make ENABLE_INTL_API and ENABLE_TYPED_OBJECTS into js-c…
Browse files Browse the repository at this point in the history
…onfig macros. r=sfink,firefox-build-system-reviewers,mshal

Whether ENABLE_INTL_API and ENABLE_TYPED_OBJECTS are defined, affects
the behaviour of JS_FOR_PROTOTYPES for the prototypes of Intl and
TypedObject. Therefore, these macros have to be available to embedders.
Rename them to JS_HAS_INTL_API and JS_HAS_TYPED_OBJECTS (in line with
the existing JS_HAS_CTYPES) everywhere they are used, and add them to
js-config.h.in.

Differential Revision: https://phabricator.services.mozilla.com/D52461
  • Loading branch information
ptomato committed Nov 26, 2019
1 parent 3468e3f commit 87bae49
Show file tree
Hide file tree
Showing 39 changed files with 135 additions and 129 deletions.
12 changes: 6 additions & 6 deletions build/autoconf/icu.m4
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,24 @@ MOZ_ARG_WITH_STRING(intl-api,
build ICU at all.],
_INTL_API=$withval)
ENABLE_INTL_API=
JS_HAS_INTL_API=
case "$_INTL_API" in
no)
;;
yes)
ENABLE_INTL_API=1
JS_HAS_INTL_API=1
;;
*)
AC_MSG_ERROR([Invalid value passed to --with-intl-api: $_INTL_API])
;;
esac
if test -n "$ENABLE_INTL_API"; then
if test -n "$JS_HAS_INTL_API"; then
USE_ICU=1
fi
if test -n "$ENABLE_INTL_API"; then
AC_DEFINE(ENABLE_INTL_API)
if test -n "$JS_HAS_INTL_API"; then
AC_DEFINE(JS_HAS_INTL_API)
fi
dnl Settings for the implementation of the ECMAScript Internationalization API
Expand All @@ -72,7 +72,7 @@ if test -n "$USE_ICU"; then
fi
AC_SUBST(MOZ_ICU_VERSION)
AC_SUBST(ENABLE_INTL_API)
AC_SUBST(JS_HAS_INTL_API)
AC_SUBST(USE_ICU)
AC_SUBST(ICU_DATA_FILE)
Expand Down
4 changes: 2 additions & 2 deletions js/moz.configure
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,8 @@ js_option('--enable-typed-objects',
default=default_typed_objects,
help='{Enable|Disable} typed objects')

set_config('ENABLE_TYPED_OBJECTS', depends_if('--enable-typed-objects')(lambda x: True))
set_define('ENABLE_TYPED_OBJECTS', depends_if('--enable-typed-objects')(lambda x: True))
set_config('JS_HAS_TYPED_OBJECTS', depends_if('--enable-typed-objects')(lambda x: True))
set_define('JS_HAS_TYPED_OBJECTS', depends_if('--enable-typed-objects')(lambda x: True))


# Support for WebAssembly bulk memory operations.
Expand Down
2 changes: 1 addition & 1 deletion js/public/LocaleSensitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ using JSLocaleToUnicode = bool (*)(JSContext* cx, const char* src,
* used to implement locale-sensitive behaviors (such as those performed by
* the various toLocaleString and toLocale{Date,Time}String functions).
*
* If SpiderMonkey is compiled --with-intl-api, then #if ENABLE_INTL_API. In
* If SpiderMonkey is compiled --with-intl-api, then #if JS_HAS_INTL_API. In
* this case, SpiderMonkey itself will implement ECMA-402-compliant behavior by
* calling on ICU, and none of the fields in this struct will ever be used.
* (You'll still be able to call the get/set-callbacks functions; they just
Expand Down
4 changes: 2 additions & 2 deletions js/public/ProtoKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
#define TYPED_ARRAY_CLASP(TYPE) (&TypedArrayObject::classes[Scalar::TYPE])
#define ERROR_CLASP(TYPE) (&ErrorObject::classes[TYPE])

#ifdef ENABLE_INTL_API
#ifdef JS_HAS_INTL_API
# define IF_INTL(REAL, IMAGINARY) REAL
#else
# define IF_INTL(REAL, IMAGINARY) IMAGINARY
#endif

#ifdef ENABLE_TYPED_OBJECTS
#ifdef JS_HAS_TYPED_OBJECTS
# define IF_TYPEDOBJ(REAL, IMAGINARY) REAL
#else
# define IF_TYPEDOBJ(REAL, IMAGINARY) IMAGINARY
Expand Down
2 changes: 1 addition & 1 deletion js/src/build/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ else:
FORCE_STATIC_LIB = True
STATIC_LIBRARY_NAME = 'js_static'

if CONFIG['ENABLE_INTL_API']:
if CONFIG['JS_HAS_INTL_API']:
USE_LIBS += [
'icu',
]
Expand Down
4 changes: 2 additions & 2 deletions js/src/builtin/Array.js
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ function ArrayToLocaleString(locales, options) {
if (firstElement === undefined || firstElement === null) {
R = "";
} else {
#if ENABLE_INTL_API
#if JS_HAS_INTL_API
R = ToString(callContentFunction(firstElement.toLocaleString, firstElement, locales, options));
#else
R = ToString(callContentFunction(firstElement.toLocaleString, firstElement));
Expand All @@ -873,7 +873,7 @@ function ArrayToLocaleString(locales, options) {
// Steps 9.a, 9.c-e.
R += separator;
if (!(nextElement === undefined || nextElement === null)) {
#if ENABLE_INTL_API
#if JS_HAS_INTL_API
R += ToString(callContentFunction(nextElement.toLocaleString, nextElement, locales, options));
#else
R += ToString(callContentFunction(nextElement.toLocaleString, nextElement));
Expand Down
6 changes: 3 additions & 3 deletions js/src/builtin/BigInt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ bool BigIntObject::toString(JSContext* cx, unsigned argc, Value* vp) {
return CallNonGenericMethod<IsBigInt, toString_impl>(cx, args);
}

#ifndef ENABLE_INTL_API
#ifndef JS_HAS_INTL_API
// BigInt proposal section 5.3.2. "This function is
// implementation-dependent, and it is permissible, but not encouraged,
// for it to return the same thing as toString."
Expand All @@ -147,7 +147,7 @@ bool BigIntObject::toLocaleString(JSContext* cx, unsigned argc, Value* vp) {
CallArgs args = CallArgsFromVp(argc, vp);
return CallNonGenericMethod<IsBigInt, toLocaleString_impl>(cx, args);
}
#endif /* !ENABLE_INTL_API */
#endif /* !JS_HAS_INTL_API */

// BigInt proposal section 5.2.1. BigInt.asUintN ( bits, bigint )
bool BigIntObject::asUintN(JSContext* cx, unsigned argc, Value* vp) {
Expand Down Expand Up @@ -226,7 +226,7 @@ const JSPropertySpec BigIntObject::properties[] = {

const JSFunctionSpec BigIntObject::methods[] = {
JS_FN("valueOf", valueOf, 0, 0), JS_FN("toString", toString, 0, 0),
#ifdef ENABLE_INTL_API
#ifdef JS_HAS_INTL_API
JS_SELF_HOSTED_FN("toLocaleString", "BigInt_toLocaleString", 0, 0),
#else
JS_FN("toLocaleString", toLocaleString, 0, 0),
Expand Down
2 changes: 1 addition & 1 deletion js/src/builtin/BigInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class BigIntObject : public NativeObject {
static bool valueOf(JSContext* cx, unsigned argc, JS::Value* vp);
static bool toString_impl(JSContext* cx, const CallArgs& args);
static bool toString(JSContext* cx, unsigned argc, JS::Value* vp);
#ifndef ENABLE_INTL_API
#ifndef JS_HAS_INTL_API
static bool toLocaleString_impl(JSContext* cx, const CallArgs& args);
static bool toLocaleString(JSContext* cx, unsigned argc, JS::Value* vp);
#endif
Expand Down
4 changes: 2 additions & 2 deletions js/src/builtin/BigInt.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#if ENABLE_INTL_API
#if JS_HAS_INTL_API
/**
* Format this BigInt object into a string, using the locale and formatting
* options provided.
Expand Down Expand Up @@ -33,4 +33,4 @@ function BigInt_toLocaleString() {
// Step 3.
return intl_FormatNumber(numberFormat, x, /* formatToParts = */ false);
}
#endif // ENABLE_INTL_API
#endif // JS_HAS_INTL_API
4 changes: 2 additions & 2 deletions js/src/builtin/Date.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#if ENABLE_INTL_API
#if JS_HAS_INTL_API
// This cache, once primed, has these properties:
//
// runtimeDefaultLocale:
Expand Down Expand Up @@ -167,4 +167,4 @@ function Date_toLocaleTimeString() {
// Step 7.
return intl_FormatDateTime(dateTimeFormat, x, /* formatToParts = */ false);
}
#endif // ENABLE_INTL_API
#endif // JS_HAS_INTL_API
4 changes: 2 additions & 2 deletions js/src/builtin/Number.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#if ENABLE_INTL_API
#if JS_HAS_INTL_API
var numberFormatCache = new Record();

/**
Expand Down Expand Up @@ -37,7 +37,7 @@ function Number_toLocaleString() {
// Step 5.
return intl_FormatNumber(numberFormat, x, /* formatToParts = */ false);
}
#endif // ENABLE_INTL_API
#endif // JS_HAS_INTL_API

// ES6 draft ES6 20.1.2.4
function Number_isFinite(num) {
Expand Down
28 changes: 14 additions & 14 deletions js/src/builtin/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@

#include "builtin/Array.h"
#include "builtin/Boolean.h"
#if ENABLE_INTL_API
#if JS_HAS_INTL_API
# include "builtin/intl/CommonFunctions.h"
#endif
#include "builtin/RegExp.h"
#include "jit/InlinableNatives.h"
#include "js/Conversions.h"
#if !ENABLE_INTL_API
#if !JS_HAS_INTL_API
# include "js/LocaleSensitive.h"
#endif
#include "js/PropertySpec.h"
#include "js/StableStringChars.h"
#include "js/UniquePtr.h"
#if ENABLE_INTL_API
#if JS_HAS_INTL_API
# include "unicode/uchar.h"
# include "unicode/unorm2.h"
# include "unicode/ustring.h"
Expand Down Expand Up @@ -623,7 +623,7 @@ static char16_t Final_Sigma(const char16_t* chars, size_t length,
MOZ_ASSERT(unicode::ToLowerCase(unicode::GREEK_CAPITAL_LETTER_SIGMA) ==
unicode::GREEK_SMALL_LETTER_SIGMA);

#if ENABLE_INTL_API
#if JS_HAS_INTL_API
// Tell the analysis the BinaryProperty.contains function pointer called by
// u_hasBinaryProperty cannot GC.
JS::AutoSuppressGCAnalysis nogc;
Expand Down Expand Up @@ -889,7 +889,7 @@ bool js::str_toLowerCase(JSContext* cx, unsigned argc, Value* vp) {
return true;
}

#if ENABLE_INTL_API
#if JS_HAS_INTL_API
// String.prototype.toLocaleLowerCase is self-hosted when Intl is exposed,
// with core functionality performed by the intrinsic below.

Expand Down Expand Up @@ -1022,7 +1022,7 @@ static bool str_toLocaleLowerCase(JSContext* cx, unsigned argc, Value* vp) {
return true;
}

#endif // ENABLE_INTL_API
#endif // JS_HAS_INTL_API

static inline bool ToUpperCaseHasSpecialCasing(Latin1Char charCode) {
// U+00DF LATIN SMALL LETTER SHARP S is the only Latin-1 code point with
Expand Down Expand Up @@ -1331,7 +1331,7 @@ bool js::str_toUpperCase(JSContext* cx, unsigned argc, Value* vp) {
return true;
}

#if ENABLE_INTL_API
#if JS_HAS_INTL_API
// String.prototype.toLocaleUpperCase is self-hosted when Intl is exposed,
// with core functionality performed by the intrinsic below.

Expand Down Expand Up @@ -1438,9 +1438,9 @@ static bool str_toLocaleUpperCase(JSContext* cx, unsigned argc, Value* vp) {
return true;
}

#endif // ENABLE_INTL_API
#endif // JS_HAS_INTL_API

#if ENABLE_INTL_API
#if JS_HAS_INTL_API

// String.prototype.localeCompare is self-hosted when Intl functionality is
// exposed, and the only intrinsics it requires are provided in the
Expand Down Expand Up @@ -1483,9 +1483,9 @@ static bool str_localeCompare(JSContext* cx, unsigned argc, Value* vp) {
return true;
}

#endif // ENABLE_INTL_API
#endif // JS_HAS_INTL_API

#if ENABLE_INTL_API
#if JS_HAS_INTL_API

// ES2017 draft rev 45e890512fd77add72cc0ee742785f9f6f6482de
// 21.1.3.12 String.prototype.normalize ( [ form ] )
Expand Down Expand Up @@ -1621,7 +1621,7 @@ static bool str_normalize(JSContext* cx, unsigned argc, Value* vp) {
return true;
}

#endif // ENABLE_INTL_API
#endif // JS_HAS_INTL_API

static bool str_charAt(JSContext* cx, unsigned argc, Value* vp) {
CallArgs args = CallArgsFromVp(argc, vp);
Expand Down Expand Up @@ -3632,7 +3632,7 @@ static const JSFunctionSpec string_methods[] = {
JS_FN("endsWith", str_endsWith, 1, 0), JS_FN("trim", str_trim, 0, 0),
JS_FN("trimStart", str_trimStart, 0, 0),
JS_FN("trimEnd", str_trimEnd, 0, 0),
#if ENABLE_INTL_API
#if JS_HAS_INTL_API
JS_SELF_HOSTED_FN("toLocaleLowerCase", "String_toLocaleLowerCase", 0, 0),
JS_SELF_HOSTED_FN("toLocaleUpperCase", "String_toLocaleUpperCase", 0, 0),
JS_SELF_HOSTED_FN("localeCompare", "String_localeCompare", 1, 0),
Expand All @@ -3642,7 +3642,7 @@ static const JSFunctionSpec string_methods[] = {
JS_FN("localeCompare", str_localeCompare, 1, 0),
#endif
JS_SELF_HOSTED_FN("repeat", "String_repeat", 1, 0),
#if ENABLE_INTL_API
#if JS_HAS_INTL_API
JS_FN("normalize", str_normalize, 0, 0),
#endif

Expand Down
2 changes: 1 addition & 1 deletion js/src/builtin/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extern bool str_charCodeAt(JSContext* cx, unsigned argc, Value* vp);

extern bool str_endsWith(JSContext* cx, unsigned argc, Value* vp);

#if ENABLE_INTL_API
#if JS_HAS_INTL_API
/**
* Returns the input string converted to lower case based on the language
* specific case mappings for the input locale.
Expand Down
4 changes: 2 additions & 2 deletions js/src/builtin/String.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ function StringIteratorNext() {
return result;
}

#if ENABLE_INTL_API
#if JS_HAS_INTL_API
var collatorCache = new Record();

/**
Expand Down Expand Up @@ -791,7 +791,7 @@ function String_toLocaleUpperCase() {
// Steps 7-16.
return intl_toLocaleUpperCase(string, requestedLocale);
}
#endif // ENABLE_INTL_API
#endif // JS_HAS_INTL_API

// ES2018 draft rev 8fadde42cf6a9879b4ab0cb6142b31c4ee501667
// 21.1.2.4 String.raw ( template, ...substitutions )
Expand Down
4 changes: 2 additions & 2 deletions js/src/builtin/TestingFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ static bool GetBuildConfiguration(JSContext* cx, unsigned argc, Value* vp) {
return false;
}

#ifdef ENABLE_TYPED_OBJECTS
#ifdef JS_HAS_TYPED_OBJECTS
value = BooleanValue(true);
#else
value = BooleanValue(false);
Expand All @@ -395,7 +395,7 @@ static bool GetBuildConfiguration(JSContext* cx, unsigned argc, Value* vp) {
return false;
}

#ifdef ENABLE_INTL_API
#ifdef JS_HAS_INTL_API
value = BooleanValue(true);
#else
value = BooleanValue(false);
Expand Down
4 changes: 2 additions & 2 deletions js/src/builtin/TypedArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,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 ENABLE_INTL_API
#if JS_HAS_INTL_API
var R = ToString(callContentFunction(firstElement.toLocaleString, firstElement, locales, options));
#else
var R = ToString(callContentFunction(firstElement.toLocaleString, firstElement));
Expand All @@ -1269,7 +1269,7 @@ function TypedArrayToLocaleString(locales = undefined, options = undefined) {
// the error message. So despite bug 1079853, we can skip step 9.c.

// Step 9.d.
#if ENABLE_INTL_API
#if JS_HAS_INTL_API
R = ToString(callContentFunction(nextElement.toLocaleString, nextElement, locales, options));
#else
R = ToString(callContentFunction(nextElement.toLocaleString, nextElement));
Expand Down
2 changes: 1 addition & 1 deletion js/src/gc/RootMarking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ void js::gc::GCRuntime::traceRuntimeCommon(JSTracer* trc,
// Trace the self-hosting global compartment.
rt->traceSelfHostingGlobal(trc);

#ifdef ENABLE_INTL_API
#ifdef JS_HAS_INTL_API
// Trace the shared Intl data.
rt->traceSharedIntlData(trc);
#endif
Expand Down
4 changes: 2 additions & 2 deletions js/src/jit/MCallOptimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "jsmath.h"

#include "builtin/AtomicsObject.h"
#ifdef ENABLE_INTL_API
#ifdef JS_HAS_INTL_API
# include "builtin/intl/Collator.h"
# include "builtin/intl/DateTimeFormat.h"
# include "builtin/intl/ListFormat.h"
Expand Down Expand Up @@ -314,7 +314,7 @@ IonBuilder::InliningResult IonBuilder::inlineNativeCall(CallInfo& callInfo,
case InlinableNative::Boolean:
return inlineBoolean(callInfo);

#ifdef ENABLE_INTL_API
#ifdef JS_HAS_INTL_API
// Intl natives.
case InlinableNative::IntlGuardToCollator:
return inlineGuardToClass(callInfo, &CollatorObject::class_);
Expand Down
6 changes: 6 additions & 0 deletions js/src/js-config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
/* Define to 1 if SpiderMonkey should include trace logging support. */
#undef JS_TRACE_LOGGING

/* Define to 1 if SpiderMonkey should include typed objects support. */
#undef JS_HAS_TYPED_OBJECTS

/* Define to 1 if SpiderMonkey should include support for the Intl API. */
#undef JS_HAS_INTL_API

/* Define to 1 if SpiderMonkey should include a breakpoint function for
* artificial OOMs. */
#undef JS_OOM_BREAKPOINT
Expand Down
Loading

0 comments on commit 87bae49

Please sign in to comment.