Changeset 190591 in webkit
- Timestamp:
- Oct 5, 2015, 4:36:56 PM (10 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r190589 r190591 1 2015-10-05 Sukolsak Sakshuwong <sukolsak@gmail.com> 2 3 [Intl] Change the return type of canonicalizeLocaleList() from JSArray* to Vector<String> 4 https://bugs.webkit.org/show_bug.cgi?id=149807 5 6 Reviewed by Benjamin Poulain. 7 8 From ECMA-402, 9.2.1, the abstract operation CanonicalizeLocaleList 9 returns a List of Strings. From the spec, we never modify the result 10 from CanonicalizeLocaleList(). We never expose it to the user either. 11 This patch changes the return type of canonicalizeLocaleList() from 12 JSArray* to Vector<String>. This should ease the workload of the GC and 13 make the code a bit easier to read. 14 15 * runtime/IntlCollatorConstructor.cpp: 16 (JSC::IntlCollatorConstructorFuncSupportedLocalesOf): 17 * runtime/IntlDateTimeFormatConstructor.cpp: 18 (JSC::IntlDateTimeFormatConstructorFuncSupportedLocalesOf): 19 * runtime/IntlNumberFormatConstructor.cpp: 20 (JSC::IntlNumberFormatConstructorFuncSupportedLocalesOf): 21 * runtime/IntlObject.cpp: 22 (JSC::canonicalizeLocaleList): 23 (JSC::lookupSupportedLocales): 24 (JSC::bestFitSupportedLocales): 25 (JSC::supportedLocales): 26 * runtime/IntlObject.h: 27 1 28 2015-10-01 Geoffrey Garen <ggaren@apple.com> 2 29 -
trunk/Source/JavaScriptCore/runtime/IntlCollatorConstructor.cpp
r189811 r190591 23 23 * THE POSSIBILITY OF SUCH DAMAGE. 24 24 */ 25 26 25 27 26 #include "config.h" … … 151 150 152 151 // 1. Let requestedLocales be CanonicalizeLocaleList(locales). 153 JSArray*requestedLocales = canonicalizeLocaleList(exec, exec->argument(0));152 Vector<String> requestedLocales = canonicalizeLocaleList(exec, exec->argument(0)); 154 153 155 154 // 2. ReturnIfAbrupt(requestedLocales). -
trunk/Source/JavaScriptCore/runtime/IntlDateTimeFormatConstructor.cpp
r189811 r190591 155 155 156 156 // 2. Let requestedLocales be CanonicalizeLocaleList(locales). 157 JSArray*requestedLocales = canonicalizeLocaleList(exec, exec->argument(0));157 Vector<String> requestedLocales = canonicalizeLocaleList(exec, exec->argument(0)); 158 158 if (exec->hadException()) 159 159 return JSValue::encode(jsUndefined()); -
trunk/Source/JavaScriptCore/runtime/IntlNumberFormatConstructor.cpp
r189811 r190591 155 155 156 156 // 2. Let requestedLocales be CanonicalizeLocaleList(locales). 157 JSArray*requestedLocales = canonicalizeLocaleList(exec, exec->argument(0));157 Vector<String> requestedLocales = canonicalizeLocaleList(exec, exec->argument(0)); 158 158 if (exec->hadException()) 159 159 return JSValue::encode(jsUndefined()); -
trunk/Source/JavaScriptCore/runtime/IntlObject.cpp
r189811 r190591 428 428 } 429 429 430 JSArray*canonicalizeLocaleList(ExecState* exec, JSValue locales)430 Vector<String> canonicalizeLocaleList(ExecState* exec, JSValue locales) 431 431 { 432 432 // 9.2.1 CanonicalizeLocaleList (locales) 433 433 VM& vm = exec->vm(); 434 434 JSGlobalObject* globalObject = exec->callee()->globalObject(); 435 JSArray* seen = JSArray::tryCreateUninitialized(vm, globalObject->arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous), 0); 436 if (!seen) { 437 throwOutOfMemoryError(exec); 438 return nullptr; 439 } 435 Vector<String> seen; 440 436 441 437 // 1. If locales is undefined, then a. Return a new empty List. … … 461 457 // 5. ReturnIfAbrupt(O). 462 458 if (exec->hadException()) 463 return nullptr;459 return Vector<String>(); 464 460 465 461 // 6. Let len be ToLength(Get(O, "length")). 466 462 JSValue lengthProperty = localesObject->get(exec, vm.propertyNames->length); 467 463 if (exec->hadException()) 468 return nullptr;464 return Vector<String>(); 469 465 470 466 double length = lengthProperty.toLength(exec); 471 467 if (exec->hadException()) 472 return nullptr;468 return Vector<String>(); 473 469 474 470 // Keep track of locales that have been added to the list. … … 486 482 // c. ReturnIfAbrupt(kPresent). 487 483 if (exec->hadException()) 488 return nullptr;484 return Vector<String>(); 489 485 490 486 // d. If kPresent is true, then … … 495 491 // ii. ReturnIfAbrupt(kValue). 496 492 if (exec->hadException()) 497 return nullptr;493 return Vector<String>(); 498 494 499 495 // iii. If Type(kValue) is not String or Object, throw a TypeError exception. 500 496 if (!kValue.isString() && !kValue.isObject()) { 501 497 throwTypeError(exec, ASCIILiteral("locale value must be a string or object")); 502 return nullptr;498 return Vector<String>(); 503 499 } 504 500 … … 508 504 // v. ReturnIfAbrupt(tag). 509 505 if (exec->hadException()) 510 return nullptr;506 return Vector<String>(); 511 507 512 508 // vi. If IsStructurallyValidLanguageTag(tag) is false, throw a RangeError exception. … … 515 511 if (canonicalizedTag.isNull()) { 516 512 exec->vm().throwException(exec, createRangeError(exec, String::format("invalid language tag: %s", tag->value(exec).utf8().data()))); 517 return nullptr;513 return Vector<String>(); 518 514 } 519 515 520 516 // viii. If canonicalizedTag is not an element of seen, append canonicalizedTag as the last element of seen. 521 517 if (seenSet.add(canonicalizedTag).isNewEntry) 522 seen ->push(exec, jsString(exec, canonicalizedTag));518 seen.append(canonicalizedTag); 523 519 } 524 520 // e. Increase k by 1. … … 556 552 } 557 553 558 static JSArray* lookupSupportedLocales(ExecState* exec, const HashSet<String>& availableLocales, JSArray*requestedLocales)554 static JSArray* lookupSupportedLocales(ExecState* exec, const HashSet<String>& availableLocales, const Vector<String>& requestedLocales) 559 555 { 560 556 // 9.2.6 LookupSupportedLocales (availableLocales, requestedLocales) … … 564 560 565 561 // 2. Let len be ToLength(Get(rLocales, "length")). 566 unsigned len = requestedLocales->length();562 size_t len = requestedLocales.size(); 567 563 568 564 // 3. Let subset be an empty List. … … 577 573 // 4. Let k be 0. 578 574 // 5. Repeat while k < len 579 for ( unsignedk = 0; k < len; ++k) {575 for (size_t k = 0; k < len; ++k) { 580 576 // a. Let Pk be ToString(k). 581 577 // b. Let locale be Get(rLocales, Pk). 582 JSValue locale = requestedLocales->get(exec, k);583 584 578 // c. ReturnIfAbrupt(locale). 585 if (exec->hadException()) 586 return nullptr; 579 String locale = requestedLocales[k]; 587 580 588 581 // d. Let noExtensionsLocale be the String value that is locale with all Unicode locale extension sequences removed. 589 JSString* jsLocale = locale.toString(exec);590 if (exec->hadException())591 return nullptr;592 593 String sLocale = jsLocale->value(exec);594 582 Vector<String> parts; 595 sLocale.split('-', parts);583 locale.split('-', parts); 596 584 StringBuilder builder; 597 585 size_t partsSize = parts.size(); … … 616 604 // f. If availableLocale is not undefined, then append locale to the end of subset. 617 605 if (!availableLocale.isNull()) 618 subset->push(exec, locale);606 subset->push(exec, jsString(exec, locale)); 619 607 620 608 // g. Increment k by 1. … … 625 613 } 626 614 627 static JSArray* bestFitSupportedLocales(ExecState* exec, const HashSet<String>& availableLocales, JSArray*requestedLocales)615 static JSArray* bestFitSupportedLocales(ExecState* exec, const HashSet<String>& availableLocales, const Vector<String>& requestedLocales) 628 616 { 629 617 // 9.2.7 BestFitSupportedLocales (availableLocales, requestedLocales) … … 632 620 } 633 621 634 JSValue supportedLocales(ExecState* exec, const HashSet<String>& availableLocales, JSArray*requestedLocales, JSValue options)622 JSValue supportedLocales(ExecState* exec, const HashSet<String>& availableLocales, const Vector<String>& requestedLocales, JSValue options) 635 623 { 636 624 // 9.2.8 SupportedLocales (availableLocales, requestedLocales, options) -
trunk/Source/JavaScriptCore/runtime/IntlObject.h
r189811 r190591 58 58 }; 59 59 60 JSArray*canonicalizeLocaleList(ExecState*, JSValue locales);61 JSValue supportedLocales(ExecState*, const HashSet<String>& availableLocales, JSArray*requestedLocales, JSValue options);60 Vector<String> canonicalizeLocaleList(ExecState*, JSValue locales); 61 JSValue supportedLocales(ExecState*, const HashSet<String>& availableLocales, const Vector<String>& requestedLocales, JSValue options); 62 62 63 63 } // namespace JSC
Note:
See TracChangeset
for help on using the changeset viewer.