Changeset 190591 in webkit


Ignore:
Timestamp:
Oct 5, 2015, 4:36:56 PM (10 years ago)
Author:
Sukolsak Sakshuwong
Message:

[Intl] Change the return type of canonicalizeLocaleList() from JSArray* to Vector<String>
https://bugs.webkit.org/show_bug.cgi?id=149807

Reviewed by Benjamin Poulain.

From ECMA-402, 9.2.1, the abstract operation CanonicalizeLocaleList
returns a List of Strings. From the spec, we never modify the result
from CanonicalizeLocaleList(). We never expose it to the user either.
This patch changes the return type of canonicalizeLocaleList() from
JSArray* to Vector<String>. This should ease the workload of the GC and
make the code a bit easier to read.

  • runtime/IntlCollatorConstructor.cpp:

(JSC::IntlCollatorConstructorFuncSupportedLocalesOf):

  • runtime/IntlDateTimeFormatConstructor.cpp:

(JSC::IntlDateTimeFormatConstructorFuncSupportedLocalesOf):

  • runtime/IntlNumberFormatConstructor.cpp:

(JSC::IntlNumberFormatConstructorFuncSupportedLocalesOf):

  • runtime/IntlObject.cpp:

(JSC::canonicalizeLocaleList):
(JSC::lookupSupportedLocales):
(JSC::bestFitSupportedLocales):
(JSC::supportedLocales):

  • runtime/IntlObject.h:
