GeezerVison is showing github.com — deps: cherry-pick 6989b3f6d7 from V8 upstream · nodejs/node@35d6661
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: common.gypi +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 27 | 27 |
| 28 | 28 | # Reset this number to 0 on major V8 upgrades. | 29 | 29 | # Increment by one for each non-official patch applied to deps/v8. | 30 | | - 'v8_embedder_string': '-node.6', | | 30 | + 'v8_embedder_string': '-node.7', | 31 | 31 |
| 32 | 32 | # Enable disassembler for `--print-code` v8 options | 33 | 33 | 'v8_enable_disassembler': 1, | |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/src/js/intl.js +59-30Lines changed: 59 additions & 30 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -152,18 +152,11 @@ var AVAILABLE_LOCALES = { | 152 | 152 | */ | 153 | 153 | var DEFAULT_ICU_LOCALE = UNDEFINED; | 154 | 154 |
| 155 | | -function GetDefaultICULocaleJS(service) { | | 155 | +function GetDefaultICULocaleJS() { | 156 | 156 | if (IS_UNDEFINED(DEFAULT_ICU_LOCALE)) { | 157 | 157 | DEFAULT_ICU_LOCALE = %GetDefaultICULocale(); | 158 | 158 | } | 159 | | - // Check that this is a valid default for this service, | 160 | | - // otherwise fall back to "und" | 161 | | - // TODO(littledan,jshin): AvailableLocalesOf sometimes excludes locales | 162 | | - // which don't require tailoring, but work fine with root data. Look into | 163 | | - // exposing this fact in ICU or the way Chrome bundles data. | 164 | | - return (IS_UNDEFINED(service) || | 165 | | - HAS_OWN_PROPERTY(getAvailableLocalesOf(service), DEFAULT_ICU_LOCALE)) | 166 | | - ? DEFAULT_ICU_LOCALE : "und"; | | 159 | + return DEFAULT_ICU_LOCALE; | 167 | 160 | } | 168 | 161 |
| 169 | 162 | /** | @@ -434,6 +427,48 @@ function resolveLocale(service, requestedLocales, options) { | 434 | 427 | } | 435 | 428 |
| 436 | 429 |
| | 430 | +/** | | 431 | + * Look up the longest non-empty prefix of |locale| that is an element of | | 432 | + * |availableLocales|. Returns undefined when the |locale| is completely | | 433 | + * unsupported by |availableLocales|. | | 434 | + */ | | 435 | +function bestAvailableLocale(availableLocales, locale) { | | 436 | + do { | | 437 | + if (!IS_UNDEFINED(availableLocales[locale])) { | | 438 | + return locale; | | 439 | + } | | 440 | + // Truncate locale if possible. | | 441 | + var pos = %StringLastIndexOf(locale, '-'); | | 442 | + if (pos === -1) { | | 443 | + break; | | 444 | + } | | 445 | + locale = %_Call(StringSubstring, locale, 0, pos); | | 446 | + } while (true); | | 447 | + | | 448 | + return UNDEFINED; | | 449 | +} | | 450 | + | | 451 | + | | 452 | +/** | | 453 | + * Try to match any mutation of |requestedLocale| against |availableLocales|. | | 454 | + */ | | 455 | +function attemptSingleLookup(availableLocales, requestedLocale) { | | 456 | + // Remove all extensions. | | 457 | + var noExtensionsLocale = %RegExpInternalReplace( | | 458 | + GetAnyExtensionRE(), requestedLocale, ''); | | 459 | + var availableLocale = bestAvailableLocale( | | 460 | + availableLocales, requestedLocale); | | 461 | + if (!IS_UNDEFINED(availableLocale)) { | | 462 | + // Return the resolved locale and extension. | | 463 | + var extensionMatch = %regexp_internal_match( | | 464 | + GetUnicodeExtensionRE(), requestedLocale); | | 465 | + var extension = IS_NULL(extensionMatch) ? '' : extensionMatch[0]; | | 466 | + return {locale: availableLocale, extension: extension}; | | 467 | + } | | 468 | + return UNDEFINED; | | 469 | +} | | 470 | + | | 471 | + | 437 | 472 | /** | 438 | 473 | * Returns best matched supported locale and extension info using basic | 439 | 474 | * lookup algorithm. | @@ -446,31 +481,25 @@ function lookupMatcher(service, requestedLocales) { | 446 | 481 | var availableLocales = getAvailableLocalesOf(service); | 447 | 482 |
| 448 | 483 | for (var i = 0; i < requestedLocales.length; ++i) { | 449 | | - // Remove all extensions. | 450 | | - var locale = %RegExpInternalReplace( | 451 | | - GetAnyExtensionRE(), requestedLocales[i], ''); | 452 | | - do { | 453 | | - if (!IS_UNDEFINED(availableLocales[locale])) { | 454 | | - // Return the resolved locale and extension. | 455 | | - var extensionMatch = %regexp_internal_match( | 456 | | - GetUnicodeExtensionRE(), requestedLocales[i]); | 457 | | - var extension = IS_NULL(extensionMatch) ? '' : extensionMatch[0]; | 458 | | - return {locale: locale, extension: extension, position: i}; | 459 | | - } | 460 | | - // Truncate locale if possible. | 461 | | - var pos = %StringLastIndexOf(locale, '-'); | 462 | | - if (pos === -1) { | 463 | | - break; | 464 | | - } | 465 | | - locale = %_Call(StringSubstring, locale, 0, pos); | 466 | | - } while (true); | | 484 | + var result = attemptSingleLookup(availableLocales, requestedLocales[i]); | | 485 | + if (!IS_UNDEFINED(result)) { | | 486 | + return result; | | 487 | + } | | 488 | + } | | 489 | + | | 490 | + var defLocale = GetDefaultICULocaleJS(); | | 491 | + | | 492 | + // While ECMA-402 returns defLocale directly, we have to check if it is | | 493 | + // supported, as such support is not guaranteed. | | 494 | + var result = attemptSingleLookup(availableLocales, defLocale); | | 495 | + if (!IS_UNDEFINED(result)) { | | 496 | + return result; | 467 | 497 | } | 468 | 498 |
| 469 | 499 | // Didn't find a match, return default. | 470 | 500 | return { | 471 | | - locale: GetDefaultICULocaleJS(service), | 472 | | - extension: '', | 473 | | - position: -1 | | 501 | + locale: 'und', | | 502 | + extension: '' | 474 | 503 | }; | 475 | 504 | } | 476 | 505 |
| |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/test/intl/assert.js +41Lines changed: 41 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -132,6 +132,16 @@ function assertFalse(value, user_message = '') { | 132 | 132 | } | 133 | 133 |
| 134 | 134 |
| | 135 | +/** | | 136 | + * Throws if value is null. | | 137 | + */ | | 138 | +function assertNotNull(value, user_message = '') { | | 139 | + if (value === null) { | | 140 | + fail("not null", value, user_message); | | 141 | + } | | 142 | +} | | 143 | + | | 144 | + | 135 | 145 | /** | 136 | 146 | * Runs code() and asserts that it throws the specified exception. | 137 | 147 | */ | @@ -189,3 +199,34 @@ function assertInstanceof(obj, type) { | 189 | 199 | (actualTypeName ? ' but of < ' + actualTypeName + '>' : '')); | 190 | 200 | } | 191 | 201 | } | | 202 | + | | 203 | + | | 204 | +/** | | 205 | + * Split a BCP 47 language tag into locale and extension. | | 206 | + */ | | 207 | +function splitLanguageTag(tag) { | | 208 | + var extRe = /(-[0-9A-Za-z](-[0-9A-Za-z]{2,8})+)+$/; | | 209 | + var match = %regexp_internal_match(extRe, tag); | | 210 | + if (match) { | | 211 | + return { locale: tag.slice(0, match.index), extension: match[0] }; | | 212 | + } | | 213 | + | | 214 | + return { locale: tag, extension: '' }; | | 215 | +} | | 216 | + | | 217 | + | | 218 | +/** | | 219 | + * Throw if |parent| is not a more general language tag of |child|, nor |child| | | 220 | + * itself, per BCP 47 rules. | | 221 | + */ | | 222 | +function assertLanguageTag(child, parent) { | | 223 | + var childSplit = splitLanguageTag(child); | | 224 | + var parentSplit = splitLanguageTag(parent); | | 225 | + | | 226 | + // Do not compare extensions at this moment, as %GetDefaultICULocale() | | 227 | + // doesn't always output something we support. | | 228 | + if (childSplit.locale !== parentSplit.locale && | | 229 | + !childSplit.locale.startsWith(parentSplit.locale + '-')) { | | 230 | + fail(child, parent, 'language tag comparison'); | | 231 | + } | | 232 | +} |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/test/intl/break-iterator/default-locale.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -37,8 +37,8 @@ assertFalse(options.locale === 'und'); | 37 | 37 | assertFalse(options.locale === ''); | 38 | 38 | assertFalse(options.locale === undefined); | 39 | 39 |
| 40 | | -// Then check for equality. | 41 | | -assertEquals(options.locale, %GetDefaultICULocale()); | | 40 | +// Then check for legitimacy. | | 41 | +assertLanguageTag(%GetDefaultICULocale(), options.locale); | 42 | 42 |
| 43 | 43 | var iteratorNone = new Intl.v8BreakIterator(); | 44 | 44 | assertEquals(options.locale, iteratorNone.resolvedOptions().locale); | |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/test/intl/break-iterator/wellformed-unsupported-locale.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 29 | 29 |
| 30 | 30 | var iterator = Intl.v8BreakIterator(['xx']); | 31 | 31 |
| 32 | | -assertEquals(iterator.resolvedOptions().locale, %GetDefaultICULocale()); | | 32 | +assertLanguageTag(%GetDefaultICULocale(), iterator.resolvedOptions().locale); |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/test/intl/collator/default-locale.js +7-4Lines changed: 7 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -37,8 +37,8 @@ assertFalse(options.locale === 'und'); | 37 | 37 | assertFalse(options.locale === ''); | 38 | 38 | assertFalse(options.locale === undefined); | 39 | 39 |
| 40 | | -// Then check for equality. | 41 | | -assertEquals(options.locale, %GetDefaultICULocale()); | | 40 | +// Then check for legitimacy. | | 41 | +assertLanguageTag(%GetDefaultICULocale(), options.locale); | 42 | 42 |
| 43 | 43 | var collatorNone = new Intl.Collator(); | 44 | 44 | assertEquals(options.locale, collatorNone.resolvedOptions().locale); | @@ -48,5 +48,8 @@ var collatorBraket = new Intl.Collator({}); | 48 | 48 | assertEquals(options.locale, collatorBraket.resolvedOptions().locale); | 49 | 49 |
| 50 | 50 | var collatorWithOptions = new Intl.Collator(undefined, {usage: 'search'}); | 51 | | -assertEquals(%GetDefaultICULocale() + '-u-co-search', | 52 | | - collatorWithOptions.resolvedOptions().locale); | | 51 | +assertLanguageTag(%GetDefaultICULocale(), | | 52 | + collatorWithOptions.resolvedOptions().locale); | | 53 | +assertNotNull( | | 54 | + %regexp_internal_match(/-u(-[a-zA-Z]+-[a-zA-Z]+)*-co-search/, | | 55 | + collatorWithOptions.resolvedOptions().locale)); |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/test/intl/collator/wellformed-unsupported-locale.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 29 | 29 |
| 30 | 30 | var collator = Intl.Collator(['xx']); | 31 | 31 |
| 32 | | -assertEquals(collator.resolvedOptions().locale, %GetDefaultICULocale()); | | 32 | +assertLanguageTag(%GetDefaultICULocale(), collator.resolvedOptions().locale); |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/test/intl/date-format/default-locale.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -37,8 +37,8 @@ assertFalse(options.locale === 'und'); | 37 | 37 | assertFalse(options.locale === ''); | 38 | 38 | assertFalse(options.locale === undefined); | 39 | 39 |
| 40 | | -// Then check for equality. | 41 | | -assertEquals(options.locale, %GetDefaultICULocale()); | | 40 | +// Then check for legitimacy. | | 41 | +assertLanguageTag(%GetDefaultICULocale(), options.locale); | 42 | 42 |
| 43 | 43 | var dtfNone = new Intl.DateTimeFormat(); | 44 | 44 | assertEquals(options.locale, dtfNone.resolvedOptions().locale); |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/test/intl/date-format/wellformed-unsupported-locale.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 29 | 29 |
| 30 | 30 | var dtf = Intl.DateTimeFormat(['xx']); | 31 | 31 |
| 32 | | -assertEquals(dtf.resolvedOptions().locale, %GetDefaultICULocale()); | | 32 | +assertLanguageTag(%GetDefaultICULocale(), dtf.resolvedOptions().locale); |
Collapse file Copy file name to clipboardExpand all lines: deps/v8/test/intl/number-format/default-locale.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -37,8 +37,8 @@ assertFalse(options.locale === 'und'); | 37 | 37 | assertFalse(options.locale === ''); | 38 | 38 | assertFalse(options.locale === undefined); | 39 | 39 |
| 40 | | -// Then check for equality. | 41 | | -assertEquals(options.locale, %GetDefaultICULocale()); | | 40 | +// Then check for legitimacy. | | 41 | +assertLanguageTag(%GetDefaultICULocale(), options.locale); | 42 | 42 |
| 43 | 43 | var nfNone = new Intl.NumberFormat(); | 44 | 44 | assertEquals(options.locale, nfNone.resolvedOptions().locale); |
|