From 3bf1a3cee91252507d02ebcd0ef332d61bbad342 Mon Sep 17 00:00:00 2001 From: shaoxiangdong Date: Thu, 14 Nov 2024 19:44:53 +0800 Subject: [PATCH] Check the results of NewRuntimeCallInfo Issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IB40SU Signed-off-by: shaoxiangdong Change-Id: Ifdc5efb6ba5e9a520a2034770ca5fccc46f36b62 --- ecmascript/builtins/builtins_array.cpp | 1 - .../builtins/builtins_async_from_sync_iterator.cpp | 6 ++++-- ecmascript/ecma_context.cpp | 4 ---- ecmascript/ic/ic_runtime.cpp | 9 ++++++--- ecmascript/js_async_generator_object.cpp | 1 + ecmascript/js_typed_array.cpp | 9 +++++++-- ecmascript/stubs/runtime_stubs-inl.h | 4 ++-- ecmascript/tagged_tree.cpp | 2 +- 8 files changed, 21 insertions(+), 15 deletions(-) diff --git a/ecmascript/builtins/builtins_array.cpp b/ecmascript/builtins/builtins_array.cpp index 06f39bf9dd..cd05eba7d2 100644 --- a/ecmascript/builtins/builtins_array.cpp +++ b/ecmascript/builtins/builtins_array.cpp @@ -2720,7 +2720,6 @@ JSTaggedValue BuiltinsArray::ToString(EcmaRuntimeCallInfo *argv) JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisObjVal, undefined, 0); - RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return JSFunction::Call(info); } diff --git a/ecmascript/builtins/builtins_async_from_sync_iterator.cpp b/ecmascript/builtins/builtins_async_from_sync_iterator.cpp index 3fb6a992fd..633fba4ae9 100644 --- a/ecmascript/builtins/builtins_async_from_sync_iterator.cpp +++ b/ecmascript/builtins/builtins_async_from_sync_iterator.cpp @@ -90,6 +90,7 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::Throw(EcmaRuntimeCallInfo *argv) JSHandle reject(thread, pcap->GetReject()); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, reject, undefinedValue, undefinedValue, 1); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); info->SetCallArg(iterResult.GetTaggedValue()); return pcap->GetPromise(); } @@ -98,7 +99,6 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::Throw(EcmaRuntimeCallInfo *argv) if (value->IsNull()) { EcmaRuntimeCallInfo *callInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, throwResult, syncIterator, undefinedValue, 0); - RETURN_REJECT_PROMISE_IF_ABRUPT(thread, throwResult, pcap); ret = JSFunction::Call(callInfo); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { @@ -119,6 +119,7 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::Throw(EcmaRuntimeCallInfo *argv) JSHandle reject(thread, pcap->GetReject()); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, reject, undefinedValue, undefinedValue, 1); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); info->SetCallArg(resolutionError.GetTaggedValue()); JSFunction::Call(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -167,6 +168,7 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::Return(EcmaRuntimeCallInfo *argv) JSHandle resolve(thread, pcap->GetResolve()); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, resolve, undefinedValue, undefinedValue, 1); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); info->SetCallArg(its.GetTaggedValue()); JSHandle promise(thread, pcap->GetPromise()); return promise.GetTaggedValue(); @@ -176,7 +178,6 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::Return(EcmaRuntimeCallInfo *argv) if (value->IsNull()) { EcmaRuntimeCallInfo *callInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, returnResult, syncIterator, undefinedValue, 0); - RETURN_REJECT_PROMISE_IF_ABRUPT(thread, returnResult, pcap); ret = JSFunction::Call(callInfo); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { @@ -197,6 +198,7 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::Return(EcmaRuntimeCallInfo *argv) JSHandle reject(thread, pcap->GetReject()); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, reject, undefinedValue, undefinedValue, 1); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); info->SetCallArg(rstErr.GetTaggedValue()); JSFunction::Call(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); diff --git a/ecmascript/ecma_context.cpp b/ecmascript/ecma_context.cpp index 19db1c736b..fc53e404f4 100644 --- a/ecmascript/ecma_context.cpp +++ b/ecmascript/ecma_context.cpp @@ -467,10 +467,6 @@ void EcmaContext::CJSExecution(JSHandle &func, JSHandle(func), thisArg, undefined, 5); // 5 : argument numbers RETURN_IF_ABRUPT_COMPLETION(thread_); - if (info == nullptr) { - LOG_ECMA(ERROR) << "CJSExecution Stack overflow!"; - return; - } info->SetCallArg(cjsInfo.exportsHdl.GetTaggedValue(), cjsInfo.requireHdl.GetTaggedValue(), cjsInfo.moduleHdl.GetTaggedValue(), diff --git a/ecmascript/ic/ic_runtime.cpp b/ecmascript/ic/ic_runtime.cpp index b34399bff6..d4b549f359 100644 --- a/ecmascript/ic/ic_runtime.cpp +++ b/ecmascript/ic/ic_runtime.cpp @@ -285,7 +285,6 @@ inline JSTaggedValue LoadICRuntime::CallPrivateGetter(JSHandle re JSHandle undefined = thread_->GlobalConstants()->GetHandledUndefined(); EcmaRuntimeCallInfo* info = EcmaInterpreter::NewRuntimeCallInfo(thread_, key, receiver, undefined, 0); // 0: getter has 0 argument - RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_); JSTaggedValue resGetter = JSFunction::Call(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_); return resGetter; @@ -304,7 +303,9 @@ JSTaggedValue LoadICRuntime::LoadTypedArrayValueMiss(JSHandle rec } UpdateTypedArrayHandler(receiver); JSHandle indexHandle(GetThread(), numericIndex); - uint32_t index = static_cast(JSTaggedValue::ToInteger(GetThread(), indexHandle).ToInt32()); + JSTaggedNumber integerValue = JSTaggedValue::ToInteger(GetThread(), indexHandle); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(GetThread()); + uint32_t index = static_cast(integerValue.ToInt32()); JSType type = receiver->GetTaggedObject()->GetClass()->GetObjectType(); return JSTypedArray::FastGetPropertyByIndex(GetThread(), receiver.GetTaggedValue(), index, type); } else { @@ -448,7 +449,9 @@ JSTaggedValue StoreICRuntime::StoreTypedArrayValueMiss(JSHandle r } UpdateTypedArrayHandler(receiver); JSHandle indexHandle(GetThread(), numericIndex); - uint32_t index = static_cast(JSTaggedValue::ToInteger(GetThread(), indexHandle).ToInt32()); + JSTaggedNumber integerValue = JSTaggedValue::ToInteger(GetThread(), indexHandle); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(GetThread()); + uint32_t index = static_cast(integerValue.ToInt32()); JSType type = receiver->GetTaggedObject()->GetClass()->GetObjectType(); return JSTypedArray::FastSetPropertyByIndex(GetThread(), receiver.GetTaggedValue(), index, value.GetTaggedValue(), type); diff --git a/ecmascript/js_async_generator_object.cpp b/ecmascript/js_async_generator_object.cpp index f13972ad91..34b71e4095 100644 --- a/ecmascript/js_async_generator_object.cpp +++ b/ecmascript/js_async_generator_object.cpp @@ -67,6 +67,7 @@ JSTaggedValue JSAsyncGeneratorObject::AsyncGeneratorResolve(JSThread *thread, JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); EcmaRuntimeCallInfo* info = EcmaInterpreter::NewRuntimeCallInfo(thread, resolve, undefined, undefined, 1, StackCheck::NO); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); info->SetCallArg(its.GetTaggedValue()); [[maybe_unused]] JSTaggedValue res = JSFunction::Call(info); if ((thread)->HasPendingException()) { diff --git a/ecmascript/js_typed_array.cpp b/ecmascript/js_typed_array.cpp index 70db6dea1d..1be56a2905 100644 --- a/ecmascript/js_typed_array.cpp +++ b/ecmascript/js_typed_array.cpp @@ -429,7 +429,10 @@ OperationResult JSTypedArray::IntegerIndexedElementGet(JSThread *thread, const J // arrayTypeName. uint32_t elementSize = TypedArrayHelper::GetElementSize(typedarrayObj); // 12. Let indexedPosition = (index × elementSize) + offset. - uint32_t k = static_cast(JSTaggedValue::ToInteger(thread, indexHandle).ToInt32()); + JSTaggedNumber integerValue = JSTaggedValue::ToInteger(thread, indexHandle); + RETURN_VALUE_IF_ABRUPT_COMPLETION( + thread, OperationResult(thread, JSTaggedValue::Exception(), PropertyMetaData(false))); + uint32_t k = static_cast(integerValue.ToInt32()); uint32_t byteIndex = k * elementSize + offset; // 13. Let elementType be the String value of the Element Type value in Table 49 for arrayTypeName. DataViewType elementType = TypedArrayHelper::GetType(typedarrayObj); @@ -628,7 +631,9 @@ bool JSTypedArray::IntegerIndexedElementSet(JSThread *thread, const JSHandleIsCallable()); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, method, obj, undefined, 0); - RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSTaggedValue ret = JSFunction::Call(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!ret.IsECMAObject()) { @@ -1544,7 +1543,6 @@ JSTaggedValue RuntimeStubs::RuntimeLdPrivateProperty(JSThread *thread, JSTaggedV JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); // 0: getter has 0 arg EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, handleKey, handleObj, undefined, 0); - RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSTaggedValue resGetter = JSFunction::Call(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return resGetter; @@ -2676,6 +2674,7 @@ JSTaggedValue RuntimeStubs::RuntimeCallBigIntAsIntN(JSThread *thread, JSTaggedVa { auto biginteger = JSHandle(thread, bigint); JSTaggedNumber bitness = JSTaggedValue::ToNumber(thread, bits); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return BigInt::AsintN(thread, bitness, biginteger); } @@ -2683,6 +2682,7 @@ JSTaggedValue RuntimeStubs::RuntimeCallBigIntAsUintN(JSThread *thread, JSTaggedV { auto biginteger = JSHandle(thread, bigint); JSTaggedNumber bitness = JSTaggedValue::ToNumber(thread, bits); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return BigInt::AsUintN(thread, bitness, biginteger); } diff --git a/ecmascript/tagged_tree.cpp b/ecmascript/tagged_tree.cpp index cd7bfaa648..94df459f03 100644 --- a/ecmascript/tagged_tree.cpp +++ b/ecmascript/tagged_tree.cpp @@ -363,7 +363,6 @@ ComparisonResult TaggedTree::EntryCompare(JSThread *thread, const JSHan EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, compareFn, thisArgHandle, undefined, argsLength); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ComparisonResult::UNDEFINED); - ASSERT(info != nullptr); info->SetCallArg(valueX.GetTaggedValue(), valueY.GetTaggedValue()); JSTaggedValue callResult = JSFunction::Call(info); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ComparisonResult::UNDEFINED); @@ -372,6 +371,7 @@ ComparisonResult TaggedTree::EntryCompare(JSThread *thread, const JSHan // if callResult is true, compareResult = -1. if (callResult.IsFalse()) { info = EcmaInterpreter::NewRuntimeCallInfo(thread, compareFn, thisArgHandle, undefined, argsLength); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ComparisonResult::UNDEFINED); info->SetCallArg(valueY.GetTaggedValue(), valueX.GetTaggedValue()); callResult = JSFunction::Call(info); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ComparisonResult::UNDEFINED);