Location:
trunk/Source/JavaScriptCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r190589 r190591  
     12015-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
    1282015-10-01  Geoffrey Garen  <ggaren@apple.com>
    229
  • trunk/Source/JavaScriptCore/runtime/IntlCollatorConstructor.cpp

    r189811 r190591  
    2323 * THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
    25 
    2625
    2726#include "config.h"
     
    151150
    152151    // 1. Let requestedLocales be CanonicalizeLocaleList(locales).
    153     JSArray* requestedLocales = canonicalizeLocaleList(exec, exec->argument(0));
     152    Vector<String> requestedLocales = canonicalizeLocaleList(exec, exec->argument(0));
    154153
    155154    // 2. ReturnIfAbrupt(requestedLocales).
  • trunk/Source/JavaScriptCore/runtime/IntlDateTimeFormatConstructor.cpp

    r189811 r190591  
    155155
    156156    // 2. Let requestedLocales be CanonicalizeLocaleList(locales).
    157     JSArray* requestedLocales = canonicalizeLocaleList(exec, exec->argument(0));
     157    Vector<String> requestedLocales = canonicalizeLocaleList(exec, exec->argument(0));
    158158    if (exec->hadException())
    159159        return JSValue::encode(jsUndefined());
  • trunk/Source/JavaScriptCore/runtime/IntlNumberFormatConstructor.cpp

    r189811 r190591  
    155155
    156156    // 2. Let requestedLocales be CanonicalizeLocaleList(locales).
    157     JSArray* requestedLocales = canonicalizeLocaleList(exec, exec->argument(0));
     157    Vector<String> requestedLocales = canonicalizeLocaleList(exec, exec->argument(0));
    158158    if (exec->hadException())
    159159        return JSValue::encode(jsUndefined());
  • trunk/Source/JavaScriptCore/runtime/IntlObject.cpp

    r189811 r190591  
    428428}
    429429
    430 JSArray* canonicalizeLocaleList(ExecState* exec, JSValue locales)
     430Vector<String> canonicalizeLocaleList(ExecState* exec, JSValue locales)
    431431{
    432432    // 9.2.1 CanonicalizeLocaleList (locales)
    433433    VM& vm = exec->vm();
    434434    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;
    440436
    441437    // 1. If locales is undefined, then a. Return a new empty List.
     
    461457    // 5. ReturnIfAbrupt(O).
    462458    if (exec->hadException())
    463         return nullptr;
     459        return Vector<String>();
    464460
    465461    // 6. Let len be ToLength(Get(O, "length")).
    466462    JSValue lengthProperty = localesObject->get(exec, vm.propertyNames->length);
    467463    if (exec->hadException())
    468         return nullptr;
     464        return Vector<String>();
    469465
    470466    double length = lengthProperty.toLength(exec);
    471467    if (exec->hadException())
    472         return nullptr;
     468        return Vector<String>();
    473469
    474470    // Keep track of locales that have been added to the list.
     
    486482        // c. ReturnIfAbrupt(kPresent).
    487483        if (exec->hadException())
    488             return nullptr;
     484            return Vector<String>();
    489485
    490486        // d. If kPresent is true, then
     
    495491            // ii. ReturnIfAbrupt(kValue).
    496492            if (exec->hadException())
    497                 return nullptr;
     493                return Vector<String>();
    498494
    499495            // iii. If Type(kValue) is not String or Object, throw a TypeError exception.
    500496            if (!kValue.isString() && !kValue.isObject()) {
    501497                throwTypeError(exec, ASCIILiteral("locale value must be a string or object"));
    502                 return nullptr;
     498                return Vector<String>();
    503499            }
    504500
     
    508504            // v. ReturnIfAbrupt(tag).
    509505            if (exec->hadException())
    510                 return nullptr;
     506                return Vector<String>();
    511507
    512508            // vi. If IsStructurallyValidLanguageTag(tag) is false, throw a RangeError exception.
     
    515511            if (canonicalizedTag.isNull()) {
    516512                exec->vm().throwException(exec, createRangeError(exec, String::format("invalid language tag: %s", tag->value(exec).utf8().data())));
    517                 return nullptr;
     513                return Vector<String>();
    518514            }
    519515
    520516            // viii. If canonicalizedTag is not an element of seen, append canonicalizedTag as the last element of seen.
    521517            if (seenSet.add(canonicalizedTag).isNewEntry)
    522                 seen->push(exec, jsString(exec, canonicalizedTag));
     518                seen.append(canonicalizedTag);
    523519        }
    524520        // e. Increase k by 1.
     
    556552}
    557553
    558 static JSArray* lookupSupportedLocales(ExecState* exec, const HashSet<String>& availableLocales, JSArray* requestedLocales)
     554static JSArray* lookupSupportedLocales(ExecState* exec, const HashSet<String>& availableLocales, const Vector<String>& requestedLocales)
    559555{
    560556    // 9.2.6 LookupSupportedLocales (availableLocales, requestedLocales)
     
    564560
    565561    // 2. Let len be ToLength(Get(rLocales, "length")).
    566     unsigned len = requestedLocales->length();
     562    size_t len = requestedLocales.size();
    567563
    568564    // 3. Let subset be an empty List.
     
    577573    // 4. Let k be 0.
    578574    // 5. Repeat while k < len
    579     for (unsigned k = 0; k < len; ++k) {
     575    for (size_t k = 0; k < len; ++k) {
    580576        // a. Let Pk be ToString(k).
    581577        // b. Let locale be Get(rLocales, Pk).
    582         JSValue locale = requestedLocales->get(exec, k);
    583 
    584578        // c. ReturnIfAbrupt(locale).
    585         if (exec->hadException())
    586             return nullptr;
     579        String locale = requestedLocales[k];
    587580
    588581        // 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);
    594582        Vector<String> parts;
    595         sLocale.split('-', parts);
     583        locale.split('-', parts);
    596584        StringBuilder builder;
    597585        size_t partsSize = parts.size();
     
    616604        // f. If availableLocale is not undefined, then append locale to the end of subset.
    617605        if (!availableLocale.isNull())
    618             subset->push(exec, locale);
     606            subset->push(exec, jsString(exec, locale));
    619607
    620608        // g. Increment k by 1.
     
    625613}
    626614
    627 static JSArray* bestFitSupportedLocales(ExecState* exec, const HashSet<String>& availableLocales, JSArray* requestedLocales)
     615static JSArray* bestFitSupportedLocales(ExecState* exec, const HashSet<String>& availableLocales, const Vector<String>& requestedLocales)
    628616{
    629617    // 9.2.7 BestFitSupportedLocales (availableLocales, requestedLocales)
     
    632620}
    633621
    634 JSValue supportedLocales(ExecState* exec, const HashSet<String>& availableLocales, JSArray* requestedLocales, JSValue options)
     622JSValue supportedLocales(ExecState* exec, const HashSet<String>& availableLocales, const Vector<String>& requestedLocales, JSValue options)
    635623{
    636624    // 9.2.8 SupportedLocales (availableLocales, requestedLocales, options)
  • trunk/Source/JavaScriptCore/runtime/IntlObject.h

    r189811 r190591  
    5858};
    5959
    60 JSArray* canonicalizeLocaleList(ExecState*, JSValue locales);
    61 JSValue supportedLocales(ExecState*, const HashSet<String>& availableLocales, JSArray* requestedLocales, JSValue options);
     60Vector<String> canonicalizeLocaleList(ExecState*, JSValue locales);
     61JSValue supportedLocales(ExecState*, const HashSet<String>& availableLocales, const Vector<String>& requestedLocales, JSValue options);
    6262
    6363} // namespace JSC
Note: See TracChangeset for help on using the changeset viewer.