From df668db447d7b19ee38fe7925638feffdd2c9bd6 Mon Sep 17 00:00:00 2001 From: zhangyouyou Date: Fri, 26 Apr 2024 17:17:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9array.findIndex=20=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3IR=E5=8C=96=E5=BC=82=E5=B8=B8=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E6=AD=A3=E5=B8=B8=E6=8A=9B=E5=87=BA=20https://gitee.com/openha?= =?UTF-8?q?rmony/arkcompiler=5Fets=5Fruntime/issues/I9K03B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangyouyou --- ecmascript/builtins/builtins_global.cpp | 14 ++++++++++++-- .../builtins/builtins_array_stub_builder.cpp | 2 +- .../moduletest/arrayfindindex/arrayfindindex.js | 17 ++++++++++++++++- .../moduletest/arrayfindindex/expect_output.txt | 1 + 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/ecmascript/builtins/builtins_global.cpp b/ecmascript/builtins/builtins_global.cpp index c53aa8df24..29c24146a6 100644 --- a/ecmascript/builtins/builtins_global.cpp +++ b/ecmascript/builtins/builtins_global.cpp @@ -227,7 +227,7 @@ JSTaggedValue BuiltinsGlobal::Encode(JSThread *thread, const JSHandleGetEcmaVM()->GetFactory(); @@ -257,6 +257,7 @@ JSTaggedValue BuiltinsGlobal::Encode(JSThread *thread, const JSHandle= base::utf_helper::DECODE_TRAIL_LOW && cc <= base::utf_helper::DECODE_TRAIL_HIGH) { + errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } @@ -274,10 +275,12 @@ JSTaggedValue BuiltinsGlobal::Encode(JSThread *thread, const JSHandle base::utf_helper::DECODE_TRAIL_HIGH) { + errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } vv = base::utf_helper::UTF16Decode(cc, kc); @@ -495,16 +498,18 @@ JSTaggedValue BuiltinsGlobal::DecodePercentEncoding(JSThread *thread, const JSHa judgURIFunc IsInURISet, int32_t strLen, std::u16string &sStr) { [[maybe_unused]] uint32_t start = static_cast(k); - [[maybe_unused]] CString errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); + CString errorMsg; // ii. If k + 2 is greater than or equal to strLen, throw a URIError exception. // iii. If the code units at index (k+1) and (k + 2) within string do not represent hexadecimal digits, // throw a URIError exception. if ((k + 2) >= strLen) { // 2: means plus 2 + errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } uint16_t frontChar = EcmaStringAccessor(str).Get(k + 1); uint16_t behindChar = EcmaStringAccessor(str).Get(k + 2); // 2: means plus 2 if (!(IsHexDigits(frontChar) && IsHexDigits(behindChar))) { + errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } uint8_t bb = GetValueFromTwoHex(frontChar, behindChar); @@ -550,6 +555,7 @@ JSTaggedValue BuiltinsGlobal::DecodePercentEncoding(JSThread *thread, const JSHa } // 2. If n equals 1 or n is greater than 4, throw a URIError exception. if ((n == 1) || (n > 4)) { + errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } @@ -557,6 +563,7 @@ JSTaggedValue BuiltinsGlobal::DecodePercentEncoding(JSThread *thread, const JSHa // 5. If k + (3 × (n – 1)) is greater than or equal to strLen, throw a URIError exception. if (k + (3 * (n - 1)) >= strLen) { // 3: means multiply by 3 + errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } int32_t j = 1; @@ -567,10 +574,12 @@ JSTaggedValue BuiltinsGlobal::DecodePercentEncoding(JSThread *thread, const JSHa // c. If the code units at index (k +1) and (k + 2) within string do not represent hexadecimal // digits, throw a URIError exception. if (!(codeUnit == '%')) { + errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } if (!(IsHexDigits(EcmaStringAccessor(str).Get(k + 1)) && IsHexDigits(EcmaStringAccessor(str).Get(k + 2)))) { // 2: means plus 2 + errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } uint16_t frontChart = EcmaStringAccessor(str).Get(k + 1); @@ -578,6 +587,7 @@ JSTaggedValue BuiltinsGlobal::DecodePercentEncoding(JSThread *thread, const JSHa bb = GetValueFromTwoHex(frontChart, behindChart); // e. If the two most significant bits in B are not 10, throw a URIError exception. if (!((bb & BIT_MASK_TWO) == BIT_MASK_ONE)) { + errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } k += 2; // 2: means plus 2 diff --git a/ecmascript/compiler/builtins/builtins_array_stub_builder.cpp b/ecmascript/compiler/builtins/builtins_array_stub_builder.cpp index 03ee6ac8e1..d0ba20e09c 100644 --- a/ecmascript/compiler/builtins/builtins_array_stub_builder.cpp +++ b/ecmascript/compiler/builtins/builtins_array_stub_builder.cpp @@ -2222,7 +2222,7 @@ void BuiltinsArrayStubBuilder::FindIndex(GateRef glue, GateRef thisValue, GateRe GateRef retValue = JSCallDispatch(glue, callbackFnHandle, Int32(NUM_MANDATORY_JSFUNC_ARGS), 0, Circuit::NullGate(), JSCallMode::CALL_THIS_ARG3_WITH_RETURN, { argHandle, *kValue, key, thisValue }); - BRANCH(TaggedIsException(retValue), &hasException, ¬HasException); + BRANCH(HasPendingException(glue), &hasException, ¬HasException); Bind(&hasException); { result->WriteVariable(retValue); diff --git a/test/moduletest/arrayfindindex/arrayfindindex.js b/test/moduletest/arrayfindindex/arrayfindindex.js index 7a6019d726..b2bacfc7d5 100644 --- a/test/moduletest/arrayfindindex/arrayfindindex.js +++ b/test/moduletest/arrayfindindex/arrayfindindex.js @@ -36,4 +36,19 @@ } array1.__proto__.push(6); print(findIndex()) -})(); \ No newline at end of file +})(); + +{ + class C1 { + [28262n] = 28262n; + } + const v2 = new C1(); + const v3 = [-4.869758437495864e+307,1000000000000.0]; + function f4(a5, a6) { + for (const v7 in v2) { + } + a6(); + return a6; + } + try { v3.findIndex(f4);} catch (err) { print(err)}; +} \ No newline at end of file diff --git a/test/moduletest/arrayfindindex/expect_output.txt b/test/moduletest/arrayfindindex/expect_output.txt index 1e25f928f6..3302b499ea 100644 --- a/test/moduletest/arrayfindindex/expect_output.txt +++ b/test/moduletest/arrayfindindex/expect_output.txt @@ -13,3 +13,4 @@ 2 0 +TypeError: is not callable