diff options
Diffstat (limited to 'deps/v8/src/js/i18n.js')
-rw-r--r-- | deps/v8/src/js/i18n.js | 79 |
1 files changed, 29 insertions, 50 deletions
diff --git a/deps/v8/src/js/i18n.js b/deps/v8/src/js/i18n.js index 6046a6f2f9..a397849395 100644 --- a/deps/v8/src/js/i18n.js +++ b/deps/v8/src/js/i18n.js @@ -19,7 +19,6 @@ var ArrayJoin; var ArrayPush; -var FLAG_intl_extra; var GlobalDate = global.Date; var GlobalNumber = global.Number; var GlobalRegExp = global.RegExp; @@ -29,31 +28,21 @@ var InstallGetter = utils.InstallGetter; var InternalArray = utils.InternalArray; var InternalRegExpMatch; var InternalRegExpReplace -var IsNaN; var ObjectHasOwnProperty = utils.ImportNow("ObjectHasOwnProperty"); var OverrideFunction = utils.OverrideFunction; var patternSymbol = utils.ImportNow("intl_pattern_symbol"); var resolvedSymbol = utils.ImportNow("intl_resolved_symbol"); var SetFunctionName = utils.SetFunctionName; var StringIndexOf; -var StringLastIndexOf; -var StringSubstr; -var StringSubstring; +var StringSubstr = GlobalString.prototype.substr; +var StringSubstring = GlobalString.prototype.substring; utils.Import(function(from) { ArrayJoin = from.ArrayJoin; ArrayPush = from.ArrayPush; - IsNaN = from.IsNaN; InternalRegExpMatch = from.InternalRegExpMatch; InternalRegExpReplace = from.InternalRegExpReplace; StringIndexOf = from.StringIndexOf; - StringLastIndexOf = from.StringLastIndexOf; - StringSubstr = from.StringSubstr; - StringSubstring = from.StringSubstring; -}); - -utils.ImportFromExperimental(function(from) { - FLAG_intl_extra = from.FLAG_intl_extra; }); // Utilities for definitions @@ -318,7 +307,7 @@ function lookupSupportedLocalesOf(requestedLocales, availableLocales) { break; } // Truncate locale if possible, if not break. - var pos = %_Call(StringLastIndexOf, locale, '-'); + var pos = %StringLastIndexOf(locale, '-'); if (pos === -1) { break; } @@ -441,7 +430,7 @@ function lookupMatcher(service, requestedLocales) { return {'locale': locale, 'extension': extension, 'position': i}; } // Truncate locale if possible. - var pos = %_Call(StringLastIndexOf, locale, '-'); + var pos = %StringLastIndexOf(locale, '-'); if (pos === -1) { break; } @@ -1038,9 +1027,6 @@ function initializeCollator(collator, locales, options) { // Writable, configurable and enumerable are set to false by default. %MarkAsInitializedIntlObjectOfType(collator, 'collator', internalCollator); collator[resolvedSymbol] = resolved; - if (FLAG_intl_extra) { - %object_define_property(collator, 'resolved', resolvedAccessor); - } return collator; } @@ -1282,10 +1268,6 @@ function initializeNumberFormat(numberFormat, locales, options) { %MarkAsInitializedIntlObjectOfType(numberFormat, 'numberformat', formatter); numberFormat[resolvedSymbol] = resolved; - if (FLAG_intl_extra) { - %object_define_property(resolved, 'pattern', patternAccessor); - %object_define_property(numberFormat, 'resolved', resolvedAccessor); - } return numberFormat; } @@ -1388,14 +1370,6 @@ function formatNumber(formatter, value) { } -/** - * Returns a Number that represents string value that was passed in. - */ -function IntlParseNumber(formatter, value) { - return %InternalNumberParse(%GetImplFromInitializedIntlObject(formatter), - TO_STRING(value)); -} - AddBoundMethod(Intl.NumberFormat, 'format', formatNumber, 1, 'numberformat'); /** @@ -1676,10 +1650,6 @@ function initializeDateTimeFormat(dateFormat, locales, options) { %MarkAsInitializedIntlObjectOfType(dateFormat, 'dateformat', formatter); dateFormat[resolvedSymbol] = resolved; - if (FLAG_intl_extra) { - %object_define_property(resolved, 'pattern', patternAccessor); - %object_define_property(dateFormat, 'resolved', resolvedAccessor); - } return dateFormat; } @@ -1797,18 +1767,29 @@ function formatDate(formatter, dateValue) { 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); + } + var dateMs; + if (IS_UNDEFINED(dateValue)) { + dateMs = %DateCurrentTime(); + } else { + dateMs = TO_NUMBER(dateValue); + } + + if (!NUMBER_IS_FINITE(dateMs)) throw %make_range_error(kDateRange); -/** - * Returns a Date object representing the result of calling ToString(value) - * according to the effective locale and the formatting options of this - * DateTimeFormat. - * Returns undefined if date string cannot be parsed. - */ -function IntlParseDate(formatter, value) { - return %InternalDateParse(%GetImplFromInitializedIntlObject(formatter), - TO_STRING(value)); + return %InternalDateFormatToParts( + %GetImplFromInitializedIntlObject(this), new GlobalDate(dateMs)); } +%FunctionSetLength(FormatDateToParts, 0); + // 0 because date is optional argument. AddBoundMethod(Intl.DateTimeFormat, 'format', formatDate, 0, 'dateformat'); @@ -1889,9 +1870,6 @@ function initializeBreakIterator(iterator, locales, options) { %MarkAsInitializedIntlObjectOfType(iterator, 'breakiterator', internalIterator); iterator[resolvedSymbol] = resolved; - if (FLAG_intl_extra) { - %object_define_property(iterator, 'resolved', resolvedAccessor); - } return iterator; } @@ -2227,7 +2205,8 @@ function toLocaleDateTime(date, locales, options, required, defaults, service) { throw %make_type_error(kMethodInvokedOnWrongType, "Date"); } - if (IsNaN(date)) return 'Invalid Date'; + var dateValue = TO_NUMBER(date); + if (NUMBER_IS_NAN(dateValue)) return 'Invalid Date'; var internalOptions = toDateTimeOptions(options, required, defaults); @@ -2291,10 +2270,10 @@ OverrideFunction(GlobalDate.prototype, 'toLocaleTimeString', function() { } ); +%FunctionRemovePrototype(FormatDateToParts); + utils.Export(function(to) { - to.AddBoundMethod = AddBoundMethod; - to.IntlParseDate = IntlParseDate; - to.IntlParseNumber = IntlParseNumber; + to.FormatDateToParts = FormatDateToParts; }); }) |