summaryrefslogtreecommitdiff
path: root/deps/v8/src/js/i18n.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/js/i18n.js')
-rw-r--r--deps/v8/src/js/i18n.js385
1 files changed, 143 insertions, 242 deletions
diff --git a/deps/v8/src/js/i18n.js b/deps/v8/src/js/i18n.js
index b051b090bc..50ed5bcb89 100644
--- a/deps/v8/src/js/i18n.js
+++ b/deps/v8/src/js/i18n.js
@@ -20,9 +20,15 @@
var ArrayJoin;
var ArrayPush;
var GlobalDate = global.Date;
+var GlobalIntl = global.Intl;
+var GlobalIntlDateTimeFormat = GlobalIntl.DateTimeFormat;
+var GlobalIntlNumberFormat = GlobalIntl.NumberFormat;
+var GlobalIntlCollator = GlobalIntl.Collator;
+var GlobalIntlv8BreakIterator = GlobalIntl.v8BreakIterator;
var GlobalNumber = global.Number;
var GlobalRegExp = global.RegExp;
var GlobalString = global.String;
+var IntlFallbackSymbol = utils.ImportNow("intl_fallback_symbol");
var InstallFunctions = utils.InstallFunctions;
var InstallGetter = utils.InstallGetter;
var InternalArray = utils.InternalArray;
@@ -46,18 +52,11 @@ function InstallFunction(object, name, func) {
}
-function InstallConstructor(object, name, func) {
- %CheckIsBootstrapping();
- SetFunctionName(func, name);
- %AddNamedProperty(object, name, func, DONT_ENUM);
- %SetNativeFlag(func);
- %ToFastProperties(object);
-}
-
/**
* Adds bound method to the prototype of the given object.
*/
-function AddBoundMethod(obj, methodName, implementation, length, type) {
+function AddBoundMethod(obj, methodName, implementation, length, typename,
+ compat) {
%CheckIsBootstrapping();
var internalName = %CreatePrivateSymbol(methodName);
// Making getter an anonymous function will cause
@@ -66,32 +65,30 @@ function AddBoundMethod(obj, methodName, implementation, length, type) {
// than (as utils.InstallGetter would) on the SharedFunctionInfo
// associated with all functions returned from AddBoundMethod.
var getter = ANONYMOUS_FUNCTION(function() {
- if (!%IsInitializedIntlObjectOfType(this, type)) {
- throw %make_type_error(kMethodCalledOnWrongObject, methodName);
- }
- if (IS_UNDEFINED(this[internalName])) {
+ var receiver = Unwrap(this, typename, obj, methodName, compat);
+ if (IS_UNDEFINED(receiver[internalName])) {
var boundMethod;
if (IS_UNDEFINED(length) || length === 2) {
boundMethod =
- ANONYMOUS_FUNCTION((fst, snd) => implementation(this, fst, snd));
+ ANONYMOUS_FUNCTION((fst, snd) => implementation(receiver, fst, snd));
} else if (length === 1) {
- boundMethod = ANONYMOUS_FUNCTION(fst => implementation(this, fst));
+ boundMethod = ANONYMOUS_FUNCTION(fst => implementation(receiver, fst));
} else {
boundMethod = ANONYMOUS_FUNCTION((...args) => {
// DateTimeFormat.format needs to be 0 arg method, but can still
// receive an optional dateValue param. If one was provided, pass it
// along.
if (args.length > 0) {
- return implementation(this, args[0]);
+ return implementation(receiver, args[0]);
} else {
- return implementation(this);
+ return implementation(receiver);
}
});
}
%SetNativeFlag(boundMethod);
- this[internalName] = boundMethod;
+ receiver[internalName] = boundMethod;
}
- return this[internalName];
+ return receiver[internalName];
});
%FunctionRemovePrototype(getter);
@@ -99,11 +96,44 @@ function AddBoundMethod(obj, methodName, implementation, length, type) {
%SetNativeFlag(getter);
}
-// -------------------------------------------------------------------
+function IntlConstruct(receiver, constructor, create, newTarget, args,
+ compat) {
+ var locales = args[0];
+ var options = args[1];
+
+ if (IS_UNDEFINED(newTarget)) {
+ if (compat && receiver instanceof constructor) {
+ let success = %object_define_property(receiver, IntlFallbackSymbol,
+ { value: new constructor(locales, options) });
+ if (!success) {
+ throw %make_type_error(kReinitializeIntl, constructor);
+ }
+ return receiver;
+ }
+
+ return new constructor(locales, options);
+ }
+
+ return create(locales, options);
+}
+
+
+
+function Unwrap(receiver, typename, constructor, method, compat) {
+ if (!%IsInitializedIntlObjectOfType(receiver, typename)) {
+ if (compat && receiver instanceof constructor) {
+ let fallback = receiver[IntlFallbackSymbol];
+ if (%IsInitializedIntlObjectOfType(fallback, typename)) {
+ return fallback;
+ }
+ }
+ throw %make_type_error(kIncompatibleMethodReceiver, method, receiver);
+ }
+ return receiver;
+}
-var Intl = {};
-%AddNamedProperty(global, "Intl", Intl, DONT_ENUM);
+// -------------------------------------------------------------------
/**
* Caches available locales for each service.
@@ -911,11 +941,7 @@ var resolvedAccessor = {
};
// ECMA 402 section 8.2.1
-InstallFunction(Intl, 'getCanonicalLocales', function(locales) {
- if (!IS_UNDEFINED(new.target)) {
- throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
- }
-
+InstallFunction(GlobalIntl, 'getCanonicalLocales', function(locales) {
return makeArray(canonicalizeLocaleList(locales));
}
);
@@ -924,11 +950,7 @@ InstallFunction(Intl, 'getCanonicalLocales', function(locales) {
* Initializes the given object so it's a valid Collator instance.
* Useful for subclassing.
*/
-function initializeCollator(collator, locales, options) {
- if (%IsInitializedIntlObject(collator)) {
- throw %make_type_error(kReinitializeIntl, "Collator");
- }
-
+function CreateCollator(locales, options) {
if (IS_UNDEFINED(options)) {
options = {};
}
@@ -1015,12 +1037,9 @@ function initializeCollator(collator, locales, options) {
usage: {value: internalOptions.usage, writable: true}
});
- var internalCollator = %CreateCollator(requestedLocale,
- internalOptions,
- resolved);
+ var collator = %CreateCollator(requestedLocale, internalOptions, resolved);
- // Writable, configurable and enumerable are set to false by default.
- %MarkAsInitializedIntlObjectOfType(collator, 'collator', internalCollator);
+ %MarkAsInitializedIntlObjectOfType(collator, 'collator');
collator[resolvedSymbol] = resolved;
return collator;
@@ -1033,33 +1052,19 @@ function initializeCollator(collator, locales, options) {
*
* @constructor
*/
-InstallConstructor(Intl, 'Collator', function() {
- var locales = arguments[0];
- var options = arguments[1];
-
- if (!this || this === Intl) {
- // Constructor is called as a function.
- return new Intl.Collator(locales, options);
- }
-
- return initializeCollator(TO_OBJECT(this), locales, options);
- }
-);
+function CollatorConstructor() {
+ return IntlConstruct(this, GlobalIntlCollator, CreateCollator, new.target,
+ arguments);
+}
+%SetCode(GlobalIntlCollator, CollatorConstructor);
/**
* Collator resolvedOptions method.
*/
-InstallFunction(Intl.Collator.prototype, 'resolvedOptions', function() {
- if (!IS_UNDEFINED(new.target)) {
- throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
- }
-
- if (!%IsInitializedIntlObjectOfType(this, 'collator')) {
- throw %make_type_error(kResolvedOptionsCalledOnNonObject, "Collator");
- }
-
- var coll = this;
+InstallFunction(GlobalIntlCollator.prototype, 'resolvedOptions', function() {
+ var coll = Unwrap(this, 'collator', GlobalIntlCollator, 'resolvedOptions',
+ false);
var locale = getOptimalLanguageTag(coll[resolvedSymbol].requestedLocale,
coll[resolvedSymbol].locale);
@@ -1082,11 +1087,7 @@ InstallFunction(Intl.Collator.prototype, 'resolvedOptions', function() {
* order in the returned list as in the input list.
* Options are optional parameter.
*/
-InstallFunction(Intl.Collator, 'supportedLocalesOf', function(locales) {
- if (!IS_UNDEFINED(new.target)) {
- throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
- }
-
+InstallFunction(GlobalIntlCollator, 'supportedLocalesOf', function(locales) {
return supportedLocalesOf('collator', locales, arguments[1]);
}
);
@@ -1103,12 +1104,11 @@ InstallFunction(Intl.Collator, 'supportedLocalesOf', function(locales) {
* the sort order, or x comes after y in the sort order, respectively.
*/
function compare(collator, x, y) {
- return %InternalCompare(%GetImplFromInitializedIntlObject(collator),
- TO_STRING(x), TO_STRING(y));
+ return %InternalCompare(collator, TO_STRING(x), TO_STRING(y));
};
-AddBoundMethod(Intl.Collator, 'compare', compare, 2, 'collator');
+AddBoundMethod(GlobalIntlCollator, 'compare', compare, 2, 'collator', false);
/**
* Verifies that the input is a well-formed ISO 4217 currency code.
@@ -1116,7 +1116,7 @@ AddBoundMethod(Intl.Collator, 'compare', compare, 2, 'collator');
* For example \u00DFP (Eszett+P) becomes SSP.
*/
function isWellFormedCurrencyCode(currency) {
- return typeof currency == "string" && currency.length == 3 &&
+ return typeof currency === "string" && currency.length === 3 &&
IS_NULL(%regexp_internal_match(/[^A-Za-z]/, currency));
}
@@ -1152,11 +1152,7 @@ var patternAccessor = {
* Initializes the given object so it's a valid NumberFormat instance.
* Useful for subclassing.
*/
-function initializeNumberFormat(numberFormat, locales, options) {
- if (%IsInitializedIntlObject(numberFormat)) {
- throw %make_type_error(kReinitializeIntl, "NumberFormat");
- }
-
+function CreateNumberFormat(locales, options) {
if (IS_UNDEFINED(options)) {
options = {};
}
@@ -1252,16 +1248,15 @@ function initializeNumberFormat(numberFormat, locales, options) {
if (HAS_OWN_PROPERTY(internalOptions, 'maximumSignificantDigits')) {
defineWEProperty(resolved, 'maximumSignificantDigits', UNDEFINED);
}
- var formatter = %CreateNumberFormat(requestedLocale,
- internalOptions,
- resolved);
+ var numberFormat = %CreateNumberFormat(requestedLocale, internalOptions,
+ resolved);
if (internalOptions.style === 'currency') {
%object_define_property(resolved, 'currencyDisplay',
{value: currencyDisplay, writable: true});
}
- %MarkAsInitializedIntlObjectOfType(numberFormat, 'numberformat', formatter);
+ %MarkAsInitializedIntlObjectOfType(numberFormat, 'numberformat');
numberFormat[resolvedSymbol] = resolved;
return numberFormat;
@@ -1274,33 +1269,20 @@ function initializeNumberFormat(numberFormat, locales, options) {
*
* @constructor
*/
-InstallConstructor(Intl, 'NumberFormat', function() {
- var locales = arguments[0];
- var options = arguments[1];
-
- if (!this || this === Intl) {
- // Constructor is called as a function.
- return new Intl.NumberFormat(locales, options);
- }
-
- return initializeNumberFormat(TO_OBJECT(this), locales, options);
- }
-);
+function NumberFormatConstructor() {
+ return IntlConstruct(this, GlobalIntlNumberFormat, CreateNumberFormat,
+ new.target, arguments, true);
+}
+%SetCode(GlobalIntlNumberFormat, NumberFormatConstructor);
/**
* NumberFormat resolvedOptions method.
*/
-InstallFunction(Intl.NumberFormat.prototype, 'resolvedOptions', function() {
- if (!IS_UNDEFINED(new.target)) {
- throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
- }
-
- if (!%IsInitializedIntlObjectOfType(this, 'numberformat')) {
- throw %make_type_error(kResolvedOptionsCalledOnNonObject, "NumberFormat");
- }
-
- var format = this;
+InstallFunction(GlobalIntlNumberFormat.prototype, 'resolvedOptions',
+ function() {
+ var format = Unwrap(this, 'numberformat', GlobalIntlNumberFormat,
+ 'resolvedOptions', true);
var locale = getOptimalLanguageTag(format[resolvedSymbol].requestedLocale,
format[resolvedSymbol].locale);
@@ -1341,11 +1323,8 @@ InstallFunction(Intl.NumberFormat.prototype, 'resolvedOptions', function() {
* order in the returned list as in the input list.
* Options are optional parameter.
*/
-InstallFunction(Intl.NumberFormat, 'supportedLocalesOf', function(locales) {
- if (!IS_UNDEFINED(new.target)) {
- throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
- }
-
+InstallFunction(GlobalIntlNumberFormat, 'supportedLocalesOf',
+ function(locales) {
return supportedLocalesOf('numberformat', locales, arguments[1]);
}
);
@@ -1360,12 +1339,12 @@ function formatNumber(formatter, value) {
// Spec treats -0 and +0 as 0.
var number = TO_NUMBER(value) + 0;
- return %InternalNumberFormat(%GetImplFromInitializedIntlObject(formatter),
- number);
+ return %InternalNumberFormat(formatter, number);
}
-AddBoundMethod(Intl.NumberFormat, 'format', formatNumber, 1, 'numberformat');
+AddBoundMethod(GlobalIntlNumberFormat, 'format', formatNumber, 1,
+ 'numberformat', true);
/**
* Returns a string that matches LDML representation of the options object.
@@ -1518,6 +1497,8 @@ function toDateTimeOptions(options, required, defaults) {
options = TO_OBJECT(options);
}
+ options = %object_create(options);
+
var needsDefault = true;
if ((required === 'date' || required === 'any') &&
(!IS_UNDEFINED(options.weekday) || !IS_UNDEFINED(options.year) ||
@@ -1569,12 +1550,7 @@ function toDateTimeOptions(options, required, defaults) {
* Initializes the given object so it's a valid DateTimeFormat instance.
* Useful for subclassing.
*/
-function initializeDateTimeFormat(dateFormat, locales, options) {
-
- if (%IsInitializedIntlObject(dateFormat)) {
- throw %make_type_error(kReinitializeIntl, "DateTimeFormat");
- }
-
+function CreateDateTimeFormat(locales, options) {
if (IS_UNDEFINED(options)) {
options = {};
}
@@ -1636,14 +1612,14 @@ function initializeDateTimeFormat(dateFormat, locales, options) {
year: {writable: true}
});
- var formatter = %CreateDateTimeFormat(
+ var dateFormat = %CreateDateTimeFormat(
requestedLocale, {skeleton: ldmlString, timeZone: tz}, resolved);
if (resolved.timeZone === "Etc/Unknown") {
throw %make_range_error(kUnsupportedTimeZone, tz);
}
- %MarkAsInitializedIntlObjectOfType(dateFormat, 'dateformat', formatter);
+ %MarkAsInitializedIntlObjectOfType(dateFormat, 'dateformat');
dateFormat[resolvedSymbol] = resolved;
return dateFormat;
@@ -1656,31 +1632,20 @@ function initializeDateTimeFormat(dateFormat, locales, options) {
*
* @constructor
*/
-InstallConstructor(Intl, 'DateTimeFormat', function() {
- var locales = arguments[0];
- var options = arguments[1];
-
- if (!this || this === Intl) {
- // Constructor is called as a function.
- return new Intl.DateTimeFormat(locales, options);
- }
-
- return initializeDateTimeFormat(TO_OBJECT(this), locales, options);
- }
-);
+function DateTimeFormatConstructor() {
+ return IntlConstruct(this, GlobalIntlDateTimeFormat, CreateDateTimeFormat,
+ new.target, arguments, true);
+}
+%SetCode(GlobalIntlDateTimeFormat, DateTimeFormatConstructor);
/**
* DateTimeFormat resolvedOptions method.
*/
-InstallFunction(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() {
- if (!IS_UNDEFINED(new.target)) {
- throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
- }
-
- if (!%IsInitializedIntlObjectOfType(this, 'dateformat')) {
- throw %make_type_error(kResolvedOptionsCalledOnNonObject, "DateTimeFormat");
- }
+InstallFunction(GlobalIntlDateTimeFormat.prototype, 'resolvedOptions',
+ function() {
+ var format = Unwrap(this, 'dateformat', GlobalIntlDateTimeFormat,
+ 'resolvedOptions', true);
/**
* Maps ICU calendar names to LDML/BCP47 types for key 'ca'.
@@ -1693,7 +1658,6 @@ InstallFunction(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() {
'ethiopic-amete-alem': 'ethioaa'
};
- var format = this;
var fromPattern = fromLDMLString(format[resolvedSymbol][patternSymbol]);
var userCalendar = ICU_CALENDAR_MAP[format[resolvedSymbol].calendar];
if (IS_UNDEFINED(userCalendar)) {
@@ -1733,11 +1697,8 @@ InstallFunction(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() {
* order in the returned list as in the input list.
* Options are optional parameter.
*/
-InstallFunction(Intl.DateTimeFormat, 'supportedLocalesOf', function(locales) {
- if (!IS_UNDEFINED(new.target)) {
- throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
- }
-
+InstallFunction(GlobalIntlDateTimeFormat, 'supportedLocalesOf',
+ function(locales) {
return supportedLocalesOf('dateformat', locales, arguments[1]);
}
);
@@ -1758,18 +1719,19 @@ function formatDate(formatter, dateValue) {
if (!NUMBER_IS_FINITE(dateMs)) throw %make_range_error(kDateRange);
- return %InternalDateFormat(%GetImplFromInitializedIntlObject(formatter),
- new GlobalDate(dateMs));
+ return %InternalDateFormat(formatter, new GlobalDate(dateMs));
}
function FormatDateToParts(dateValue) {
- if (!IS_UNDEFINED(new.target)) {
- throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
- }
CHECK_OBJECT_COERCIBLE(this, "Intl.DateTimeFormat.prototype.formatToParts");
if (!IS_OBJECT(this)) {
throw %make_type_error(kCalledOnNonObject, this);
}
+ if (!%IsInitializedIntlObjectOfType(this, 'dateformat')) {
+ throw %make_type_error(kIncompatibleMethodReceiver,
+ 'Intl.DateTimeFormat.prototype.formatToParts',
+ this);
+ }
var dateMs;
if (IS_UNDEFINED(dateValue)) {
dateMs = %DateCurrentTime();
@@ -1779,15 +1741,15 @@ function FormatDateToParts(dateValue) {
if (!NUMBER_IS_FINITE(dateMs)) throw %make_range_error(kDateRange);
- return %InternalDateFormatToParts(
- %GetImplFromInitializedIntlObject(this), new GlobalDate(dateMs));
+ return %InternalDateFormatToParts(this, new GlobalDate(dateMs));
}
%FunctionSetLength(FormatDateToParts, 0);
// 0 because date is optional argument.
-AddBoundMethod(Intl.DateTimeFormat, 'format', formatDate, 0, 'dateformat');
+AddBoundMethod(GlobalIntlDateTimeFormat, 'format', formatDate, 0, 'dateformat',
+ true);
/**
@@ -1835,11 +1797,7 @@ function canonicalizeTimeZoneID(tzID) {
* Initializes the given object so it's a valid BreakIterator instance.
* Useful for subclassing.
*/
-function initializeBreakIterator(iterator, locales, options) {
- if (%IsInitializedIntlObject(iterator)) {
- throw %make_type_error(kReinitializeIntl, "v8BreakIterator");
- }
-
+function CreateBreakIterator(locales, options) {
if (IS_UNDEFINED(options)) {
options = {};
}
@@ -1858,12 +1816,9 @@ function initializeBreakIterator(iterator, locales, options) {
locale: {writable: true}
});
- var internalIterator = %CreateBreakIterator(locale.locale,
- internalOptions,
- resolved);
+ var iterator = %CreateBreakIterator(locale.locale, internalOptions, resolved);
- %MarkAsInitializedIntlObjectOfType(iterator, 'breakiterator',
- internalIterator);
+ %MarkAsInitializedIntlObjectOfType(iterator, 'breakiterator');
iterator[resolvedSymbol] = resolved;
return iterator;
@@ -1876,34 +1831,25 @@ function initializeBreakIterator(iterator, locales, options) {
*
* @constructor
*/
-InstallConstructor(Intl, 'v8BreakIterator', function() {
- var locales = arguments[0];
- var options = arguments[1];
-
- if (!this || this === Intl) {
- // Constructor is called as a function.
- return new Intl.v8BreakIterator(locales, options);
- }
-
- return initializeBreakIterator(TO_OBJECT(this), locales, options);
- }
-);
+function v8BreakIteratorConstructor() {
+ return IntlConstruct(this, GlobalIntlv8BreakIterator, CreateBreakIterator,
+ new.target, arguments);
+}
+%SetCode(GlobalIntlv8BreakIterator, v8BreakIteratorConstructor);
/**
* BreakIterator resolvedOptions method.
*/
-InstallFunction(Intl.v8BreakIterator.prototype, 'resolvedOptions',
+InstallFunction(GlobalIntlv8BreakIterator.prototype, 'resolvedOptions',
function() {
if (!IS_UNDEFINED(new.target)) {
throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
}
- if (!%IsInitializedIntlObjectOfType(this, 'breakiterator')) {
- throw %make_type_error(kResolvedOptionsCalledOnNonObject, "v8BreakIterator");
- }
+ var segmenter = Unwrap(this, 'breakiterator', GlobalIntlv8BreakIterator,
+ 'resolvedOptions', false);
- var segmenter = this;
var locale =
getOptimalLanguageTag(segmenter[resolvedSymbol].requestedLocale,
segmenter[resolvedSymbol].locale);
@@ -1922,7 +1868,7 @@ InstallFunction(Intl.v8BreakIterator.prototype, 'resolvedOptions',
* order in the returned list as in the input list.
* Options are optional parameter.
*/
-InstallFunction(Intl.v8BreakIterator, 'supportedLocalesOf',
+InstallFunction(GlobalIntlv8BreakIterator, 'supportedLocalesOf',
function(locales) {
if (!IS_UNDEFINED(new.target)) {
throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
@@ -1938,8 +1884,7 @@ InstallFunction(Intl.v8BreakIterator, 'supportedLocalesOf',
* gets discarded.
*/
function adoptText(iterator, text) {
- %BreakIteratorAdoptText(%GetImplFromInitializedIntlObject(iterator),
- TO_STRING(text));
+ %BreakIteratorAdoptText(iterator, TO_STRING(text));
}
@@ -1947,7 +1892,7 @@ function adoptText(iterator, text) {
* Returns index of the first break in the string and moves current pointer.
*/
function first(iterator) {
- return %BreakIteratorFirst(%GetImplFromInitializedIntlObject(iterator));
+ return %BreakIteratorFirst(iterator);
}
@@ -1955,7 +1900,7 @@ function first(iterator) {
* Returns the index of the next break and moves the pointer.
*/
function next(iterator) {
- return %BreakIteratorNext(%GetImplFromInitializedIntlObject(iterator));
+ return %BreakIteratorNext(iterator);
}
@@ -1963,7 +1908,7 @@ function next(iterator) {
* Returns index of the current break.
*/
function current(iterator) {
- return %BreakIteratorCurrent(%GetImplFromInitializedIntlObject(iterator));
+ return %BreakIteratorCurrent(iterator);
}
@@ -1971,25 +1916,26 @@ function current(iterator) {
* Returns type of the current break.
*/
function breakType(iterator) {
- return %BreakIteratorBreakType(%GetImplFromInitializedIntlObject(iterator));
+ return %BreakIteratorBreakType(iterator);
}
-AddBoundMethod(Intl.v8BreakIterator, 'adoptText', adoptText, 1,
+AddBoundMethod(GlobalIntlv8BreakIterator, 'adoptText', adoptText, 1,
'breakiterator');
-AddBoundMethod(Intl.v8BreakIterator, 'first', first, 0, 'breakiterator');
-AddBoundMethod(Intl.v8BreakIterator, 'next', next, 0, 'breakiterator');
-AddBoundMethod(Intl.v8BreakIterator, 'current', current, 0, 'breakiterator');
-AddBoundMethod(Intl.v8BreakIterator, 'breakType', breakType, 0,
+AddBoundMethod(GlobalIntlv8BreakIterator, 'first', first, 0, 'breakiterator');
+AddBoundMethod(GlobalIntlv8BreakIterator, 'next', next, 0, 'breakiterator');
+AddBoundMethod(GlobalIntlv8BreakIterator, 'current', current, 0,
+ 'breakiterator');
+AddBoundMethod(GlobalIntlv8BreakIterator, 'breakType', breakType, 0,
'breakiterator');
// Save references to Intl objects and methods we use, for added security.
var savedObjects = {
- 'collator': Intl.Collator,
- 'numberformat': Intl.NumberFormat,
- 'dateformatall': Intl.DateTimeFormat,
- 'dateformatdate': Intl.DateTimeFormat,
- 'dateformattime': Intl.DateTimeFormat
+ 'collator': GlobalIntlCollator,
+ 'numberformat': GlobalIntlNumberFormat,
+ 'dateformatall': GlobalIntlDateTimeFormat,
+ 'dateformatdate': GlobalIntlDateTimeFormat,
+ 'dateformattime': GlobalIntlDateTimeFormat
};
@@ -2054,18 +2000,11 @@ function LocaleConvertCase(s, locales, isToUpper) {
// StringSplit is slower than this.
var pos = %StringIndexOf(language, '-', 0);
- if (pos != -1) {
+ if (pos !== -1) {
language = %_Call(StringSubstring, language, 0, pos);
}
- var CUSTOM_CASE_LANGUAGES = ['az', 'el', 'lt', 'tr'];
- var langIndex = %ArrayIndexOf(CUSTOM_CASE_LANGUAGES, language, 0);
- if (langIndex == -1) {
- // language-independent case conversion.
- return isToUpper ? %StringToUpperCaseI18N(s) : %StringToLowerCaseI18N(s);
- }
- return %StringLocaleConvertCase(s, isToUpper,
- CUSTOM_CASE_LANGUAGES[langIndex]);
+ return %StringLocaleConvertCase(s, isToUpper, language);
}
/**
@@ -2073,10 +2012,6 @@ function LocaleConvertCase(s, locales, isToUpper) {
* Overrides the built-in method.
*/
OverrideFunction(GlobalString.prototype, 'localeCompare', function(that) {
- if (!IS_UNDEFINED(new.target)) {
- throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
- }
-
if (IS_NULL_OR_UNDEFINED(this)) {
throw %make_type_error(kMethodInvokedOnNullOrUndefined);
}
@@ -2098,10 +2033,6 @@ OverrideFunction(GlobalString.prototype, 'localeCompare', function(that) {
*/
OverrideFunction(GlobalString.prototype, 'normalize', function() {
- if (!IS_UNDEFINED(new.target)) {
- throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
- }
-
CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize");
var s = TO_STRING(this);
@@ -2121,27 +2052,16 @@ OverrideFunction(GlobalString.prototype, 'normalize', function() {
);
function ToLowerCaseI18N() {
- if (!IS_UNDEFINED(new.target)) {
- throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
- }
CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLowerCase");
- var s = TO_STRING(this);
- return %StringToLowerCaseI18N(s);
+ return %StringToLowerCaseI18N(TO_STRING(this));
}
function ToUpperCaseI18N() {
- if (!IS_UNDEFINED(new.target)) {
- throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
- }
CHECK_OBJECT_COERCIBLE(this, "String.prototype.toUpperCase");
- var s = TO_STRING(this);
- return %StringToUpperCaseI18N(s);
+ return %StringToUpperCaseI18N(TO_STRING(this));
}
function ToLocaleLowerCaseI18N(locales) {
- if (!IS_UNDEFINED(new.target)) {
- throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
- }
CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleLowerCase");
return LocaleConvertCase(TO_STRING(this), locales, false);
}
@@ -2149,9 +2069,6 @@ function ToLocaleLowerCaseI18N(locales) {
%FunctionSetLength(ToLocaleLowerCaseI18N, 0);
function ToLocaleUpperCaseI18N(locales) {
- if (!IS_UNDEFINED(new.target)) {
- throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
- }
CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleUpperCase");
return LocaleConvertCase(TO_STRING(this), locales, true);
}
@@ -2176,10 +2093,6 @@ utils.Export(function(to) {
* If locale or options are omitted, defaults are used.
*/
OverrideFunction(GlobalNumber.prototype, 'toLocaleString', function() {
- if (!IS_UNDEFINED(new.target)) {
- throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
- }
-
if (!(this instanceof GlobalNumber) && typeof(this) !== 'number') {
throw %make_type_error(kMethodInvokedOnWrongType, "Number");
}
@@ -2218,10 +2131,6 @@ function toLocaleDateTime(date, locales, options, required, defaults, service) {
* present in the output.
*/
OverrideFunction(GlobalDate.prototype, 'toLocaleString', function() {
- if (!IS_UNDEFINED(new.target)) {
- throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
- }
-
var locales = arguments[0];
var options = arguments[1];
return toLocaleDateTime(
@@ -2236,10 +2145,6 @@ OverrideFunction(GlobalDate.prototype, 'toLocaleString', function() {
* in the output.
*/
OverrideFunction(GlobalDate.prototype, 'toLocaleDateString', function() {
- if (!IS_UNDEFINED(new.target)) {
- throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
- }
-
var locales = arguments[0];
var options = arguments[1];
return toLocaleDateTime(
@@ -2254,10 +2159,6 @@ OverrideFunction(GlobalDate.prototype, 'toLocaleDateString', function() {
* in the output.
*/
OverrideFunction(GlobalDate.prototype, 'toLocaleTimeString', function() {
- if (!IS_UNDEFINED(new.target)) {
- throw %make_type_error(kOrdinaryFunctionCalledAsConstructor);
- }
-
var locales = arguments[0];
var options = arguments[1];
return toLocaleDateTime(