diff --git a/ecmascript/base/array_helper.cpp b/ecmascript/base/array_helper.cpp index b48d3e7ad1..617be2f3b1 100644 --- a/ecmascript/base/array_helper.cpp +++ b/ecmascript/base/array_helper.cpp @@ -112,6 +112,7 @@ bool ArrayHelper::ElementIsStrictEqualTo(JSThread *thread, const JSHandle &target) { bool exists = thisObjVal->IsTypedArray() || JSTaggedValue::HasProperty(thread, thisObjVal, keyHandle); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); if (thread->HasPendingException() || !exists) { return false; } diff --git a/ecmascript/builtins/builtins_ark_tools.cpp b/ecmascript/builtins/builtins_ark_tools.cpp index 59b4a3045d..77f62e029f 100644 --- a/ecmascript/builtins/builtins_ark_tools.cpp +++ b/ecmascript/builtins/builtins_ark_tools.cpp @@ -728,6 +728,7 @@ JSTaggedValue BuiltinsArkTools::CreateDataProperty([[maybe_unused]] EcmaRuntimeC JSHandle value = GetCallArg(info, secondArg); JSHandle obj = JSHandle::Cast(GetCallArg(info, 0)); JSObject::CreateDataPropertyOrThrow(thread, obj, key, value); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return value.GetTaggedValue(); } diff --git a/ecmascript/builtins/builtins_array.cpp b/ecmascript/builtins/builtins_array.cpp index ff8a33ded7..6c23b7201e 100644 --- a/ecmascript/builtins/builtins_array.cpp +++ b/ecmascript/builtins/builtins_array.cpp @@ -431,6 +431,7 @@ JSTaggedValue BuiltinsArray::Concat(EcmaRuntimeCallInfo *argv) // 2. Let A be ArraySpeciesCreate(O, 0). uint32_t arrayLen = 0; JSTaggedValue newArray = JSArray::ArraySpeciesCreate(thread, thisObjHandle, JSTaggedNumber(arrayLen)); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!(newArray.IsECMAObject() || newArray.IsUndefined())) { THROW_TYPE_ERROR_AND_RETURN(thread, "array must be object or undefined.", JSTaggedValue::Exception()); } @@ -469,6 +470,7 @@ JSTaggedValue BuiltinsArray::Concat(EcmaRuntimeCallInfo *argv) if (ele->IsStableJSArray(thread)) { JSStableArray::Concat(thread, newArrayHandle, JSHandle::Cast(ele), k, n); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // iv. Repeat, while k < len, while (k < len) { @@ -932,6 +934,7 @@ JSTaggedValue BuiltinsArray::Filter(EcmaRuntimeCallInfo *argv) uint32_t k = 0; if (thisObjVal->IsStableJSArray(thread)) { JSStableArray::Filter(newArrayHandle, thisObjHandle, argv, k, toIndex); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } return FilterUnStableJSArray(thread, thisArgHandle, thisObjVal, k, len, toIndex, newArrayHandle, callbackFnHandle); } @@ -1481,6 +1484,7 @@ JSTaggedValue BuiltinsArray::Map(EcmaRuntimeCallInfo *argv) uint32_t len = static_cast(rawLen); if (thisObjVal->IsStableJSArray(thread)) { JSStableArray::Map(newArrayHandle, thisObjHandle, argv, k, len); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } JSMutableHandle key(thread, JSTaggedValue::Undefined()); JSMutableHandle mapResultHandle(thread, JSTaggedValue::Undefined()); diff --git a/ecmascript/builtins/builtins_async_from_sync_iterator.cpp b/ecmascript/builtins/builtins_async_from_sync_iterator.cpp index ae63f7c4b8..ec121a5bee 100644 --- a/ecmascript/builtins/builtins_async_from_sync_iterator.cpp +++ b/ecmascript/builtins/builtins_async_from_sync_iterator.cpp @@ -106,15 +106,16 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::Throw(EcmaRuntimeCallInfo *argv) 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 { EcmaRuntimeCallInfo *callInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, throwResult, syncIterator, undefinedValue, 1); RETURN_REJECT_PROMISE_IF_ABRUPT(thread, throwResult, pcap); callInfo->SetCallArg(value.GetTaggedValue()); ret = JSFunction::Call(callInfo); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } JSHandle result(thread, ret); - RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, pcap); // 11.If Type(result) is not Object, then if (!result->IsECMAObject()) { // a.Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »). @@ -125,6 +126,7 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::Throw(EcmaRuntimeCallInfo *argv) EcmaInterpreter::NewRuntimeCallInfo(thread, reject, undefinedValue, undefinedValue, 1); info->SetCallArg(resolutionError.GetTaggedValue()); JSFunction::Call(info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // b.Return promiseCapability.[[Promise]]. JSHandle promise(thread, pcap->GetPromise()); @@ -181,15 +183,16 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::Return(EcmaRuntimeCallInfo *argv) 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 { EcmaRuntimeCallInfo *callInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, returnResult, syncIterator, undefinedValue, 1); RETURN_REJECT_PROMISE_IF_ABRUPT(thread, returnResult, pcap); callInfo->SetCallArg(value.GetTaggedValue()); ret = JSFunction::Call(callInfo); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } JSHandle result(thread, ret); - RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, pcap); // 11.If Type(result) is not Object, then if (!result->IsECMAObject()) { // a.Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »). @@ -201,6 +204,7 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::Return(EcmaRuntimeCallInfo *argv) EcmaInterpreter::NewRuntimeCallInfo(thread, reject, undefinedValue, undefinedValue, 1); info->SetCallArg(rstErr.GetTaggedValue()); JSFunction::Call(info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // b.Return promiseCapability.[[Promise]]. JSHandle promise(thread, pcap->GetPromise()); diff --git a/ecmascript/builtins/builtins_bigint.cpp b/ecmascript/builtins/builtins_bigint.cpp index 9498342fcc..6c8992c28d 100644 --- a/ecmascript/builtins/builtins_bigint.cpp +++ b/ecmascript/builtins/builtins_bigint.cpp @@ -40,6 +40,7 @@ JSTaggedValue BuiltinsBigInt::BigIntConstructor(EcmaRuntimeCallInfo *argv) JSHandle value = GetCallArg(argv, 0); // 2. Let prim be ? ToPrimitive(value). JSHandle Primitive(thread, JSTaggedValue::ToPrimitive(thread, value)); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If Type(prim) is Number, return ? NumberToBigInt(prim). if (Primitive->IsNumber()) { return BigInt::NumberToBigInt(thread, Primitive); diff --git a/ecmascript/builtins/builtins_date.cpp b/ecmascript/builtins/builtins_date.cpp index 29a465e796..9b1a7c4a48 100644 --- a/ecmascript/builtins/builtins_date.cpp +++ b/ecmascript/builtins/builtins_date.cpp @@ -160,7 +160,7 @@ JSTaggedValue BuiltinsDate::ToJSON(EcmaRuntimeCallInfo *argv) JSHandle objectHandle = JSHandle::Cast(object); JSHandle tv(thread, JSTaggedValue::ToPrimitive(thread, objectHandle, PreferredPrimitiveType::PREFER_NUMBER)); - + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If Type(tv) is Number and tv is not finite, return null if (tv->IsNumber()) { if (tv->IsDouble() && !std::isfinite(tv->GetDouble())) { diff --git a/ecmascript/builtins/builtins_regexp.cpp b/ecmascript/builtins/builtins_regexp.cpp index f84b8255d8..d713acd223 100644 --- a/ecmascript/builtins/builtins_regexp.cpp +++ b/ecmascript/builtins/builtins_regexp.cpp @@ -457,7 +457,9 @@ JSTaggedValue BuiltinsRegExp::GetSource(EcmaRuntimeCallInfo *argv) JSHandle constructor = GetConstructor(argv); if (objConstructor->IsJSFunction() && constructor->IsJSFunction()) { JSHandle objRealm = JSObject::GetFunctionRealm(thread, objConstructor); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle ctorRealm = JSObject::GetFunctionRealm(thread, constructor); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (objRealm->GetRegExpPrototype() == thisObj && *objRealm == *ctorRealm) { JSHandle result = thread->GetEcmaVM()->GetFactory()->NewFromASCII("(?:)"); return result.GetTaggedValue(); @@ -1079,6 +1081,7 @@ JSTaggedValue BuiltinsRegExp::ReplaceInternal(JSThread *thread, ncaptures = std::max((ncaptures - 1), 0); // d. Let matched be ToString(Get(result, "0")). JSTaggedValue value = ObjectFastOperator::GetPropertyByIndex(thread, resultValues.GetTaggedValue(), 0); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); getMatchString.Update(value); JSHandle matchString = JSTaggedValue::ToString(thread, getMatchString); // e. ReturnIfAbrupt(matched). @@ -1328,6 +1331,7 @@ JSTaggedValue BuiltinsRegExp::Split(EcmaRuntimeCallInfo *argv) const GlobalEnvConstants *globalConstants = thread->GlobalConstants(); JSHandle flagsString(globalConstants->GetHandledFlagsString()); JSHandle taggedFlags = JSObject::GetProperty(thread, thisObj, flagsString).GetValue(); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle flags; if (taggedFlags->IsUndefined()) { @@ -1447,6 +1451,7 @@ JSTaggedValue BuiltinsRegExp::Split(EcmaRuntimeCallInfo *argv) // i. Let e be ToLength(Get(splitter, "lastIndex")). JSHandle lastIndexHandle = JSObject::GetProperty(thread, splitter, lastIndexString).GetValue(); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSTaggedNumber lastIndexNumber = JSTaggedValue::ToLength(thread, lastIndexHandle); // ii. ReturnIfAbrupt(e). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1482,6 +1487,7 @@ JSTaggedValue BuiltinsRegExp::Split(EcmaRuntimeCallInfo *argv) JSHandle lengthString(thread->GlobalConstants()->GetHandledLengthString()); JSHandle capturesHandle = JSObject::GetProperty(thread, execResult, lengthString).GetValue(); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSTaggedNumber numberOfCapturesNumber = JSTaggedValue::ToLength(thread, capturesHandle); // 8. ReturnIfAbrupt(numberOfCaptures). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1757,6 +1763,7 @@ JSTaggedValue BuiltinsRegExp::GetFlagsInternal(JSThread *thread, const JSHandle< if (objConstructor->IsJSFunction() && constructor->IsJSFunction()) { JSHandle objRealm = JSObject::GetFunctionRealm(thread, objConstructor); JSHandle ctorRealm = JSObject::GetFunctionRealm(thread, constructor); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (objRealm->GetRegExpPrototype() == obj && *objRealm == *ctorRealm) { return JSTaggedValue::Undefined(); } diff --git a/ecmascript/containers/containers_private.cpp b/ecmascript/containers/containers_private.cpp index da58e89350..7ceb4a1871 100644 --- a/ecmascript/containers/containers_private.cpp +++ b/ecmascript/containers/containers_private.cpp @@ -289,6 +289,7 @@ JSHandle ContainersPrivate::InitializeArrayList(JSThread *thread) // "constructor" property on the prototype JSHandle constructorKey = globalConst->GetHandledConstructorString(); JSObject::SetProperty(thread, JSHandle(prototype), constructorKey, arrayListFunction); + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); // ArrayList.prototype SetFrozenFunction(thread, prototype, "add", ContainersArrayList::Add, FuncLength::ONE); @@ -363,6 +364,7 @@ JSHandle ContainersPrivate::InitializeLightWeightMap(JSThread *th // "constructor" property on the prototype JSHandle constructorKey = globalConst->GetHandledConstructorString(); JSObject::SetProperty(thread, JSHandle(funcPrototype), constructorKey, lightWeightMapFunction); + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); // LightWeightMap.prototype.add() SetFrozenFunction(thread, funcPrototype, "hasAll", ContainersLightWeightMap::HasAll, FuncLength::ONE); @@ -436,6 +438,7 @@ JSHandle ContainersPrivate::InitializeLightWeightSet(JSThread *th // "constructor" property on the prototype JSHandle constructorKey = globalConst->GetHandledConstructorString(); JSObject::SetProperty(thread, JSHandle(funcPrototype), constructorKey, lightweightSetFunction); + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); SetFrozenFunction(thread, funcPrototype, "add", ContainersLightWeightSet::Add, FuncLength::ONE); SetFrozenFunction(thread, funcPrototype, "addAll", ContainersLightWeightSet::AddAll, FuncLength::ONE); SetFrozenFunction(thread, funcPrototype, "isEmpty", ContainersLightWeightSet::IsEmpty, FuncLength::ONE); @@ -502,7 +505,7 @@ JSHandle ContainersPrivate::InitializeTreeMap(JSThread *thread) // "constructor" property on the prototype JSHandle constructorKey = globalConst->GetHandledConstructorString(); JSObject::SetProperty(thread, JSHandle(mapFuncPrototype), constructorKey, mapFunction); - + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); // TreeMap.prototype SetFrozenFunction(thread, mapFuncPrototype, "set", ContainersTreeMap::Set, FuncLength::TWO); SetFrozenFunction(thread, mapFuncPrototype, "get", ContainersTreeMap::Get, FuncLength::ONE); @@ -579,7 +582,7 @@ JSHandle ContainersPrivate::InitializeTreeSet(JSThread *thread) // "constructor" property on the prototype JSHandle constructorKey = globalConst->GetHandledConstructorString(); JSObject::SetProperty(thread, JSHandle(setFuncPrototype), constructorKey, setFunction); - + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); // TreeSet.prototype SetFrozenFunction(thread, setFuncPrototype, "add", ContainersTreeSet::Add, FuncLength::TWO); SetFrozenFunction(thread, setFuncPrototype, "remove", ContainersTreeSet::Remove, FuncLength::ONE); @@ -654,6 +657,7 @@ JSHandle ContainersPrivate::InitializePlainArray(JSThread *thread JSHandle constructorKey = globalConst->GetHandledConstructorString(); JSObject::SetProperty(thread, JSHandle(plainArrayFuncPrototype), constructorKey, plainArrayFunction); + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); // PlainArray.prototype.add() SetFrozenFunction(thread, plainArrayFuncPrototype, "add", ContainersPlainArray::Add, FuncLength::ONE); SetFrozenFunction(thread, plainArrayFuncPrototype, "clear", ContainersPlainArray::Clear, FuncLength::ONE); @@ -727,7 +731,7 @@ JSHandle ContainersPrivate::InitializeStack(JSThread *thread) // "constructor" property on the prototype JSHandle constructorKey = globalConst->GetHandledConstructorString(); JSObject::SetProperty(thread, JSHandle(stackFuncPrototype), constructorKey, stackFunction); - + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); // Stack.prototype.push() SetFrozenFunction(thread, stackFuncPrototype, "push", ContainersStack::Push, FuncLength::ONE); // Stack.prototype.empty() @@ -786,7 +790,7 @@ JSHandle ContainersPrivate::InitializeVector(JSThread *thread) // "constructor" property on the prototype JSHandle constructorKey = globalConst->GetHandledConstructorString(); JSObject::SetProperty(thread, JSHandle(prototype), constructorKey, vectorFunction); - + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); // Vector.prototype SetFrozenFunction(thread, prototype, "add", ContainersVector::Add, FuncLength::ONE); SetFrozenFunction(thread, prototype, "insert", ContainersVector::Insert, FuncLength::TWO); @@ -868,7 +872,7 @@ JSHandle ContainersPrivate::InitializeQueue(JSThread *thread) // "constructor" property on the prototype JSHandle constructorKey = globalConst->GetHandledConstructorString(); JSObject::SetProperty(thread, JSHandle(queueFuncPrototype), constructorKey, queueFunction); - + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); // Queue.prototype.add() SetFrozenFunction(thread, queueFuncPrototype, "add", ContainersQueue::Add, FuncLength::ONE); SetFrozenFunction(thread, queueFuncPrototype, "getFirst", ContainersQueue::GetFirst, FuncLength::ZERO); @@ -923,7 +927,7 @@ JSHandle ContainersPrivate::InitializeDeque(JSThread *thread) // "constructor" property on the prototype JSHandle constructorKey = globalConst->GetHandledConstructorString(); JSObject::SetProperty(thread, JSHandle(dequeFuncPrototype), constructorKey, dequeFunction); - + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); SetFrozenFunction(thread, dequeFuncPrototype, "insertFront", ContainersDeque::InsertFront, FuncLength::ONE); SetFrozenFunction(thread, dequeFuncPrototype, "insertEnd", ContainersDeque::InsertEnd, FuncLength::ONE); SetFrozenFunction(thread, dequeFuncPrototype, "getFirst", ContainersDeque::GetFirst, FuncLength::ZERO); @@ -976,7 +980,7 @@ JSHandle ContainersPrivate::InitializeList(JSThread *thread) JSHandle constructorKey = globalConst->GetHandledConstructorString(); JSObject::SetProperty(thread, JSHandle(listFuncPrototype), constructorKey, listFunction); - + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); SetFrozenFunction(thread, listFuncPrototype, "add", ContainersList::Add, FuncLength::ONE); SetFrozenFunction(thread, listFuncPrototype, "getFirst", ContainersList::GetFirst, FuncLength::ONE); SetFrozenFunction(thread, listFuncPrototype, "getLast", ContainersList::GetLast, FuncLength::ONE); @@ -1027,7 +1031,7 @@ JSHandle ContainersPrivate::InitializeLinkedList(JSThread *thread JSHandle constructorKey = globalConst->GetHandledConstructorString(); JSObject::SetProperty(thread, JSHandle(linkedListFuncPrototype), constructorKey, linkedListFunction); - + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); SetFrozenFunction(thread, linkedListFuncPrototype, "add", ContainersLinkedList::Add, FuncLength::ONE); SetFrozenFunction(thread, linkedListFuncPrototype, "insert", ContainersLinkedList::Insert, FuncLength::ONE); SetFrozenFunction(thread, linkedListFuncPrototype, "clear", ContainersLinkedList::Clear, FuncLength::ONE); @@ -1114,6 +1118,7 @@ JSHandle ContainersPrivate::InitializeHashMap(JSThread *thread) // "constructor" property on the prototype JSHandle constructorKey = globalConst->GetHandledConstructorString(); JSObject::SetProperty(thread, JSHandle(hashMapFuncPrototype), constructorKey, hashMapFunction); + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); // HashMap.prototype.set() SetFrozenFunction(thread, hashMapFuncPrototype, "set", ContainersHashMap::Set, FuncLength::TWO); // HashMap.prototype.setall() @@ -1197,7 +1202,7 @@ JSHandle ContainersPrivate::InitializeHashSet(JSThread *thread) // "constructor" property on the prototype JSHandle constructorKey = globalConst->GetHandledConstructorString(); JSObject::SetProperty(thread, JSHandle(hashSetFuncPrototype), constructorKey, hashSetFunction); - + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); SetFrozenFunction(thread, hashSetFuncPrototype, "isEmpty", ContainersHashSet::IsEmpty, FuncLength::ZERO); SetFrozenFunction(thread, hashSetFuncPrototype, "has", ContainersHashSet::Has, FuncLength::ONE); SetFrozenFunction(thread, hashSetFuncPrototype, "add", ContainersHashSet::Add, FuncLength::ONE); diff --git a/ecmascript/ecma_context.cpp b/ecmascript/ecma_context.cpp index aafa3efe6b..25dc5bc07e 100644 --- a/ecmascript/ecma_context.cpp +++ b/ecmascript/ecma_context.cpp @@ -628,6 +628,7 @@ void EcmaContext::PrintJSErrorInfo(JSThread *thread, const JSHandle nameKey = thread->GlobalConstants()->GetHandledNameString(); JSHandle nameValue = JSObject::GetProperty(thread, exceptionInfo, nameKey).GetValue(); + RETURN_IF_ABRUPT_COMPLETION(thread); JSHandle name = JSTaggedValue::ToString(thread, nameValue); // JSTaggedValue::ToString may cause exception. In this case, do not return, use "" instead. if (thread->HasPendingException()) { @@ -636,6 +637,7 @@ void EcmaContext::PrintJSErrorInfo(JSThread *thread, const JSHandle msgKey = thread->GlobalConstants()->GetHandledMessageString(); JSHandle msgValue = JSObject::GetProperty(thread, exceptionInfo, msgKey).GetValue(); + RETURN_IF_ABRUPT_COMPLETION(thread); JSHandle msg = JSTaggedValue::ToString(thread, msgValue); // JSTaggedValue::ToString may cause exception. In this case, do not return, use "" instead. if (thread->HasPendingException()) { @@ -644,6 +646,7 @@ void EcmaContext::PrintJSErrorInfo(JSThread *thread, const JSHandle stackKey = thread->GlobalConstants()->GetHandledStackString(); JSHandle stackValue = JSObject::GetProperty(thread, exceptionInfo, stackKey).GetValue(); + RETURN_IF_ABRUPT_COMPLETION(thread); JSHandle stack = JSTaggedValue::ToString(thread, stackValue); // JSTaggedValue::ToString may cause exception. In this case, do not return, use "" instead. if (thread->HasPendingException()) { diff --git a/ecmascript/ic/ic_runtime.cpp b/ecmascript/ic/ic_runtime.cpp index 82bcbddd32..7b3f27548b 100644 --- a/ecmascript/ic/ic_runtime.cpp +++ b/ecmascript/ic/ic_runtime.cpp @@ -189,6 +189,7 @@ JSTaggedValue LoadICRuntime::LoadValueMiss(JSHandle receiver, JSH } ObjectOperator op(GetThread(), receiver, key); auto result = JSHandle(thread_, JSObject::GetProperty(GetThread(), &op)); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_); if (receiver->IsString()) { // do not cache element @@ -287,6 +288,7 @@ JSTaggedValue LoadICRuntime::LoadTypedArrayValueMiss(JSHandle rec } else { ObjectOperator op(GetThread(), receiver, key); auto result = JSHandle(GetThread(), JSObject::GetProperty(GetThread(), &op)); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(GetThread()); if (op.GetValue().IsInternalAccessor()) { op = ObjectOperator(GetThread(), receiver, key); } diff --git a/ecmascript/js_date_time_format.cpp b/ecmascript/js_date_time_format.cpp index af844f72c3..5396074b34 100644 --- a/ecmascript/js_date_time_format.cpp +++ b/ecmascript/js_date_time_format.cpp @@ -1090,11 +1090,13 @@ void JSDateTimeFormat::ResolvedOptions(JSThread *thread, const JSHandleGetHandledDateStyleString(); hcValue = ToDateTimeStyleEcmaString(thread, dateTimeFormat->GetDateStyle()); JSObject::CreateDataPropertyOrThrow(thread, options, property, hcValue); + RETURN_IF_ABRUPT_COMPLETION(thread); } if (dateTimeFormat->GetTimeStyle() != DateTimeStyleOption::UNDEFINED) { property = globalConst->GetHandledTimeStyleString(); hcValue = ToDateTimeStyleEcmaString(thread, dateTimeFormat->GetTimeStyle()); JSObject::CreateDataPropertyOrThrow(thread, options, property, hcValue); + RETURN_IF_ABRUPT_COMPLETION(thread); } } @@ -1270,6 +1272,7 @@ JSHandle JSDateTimeFormat::ConstructFDateIntervalToJSArray(JSThread *th element = JSLocale::PutElement(thread, part.index, array, ConvertFieldIdToDateType(thread, part.fField), JSHandle::Cast(substring)); } + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSArray, thread); JSHandle value = JSHandle::Cast( ToValueString(thread, TrackValue(part.fBeginIndex, part.fEndIndex, begin, end))); JSObject::SetProperty(thread, element, thread->GlobalConstants()->GetHandledSourceString(), value, true); diff --git a/ecmascript/js_for_in_iterator.cpp b/ecmascript/js_for_in_iterator.cpp index c7f4ac9843..91cc2c4186 100644 --- a/ecmascript/js_for_in_iterator.cpp +++ b/ecmascript/js_for_in_iterator.cpp @@ -65,6 +65,7 @@ bool JSForInIterator::HasProperty(JSThread *thread, JSHandle rece while (current->IsHeapObject()) { PropertyDescriptor desc(thread); bool has = JSTaggedValue::GetOwnProperty(thread, current, key, desc); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); if (has && desc.IsEnumerable()) { return true; } diff --git a/ecmascript/js_function.cpp b/ecmascript/js_function.cpp index 1991a5eb6d..12cae9fca6 100644 --- a/ecmascript/js_function.cpp +++ b/ecmascript/js_function.cpp @@ -169,7 +169,8 @@ JSTaggedValue JSFunction::NameGetter(JSThread *thread, const JSHandle JSHandle nameKey = globalConst->GetHandledNameString(); JSHandle boundName = thread->GlobalConstants()->GetHandledBoundString(); JSHandle targetName = JSObject::GetProperty(thread, target, nameKey).GetValue(); - + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + JSHandle handlePrefixString = JSTaggedValue::ToString(thread, boundName); JSHandle spaceString(globalConst->GetHandledSpaceString()); JSHandle concatString = factory->ConcatFromString(handlePrefixString, spaceString); diff --git a/ecmascript/js_iterator.cpp b/ecmascript/js_iterator.cpp index 2f5d422cb9..8620fc3457 100644 --- a/ecmascript/js_iterator.cpp +++ b/ecmascript/js_iterator.cpp @@ -63,9 +63,8 @@ JSHandle JSIterator::GetIterator(JSThread *thread, const JSHandle JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, method, obj, undefined, 0); JSTaggedValue ret = JSFunction::Call(info); + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); JSHandle iter(thread, ret); - // 4.ReturnIfAbrupt(iterator). - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, iter); // 5.If Type(iterator) is not Object, throw a TypeError exception if (!iter->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSIterator::GetIterator: iter is not object", undefined); @@ -86,6 +85,7 @@ JSHandle JSIterator::GetAsyncIterator(JSThread *thread, const JSH if (method->IsUndefined()) { JSHandle iteratorSymbol = env->GetIteratorSymbol(); JSHandle func = JSObject::GetMethod(thread, obj, iteratorSymbol); + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); JSHandle syncIterator = GetIterator(thread, obj, func); JSHandle nextStr = thread->GlobalConstants()->GetHandledNextString(); JSHandle nextMethod = JSTaggedValue::GetProperty(thread, syncIterator, nextStr).GetValue(); diff --git a/ecmascript/js_number_format.cpp b/ecmascript/js_number_format.cpp index 768ade5412..69da22ee6c 100644 --- a/ecmascript/js_number_format.cpp +++ b/ecmascript/js_number_format.cpp @@ -838,6 +838,7 @@ void GroupToParts(JSThread *thread, const icu::number::FormattedNumber &formatte JSHandle substring = intl::LocaleHelper::UStringToString(thread, formattedText, previousLimit, formattedText.length()); JSLocale::PutElement(thread, index, receiver, typeString, JSHandle::Cast(substring)); + RETURN_IF_ABRUPT_COMPLETION(thread); } } @@ -1056,5 +1057,6 @@ void JSNumberFormat::ResolvedOptions(JSThread *thread, const JSHandleGetSignDisplay(); JSHandle signDisplayString = OptionToEcmaString(thread, signDisplay); JSObject::CreateDataPropertyOrThrow(thread, options, property, signDisplayString); + RETURN_IF_ABRUPT_COMPLETION(thread); } } // namespace panda::ecmascript \ No newline at end of file diff --git a/ecmascript/js_plural_rules.cpp b/ecmascript/js_plural_rules.cpp index bbf14ec131..1c903ea28b 100644 --- a/ecmascript/js_plural_rules.cpp +++ b/ecmascript/js_plural_rules.cpp @@ -376,5 +376,6 @@ void JSPluralRules::ResolvedOptions(JSThread *thread, const JSHandleGetHandledPluralCategoriesString(); JSHandle jsPluralCategories = JSArray::CreateArrayFromList(thread, pluralCategories); JSObject::CreateDataPropertyOrThrow(thread, options, property, JSHandle::Cast(jsPluralCategories)); + RETURN_IF_ABRUPT_COMPLETION(thread); } } // namespace panda::ecmascript diff --git a/ecmascript/js_regexp_iterator.cpp b/ecmascript/js_regexp_iterator.cpp index 3bb00467af..2d635306b8 100644 --- a/ecmascript/js_regexp_iterator.cpp +++ b/ecmascript/js_regexp_iterator.cpp @@ -86,6 +86,7 @@ JSTaggedValue JSRegExpIterator::Next(EcmaRuntimeCallInfo *argv) JSHandle lastIndexString(globalConstants->GetHandledLastIndexString()); JSHandle getLastIndex(JSObject::GetProperty(thread, regexHandle, lastIndexString).GetValue()); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSTaggedNumber thisIndex = JSTaggedValue::ToLength(thread, getLastIndex); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); uint32_t nextIndex = BuiltinsRegExp::AdvanceStringIndex(inputStr, thisIndex.ToUint32(), diff --git a/ecmascript/napi/jsnapi_expo.cpp b/ecmascript/napi/jsnapi_expo.cpp index c85d6a73fd..80fd59934a 100644 --- a/ecmascript/napi/jsnapi_expo.cpp +++ b/ecmascript/napi/jsnapi_expo.cpp @@ -991,6 +991,7 @@ Local MapIteratorRef::New(const EcmaVM *vm, Local map) IterationKind iterKind = IterationKind::KEY_AND_VALUE; JSHandle mapIteratorKeyAndValue = JSMapIterator::CreateMapIterator(vm->GetJSThread(), JSHandle::Cast(jsMap), iterKind); + RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Undefined(vm)); return JSNApiHelper::ToLocal(mapIteratorKeyAndValue); } @@ -1010,6 +1011,7 @@ Local MapIteratorRef::Next(const EcmaVM *vm, ecmascript::EcmaRuntimeCa { CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); JSHandle nextTagValResult(vm->GetJSThread(), JSMapIterator::Next(ecmaRuntimeCallInfo)); + RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Undefined(vm)); JSHandle iteratorVal(vm->GetJSThread(), JSIterator::IteratorValue(vm->GetJSThread(), nextTagValResult).GetTaggedValue()); return JSNApiHelper::ToLocal(iteratorVal); @@ -1053,6 +1055,7 @@ Local SetIteratorRef::New(const EcmaVM *vm, Local set) IterationKind iterKind = IterationKind::KEY_AND_VALUE; JSHandle setIteratorKeyAndValue = JSSetIterator::CreateSetIterator(vm->GetJSThread(), JSHandle::Cast(jsSet), iterKind); + RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Undefined(vm)); return JSNApiHelper::ToLocal(setIteratorKeyAndValue); } @@ -1072,6 +1075,7 @@ Local SetIteratorRef::Next(const EcmaVM *vm, ecmascript::EcmaRuntimeCa { CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); JSHandle nextTagValResult(vm->GetJSThread(), JSSetIterator::Next(ecmaRuntimeCallInfo)); + RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Undefined(vm)); JSHandle iteratorVal(vm->GetJSThread(), JSIterator::IteratorValue(vm->GetJSThread(), nextTagValResult).GetTaggedValue()); return JSNApiHelper::ToLocal(iteratorVal); @@ -1180,6 +1184,7 @@ Local PromiseCapabilityRef::New(const EcmaVM *vm) JSHandle globalEnv = vm->GetGlobalEnv(); JSHandle constructor(globalEnv->GetPromiseFunction()); JSHandle capability(JSPromise::NewPromiseCapability(thread, constructor)); + RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Undefined(vm)); return JSNApiHelper::ToLocal(capability); } diff --git a/ecmascript/object_factory.cpp b/ecmascript/object_factory.cpp index de7f6c12f5..aed9ed9554 100644 --- a/ecmascript/object_factory.cpp +++ b/ecmascript/object_factory.cpp @@ -917,6 +917,7 @@ JSHandle ObjectFactory::NewJSError(const ErrorType &errorType, const J JSHandle nativePrototype(thread_, nativeFunc->GetFunctionPrototype()); JSHandle ctorKey = globalConst->GetHandledConstructorString(); JSHandle ctor(JSTaggedValue::GetProperty(thread_, nativePrototype, ctorKey).GetValue()); + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSObject, thread_); JSHandle undefined = thread_->GlobalConstants()->GetHandledUndefined(); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread_, ctor, nativePrototype, undefined, 1, needCheckStack); diff --git a/ecmascript/object_fast_operator-inl.h b/ecmascript/object_fast_operator-inl.h index e8ab658b71..d2818f3309 100644 --- a/ecmascript/object_fast_operator-inl.h +++ b/ecmascript/object_fast_operator-inl.h @@ -559,6 +559,7 @@ JSTaggedValue ObjectFastOperator::FastGetPropertyByIndex(JSThread *thread, JSTag { INTERPRETER_TRACE(thread, FastGetPropertyByIndex); JSTaggedValue result = ObjectFastOperator::GetPropertyByIndex(thread, receiver, index); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (result.IsHole()) { return JSTaggedValue::GetProperty(thread, JSHandle(thread, receiver), index).GetValue().GetTaggedValue(); diff --git a/ecmascript/object_operator.cpp b/ecmascript/object_operator.cpp index 803b251ce0..f3ccc68e2d 100644 --- a/ecmascript/object_operator.cpp +++ b/ecmascript/object_operator.cpp @@ -82,6 +82,7 @@ void ObjectOperator::HandleKey(const JSHandle &key) } JSHandle keyHandle(thread_, JSTaggedValue::ToPrimitive(thread_, key, PREFER_STRING)); + RETURN_IF_ABRUPT_COMPLETION(thread_); if (key->IsSymbol()) { key_ = keyHandle; return; @@ -641,6 +642,7 @@ bool ObjectOperator::UpdateDataValue(const JSHandle &receiver, const J JSType jsType = holder.GetTaggedObject()->GetClass()->GetObjectType(); JSTaggedValue typedArrayProperty = JSTypedArray::FastSetPropertyByIndex(thread_, receiver.GetTaggedValue(), GetIndex(), value.GetTaggedValue(), jsType); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); if (typedArrayProperty.IsHole()) { return false; } @@ -924,6 +926,7 @@ void ObjectOperator::LookupElementInlinedProps(const JSHandle &obj) if (obj->IsTypedArray()) { JSTaggedValue val = JSTypedArray::FastElementGet(thread_, JSHandle::Cast(obj), elementIndex_).GetValue().GetTaggedValue(); + RETURN_IF_ABRUPT_COMPLETION(thread_); if (!val.IsHole()) { SetFound(elementIndex_, val, PropertyAttributes::GetDefaultAttributes(), true); } diff --git a/ecmascript/stubs/runtime_stubs-inl.h b/ecmascript/stubs/runtime_stubs-inl.h index 67675bbfd9..77a34fce12 100644 --- a/ecmascript/stubs/runtime_stubs-inl.h +++ b/ecmascript/stubs/runtime_stubs-inl.h @@ -494,6 +494,7 @@ JSTaggedValue RuntimeStubs::RuntimeStArraySpread(JSThread *thread, const JSHandl break; } bool success = JSTaggedValue::GetOwnProperty(thread, iterResult, valueStr, desc); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (success && desc.IsEnumerable()) { JSTaggedValue::DefineOwnProperty(thread, dst, indexHandle, desc); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -2389,6 +2390,7 @@ JSTaggedValue RuntimeStubs::RuntimeGetCallSpreadArgs(JSThread *thread, const JSH ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle argv = factory->NewTaggedArray(argvMayMaxLength); JSHandle itor = JSIterator::GetIterator(thread, jsArray); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Fast path when array is stablearray and Iterator not change. if (jsArray->IsStableJSArray(thread) && itor->IsJSArrayIterator()) { @@ -3031,6 +3033,7 @@ JSTaggedValue RuntimeStubs::RuntimeDefinePrivateProperty(JSThread *thread, JSTag } bool result = JSObject::CreateDataPropertyOrThrow(thread, JSHandle::Cast(handleObj), handleKey, handleValue); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!extensible) { handleObj->GetTaggedObject()->GetClass()->SetExtensible(false); } diff --git a/ecmascript/stubs/runtime_stubs.cpp b/ecmascript/stubs/runtime_stubs.cpp index 952388d48c..1575e31bc0 100644 --- a/ecmascript/stubs/runtime_stubs.cpp +++ b/ecmascript/stubs/runtime_stubs.cpp @@ -2489,6 +2489,7 @@ DEF_RUNTIME_STUBS(VerifyVTableLoading) JSHandle typedPathValue = GetHArg(argv, argc, 2); // 2: means the second parameter JSHandle verifiedPathValue = JSTaggedValue::GetProperty(thread, receiver, key).GetValue(); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData()); if (UNLIKELY(!JSTaggedValue::SameValue(typedPathValue, verifiedPathValue))) { std::ostringstream oss; receiver->Dump(oss); @@ -2516,6 +2517,7 @@ DEF_RUNTIME_STUBS(VerifyVTableStoring) JSHandle storeValue = GetHArg(argv, argc, 2); // 2: means the second parameter JSHandle verifiedValue = JSTaggedValue::GetProperty(thread, receiver, key).GetValue(); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData()); if (UNLIKELY(!JSTaggedValue::SameValue(storeValue, verifiedValue))) { std::ostringstream oss; receiver->Dump(oss); @@ -2541,6 +2543,7 @@ DEF_RUNTIME_STUBS(JSObjectGetMethod) JSHandle obj(thread, GetArg(argv, argc, 0)); JSHandle key(thread, GetArg(argv, argc, 1)); JSHandle result = JSObject::GetMethod(thread, obj, key); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData()); return result->GetRawData(); } diff --git a/ecmascript/template_string.cpp b/ecmascript/template_string.cpp index 8b8271003c..901a45bd68 100644 --- a/ecmascript/template_string.cpp +++ b/ecmascript/template_string.cpp @@ -28,6 +28,7 @@ JSHandle TemplateString::GetTemplateObject(JSThread *thread, JSHa { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle rawStringsTag = JSObject::GetProperty(thread, templateLiteral, 0).GetValue(); + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); JSHandle templateMapTag = env->GetTemplateMap(); JSHandle templateMap(templateMapTag); int32_t element = templateMap->FindEntry(rawStringsTag.GetTaggedValue()); @@ -35,6 +36,7 @@ JSHandle TemplateString::GetTemplateObject(JSThread *thread, JSHa return JSHandle(thread, templateMap->GetValue(element)); } JSHandle cookedStringsTag = JSObject::GetProperty(thread, templateLiteral, 1).GetValue(); + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); JSHandle cookedStrings(cookedStringsTag); uint32_t count = cookedStrings->GetArrayLength(); auto countNum = JSTaggedNumber(count); @@ -46,9 +48,11 @@ JSHandle TemplateString::GetTemplateObject(JSThread *thread, JSHa JSHandle rawObj(rawArr); for (uint32_t i = 0; i < count; i++) { JSHandle cookedValue = JSObject::GetProperty(thread, cookedStringsTag, i).GetValue(); + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); PropertyDescriptor descCooked(thread, cookedValue, true, false, false); JSArray::DefineOwnProperty(thread, templateObj, i, descCooked); JSHandle rawValue = JSObject::GetProperty(thread, rawStringsTag, i).GetValue(); + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); PropertyDescriptor descRaw(thread, rawValue, true, false, false); JSArray::DefineOwnProperty(thread, rawObj, i, descRaw); }