From 51e176cc47298963dd1c6b4fc1a71c824ffc338c Mon Sep 17 00:00:00 2001 From: Nazarov Konstantin Date: Thu, 1 Dec 2022 22:41:18 +0300 Subject: [PATCH] bring up tests from test262 from DateTimeFormat and Date --- .../builtins/builtins_date_time_format.cpp | 5 ++-- runtime/js_date_time_format.cpp | 24 +++++++++---------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/runtime/builtins/builtins_date_time_format.cpp b/runtime/builtins/builtins_date_time_format.cpp index cb05d07bc..1d41e5ae7 100644 --- a/runtime/builtins/builtins_date_time_format.cpp +++ b/runtime/builtins/builtins_date_time_format.cpp @@ -55,12 +55,11 @@ JSTaggedValue BuiltinsDateTimeFormat::DateTimeFormatConstructor(EcmaRuntimeCallI // 4. Let this be the this value. JSHandle thisValue = GetThis(argv); - // 5. If NewTarget is undefined and Type(this) is Object and ? InstanceofOperator(this, %DateTimeFormat%) is true, - // then + // 5. If newTarget is undefined and ? OrdinaryHasInstance(%DateTimeFormat%, this) is true, then // a. Perform ? DefinePropertyOrThrow(this, %Intl%.[[FallbackSymbol]], PropertyDescriptor{ [[Value]]: // dateTimeFormat, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }). // b. Return this. - bool isInstanceOf = JSObject::InstanceOf(thread, thisValue, env->GetDateTimeFormatFunction()); + bool isInstanceOf = JSFunction::OrdinaryHasInstance(thread, env->GetDateTimeFormatFunction(), thisValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (new_target->IsUndefined() && thisValue->IsJSObject() && isInstanceOf) { PropertyDescriptor descriptor(thread, JSHandle::Cast(dtf), false, false, false); diff --git a/runtime/js_date_time_format.cpp b/runtime/js_date_time_format.cpp index 7772150c9..6a632f557 100644 --- a/runtime/js_date_time_format.cpp +++ b/runtime/js_date_time_format.cpp @@ -117,8 +117,8 @@ void JSDateTimeFormat::SetIcuLocale(JSThread *thread, JSHandle native->ResetExternalPointer(icuPointer); return; } - JSHandle pointer = factory->NewJSNativePointer(icuPointer); - pointer->SetDeleter(callback); + JSHandle pointer(thread, + factory->NewJSNativePointer(icuPointer, callback, ecmaVm).GetTaggedValue()); obj->SetLocaleIcu(thread, pointer.GetTaggedValue()); ecmaVm->PushToArrayDataList(*pointer); } @@ -129,9 +129,7 @@ void JSDateTimeFormat::FreeIcuLocale(void *pointer, [[maybe_unused]] void *data) return; } auto icuLocale = reinterpret_cast(pointer); - if (data != nullptr) { - Runtime::GetCurrent()->GetInternalAllocator()->Delete(icuLocale); - } + Runtime::GetCurrent()->GetInternalAllocator()->Delete(icuLocale); } icu::SimpleDateFormat *JSDateTimeFormat::GetIcuSimpleDateFormat() const @@ -157,8 +155,8 @@ void JSDateTimeFormat::SetIcuSimpleDateFormat(JSThread *thread, JSHandleResetExternalPointer(icuPointer); return; } - JSHandle pointer = factory->NewJSNativePointer(icuPointer); - pointer->SetDeleter(callback); + JSHandle pointer(thread, + factory->NewJSNativePointer(icuPointer, callback, ecmaVm).GetTaggedValue()); obj->SetSimpleDateTimeFormatIcu(thread, pointer.GetTaggedValue()); ecmaVm->PushToArrayDataList(*pointer); } @@ -169,9 +167,7 @@ void JSDateTimeFormat::FreeSimpleDateFormat(void *pointer, [[maybe_unused]] void return; } auto icuSimpleDateFormat = reinterpret_cast(pointer); - if (data != nullptr) { - Runtime::GetCurrent()->GetInternalAllocator()->Delete(icuSimpleDateFormat); - } + Runtime::GetCurrent()->GetInternalAllocator()->Delete(icuSimpleDateFormat); } JSHandle JSDateTimeFormat::ToValueString(JSThread *thread, const Value value) @@ -331,9 +327,11 @@ JSHandle JSDateTimeFormat::InitializeDateTimeFormat(JSThread * ASSERT_PRINT(U_SUCCESS(status), "constructGenerator failed"); HourCycleOption hcDefault = OptionToHourCycle(generator->getDefaultHourCycle(status)); // b. Let hc be dateTimeFormat.[[HourCycle]]. - HourCycleOption hc = HourCycleOption::UNDEFINED; - hc = (hourCycle == HourCycleOption::UNDEFINED) ? OptionToHourCycle(resolvedLocale.extensions.find("hc")->second) - : hourCycle; + HourCycleOption hc = hourCycle; + if (hc == HourCycleOption::UNDEFINED && resolvedLocale.extensions.find("hc") != resolvedLocale.extensions.end()) { + hc = OptionToHourCycle(resolvedLocale.extensions.find("hc")->second); + } + // c. If hc is null, then // i. Set hc to hcDefault. if (hc == HourCycleOption::UNDEFINED) { -- Gitee