From bb9b03b991a069967796538287360500f8002a74 Mon Sep 17 00:00:00 2001 From: liuzhongyu101 Date: Wed, 27 Mar 2024 15:28:06 +0800 Subject: [PATCH] UnwrapNumberFormatUseOrdinaryHaslnstance.js&UnwrapDateTimeFormatUseOrdinaryHaslnstance.js&format-range-to-parts.js --- .../builtins/builtins_date_time_format.cpp | 20 +++++++++---------- .../builtins/builtins_number_format.cpp | 16 ++++++++------- ecmascript/js_date_time_format.cpp | 2 +- ecmascript/js_number_format.cpp | 2 +- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/ecmascript/builtins/builtins_date_time_format.cpp b/ecmascript/builtins/builtins_date_time_format.cpp index 8bd8bb70bf..dda9f7f75c 100644 --- a/ecmascript/builtins/builtins_date_time_format.cpp +++ b/ecmascript/builtins/builtins_date_time_format.cpp @@ -64,14 +64,16 @@ JSTaggedValue BuiltinsDateTimeFormat::DateTimeFormatConstructor(EcmaRuntimeCallI // 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()); - RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (newTarget->IsUndefined() && thisValue->IsJSObject() && isInstanceOf) { - PropertyDescriptor descriptor(thread, JSHandle::Cast(dtf), false, false, false); - JSHandle key(thread, JSHandle::Cast(env->GetIntlFunction())->GetFallbackSymbol()); - JSTaggedValue::DefinePropertyOrThrow(thread, thisValue, key, descriptor); + if (newTarget->IsUndefined() && thisValue->IsJSObject()) { + bool isInstanceOf = JSObject::InstanceOf(thread, thisValue, env->GetDateTimeFormatFunction()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return thisValue.GetTaggedValue(); + if (isInstanceOf) { + PropertyDescriptor descriptor(thread, JSHandle::Cast(dtf), false, false, false); + JSHandle key(thread, JSHandle::Cast(env->GetIntlFunction())->GetFallbackSymbol()); + JSTaggedValue::DefinePropertyOrThrow(thread, thisValue, key, descriptor); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + return thisValue.GetTaggedValue(); + } } // 6. Return dateTimeFormat. @@ -326,10 +328,6 @@ JSTaggedValue BuiltinsDateTimeFormat::FormatRangeToParts(EcmaRuntimeCallInfo *ar JSTaggedNumber valueY = JSTaggedValue::ToNumber(thread, endDate); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); double y = valueY.GetNumber(); - // 7. If x is greater than y, throw a RangeError exception. - if (x > y) { - THROW_RANGE_ERROR_AND_RETURN(thread, "x is greater than y", JSTaggedValue::Exception()); - } // 8. Return ? FormatDateTimeRangeToParts(dtf, x, y) JSHandle dtf = JSHandle::Cast(thisValue); diff --git a/ecmascript/builtins/builtins_number_format.cpp b/ecmascript/builtins/builtins_number_format.cpp index 71bebfd5d6..cb045399c6 100644 --- a/ecmascript/builtins/builtins_number_format.cpp +++ b/ecmascript/builtins/builtins_number_format.cpp @@ -66,14 +66,16 @@ JSTaggedValue BuiltinsNumberFormat::NumberFormatConstructor(EcmaRuntimeCallInfo // a. Perform ? DefinePropertyOrThrow(this, %Intl%.[[FallbackSymbol]], PropertyDescriptor{ // [[Value]]: numberFormat, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }). // b. Return this. - bool isInstanceOf = JSObject::InstanceOf(thread, thisValue, env->GetNumberFormatFunction()); - RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (newTarget->IsUndefined() && thisValue->IsJSObject() && isInstanceOf) { - PropertyDescriptor descriptor(thread, JSHandle::Cast(numberFormat), false, false, false); - JSHandle key(thread, JSHandle::Cast(env->GetIntlFunction())->GetFallbackSymbol()); - JSTaggedValue::DefinePropertyOrThrow(thread, thisValue, key, descriptor); + if (newTarget->IsUndefined() && thisValue->IsJSObject()) { + bool isInstanceOf = JSObject::InstanceOf(thread, thisValue, env->GetNumberFormatFunction()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return thisValue.GetTaggedValue(); + if (isInstanceOf) { + PropertyDescriptor descriptor(thread, JSHandle::Cast(numberFormat), false, false, false); + JSHandle key(thread, JSHandle::Cast(env->GetIntlFunction())->GetFallbackSymbol()); + JSTaggedValue::DefinePropertyOrThrow(thread, thisValue, key, descriptor); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + return thisValue.GetTaggedValue(); + } } // 6. Return numberFormat. diff --git a/ecmascript/js_date_time_format.cpp b/ecmascript/js_date_time_format.cpp index a70ed87028..e52516765f 100644 --- a/ecmascript/js_date_time_format.cpp +++ b/ecmascript/js_date_time_format.cpp @@ -910,7 +910,7 @@ JSHandle JSDateTimeFormat::UnwrapDateTimeFormat(JSThread *thread, // and ? InstanceofOperator(dateTimeFormat, %DateTimeFormat%) is true, then // a. Let dateTimeFormat be ? Get(dateTimeFormat, %Intl%.[[FallbackSymbol]]). JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - bool isInstanceOf = JSFunction::InstanceOf(thread, dateTimeFormat, env->GetDateTimeFormatFunction()); + bool isInstanceOf = JSFunction::OrdinaryHasInstance(thread, env->GetDateTimeFormatFunction(), dateTimeFormat); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, dateTimeFormat); if (!dateTimeFormat->IsJSDateTimeFormat() && isInstanceOf) { JSHandle key(thread, JSHandle::Cast(env->GetIntlFunction())->GetFallbackSymbol()); diff --git a/ecmascript/js_number_format.cpp b/ecmascript/js_number_format.cpp index 55339c0b9c..823d0cc616 100644 --- a/ecmascript/js_number_format.cpp +++ b/ecmascript/js_number_format.cpp @@ -1060,7 +1060,7 @@ JSHandle JSNumberFormat::UnwrapNumberFormat(JSThread *thread, con // 2. If nf does not have an [[InitializedNumberFormat]] internal slot and ? // InstanceofOperator(nf, %NumberFormat%) is true, then Let nf be ? Get(nf, %Intl%.[[FallbackSymbol]]). JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - bool hasInstance = JSObject::InstanceOf(thread, nf, env->GetNumberFormatFunction()); + bool hasInstance = JSFunction::OrdinaryHasInstance(thread, env->GetNumberFormatFunction(), nf ); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSHandle(thread, JSTaggedValue::Undefined())); bool isJSNumberFormat = nf->IsJSNumberFormat(); -- Gitee