Ignore:
Timestamp:
Sep 4, 2020, 9:53:16 PM (5 years ago)
Author:
[email protected]
Message:

[JSC] Align legacy Intl constructor behavior to spec
https://bugs.webkit.org/show_bug.cgi?id=216193

Reviewed by Darin Adler.

JSTests:

  • stress/intl-datetimeformat.js:
  • stress/intl-legacy-constructors.js: Added.

(shouldBe):
(shouldThrow):
(testLegacyConstructor):

  • stress/intl-numberformat.js:

Source/JavaScriptCore:

Legacy Intl constructors (Intl.DateTimeFormat and Intl.NumberFormat) have special handling when it is called via Intl.DateTimeFormat() form.
This allowed legacy Intl constructors to be used with prototype-based inheritance without using class syntax. This legacy behavior is later specified
explicitly in the spec. So we should align our implementation to the spec's one.

  1. When defining fallback formats, we need to put them into the property which is visible via Symbol("IntlLegacyConstructedSymbol").
  2. Even if the provided thisValue is IntlDateTimeFormat* / IntlNumberFormat*, we should create another instance and put it to Symbol("IntlLegacyConstructedSymbol") field.

(JSC::BuiltinNames::BuiltinNames):

  • builtins/BuiltinNames.h:

(JSC::BuiltinNames::intlLegacyConstructedSymbol const):

  • runtime/CommonIdentifiers.h:
  • runtime/IntlDateTimeFormat.h:
  • runtime/IntlDateTimeFormatConstructor.cpp:

(JSC::IntlDateTimeFormatConstructor::finishCreation):
(JSC::callIntlDateTimeFormat):

  • runtime/IntlDateTimeFormatInlines.h: Added.

(JSC::IntlDateTimeFormat::unwrapForOldFunctions):

  • runtime/IntlDateTimeFormatPrototype.cpp:

(JSC::IntlDateTimeFormatPrototypeGetterFormat):
(JSC::IntlDateTimeFormatPrototypeFuncFormatToParts):
(JSC::IntlDateTimeFormatPrototypeFuncFormatRange):
(JSC::IntlDateTimeFormatPrototypeFuncResolvedOptions):

  • runtime/IntlNumberFormat.h:
  • runtime/IntlNumberFormatConstructor.cpp:

(JSC::IntlNumberFormatConstructor::finishCreation):
(JSC::callIntlNumberFormat):

  • runtime/IntlNumberFormatInlines.h:

(JSC::IntlNumberFormat::unwrapForOldFunctions):

  • runtime/IntlNumberFormatPrototype.cpp:

(JSC::IntlNumberFormatPrototypeGetterFormat):
(JSC::IntlNumberFormatPrototypeFuncFormatToParts):
(JSC::IntlNumberFormatPrototypeFuncResolvedOptions):

  • runtime/IntlObject.cpp:

(JSC::createDateTimeFormatConstructor):
(JSC::createNumberFormatConstructor):

  • runtime/IntlObjectInlines.h:

(JSC::constructIntlInstanceWithWorkaroundForLegacyIntlConstructor):
(JSC::unwrapForLegacyIntlConstructor):

  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::init):
(JSC::JSGlobalObject::visitChildren):

  • runtime/JSGlobalObject.h:

(JSC::JSGlobalObject::dateTimeFormatConstructor):
(JSC::JSGlobalObject::dateTimeFormatPrototype):
(JSC::JSGlobalObject::numberFormatConstructor):
(JSC::JSGlobalObject::numberFormatPrototype):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/builtins/BuiltinNames.cpp

    r257681 r266655  
    4242#undef INITIALIZE_BUILTIN_STATIC_SYMBOLS
    4343
     44SymbolImpl::StaticSymbolImpl intlLegacyConstructedSymbol { "IntlLegacyConstructedSymbol" };
     45
    4446#define INITIALIZE_BUILTIN_PRIVATE_NAMES(name) SymbolImpl::StaticSymbolImpl name##PrivateName { #name, SymbolImpl::s_flagIsPrivate };
    4547JSC_FOREACH_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_PRIVATE_NAMES)
     
    7779    JSC_COMMON_PRIVATE_IDENTIFIERS_EACH_PROPERTY_NAME(INITIALIZE_BUILTIN_NAMES_IN_JSC)
    7880    JSC_COMMON_PRIVATE_IDENTIFIERS_EACH_WELL_KNOWN_SYMBOL(INITIALIZE_BUILTIN_SYMBOLS_IN_JSC)
     81    , m_intlLegacyConstructedSymbol(JSC::Identifier::fromUid(vm, &static_cast<SymbolImpl&>(Symbols::intlLegacyConstructedSymbol)))
    7982    , m_dollarVMName(Identifier::fromString(vm, "$vm"))
    8083    , m_dollarVMPrivateName(Identifier::fromUid(vm, &static_cast<SymbolImpl&>(Symbols::dollarVMPrivateName)))
Note: See TracChangeset for help on using the changeset viewer.