Changeset 273153 in webkit


Ignore:
Timestamp:
Feb 19, 2021 11:38:57 AM (3 years ago)
Author:
ysuzuki@apple.com
Message:

[JSC] Do not use toObject for options in new Intl constructors
https://bugs.webkit.org/show_bug.cgi?id=222164

Reviewed by Alexey Shvayka.

JSTests:

  • stress/intl-get-options-not-using-toobject.js: Added.

(shouldThrow):

Source/JavaScriptCore:

New spec change[1] introduced stricter GetOptionsObject for relatively new Intl constructors: Intl.DisplayNames, Intl.ListFormat, and Intl.Segmenter[2].
This does not perform ToObject, and instead,

  1. If the input is an undefined, then it returns empty object.
  2. If the input is an object, then it returns this object.
  3. Otherwise, throwing a TypeError.

This patch implements it.

[1]: https://github.com/tc39/ecma402/pull/538
[2]: https://github.com/tc39/proposal-intl-segmenter/issues/132

  • runtime/IntlDisplayNames.cpp:

(JSC::IntlDisplayNames::initializeDisplayNames):

  • runtime/IntlListFormat.cpp:

(JSC::IntlListFormat::initializeListFormat):

  • runtime/IntlObjectInlines.h:

(JSC::intlGetOptionsObject):

  • runtime/IntlSegmenter.cpp:

(JSC::IntlSegmenter::initializeSegmenter):

Location:
trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r273140 r273153  
     12021-02-19  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Do not use toObject for options in new Intl constructors
     4        https://bugs.webkit.org/show_bug.cgi?id=222164
     5
     6        Reviewed by Alexey Shvayka.
     7
     8        * stress/intl-get-options-not-using-toobject.js: Added.
     9        (shouldThrow):
     10
    1112021-02-19  Caio Lima  <ticaiolima@gmail.com>
    212
  • trunk/JSTests/stress/intl-displaynames.js

    r266029 r273153  
    2222if ($vm.icuVersion() >= 61) {
    2323    shouldBe(Intl.DisplayNames.length, 2);
    24     shouldThrow(() => new Intl.DisplayNames, `TypeError: undefined is not an object (evaluating 'new Intl.DisplayNames')`);
     24    shouldThrow(() => new Intl.DisplayNames, `TypeError: type must not be undefined`);
    2525
    2626    // Get display names of region in English
  • trunk/Source/JavaScriptCore/ChangeLog

    r273152 r273153  
     12021-02-19  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Do not use toObject for options in new Intl constructors
     4        https://bugs.webkit.org/show_bug.cgi?id=222164
     5
     6        Reviewed by Alexey Shvayka.
     7
     8        New spec change[1] introduced stricter GetOptionsObject for relatively new Intl constructors: Intl.DisplayNames, Intl.ListFormat, and Intl.Segmenter[2].
     9        This does not perform `ToObject`, and instead,
     10
     11            1. If the input is an undefined, then it returns empty object.
     12            2. If the input is an object, then it returns this object.
     13            3. Otherwise, throwing a TypeError.
     14
     15        This patch implements it.
     16
     17        [1]: https://github.com/tc39/ecma402/pull/538
     18        [2]: https://github.com/tc39/proposal-intl-segmenter/issues/132
     19
     20        * runtime/IntlDisplayNames.cpp:
     21        (JSC::IntlDisplayNames::initializeDisplayNames):
     22        * runtime/IntlListFormat.cpp:
     23        (JSC::IntlListFormat::initializeListFormat):
     24        * runtime/IntlObjectInlines.h:
     25        (JSC::intlGetOptionsObject):
     26        * runtime/IntlSegmenter.cpp:
     27        (JSC::IntlSegmenter::initializeSegmenter):
     28
    1292021-02-19  Mark Lam  <mark.lam@apple.com>
    230
  • trunk/Source/JavaScriptCore/runtime/IntlDisplayNames.cpp

    r268956 r273153  
    7070    RETURN_IF_EXCEPTION(scope, void());
    7171
    72     JSObject* options = optionsValue.toObject(globalObject);
     72    JSObject* options = intlGetOptionsObject(globalObject, optionsValue);
    7373    RETURN_IF_EXCEPTION(scope, void());
    7474
  • trunk/Source/JavaScriptCore/runtime/IntlListFormat.cpp

    r268956 r273153  
    9292    RETURN_IF_EXCEPTION(scope, void());
    9393
    94     JSObject* options;
    95     if (optionsValue.isUndefined())
    96         options = constructEmptyObject(vm, globalObject->nullPrototypeObjectStructure());
    97     else {
    98         options = optionsValue.toObject(globalObject);
    99         RETURN_IF_EXCEPTION(scope, void());
    100     }
     94    JSObject* options = intlGetOptionsObject(globalObject, optionsValue);
     95    RETURN_IF_EXCEPTION(scope, void());
    10196
    10297    ResolveLocaleOptions localeOptions;
  • trunk/Source/JavaScriptCore/runtime/IntlObjectInlines.h

    r266973 r273153  
    3131#include "JSBoundFunction.h"
    3232#include "JSObject.h"
     33#include "ObjectConstructor.h"
    3334#include <unicode/ucol.h>
    3435
     
    181182}
    182183
     184// https://tc39.es/ecma402/#sec-getoptionsobject
     185inline JSObject* intlGetOptionsObject(JSGlobalObject* globalObject, JSValue options)
     186{
     187    VM& vm = globalObject->vm();
     188    auto scope = DECLARE_THROW_SCOPE(vm);
     189    if (options.isUndefined())
     190        return constructEmptyObject(vm, globalObject->nullPrototypeObjectStructure());
     191    if (LIKELY(options.isObject()))
     192        return asObject(options);
     193    throwTypeError(globalObject, scope, "options argument is not an object or undefined"_s);
     194    return nullptr;
     195}
     196
    183197} // namespace JSC
  • trunk/Source/JavaScriptCore/runtime/IntlSegmenter.cpp

    r266032 r273153  
    6868    RETURN_IF_EXCEPTION(scope, void());
    6969
    70     JSObject* options;
    71     if (optionsValue.isUndefined())
    72         options = constructEmptyObject(vm, globalObject->nullPrototypeObjectStructure());
    73     else {
    74         options = optionsValue.toObject(globalObject);
    75         RETURN_IF_EXCEPTION(scope, void());
    76     }
     70    JSObject* options = intlGetOptionsObject(globalObject, optionsValue);
     71    RETURN_IF_EXCEPTION(scope, void());
    7772
    7873    ResolveLocaleOptions localeOptions;
Note: See TracChangeset for help on using the changeset viewer.