| Index: src/i18n.js
|
| diff --git a/src/i18n.js b/src/i18n.js
|
| index e5dc8d2c370a1cc7843ffd13ca3719450e386890..302a929593b94fde1149faa0b92996527cb7c2c3 100644
|
| --- a/src/i18n.js
|
| +++ b/src/i18n.js
|
| @@ -219,8 +219,7 @@ var ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR =
|
| function addBoundMethod(obj, methodName, implementation, length) {
|
| function getter() {
|
| if (!%IsInitializedIntlObject(this)) {
|
| - throw new $TypeError('Method ' + methodName + ' called on a ' +
|
| - 'non-object or on a wrong type of object.');
|
| + throw MakeTypeError(kMethodCalledOnWrongObject, methodName);
|
| }
|
| var internalName = '__bound' + methodName + '__';
|
| if (this[internalName] === undefined) {
|
| @@ -229,21 +228,21 @@ function addBoundMethod(obj, methodName, implementation, length) {
|
| if (length === undefined || length === 2) {
|
| boundMethod = function(x, y) {
|
| if (%_IsConstructCall()) {
|
| - throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
|
| + throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
|
| }
|
| return implementation(that, x, y);
|
| }
|
| } else if (length === 1) {
|
| boundMethod = function(x) {
|
| if (%_IsConstructCall()) {
|
| - throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
|
| + throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
|
| }
|
| return implementation(that, x);
|
| }
|
| } else {
|
| boundMethod = function() {
|
| if (%_IsConstructCall()) {
|
| - throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
|
| + throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
|
| }
|
| // DateTimeFormat.format needs to be 0 arg method, but can stil
|
| // receive optional dateValue param. If one was provided, pass it
|
| @@ -281,7 +280,7 @@ function addBoundMethod(obj, methodName, implementation, length) {
|
| */
|
| function supportedLocalesOf(service, locales, options) {
|
| if (IS_NULL(service.match(GetServiceRE()))) {
|
| - throw new $Error('Internal error, wrong service type: ' + service);
|
| + throw MakeError(kWrongServiceType, service);
|
| }
|
|
|
| // Provide defaults if matcher was not specified.
|
| @@ -295,7 +294,7 @@ function supportedLocalesOf(service, locales, options) {
|
| if (matcher !== undefined) {
|
| matcher = GlobalString(matcher);
|
| if (matcher !== 'lookup' && matcher !== 'best fit') {
|
| - throw new $RangeError('Illegal value for localeMatcher:' + matcher);
|
| + throw MakeRangeError(kLocaleMatcher, matcher);
|
| }
|
| } else {
|
| matcher = 'best fit';
|
| @@ -366,10 +365,7 @@ function bestFitSupportedLocalesOf(requestedLocales, availableLocales) {
|
| * is out of range for that property it throws RangeError.
|
| */
|
| function getGetOption(options, caller) {
|
| - if (options === undefined) {
|
| - throw new $Error('Internal ' + caller + ' error. ' +
|
| - 'Default options are missing.');
|
| - }
|
| + if (options === undefined) throw MakeError(kDefaultOptionsMissing, caller);
|
|
|
| var getOption = function getOption(property, type, values, defaultValue) {
|
| if (options[property] !== undefined) {
|
| @@ -385,11 +381,10 @@ function getGetOption(options, caller) {
|
| value = GlobalNumber(value);
|
| break;
|
| default:
|
| - throw new $Error('Internal error. Wrong value type.');
|
| + throw MakeError(kWrongValueType);
|
| }
|
| if (values !== undefined && values.indexOf(value) === -1) {
|
| - throw new $RangeError('Value ' + value + ' out of range for ' + caller +
|
| - ' options property ' + property);
|
| + throw MakeRangeError(kValueOutOfRange, value, caller, property);
|
| }
|
|
|
| return value;
|
| @@ -438,7 +433,7 @@ function resolveLocale(service, requestedLocales, options) {
|
| */
|
| function lookupMatcher(service, requestedLocales) {
|
| if (IS_NULL(service.match(GetServiceRE()))) {
|
| - throw new $Error('Internal error, wrong service type: ' + service);
|
| + throw MakeError(kWrongServiceType, service);
|
| }
|
|
|
| // Cache these, they don't ever change per service.
|
| @@ -711,13 +706,13 @@ function canonicalizeLanguageTag(localeID) {
|
| // null is typeof 'object' so we have to do extra check.
|
| if (typeof localeID !== 'string' && typeof localeID !== 'object' ||
|
| IS_NULL(localeID)) {
|
| - throw new $TypeError('Language ID should be string or object.');
|
| + throw MakeTypeError(kLanguageID);
|
| }
|
|
|
| var localeString = GlobalString(localeID);
|
|
|
| if (isValidLanguageTag(localeString) === false) {
|
| - throw new $RangeError('Invalid language tag: ' + localeString);
|
| + throw MakeRangeError(kInvalidLanguageTag, localeString);
|
| }
|
|
|
| // This call will strip -kn but not -kn-true extensions.
|
| @@ -726,7 +721,7 @@ function canonicalizeLanguageTag(localeID) {
|
| // upgrade to ICU 4.9.
|
| var tag = %CanonicalizeLanguageTag(localeString);
|
| if (tag === 'invalid-tag') {
|
| - throw new $RangeError('Invalid language tag: ' + localeString);
|
| + throw MakeRangeError(kInvalidLanguageTag, localeString);
|
| }
|
|
|
| return tag;
|
| @@ -869,7 +864,7 @@ function BuildLanguageTagREs() {
|
| */
|
| function initializeCollator(collator, locales, options) {
|
| if (%IsInitializedIntlObject(collator)) {
|
| - throw new $TypeError('Trying to re-initialize Collator object.');
|
| + throw MakeTypeError(kReinitializeIntl, "Collator");
|
| }
|
|
|
| if (options === undefined) {
|
| @@ -972,12 +967,11 @@ function initializeCollator(collator, locales, options) {
|
| */
|
| %AddNamedProperty(Intl.Collator.prototype, 'resolvedOptions', function() {
|
| if (%_IsConstructCall()) {
|
| - throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
|
| + throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
|
| }
|
|
|
| if (!%IsInitializedIntlObjectOfType(this, 'collator')) {
|
| - throw new $TypeError('resolvedOptions method called on a non-object ' +
|
| - 'or on a object that is not Intl.Collator.');
|
| + throw MakeTypeError(kResolvedOptionsCalledOnNonObject, "Collator");
|
| }
|
|
|
| var coll = this;
|
| @@ -1009,7 +1003,7 @@ function initializeCollator(collator, locales, options) {
|
| */
|
| %AddNamedProperty(Intl.Collator, 'supportedLocalesOf', function(locales) {
|
| if (%_IsConstructCall()) {
|
| - throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
|
| + throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
|
| }
|
|
|
| return supportedLocalesOf('collator', locales, %_Arguments(1));
|
| @@ -1060,7 +1054,7 @@ function getNumberOption(options, property, min, max, fallback) {
|
| if (value !== undefined) {
|
| value = GlobalNumber(value);
|
| if ($isNaN(value) || value < min || value > max) {
|
| - throw new $RangeError(property + ' value is out of range.');
|
| + throw MakeRangeError(kPropertyValueOutOfRange, property);
|
| }
|
| return $floor(value);
|
| }
|
| @@ -1075,7 +1069,7 @@ function getNumberOption(options, property, min, max, fallback) {
|
| */
|
| function initializeNumberFormat(numberFormat, locales, options) {
|
| if (%IsInitializedIntlObject(numberFormat)) {
|
| - throw new $TypeError('Trying to re-initialize NumberFormat object.');
|
| + throw MakeTypeError(kReinitializeIntl, "NumberFormat");
|
| }
|
|
|
| if (options === undefined) {
|
| @@ -1092,11 +1086,11 @@ function initializeNumberFormat(numberFormat, locales, options) {
|
|
|
| var currency = getOption('currency', 'string');
|
| if (currency !== undefined && !isWellFormedCurrencyCode(currency)) {
|
| - throw new $RangeError('Invalid currency code: ' + currency);
|
| + throw MakeRangeError(kInvalidCurrencyCode, currency);
|
| }
|
|
|
| if (internalOptions.style === 'currency' && currency === undefined) {
|
| - throw new $TypeError('Currency code is required with currency style.');
|
| + throw MakeTypeError(kCurrencyCode);
|
| }
|
|
|
| var currencyDisplay = getOption(
|
| @@ -1199,12 +1193,11 @@ function initializeNumberFormat(numberFormat, locales, options) {
|
| */
|
| %AddNamedProperty(Intl.NumberFormat.prototype, 'resolvedOptions', function() {
|
| if (%_IsConstructCall()) {
|
| - throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
|
| + throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
|
| }
|
|
|
| if (!%IsInitializedIntlObjectOfType(this, 'numberformat')) {
|
| - throw new $TypeError('resolvedOptions method called on a non-object' +
|
| - ' or on a object that is not Intl.NumberFormat.');
|
| + throw MakeTypeError(kResolvedOptionsCalledOnNonObject, "NumberFormat");
|
| }
|
|
|
| var format = this;
|
| @@ -1255,7 +1248,7 @@ function initializeNumberFormat(numberFormat, locales, options) {
|
| */
|
| %AddNamedProperty(Intl.NumberFormat, 'supportedLocalesOf', function(locales) {
|
| if (%_IsConstructCall()) {
|
| - throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
|
| + throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
|
| }
|
|
|
| return supportedLocalesOf('numberformat', locales, %_Arguments(1));
|
| @@ -1498,7 +1491,7 @@ function toDateTimeOptions(options, required, defaults) {
|
| function initializeDateTimeFormat(dateFormat, locales, options) {
|
|
|
| if (%IsInitializedIntlObject(dateFormat)) {
|
| - throw new $TypeError('Trying to re-initialize DateTimeFormat object.');
|
| + throw MakeTypeError(kReinitializeIntl, "DateTimeFormat");
|
| }
|
|
|
| if (options === undefined) {
|
| @@ -1556,7 +1549,7 @@ function initializeDateTimeFormat(dateFormat, locales, options) {
|
| requestedLocale, {skeleton: ldmlString, timeZone: tz}, resolved);
|
|
|
| if (tz !== undefined && tz !== resolved.timeZone) {
|
| - throw new $RangeError('Unsupported time zone specified ' + tz);
|
| + throw MakeRangeError(kUnsupportedTimeZone, tz);
|
| }
|
|
|
| %MarkAsInitializedIntlObjectOfType(dateFormat, 'dateformat', formatter);
|
| @@ -1592,12 +1585,11 @@ function initializeDateTimeFormat(dateFormat, locales, options) {
|
| */
|
| %AddNamedProperty(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() {
|
| if (%_IsConstructCall()) {
|
| - throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
|
| + throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
|
| }
|
|
|
| if (!%IsInitializedIntlObjectOfType(this, 'dateformat')) {
|
| - throw new $TypeError('resolvedOptions method called on a non-object or ' +
|
| - 'on a object that is not Intl.DateTimeFormat.');
|
| + throw MakeTypeError(kResolvedOptionsCalledOnNonObject, "DateTimeFormat");
|
| }
|
|
|
| var format = this;
|
| @@ -1648,7 +1640,7 @@ function initializeDateTimeFormat(dateFormat, locales, options) {
|
| */
|
| %AddNamedProperty(Intl.DateTimeFormat, 'supportedLocalesOf', function(locales) {
|
| if (%_IsConstructCall()) {
|
| - throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
|
| + throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
|
| }
|
|
|
| return supportedLocalesOf('dateformat', locales, %_Arguments(1));
|
| @@ -1673,9 +1665,7 @@ function formatDate(formatter, dateValue) {
|
| dateMs = GlobalNumber(dateValue);
|
| }
|
|
|
| - if (!$isFinite(dateMs)) {
|
| - throw new $RangeError('Provided date is not in valid range.');
|
| - }
|
| + if (!$isFinite(dateMs)) throw MakeRangeError(kDateRange);
|
|
|
| return %InternalDateFormat(%GetImplFromInitializedIntlObject(formatter),
|
| new GlobalDate(dateMs));
|
| @@ -1719,9 +1709,7 @@ function canonicalizeTimeZoneID(tzID) {
|
| // We expect only _ and / beside ASCII letters.
|
| // All inputs should conform to Area/Location from now on.
|
| var match = GetTimezoneNameCheckRE().exec(tzID);
|
| - if (IS_NULL(match)) {
|
| - throw new $RangeError('Expected Area/Location for time zone, got ' + tzID);
|
| - }
|
| + if (IS_NULL(match)) throw MakeRangeError(kExpectedLocation, tzID);
|
|
|
| var result = toTitleCaseWord(match[1]) + '/' + toTitleCaseWord(match[2]);
|
| var i = 3;
|
| @@ -1739,7 +1727,7 @@ function canonicalizeTimeZoneID(tzID) {
|
| */
|
| function initializeBreakIterator(iterator, locales, options) {
|
| if (%IsInitializedIntlObject(iterator)) {
|
| - throw new $TypeError('Trying to re-initialize v8BreakIterator object.');
|
| + throw MakeTypeError(kReinitializeIntl, "v8BreakIterator");
|
| }
|
|
|
| if (options === undefined) {
|
| @@ -1799,12 +1787,11 @@ function initializeBreakIterator(iterator, locales, options) {
|
| %AddNamedProperty(Intl.v8BreakIterator.prototype, 'resolvedOptions',
|
| function() {
|
| if (%_IsConstructCall()) {
|
| - throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
|
| + throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
|
| }
|
|
|
| if (!%IsInitializedIntlObjectOfType(this, 'breakiterator')) {
|
| - throw new $TypeError('resolvedOptions method called on a non-object or ' +
|
| - 'on a object that is not Intl.v8BreakIterator.');
|
| + throw MakeTypeError(kResolvedOptionsCalledOnNonObject, "v8BreakIterator");
|
| }
|
|
|
| var segmenter = this;
|
| @@ -1833,7 +1820,7 @@ function initializeBreakIterator(iterator, locales, options) {
|
| %AddNamedProperty(Intl.v8BreakIterator, 'supportedLocalesOf',
|
| function(locales) {
|
| if (%_IsConstructCall()) {
|
| - throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
|
| + throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
|
| }
|
|
|
| return supportedLocalesOf('breakiterator', locales, %_Arguments(1));
|
| @@ -1936,11 +1923,11 @@ function cachedOrNewService(service, locales, options, defaults) {
|
| */
|
| OverrideFunction(GlobalString.prototype, 'localeCompare', function(that) {
|
| if (%_IsConstructCall()) {
|
| - throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
|
| + throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
|
| }
|
|
|
| if (IS_NULL_OR_UNDEFINED(this)) {
|
| - throw new $TypeError('Method invoked on undefined or null value.');
|
| + throw MakeTypeError(kMethodInvokedOnNullOrUndefined);
|
| }
|
|
|
| var locales = %_Arguments(1);
|
| @@ -1960,7 +1947,7 @@ OverrideFunction(GlobalString.prototype, 'localeCompare', function(that) {
|
| */
|
| OverrideFunction(GlobalString.prototype, 'normalize', function(that) {
|
| if (%_IsConstructCall()) {
|
| - throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
|
| + throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
|
| }
|
|
|
| CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize");
|
| @@ -1969,8 +1956,7 @@ OverrideFunction(GlobalString.prototype, 'normalize', function(that) {
|
|
|
| var normalizationForm = NORMALIZATION_FORMS.indexOf(form);
|
| if (normalizationForm === -1) {
|
| - throw new $RangeError('The normalization form should be one of '
|
| - + NORMALIZATION_FORMS.join(', ') + '.');
|
| + throw MakeRangeError(kNormalizationForm, NORMALIZATION_FORMS.join(', '));
|
| }
|
|
|
| return %StringNormalize(this, normalizationForm);
|
| @@ -1984,11 +1970,11 @@ OverrideFunction(GlobalString.prototype, 'normalize', function(that) {
|
| */
|
| OverrideFunction(GlobalNumber.prototype, 'toLocaleString', function() {
|
| if (%_IsConstructCall()) {
|
| - throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
|
| + throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
|
| }
|
|
|
| if (!(this instanceof GlobalNumber) && typeof(this) !== 'number') {
|
| - throw new $TypeError('Method invoked on an object that is not Number.');
|
| + throw MakeTypeError(kMethodInvokedOnWrongType, "Number");
|
| }
|
|
|
| var locales = %_Arguments(0);
|
| @@ -2004,7 +1990,7 @@ OverrideFunction(GlobalNumber.prototype, 'toLocaleString', function() {
|
| */
|
| function toLocaleDateTime(date, locales, options, required, defaults, service) {
|
| if (!(date instanceof GlobalDate)) {
|
| - throw new $TypeError('Method invoked on an object that is not Date.');
|
| + throw MakeTypeError(kMethodInvokedOnWrongType, "Date");
|
| }
|
|
|
| if ($isNaN(date)) {
|
| @@ -2027,7 +2013,7 @@ function toLocaleDateTime(date, locales, options, required, defaults, service) {
|
| */
|
| OverrideFunction(GlobalDate.prototype, 'toLocaleString', function() {
|
| if (%_IsConstructCall()) {
|
| - throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
|
| + throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
|
| }
|
|
|
| var locales = %_Arguments(0);
|
| @@ -2045,7 +2031,7 @@ OverrideFunction(GlobalDate.prototype, 'toLocaleString', function() {
|
| */
|
| OverrideFunction(GlobalDate.prototype, 'toLocaleDateString', function() {
|
| if (%_IsConstructCall()) {
|
| - throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
|
| + throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
|
| }
|
|
|
| var locales = %_Arguments(0);
|
| @@ -2063,7 +2049,7 @@ OverrideFunction(GlobalDate.prototype, 'toLocaleDateString', function() {
|
| */
|
| OverrideFunction(GlobalDate.prototype, 'toLocaleTimeString', function() {
|
| if (%_IsConstructCall()) {
|
| - throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
|
| + throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
|
| }
|
|
|
| var locales = %_Arguments(0);
|
|
|