From 4fde20f36b4bf5c83adfbf08ccc01303466b8604 Mon Sep 17 00:00:00 2001 From: wangrx Date: Sun, 4 Feb 2024 11:01:18 +0800 Subject: [PATCH] Fix intl/regress-14307.js --- ecmascript/js_collator.cpp | 46 ++++++++------------------------------ ecmascript/js_collator.h | 3 --- 2 files changed, 9 insertions(+), 40 deletions(-) diff --git a/ecmascript/js_collator.cpp b/ecmascript/js_collator.cpp index dbac28a0c5..ad7a4cd97c 100644 --- a/ecmascript/js_collator.cpp +++ b/ecmascript/js_collator.cpp @@ -294,9 +294,15 @@ JSHandle JSCollator::InitializeCollator(JSThread *thread, // 27. Let ignorePunctuation be ? GetOption(options, "ignorePunctuation", "boolean", undefined, false). // 28. Set collator.[[IgnorePunctuation]] to ignorePunctuation. bool ignorePunctuation = false; - JSHandle collatorOptions = ToCollatorOptions(thread, options, locales); - RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSCollator, thread); - JSLocale::GetOptionOfBool(thread, collatorOptions, globalConst->GetHandledIgnorePunctuationString(), false, + bool defaultIgnorePunctuation = false; + std::string localesString = + locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString(); + transform(localesString.begin(), localesString.end(), localesString.begin(), ::tolower); + // If the ignorePunctuation is not defined, which in "th" locale that is true but false on other locales. + if (localesString == "th") { + defaultIgnorePunctuation = true; + } + JSLocale::GetOptionOfBool(thread, optionsObject, globalConst->GetHandledIgnorePunctuationString(), defaultIgnorePunctuation, &ignorePunctuation); collator->SetIgnorePunctuation(ignorePunctuation); if (ignorePunctuation) { @@ -318,40 +324,6 @@ JSHandle JSCollator::InitializeCollator(JSThread *thread, return collator; } -JSHandle JSCollator::ToCollatorOptions(JSThread *thread, const JSHandle &options, - const JSHandle &locales) -{ - // 1. If options is undefined, let options be null; otherwise let options be ? ToObject(options). - JSHandle optionsResult(thread, JSTaggedValue::Null()); - if (!options->IsUndefined()) { - optionsResult = JSTaggedValue::ToObject(thread, options); - RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSObject, thread); - } - - // 2. Let options be ObjectCreate(options). - optionsResult = JSObject::ObjectCreate(thread, optionsResult); - - // 3. If the ignorePunctuation is not defined, which in "th" locale that is true but false on other locales. - auto globalConst = thread->GlobalConstants(); - std::string localesString = - locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString(); - transform(localesString.begin(), localesString.end(), localesString.begin(), ::tolower); - if (localesString == "th") { - // Let ignorePunctuation be ? Get(options, "ignorePunctuation"). - OperationResult operationResult = - JSObject::GetProperty(thread, optionsResult, globalConst->GetHandledIgnorePunctuationString()); - RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSObject, thread); - if (operationResult.GetValue()->IsUndefined()) { - JSHandle value(thread, JSTaggedValue(true)); - JSObject::CreateDataPropertyOrThrow(thread, optionsResult, globalConst->GetHandledIgnorePunctuationString(), value); - RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSObject, thread); - } - } - - // 4. Return options. - return optionsResult; -} - icu::Collator *JSCollator::GetCachedIcuCollator(JSThread *thread, const JSTaggedValue &locales) { std::string cacheEntry = locales.IsUndefined() ? "" : EcmaStringAccessor(locales).ToStdString(); diff --git a/ecmascript/js_collator.h b/ecmascript/js_collator.h index 3474d02f27..ffdd542726 100644 --- a/ecmascript/js_collator.h +++ b/ecmascript/js_collator.h @@ -87,9 +87,6 @@ public: bool forIcuCache = false, bool enableLocaleCache = false); - static JSHandle ToCollatorOptions(JSThread *thread, const JSHandle &options, - const JSHandle &locales); - static icu::Collator *GetCachedIcuCollator(JSThread *thread, const JSHandle &locales); static icu::Collator *GetCachedIcuCollator(JSThread *thread, const JSTaggedValue &locales); -- Gitee