Index: src/i18n.js |
diff --git a/src/i18n.js b/src/i18n.js |
index 2e5485749ae766fc469c8cd52c8257fe5b57e7b4..edfb065c9c998afd12ec059c04b30532289592bb 100644 |
--- a/src/i18n.js |
+++ b/src/i18n.js |
@@ -232,8 +232,7 @@ var ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR = |
*/ |
function addBoundMethod(obj, methodName, implementation, length) { |
function getter() { |
- if (!this || typeof this !== 'object' || |
- this.__initializedIntlObject === undefined) { |
+ if (!%IsInitializedIntlObject(this)) { |
throw new $TypeError('Method ' + methodName + ' called on a ' + |
'non-object or on a wrong type of object.'); |
} |
@@ -896,7 +895,7 @@ function BuildLanguageTagREs() { |
* Useful for subclassing. |
*/ |
function initializeCollator(collator, locales, options) { |
- if (collator.hasOwnProperty('__initializedIntlObject')) { |
+ if (%IsInitializedIntlObject(collator)) { |
throw new $TypeError('Trying to re-initialize Collator object.'); |
} |
@@ -967,9 +966,7 @@ function initializeCollator(collator, locales, options) { |
resolved); |
// Writable, configurable and enumerable are set to false by default. |
- $Object.defineProperty(collator, 'collator', {value: internalCollator}); |
- $Object.defineProperty(collator, '__initializedIntlObject', |
- {value: 'collator'}); |
+ %MarkAsInitializedIntlObjectOfType(collator, 'collator', internalCollator); |
$Object.defineProperty(collator, 'resolved', {value: resolved}); |
return collator; |
@@ -1005,8 +1002,7 @@ function initializeCollator(collator, locales, options) { |
throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); |
} |
- if (!this || typeof this !== 'object' || |
- this.__initializedIntlObject !== 'collator') { |
+ if (!%IsInitializedIntlObjectOfType(this, 'collator')) { |
throw new $TypeError('resolvedOptions method called on a non-object ' + |
'or on a object that is not Intl.Collator.'); |
} |
@@ -1063,7 +1059,8 @@ function initializeCollator(collator, locales, options) { |
* the sort order, or x comes after y in the sort order, respectively. |
*/ |
function compare(collator, x, y) { |
- return %InternalCompare(collator.collator, $String(x), $String(y)); |
+ return %InternalCompare(%GetImplFromInitializedIntlObject(collator), |
+ $String(x), $String(y)); |
}; |
@@ -1104,7 +1101,7 @@ function getNumberOption(options, property, min, max, fallback) { |
* Useful for subclassing. |
*/ |
function initializeNumberFormat(numberFormat, locales, options) { |
- if (numberFormat.hasOwnProperty('__initializedIntlObject')) { |
+ if (%IsInitializedIntlObject(numberFormat)) { |
throw new $TypeError('Trying to re-initialize NumberFormat object.'); |
} |
@@ -1196,10 +1193,8 @@ function initializeNumberFormat(numberFormat, locales, options) { |
writable: true}); |
} |
- $Object.defineProperty(numberFormat, 'formatter', {value: formatter}); |
+ %MarkAsInitializedIntlObjectOfType(numberFormat, 'numberformat', formatter); |
$Object.defineProperty(numberFormat, 'resolved', {value: resolved}); |
- $Object.defineProperty(numberFormat, '__initializedIntlObject', |
- {value: 'numberformat'}); |
return numberFormat; |
} |
@@ -1234,8 +1229,7 @@ function initializeNumberFormat(numberFormat, locales, options) { |
throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); |
} |
- if (!this || typeof this !== 'object' || |
- this.__initializedIntlObject !== 'numberformat') { |
+ if (!%IsInitializedIntlObjectOfType(this, 'numberformat')) { |
throw new $TypeError('resolvedOptions method called on a non-object' + |
' or on a object that is not Intl.NumberFormat.'); |
} |
@@ -1309,7 +1303,8 @@ function formatNumber(formatter, value) { |
// Spec treats -0 and +0 as 0. |
var number = $Number(value) + 0; |
- return %InternalNumberFormat(formatter.formatter, number); |
+ return %InternalNumberFormat(%GetImplFromInitializedIntlObject(formatter), |
+ number); |
} |
@@ -1317,7 +1312,8 @@ function formatNumber(formatter, value) { |
* Returns a Number that represents string value that was passed in. |
*/ |
function parseNumber(formatter, value) { |
- return %InternalNumberParse(formatter.formatter, $String(value)); |
+ return %InternalNumberParse(%GetImplFromInitializedIntlObject(formatter), |
+ $String(value)); |
} |
@@ -1530,7 +1526,7 @@ function toDateTimeOptions(options, required, defaults) { |
*/ |
function initializeDateTimeFormat(dateFormat, locales, options) { |
- if (dateFormat.hasOwnProperty('__initializedIntlObject')) { |
+ if (%IsInitializedIntlObject(dateFormat)) { |
throw new $TypeError('Trying to re-initialize DateTimeFormat object.'); |
} |
@@ -1592,10 +1588,8 @@ function initializeDateTimeFormat(dateFormat, locales, options) { |
throw new $RangeError('Unsupported time zone specified ' + tz); |
} |
- $Object.defineProperty(dateFormat, 'formatter', {value: formatter}); |
+ %MarkAsInitializedIntlObjectOfType(dateFormat, 'dateformat', formatter); |
$Object.defineProperty(dateFormat, 'resolved', {value: resolved}); |
- $Object.defineProperty(dateFormat, '__initializedIntlObject', |
- {value: 'dateformat'}); |
return dateFormat; |
} |
@@ -1630,8 +1624,7 @@ function initializeDateTimeFormat(dateFormat, locales, options) { |
throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); |
} |
- if (!this || typeof this !== 'object' || |
- this.__initializedIntlObject !== 'dateformat') { |
+ if (!%IsInitializedIntlObjectOfType(this, 'dateformat')) { |
throw new $TypeError('resolvedOptions method called on a non-object or ' + |
'on a object that is not Intl.DateTimeFormat.'); |
} |
@@ -1713,7 +1706,8 @@ function formatDate(formatter, dateValue) { |
throw new $RangeError('Provided date is not in valid range.'); |
} |
- return %InternalDateFormat(formatter.formatter, new $Date(dateMs)); |
+ return %InternalDateFormat(%GetImplFromInitializedIntlObject(formatter), |
+ new $Date(dateMs)); |
} |
@@ -1724,7 +1718,8 @@ function formatDate(formatter, dateValue) { |
* Returns undefined if date string cannot be parsed. |
*/ |
function parseDate(formatter, value) { |
- return %InternalDateParse(formatter.formatter, $String(value)); |
+ return %InternalDateParse(%GetImplFromInitializedIntlObject(formatter), |
+ $String(value)); |
} |
@@ -1772,7 +1767,7 @@ function canonicalizeTimeZoneID(tzID) { |
* Useful for subclassing. |
*/ |
function initializeBreakIterator(iterator, locales, options) { |
- if (iterator.hasOwnProperty('__initializedIntlObject')) { |
+ if (%IsInitializedIntlObject(iterator)) { |
throw new $TypeError('Trying to re-initialize v8BreakIterator object.'); |
} |
@@ -1798,10 +1793,9 @@ function initializeBreakIterator(iterator, locales, options) { |
internalOptions, |
resolved); |
- $Object.defineProperty(iterator, 'iterator', {value: internalIterator}); |
+ %MarkAsInitializedIntlObjectOfType(iterator, 'breakiterator', |
+ internalIterator); |
$Object.defineProperty(iterator, 'resolved', {value: resolved}); |
- $Object.defineProperty(iterator, '__initializedIntlObject', |
- {value: 'breakiterator'}); |
return iterator; |
} |
@@ -1836,8 +1830,7 @@ function initializeBreakIterator(iterator, locales, options) { |
throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR); |
} |
- if (!this || typeof this !== 'object' || |
- this.__initializedIntlObject !== 'breakiterator') { |
+ if (!%IsInitializedIntlObjectOfType(this, 'breakiterator')) { |
throw new $TypeError('resolvedOptions method called on a non-object or ' + |
'on a object that is not Intl.v8BreakIterator.'); |
} |
@@ -1884,7 +1877,8 @@ function initializeBreakIterator(iterator, locales, options) { |
* gets discarded. |
*/ |
function adoptText(iterator, text) { |
- %BreakIteratorAdoptText(iterator.iterator, $String(text)); |
+ %BreakIteratorAdoptText(%GetImplFromInitializedIntlObject(iterator), |
+ $String(text)); |
} |
@@ -1892,7 +1886,7 @@ function adoptText(iterator, text) { |
* Returns index of the first break in the string and moves current pointer. |
*/ |
function first(iterator) { |
- return %BreakIteratorFirst(iterator.iterator); |
+ return %BreakIteratorFirst(%GetImplFromInitializedIntlObject(iterator)); |
} |
@@ -1900,7 +1894,7 @@ function first(iterator) { |
* Returns the index of the next break and moves the pointer. |
*/ |
function next(iterator) { |
- return %BreakIteratorNext(iterator.iterator); |
+ return %BreakIteratorNext(%GetImplFromInitializedIntlObject(iterator)); |
} |
@@ -1908,7 +1902,7 @@ function next(iterator) { |
* Returns index of the current break. |
*/ |
function current(iterator) { |
- return %BreakIteratorCurrent(iterator.iterator); |
+ return %BreakIteratorCurrent(%GetImplFromInitializedIntlObject(iterator)); |
} |
@@ -1916,7 +1910,7 @@ function current(iterator) { |
* Returns type of the current break. |
*/ |
function breakType(iterator) { |
- return %BreakIteratorBreakType(iterator.iterator); |
+ return %BreakIteratorBreakType(%GetImplFromInitializedIntlObject(iterator)); |
} |