From e5673ac4b0bb3a4fdf16656203f862ff7ceb8ce5 Mon Sep 17 00:00:00 2001 From: Artem Udovichenko Date: Fri, 18 Nov 2022 13:24:12 +0300 Subject: [PATCH 1/2] Use handles in FastRuntimeStub * FastRuntimeStub::(Set|Get)PropertyByXXX methods accept handles now * Implement JSPrimitiveHandle to get handle for a primitive value * Remove all CSA suppressions from fast_runtime_stub-inl.h Change-Id: I2d24621df47068762823b911311d7e958ac65c7c --- runtime/CMakeLists.txt | 1 + runtime/base/json_parser.h | 13 +- runtime/base/json_stringifier.cpp | 9 +- runtime/builtins/builtins_array.cpp | 22 +- runtime/builtins/builtins_global.cpp | 6 +- runtime/builtins/builtins_object.cpp | 7 +- runtime/builtins/builtins_regexp.cpp | 103 ++++----- runtime/containers/containers_private.cpp | 2 +- runtime/ic/ic_runtime_stub-inl.h | 7 +- runtime/interpreter/fast_runtime_stub-inl.h | 222 ++++++++------------ runtime/interpreter/fast_runtime_stub.h | 50 +++-- runtime/intrinsics-inl.h | 123 ++++++----- runtime/js_array.cpp | 9 +- runtime/js_handle.cpp | 27 +++ runtime/js_handle.h | 57 ++++- runtime/js_object.cpp | 8 +- runtime/js_regexp_iterator.cpp | 6 +- subproject_sources.gn | 1 + 18 files changed, 343 insertions(+), 330 deletions(-) create mode 100644 runtime/js_handle.cpp diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 8542c2b1d..63053e197 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -183,6 +183,7 @@ set(ECMASCRIPT_SOURCES ${ECMA_SRC_DIR}/vmstat/runtime_stat.cpp ${ECMA_SRC_DIR}/weak_vector.cpp ${ECMA_SRC_DIR}/class_info_extractor.cpp + ${ECMA_SRC_DIR}/js_handle.cpp ${ECMA_SRC_DIR}/compiler/ecmascript_runtime_interface.cpp ${BUILTIN_BRIDGE_SOURCE} diff --git a/runtime/base/json_parser.h b/runtime/base/json_parser.h index edbe03dbb..0ebc208ff 100644 --- a/runtime/base/json_parser.h +++ b/runtime/base/json_parser.h @@ -311,12 +311,12 @@ private: return arr.GetTaggedValue(); } - JSTaggedValue value; + JSMutableHandle value(thread_, JSTaggedValue::Undefined()); uint32_t index = 0; while (current_ <= range_) { - value = ParseJSONText(); + value.Update(ParseJSONText()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_); - FastRuntimeStub::SetPropertyByIndex(thread_, arr.GetTaggedValue(), index++, value); + FastRuntimeStub::SetPropertyByIndex(thread_, JSHandle(arr), index++, value); GetNextNonSpaceChar(); if (*current_ == ',') { current_++; @@ -345,7 +345,7 @@ private: } JSMutableHandle keyHandle(thread_, JSTaggedValue::Undefined()); - JSTaggedValue value; + JSMutableHandle value(thread_, JSTaggedValue::Undefined()); while (current_ <= range_) { SkipStartWhiteSpace(); if (*current_ == '"') { @@ -362,9 +362,8 @@ private: } else { THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected Object in JSON", JSTaggedValue::Exception()); } - value = ParseJSONText(); - FastRuntimeStub::SetPropertyByValue(thread_, result.GetTaggedValue(), keyHandle.GetTaggedValue(), - value); + value.Update(ParseJSONText()); + FastRuntimeStub::SetPropertyByValue(thread_, JSHandle(result), keyHandle, value); GetNextNonSpaceChar(); if (*current_ == ',') { current_++; diff --git a/runtime/base/json_stringifier.cpp b/runtime/base/json_stringifier.cpp index 71bf9371e..6423731ba 100644 --- a/runtime/base/json_stringifier.cpp +++ b/runtime/base/json_stringifier.cpp @@ -169,7 +169,7 @@ JSHandle JsonStringifier::Stringify(const JSHandle // Repeat while k & if (value->IsECMAObject()) { // a. Let toJSON be Get(value, "toJSON"). JSHandle toJson = thread_->GlobalConstants()->GetHandledToJsonString(); - JSHandle toJsonFun( - thread_, FastRuntimeStub::FastGetPropertyByValue(thread_, tagValue, toJson.GetTaggedValue())); + JSHandle toJsonFun(thread_, FastRuntimeStub::FastGetPropertyByValue(thread_, value, toJson)); // b. ReturnIfAbrupt(toJSON). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_); // Reread tagValue because GC may move it in FastRuntimeStub::FastGetPropertyByValue @@ -477,7 +476,7 @@ bool JsonStringifier::SerializeJSONObject(const JSHandle &value, uint32_t propLen = propList_.size(); for (uint32_t i = 0; i < propLen; i++) { JSTaggedValue tagVal = - FastRuntimeStub::FastGetPropertyByValue(thread_, obj.GetTaggedValue(), propList_[i].GetTaggedValue()); + FastRuntimeStub::FastGetPropertyByValue(thread_, JSHandle(obj), propList_[i]); handleValue_.Update(tagVal); JSTaggedValue serializeValue = GetSerializeValue(value, propList_[i], handleValue_, replacer); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); @@ -576,7 +575,7 @@ bool JsonStringifier::SerializeJSArray(const JSHandle &value, con uint32_t len = jsArr->GetArrayLength(); if (len > 0) { for (uint32_t i = 0; i < len; i++) { - JSTaggedValue tagVal = FastRuntimeStub::FastGetPropertyByIndex(thread_, value.GetTaggedValue(), i); + JSTaggedValue tagVal = FastRuntimeStub::FastGetPropertyByIndex(thread_, value, i); if (UNLIKELY(tagVal.IsAccessor())) { tagVal = JSObject::CallGetter(thread_, AccessorData::Cast(tagVal.GetTaggedObject()), value); } diff --git a/runtime/builtins/builtins_array.cpp b/runtime/builtins/builtins_array.cpp index 841f16340..91645134c 100644 --- a/runtime/builtins/builtins_array.cpp +++ b/runtime/builtins/builtins_array.cpp @@ -2346,9 +2346,9 @@ JSTaggedValue BuiltinsArray::Sort(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let obj be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, GetThis(argv)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + JSHandle thisHandle = JSHandle(thisObjHandle); JSHandle callbackFnHandle = GetCallArg(argv, 0); if (!callbackFnHandle->IsUndefined() && !callbackFnHandle->IsCallable()) { @@ -2356,7 +2356,7 @@ JSTaggedValue BuiltinsArray::Sort(EcmaRuntimeCallInfo *argv) } // 2. Let len be ToLength(Get(obj, "length")). - double len = ArrayHelper::GetArrayLength(thread, JSHandle(thisObjHandle)); + double len = ArrayHelper::GetArrayLength(thread, thisHandle); // 3. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -2366,12 +2366,11 @@ JSTaggedValue BuiltinsArray::Sort(EcmaRuntimeCallInfo *argv) for (int i = 1; i < len; i++) { int beginIndex = 0; int endIndex = i; - presentValue.Update(FastRuntimeStub::FastGetPropertyByIndex(thread, thisObjHandle.GetTaggedValue(), i)); + presentValue.Update(FastRuntimeStub::FastGetPropertyByIndex(thread, thisHandle, i)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); while (beginIndex < endIndex) { int middleIndex = (beginIndex + endIndex) / 2; // 2 : half - middleValue.Update( - FastRuntimeStub::FastGetPropertyByIndex(thread, thisObjHandle.GetTaggedValue(), middleIndex)); + middleValue.Update(FastRuntimeStub::FastGetPropertyByIndex(thread, thisHandle, middleIndex)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); int32_t compareResult = ArrayHelper::SortCompare(thread, callbackFnHandle, middleValue, presentValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -2384,20 +2383,17 @@ JSTaggedValue BuiltinsArray::Sort(EcmaRuntimeCallInfo *argv) if (endIndex >= 0 && endIndex < i) { for (int j = i; j > endIndex; j--) { - previousValue.Update( - FastRuntimeStub::FastGetPropertyByIndex(thread, thisObjHandle.GetTaggedValue(), j - 1)); + previousValue.Update(FastRuntimeStub::FastGetPropertyByIndex(thread, thisHandle, j - 1)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - FastRuntimeStub::FastSetPropertyByIndex(thread, thisObjHandle.GetTaggedValue(), j, - previousValue.GetTaggedValue()); + FastRuntimeStub::FastSetPropertyByIndex(thread, thisHandle, j, previousValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - FastRuntimeStub::FastSetPropertyByIndex(thread, thisObjHandle.GetTaggedValue(), endIndex, - presentValue.GetTaggedValue()); + FastRuntimeStub::FastSetPropertyByIndex(thread, thisHandle, endIndex, presentValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } } - return thisObjHandle.GetTaggedValue(); + return thisHandle.GetTaggedValue(); } // 22.1.3.25 Array.prototype.splice (start, deleteCount , ...items ) diff --git a/runtime/builtins/builtins_global.cpp b/runtime/builtins/builtins_global.cpp index 295e30eb1..84740f987 100644 --- a/runtime/builtins/builtins_global.cpp +++ b/runtime/builtins/builtins_global.cpp @@ -917,8 +917,10 @@ JSTaggedValue BuiltinsGlobal::GetMarkQueue(EcmaRuntimeCallInfo *msg) JSHandle array = vm->GetFactory()->NewJSArray(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); size_t index = 0; - vm->IterateOverMarkQueue([&index, &array, thread](ObjectHeader *obj) { - FastRuntimeStub::SetPropertyByIndex(thread, array.GetTaggedValue(), index++, JSTaggedValue(obj)); + JSMutableHandle objHandle(thread, JSTaggedValue::Undefined()); + vm->IterateOverMarkQueue([&index, &array, thread, &objHandle](ObjectHeader *obj) { + objHandle.Update(JSTaggedValue(obj)); + FastRuntimeStub::SetPropertyByIndex(thread, JSHandle(array), index++, objHandle); }); return array.GetTaggedValue(); } diff --git a/runtime/builtins/builtins_object.cpp b/runtime/builtins/builtins_object.cpp index b193d8a0c..0ef7df546 100644 --- a/runtime/builtins/builtins_object.cpp +++ b/runtime/builtins/builtins_object.cpp @@ -83,6 +83,7 @@ JSTaggedValue BuiltinsObject::Assign(EcmaRuntimeCallInfo *argv) // ii.Let keys be from.[[OwnPropertyKeys]](). // iii.ReturnIfAbrupt(keys). JSMutableHandle key(thread, JSTaggedValue::Undefined()); + JSMutableHandle value(thread, JSTaggedValue::Undefined()); for (uint32_t i = 1; i < numArgs; i++) { JSHandle source = GetCallArg(argv, i); if (!source->IsNull() && !source->IsUndefined()) { @@ -110,13 +111,11 @@ JSTaggedValue BuiltinsObject::Assign(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (success && desc.IsEnumerable()) { - JSTaggedValue value = - FastRuntimeStub::FastGetPropertyByValue(thread, from.GetTaggedValue(), key.GetTaggedValue()); + value.Update(FastRuntimeStub::FastGetPropertyByValue(thread, JSHandle(from), key)); // ReturnIfAbrupt(prop_value) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - FastRuntimeStub::FastSetPropertyByValue(thread, toAssign.GetTaggedValue(), key.GetTaggedValue(), - value); + FastRuntimeStub::FastSetPropertyByValue(thread, JSHandle(toAssign), key, value); // ReturnIfAbrupt(status) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } diff --git a/runtime/builtins/builtins_regexp.cpp b/runtime/builtins/builtins_regexp.cpp index 6537673c0..8ed81912f 100644 --- a/runtime/builtins/builtins_regexp.cpp +++ b/runtime/builtins/builtins_regexp.cpp @@ -63,8 +63,8 @@ JSTaggedValue BuiltinsRegExp::RegExpConstructor(EcmaRuntimeCallInfo *argv) // 4.b If patternIsRegExp is true and flags is undefined if (patternIsRegExp && flags->IsUndefined()) { // 4.b.i Let patternConstructor be Get(pattern, "constructor"). - JSTaggedValue patternConstructor = FastRuntimeStub::FastGetPropertyByValue( - thread, pattern.GetTaggedValue(), constructorString.GetTaggedValue()); + JSTaggedValue patternConstructor = + FastRuntimeStub::FastGetPropertyByValue(thread, pattern, constructorString); // 4.b.ii ReturnIfAbrupt(patternConstructor). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4.b.iii If SameValue(new_target, patternConstructor) is true, return pattern. @@ -434,8 +434,7 @@ JSTaggedValue BuiltinsRegExp::Match(EcmaRuntimeCallInfo *argv) // 5. Let global be ToBoolean(Get(rx, "global")). JSHandle global = globalConst->GetHandledGlobalString(); - JSTaggedValue globalValue = - FastRuntimeStub::FastGetPropertyByValue(thread, thisObj.GetTaggedValue(), global.GetTaggedValue()); + JSTaggedValue globalValue = FastRuntimeStub::FastGetPropertyByValue(thread, thisObj, global); // 6. ReturnIfAbrupt(global). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -472,16 +471,15 @@ JSTaggedValue BuiltinsRegExp::Match(EcmaRuntimeCallInfo *argv) // 8. Else global is true // a. Let fullUnicode be ToBoolean(Get(rx, "unicode")). JSHandle unicode = globalConst->GetHandledUnicodeString(); - JSTaggedValue uincodeValue = - FastRuntimeStub::FastGetPropertyByValue(thread, thisObj.GetTaggedValue(), unicode.GetTaggedValue()); + JSTaggedValue uincodeValue = FastRuntimeStub::FastGetPropertyByValue(thread, thisObj, unicode); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); bool fullUnicode = uincodeValue.ToBoolean(); // b. ReturnIfAbrupt(fullUnicode) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // c. Let setStatus be Set(rx, "lastIndex", 0, true). JSHandle lastIndexString(globalConst->GetHandledLastIndexString()); - FastRuntimeStub::FastSetPropertyByValue(thread, thisObj.GetTaggedValue(), lastIndexString.GetTaggedValue(), - JSTaggedValue(0)); + FastRuntimeStub::FastSetPropertyByValue(thread, JSHandle(thisObj), lastIndexString, + JSPrimitiveHandle::Zero()); // d. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // e. Let A be ArrayCreate(0). @@ -513,8 +511,7 @@ JSTaggedValue BuiltinsRegExp::Match(EcmaRuntimeCallInfo *argv) // iv. Else result is not null, // 1. Let matchStr be ToString(Get(result, "0")). JSHandle zeroString = globalConst->GetHandledZeroString(); - JSTaggedValue matchVal = - FastRuntimeStub::FastGetPropertyByValue(thread, result.GetTaggedValue(), zeroString.GetTaggedValue()); + JSTaggedValue matchVal = FastRuntimeStub::FastGetPropertyByValue(thread, result, zeroString); JSHandle matchStr(thread, matchVal); JSHandle matchString = JSTaggedValue::ToString(thread, matchStr); // 2. ReturnIfAbrupt(matchStr). @@ -525,8 +522,7 @@ JSTaggedValue BuiltinsRegExp::Match(EcmaRuntimeCallInfo *argv) // 5. If matchStr is the empty String, then if (JSTaggedValue::ToString(thread, matchValue)->GetLength() == 0) { // a. Let thisIndex be ToLength(Get(rx, "lastIndex")). - JSTaggedValue lastIndex = FastRuntimeStub::FastGetPropertyByValue(thread, thisObj.GetTaggedValue(), - lastIndexString.GetTaggedValue()); + JSTaggedValue lastIndex = FastRuntimeStub::FastGetPropertyByValue(thread, thisObj, lastIndexString); JSHandle lastIndexHandle(thread, lastIndex); JSTaggedNumber thisIndex = JSTaggedValue::ToLength(thread, lastIndexHandle); // b. ReturnIfAbrupt(thisIndex). @@ -534,8 +530,8 @@ JSTaggedValue BuiltinsRegExp::Match(EcmaRuntimeCallInfo *argv) // c. Let nextIndex be AdvanceStringIndex(S, thisIndex, fullUnicode). // d. Let setStatus be Set(rx, "lastIndex", nextIndex, true). auto nextIndex = JSTaggedValue(AdvanceStringIndex(string, thisIndex.GetNumber(), fullUnicode)); - FastRuntimeStub::FastSetPropertyByValue(thread, thisObj.GetTaggedValue(), lastIndexString.GetTaggedValue(), - nextIndex); + FastRuntimeStub::FastSetPropertyByValue(thread, JSHandle(thisObj), lastIndexString, + JSPrimitiveHandle(&nextIndex)); // e. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } @@ -593,8 +589,7 @@ JSTaggedValue BuiltinsRegExp::MatchAll(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 8. Perform ? Set(matcher, "lastIndex", lastIndex, true). - FastRuntimeStub::FastSetPropertyByValue(thread, matcherHandle.GetTaggedValue(), lastIndexString.GetTaggedValue(), - thisLastIndex); + FastRuntimeStub::FastSetPropertyByValue(thread, matcherHandle, lastIndexString, JSPrimitiveHandle(&thisLastIndex)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 9. If flags contains "g", let global be true. @@ -637,8 +632,7 @@ JSTaggedValue BuiltinsRegExp::RegExpReplaceFast(JSThread *thread, JSHandle(thisIndex.GetInt()); } else { @@ -703,8 +697,8 @@ JSTaggedValue BuiltinsRegExp::RegExpReplaceFast(JSThread *thread, JSHandle(regexp), lastIndexHandle, + JSPrimitiveHandle::Zero()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } break; @@ -718,8 +712,9 @@ JSTaggedValue BuiltinsRegExp::RegExpReplaceFast(JSThread *thread, JSHandle(regexp), lastIndexHandle, + JSPrimitiveHandle(&lastIndexValue)); // b. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); break; @@ -776,8 +771,7 @@ JSTaggedValue BuiltinsRegExp::Replace(EcmaRuntimeCallInfo *argv) // 8. Let global be ToBoolean(Get(rx, "global")). ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle global = globalConst->GetHandledGlobalString(); - JSTaggedValue globalValue = - FastRuntimeStub::FastGetPropertyByValue(thread, thisObj.GetTaggedValue(), global.GetTaggedValue()); + JSTaggedValue globalValue = FastRuntimeStub::FastGetPropertyByValue(thread, thisObj, global); // 9. ReturnIfAbrupt(global). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); bool isGlobal = globalValue.ToBoolean(); @@ -787,15 +781,13 @@ JSTaggedValue BuiltinsRegExp::Replace(EcmaRuntimeCallInfo *argv) if (isGlobal) { // a. Let fullUnicode be ToBoolean(Get(rx, "unicode")). JSHandle unicode = globalConst->GetHandledUnicodeString(); - JSTaggedValue fullUnicodeTag = - FastRuntimeStub::FastGetPropertyByValue(thread, thisObj.GetTaggedValue(), unicode.GetTaggedValue()); + JSTaggedValue fullUnicodeTag = FastRuntimeStub::FastGetPropertyByValue(thread, thisObj, unicode); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); fullUnicode = fullUnicodeTag.ToBoolean(); // b. ReturnIfAbrupt(fullUnicode). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // c. Let setStatus be Set(rx, "lastIndex", 0, true). - FastRuntimeStub::FastSetPropertyByValue(thread, thisObj.GetTaggedValue(), lastIndex.GetTaggedValue(), - JSTaggedValue(0)); + FastRuntimeStub::FastSetPropertyByValue(thread, thisObj, lastIndex, JSPrimitiveHandle::Zero()); // d. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } @@ -863,8 +855,7 @@ JSTaggedValue BuiltinsRegExp::Replace(EcmaRuntimeCallInfo *argv) break; } // iii. Else, 1. Let matchStr be ToString(Get(result, "0")). - JSTaggedValue getMatchVal = - FastRuntimeStub::FastGetPropertyByValue(thread, execResult.GetTaggedValue(), matchedStr.GetTaggedValue()); + JSTaggedValue getMatchVal = FastRuntimeStub::FastGetPropertyByValue(thread, execResult, matchedStr); JSHandle getMatch(thread, getMatchVal); JSHandle matchString = JSTaggedValue::ToString(thread, getMatch); // 2. ReturnIfAbrupt(matchStr). @@ -872,8 +863,7 @@ JSTaggedValue BuiltinsRegExp::Replace(EcmaRuntimeCallInfo *argv) // 3. If matchStr is the empty String, then if (matchString->GetLength() == 0) { // a. Let thisIndex be ToLength(Get(rx, "lastIndex")). - JSTaggedValue thisIndexVal = - FastRuntimeStub::FastGetPropertyByValue(thread, thisObj.GetTaggedValue(), lastIndex.GetTaggedValue()); + JSTaggedValue thisIndexVal = FastRuntimeStub::FastGetPropertyByValue(thread, thisObj, lastIndex); JSHandle thisIndexHandle(thread, thisIndexVal); uint32_t thisIndex = 0; if (thisIndexHandle->IsInt()) { @@ -888,8 +878,7 @@ JSTaggedValue BuiltinsRegExp::Replace(EcmaRuntimeCallInfo *argv) uint32_t nextIndex = AdvanceStringIndex(inputStr, thisIndex, fullUnicode); nextIndexHandle.Update(JSTaggedValue(nextIndex)); // d. Let setStatus be Set(rx, "lastIndex", nextIndex, true). - FastRuntimeStub::FastSetPropertyByValue(thread, thisObj.GetTaggedValue(), lastIndex.GetTaggedValue(), - nextIndexHandle.GetTaggedValue()); + FastRuntimeStub::FastSetPropertyByValue(thread, thisObj, lastIndex, nextIndexHandle); // e. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } @@ -904,18 +893,17 @@ JSTaggedValue BuiltinsRegExp::Replace(EcmaRuntimeCallInfo *argv) JSMutableHandle capN(thread, JSTaggedValue(0)); // 16. Repeat, for each result in results, for (int i = 0; i < resultsIndex; i++) { - resultValues.Update(FastRuntimeStub::FastGetPropertyByIndex(thread, resultsList.GetTaggedValue(), i)); + resultValues.Update(FastRuntimeStub::FastGetPropertyByIndex(thread, JSHandle(resultsList), i)); // a. Let nCaptures be ToLength(Get(result, "length")). JSHandle lengthHandle = globalConst->GetHandledLengthString(); - ncapturesHandle.Update(FastRuntimeStub::FastGetPropertyByValue(thread, resultValues.GetTaggedValue(), - lengthHandle.GetTaggedValue())); + ncapturesHandle.Update(FastRuntimeStub::FastGetPropertyByValue(thread, resultValues, lengthHandle)); uint32_t ncaptures = JSTaggedValue::ToUint32(thread, ncapturesHandle); // b. ReturnIfAbrupt(nCaptures). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // c. Let nCaptures be max(nCaptures − 1, 0). ncaptures = std::max((ncaptures - 1), 0); // d. Let matched be ToString(Get(result, "0")). - JSTaggedValue value = FastRuntimeStub::GetPropertyByIndex(thread, resultValues.GetTaggedValue(), 0); + JSTaggedValue value = FastRuntimeStub::GetPropertyByIndex(thread, resultValues, 0); getMatchString = JSHandle(thread, value); JSHandle matchString = JSTaggedValue::ToString(thread, getMatchString); // e. ReturnIfAbrupt(matched). @@ -924,8 +912,7 @@ JSTaggedValue BuiltinsRegExp::Replace(EcmaRuntimeCallInfo *argv) uint32_t matchLength = matchString->GetLength(); // g. Let position be ToInteger(Get(result, "index")). JSHandle resultIndex = globalConst->GetHandledIndexString(); - JSTaggedValue positionTag = FastRuntimeStub::FastGetPropertyByValue(thread, resultValues.GetTaggedValue(), - resultIndex.GetTaggedValue()); + JSTaggedValue positionTag = FastRuntimeStub::FastGetPropertyByValue(thread, resultValues, resultIndex); JSHandle positionHandle(thread, positionTag); uint32_t position = 0; if (positionHandle->IsInt()) { @@ -944,7 +931,7 @@ JSTaggedValue BuiltinsRegExp::Replace(EcmaRuntimeCallInfo *argv) // l. Repeat while n ≤ nCaptures while (index <= ncaptures) { // i. Let capN be Get(result, ToString(n)). - capN.Update(FastRuntimeStub::FastGetPropertyByIndex(thread, resultValues.GetTaggedValue(), index)); + capN.Update(FastRuntimeStub::FastGetPropertyByIndex(thread, resultValues, index)); // ii. ReturnIfAbrupt(capN). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // iii. If capN is not undefined, then @@ -965,8 +952,7 @@ JSTaggedValue BuiltinsRegExp::Replace(EcmaRuntimeCallInfo *argv) // j. Let namedCaptures be ? Get(result, "groups"). JSHandle groupsKey = globalConst->GetHandledGroupsString(); - JSTaggedValue named = - FastRuntimeStub::FastGetPropertyByValue(thread, resultValues.GetTaggedValue(), groupsKey.GetTaggedValue()); + JSTaggedValue named = FastRuntimeStub::FastGetPropertyByValue(thread, resultValues, groupsKey); JSHandle namedCaptures(thread, named); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // m. If functionalReplace is true, then @@ -1425,8 +1411,7 @@ JSTaggedValue BuiltinsRegExp::RegExpBuiltinExec(JSThread *thread, const JSHandle const GlobalEnvConstants *globalConst = thread->GlobalConstants(); JSHandle lastIndexHandle = globalConst->GetHandledLastIndexString(); - JSTaggedValue result = - FastRuntimeStub::FastGetPropertyByValue(thread, regexp.GetTaggedValue(), lastIndexHandle.GetTaggedValue()); + JSTaggedValue result = FastRuntimeStub::FastGetPropertyByValue(thread, regexp, lastIndexHandle); int32_t lastIndex = 0; if (result.IsInt()) { lastIndex = result.GetInt(); @@ -1438,14 +1423,10 @@ JSTaggedValue BuiltinsRegExp::RegExpBuiltinExec(JSThread *thread, const JSHandle } JSHandle globalHandle = globalConst->GetHandledGlobalString(); - bool global = - FastRuntimeStub::FastGetPropertyByValue(thread, regexp.GetTaggedValue(), globalHandle.GetTaggedValue()) - .ToBoolean(); + bool global = FastRuntimeStub::FastGetPropertyByValue(thread, regexp, globalHandle).ToBoolean(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle stickyHandle = globalConst->GetHandledStickyString(); - bool sticky = - FastRuntimeStub::FastGetPropertyByValue(thread, regexp.GetTaggedValue(), stickyHandle.GetTaggedValue()) - .ToBoolean(); + bool sticky = FastRuntimeStub::FastGetPropertyByValue(thread, regexp, stickyHandle).ToBoolean(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!global && !sticky) { lastIndex = 0; @@ -1458,8 +1439,7 @@ JSTaggedValue BuiltinsRegExp::RegExpBuiltinExec(JSThread *thread, const JSHandle JSHandle cacheTable(thread->GetEcmaVM()->GetRegExpCache()); uint32_t length = static_cast(inputStr->GetTaggedObject())->GetLength(); if (lastIndex > static_cast(length)) { - FastRuntimeStub::FastSetPropertyByValue(thread, regexp.GetTaggedValue(), lastIndexHandle.GetTaggedValue(), - JSTaggedValue(0)); + FastRuntimeStub::FastSetPropertyByValue(thread, regexp, lastIndexHandle, JSPrimitiveHandle::Zero()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return JSTaggedValue::Null(); } @@ -1482,8 +1462,7 @@ JSTaggedValue BuiltinsRegExp::RegExpBuiltinExec(JSThread *thread, const JSHandle if (!matchResult.isSuccess_) { if (global || sticky) { JSHandle lastIndexValue(thread, JSTaggedValue(0)); - FastRuntimeStub::FastSetPropertyByValue(thread, regexp.GetTaggedValue(), lastIndexHandle.GetTaggedValue(), - JSTaggedValue(0)); + FastRuntimeStub::FastSetPropertyByValue(thread, regexp, lastIndexHandle, JSPrimitiveHandle::Zero()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } return JSTaggedValue::Null(); @@ -1491,8 +1470,8 @@ JSTaggedValue BuiltinsRegExp::RegExpBuiltinExec(JSThread *thread, const JSHandle uint32_t endIndex = matchResult.endIndex_; if (global || sticky) { // a. Let setStatus be Set(R, "lastIndex", e, true). - FastRuntimeStub::FastSetPropertyByValue(thread, regexp.GetTaggedValue(), lastIndexHandle.GetTaggedValue(), - JSTaggedValue(endIndex)); + JSTaggedValue endIndexVal(endIndex); + FastRuntimeStub::FastSetPropertyByValue(thread, regexp, lastIndexHandle, JSPrimitiveHandle(&endIndexVal)); // b. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } @@ -1564,8 +1543,7 @@ JSTaggedValue BuiltinsRegExp::RegExpExec(JSThread *thread, const JSHandleGlobalConstants(); JSHandle execHandle = globalConst->GetHandledExecString(); - JSTaggedValue execVal = - FastRuntimeStub::FastGetPropertyByValue(thread, regexp.GetTaggedValue(), execHandle.GetTaggedValue()); + JSTaggedValue execVal = FastRuntimeStub::FastGetPropertyByValue(thread, regexp, execHandle); JSHandle exec(thread, execVal); // 4. ReturnIfAbrupt(exec). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1766,8 +1744,7 @@ JSTaggedValue BuiltinsRegExp::RegExpInitialize(JSThread *thread, const JSHandle< } // 14. Let setStatus be Set(obj, "lastIndex", 0, true). JSHandle lastIndexString = thread->GlobalConstants()->GetHandledLastIndexString(); - FastRuntimeStub::FastSetPropertyByValue(thread, obj.GetTaggedValue(), lastIndexString.GetTaggedValue(), - JSTaggedValue(0)); + FastRuntimeStub::FastSetPropertyByValue(thread, obj, lastIndexString, JSPrimitiveHandle::Zero()); // 15. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 16. Return obj. @@ -1868,8 +1845,8 @@ JSTaggedValue RegExpExecResultCache::FindCachedResult(JSThread *thread, const JS } SetHitCount(thread, GetHitCount() + 1); JSHandle lastIndexHandle = thread->GlobalConstants()->GetHandledLastIndexString(); - FastRuntimeStub::FastSetPropertyByValue(thread, regexp.GetTaggedValue(), lastIndexHandle.GetTaggedValue(), - Get(index + LAST_INDEX_INDEX)); + JSTaggedValue lastIndex = Get(index + LAST_INDEX_INDEX); // must be primitive + FastRuntimeStub::FastSetPropertyByValue(thread, regexp, lastIndexHandle, JSPrimitiveHandle(&lastIndex)); return result; } diff --git a/runtime/containers/containers_private.cpp b/runtime/containers/containers_private.cpp index fe3ab2b0b..d4c19ac7d 100644 --- a/runtime/containers/containers_private.cpp +++ b/runtime/containers/containers_private.cpp @@ -41,7 +41,7 @@ JSTaggedValue ContainersPrivate::Load(EcmaRuntimeCallInfo *msg) case ContainerTag::ArrayList: { JSHandle key(factory->NewFromCanBeCompressString("ArrayListConstructor")); JSTaggedValue value = - FastRuntimeStub::GetPropertyByName(thread, thisValue.GetTaggedValue(), key.GetTaggedValue()); + FastRuntimeStub::GetPropertyByName(thread, JSHandle(thisValue), key); if (value != JSTaggedValue::Undefined()) { res = value; } else { diff --git a/runtime/ic/ic_runtime_stub-inl.h b/runtime/ic/ic_runtime_stub-inl.h index 38c294ed2..5d4eff937 100644 --- a/runtime/ic/ic_runtime_stub-inl.h +++ b/runtime/ic/ic_runtime_stub-inl.h @@ -258,7 +258,9 @@ JSTaggedValue ICRuntimeStub::StoreICWithHandler(JSThread *thread, JSTaggedValue } ASSERT(HandlerBase::IsAccessor(handler_info) || HandlerBase::IsInternalAccessor(handler_info)); auto accessor = LoadFromField(JSObject::Cast(holder.GetHeapObject()), handler_info); - return FastRuntimeStub::CallSetter(thread, JSTaggedValue(receiver), value, accessor); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + return FastRuntimeStub::CallSetter(thread, JSHandle(thread, receiver), + JSHandle(thread, value), accessor); } if (handler.IsTransitionHandler()) { StoreWithTransition(thread, JSObject::Cast(receiver.GetHeapObject()), value, handler); @@ -403,7 +405,8 @@ JSTaggedValue ICRuntimeStub::LoadICWithHandler(JSThread *thread, JSTaggedValue r } ASSERT(HandlerBase::IsAccessor(handler_info) || HandlerBase::IsInternalAccessor(handler_info)); auto accessor = LoadFromField(JSObject::Cast(holder.GetHeapObject()), handler_info); - return FastRuntimeStub::CallGetter(thread, receiver, holder, accessor); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + return FastRuntimeStub::CallGetter(thread, JSHandle(thread, receiver), holder, accessor); } if (handler.IsPrototypeHandler()) { diff --git a/runtime/interpreter/fast_runtime_stub-inl.h b/runtime/interpreter/fast_runtime_stub-inl.h index ab778f90d..ca2af8308 100644 --- a/runtime/interpreter/fast_runtime_stub-inl.h +++ b/runtime/interpreter/fast_runtime_stub-inl.h @@ -190,32 +190,26 @@ uint32_t FastRuntimeStub::TryToElementsIndex(JSTaggedValue key) return JSObject::MAX_ELEMENT_INDEX; } -JSTaggedValue FastRuntimeStub::CallGetter(JSThread *thread, JSTaggedValue receiver, JSTaggedValue holder, +JSTaggedValue FastRuntimeStub::CallGetter(JSThread *thread, JSHandle receiver, JSTaggedValue holder, JSTaggedValue value) { INTERPRETER_TRACE(thread, CallGetter); // Accessor - [[maybe_unused]] EcmaHandleScope handle_scope(thread); AccessorData *accessor = AccessorData::Cast(value.GetTaggedObject()); if (UNLIKELY(accessor->IsInternal())) { JSHandle obj_handle(thread, holder); return accessor->CallInternalGet(thread, obj_handle); } - JSHandle obj_handle(thread, receiver); - return JSObject::CallGetter(thread, accessor, obj_handle); + return JSObject::CallGetter(thread, accessor, receiver); } -JSTaggedValue FastRuntimeStub::CallSetter(JSThread *thread, JSTaggedValue receiver, JSTaggedValue value, - JSTaggedValue accessor_value) +JSTaggedValue FastRuntimeStub::CallSetter(JSThread *thread, JSHandle receiver, + JSHandle value, JSTaggedValue accessor_value) { INTERPRETER_TRACE(thread, CallSetter); // Accessor - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle obj_handle(thread, receiver); - JSHandle value_handle(thread, value); - auto accessor = AccessorData::Cast(accessor_value.GetTaggedObject()); - bool success = JSObject::CallSetter(thread, *accessor, obj_handle, value_handle, true); + bool success = JSObject::CallSetter(thread, *accessor, receiver, value, true); return success ? JSTaggedValue::Undefined() : JSTaggedValue::Exception(); } @@ -293,26 +287,24 @@ PropertyAttributes FastRuntimeStub::AddPropertyByName(JSThread *thread, JSHandle return attr; } -JSTaggedValue FastRuntimeStub::AddPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index, - JSTaggedValue value) +JSTaggedValue FastRuntimeStub::AddPropertyByIndex(JSThread *thread, JSHandle receiver, uint32_t index, + JSHandle value) { INTERPRETER_TRACE(thread, AddPropertyByIndex); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - if (UNLIKELY(!JSObject::Cast(receiver)->IsExtensible())) { + if (UNLIKELY(!JSObject::Cast(receiver.GetTaggedValue())->IsExtensible())) { THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot add property in prevent extensions ", JSTaggedValue::Exception()); } - bool success = JSObject::AddElementInternal(thread, JSHandle(thread, receiver), index, - JSHandle(thread, value), PropertyAttributes::Default()); + bool success = JSObject::AddElementInternal(thread, JSHandle::Cast(receiver), index, value, + PropertyAttributes::Default()); return success ? JSTaggedValue::Undefined() : JSTaggedValue::Exception(); } template -JSTaggedValue FastRuntimeStub::GetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index) +JSTaggedValue FastRuntimeStub::GetPropertyByIndex(JSThread *thread, JSHandle receiver, uint32_t index) { INTERPRETER_TRACE(thread, GetPropertyByIndex); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSTaggedValue holder = receiver; + JSTaggedValue holder = receiver.GetTaggedValue(); do { auto *hclass = holder.GetTaggedObject()->GetClass(); JSType js_type = hclass->GetObjectType(); @@ -358,39 +350,39 @@ JSTaggedValue FastRuntimeStub::GetPropertyByIndex(JSThread *thread, JSTaggedValu } template -JSTaggedValue FastRuntimeStub::GetPropertyByValue(JSThread *thread, JSTaggedValue *receiver, JSTaggedValue *key) +JSTaggedValue FastRuntimeStub::GetPropertyByValue(JSThread *thread, JSHandle receiver, + JSHandle key) { INTERPRETER_TRACE(thread, GetPropertyByValue); if (UNLIKELY(!key->IsNumber() && !key->IsStringOrSymbol())) { return JSTaggedValue::Hole(); } // fast path - auto index = TryToElementsIndex(*key); + auto index = TryToElementsIndex(key.GetTaggedValue()); if (LIKELY(index < JSObject::MAX_ELEMENT_INDEX)) { - return GetPropertyByIndex(thread, *receiver, index); + return GetPropertyByIndex(thread, receiver, index); } if (!key->IsNumber()) { if (key->IsString() && !EcmaString::Cast(key->GetTaggedObject())->IsInternString()) { // update string stable [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle receiver_handler(thread, *receiver); - *key = - JSTaggedValue(thread->GetEcmaVM()->GetFactory()->InternString(JSHandle(thread, *key))); - // Maybe moved by GC - *receiver = receiver_handler.GetTaggedValue(); + JSHandle new_key(thread, + JSTaggedValue(thread->GetEcmaVM()->GetFactory()->InternString(key))); + return FastRuntimeStub::GetPropertyByName(thread, receiver, new_key); } - return FastRuntimeStub::GetPropertyByName(thread, *receiver, *key); + return FastRuntimeStub::GetPropertyByName(thread, receiver, key); } return JSTaggedValue::Hole(); } template -JSTaggedValue FastRuntimeStub::GetPropertyByName(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key) +JSTaggedValue FastRuntimeStub::GetPropertyByName(JSThread *thread, JSHandle receiver, + JSHandle key) { INTERPRETER_TRACE(thread, GetPropertyByName); // no gc when return hole - ASSERT(key.IsStringOrSymbol()); - JSTaggedValue holder = receiver; + ASSERT(key->IsStringOrSymbol()); + JSTaggedValue holder = receiver.GetTaggedValue(); do { auto *hclass = holder.GetTaggedObject()->GetClass(); JSType js_type = hclass->GetObjectType(); @@ -403,7 +395,7 @@ JSTaggedValue FastRuntimeStub::GetPropertyByName(JSThread *thread, JSTaggedValue LayoutInfo *layout_info = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); int props_number = hclass->NumberOfProps(); - int entry = layout_info->FindElementWithCache(thread, hclass, key, props_number); + int entry = layout_info->FindElementWithCache(thread, hclass, key.GetTaggedValue(), props_number); if (entry != -1) { PropertyAttributes attr(layout_info->GetAttr(entry)); ASSERT(static_cast(attr.GetOffset()) == entry); @@ -418,7 +410,7 @@ JSTaggedValue FastRuntimeStub::GetPropertyByName(JSThread *thread, JSTaggedValue TaggedArray *array = TaggedArray::Cast(JSObject::Cast(holder)->GetProperties().GetTaggedObject()); ASSERT(array->IsDictionaryMode()); NameDictionary *dict = NameDictionary::Cast(array); - int entry = dict->FindEntry(key); + int entry = dict->FindEntry(key.GetTaggedValue()); if (entry != -1) { auto value = dict->GetValue(entry); auto attr = dict->GetAttributes(entry); @@ -439,12 +431,12 @@ JSTaggedValue FastRuntimeStub::GetPropertyByName(JSThread *thread, JSTaggedValue } template -JSTaggedValue FastRuntimeStub::SetPropertyByName(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key, - JSTaggedValue value) +JSTaggedValue FastRuntimeStub::SetPropertyByName(JSThread *thread, JSHandle receiver, + JSHandle key, JSHandle value) { INTERPRETER_TRACE(thread, SetPropertyByName); // property - JSTaggedValue holder = receiver; + JSTaggedValue holder = receiver.GetTaggedValue(); do { auto *hclass = holder.GetTaggedObject()->GetClass(); JSType js_type = hclass->GetObjectType(); @@ -461,13 +453,13 @@ JSTaggedValue FastRuntimeStub::SetPropertyByName(JSThread *thread, JSTaggedValue LayoutInfo *layout_info = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); int props_number = hclass->NumberOfProps(); - int entry = layout_info->FindElementWithCache(thread, hclass, key, props_number); + int entry = layout_info->FindElementWithCache(thread, hclass, key.GetTaggedValue(), props_number); if (entry != -1) { PropertyAttributes attr(layout_info->GetAttr(entry)); ASSERT(static_cast(attr.GetOffset()) == entry); if (UNLIKELY(attr.IsAccessor())) { auto accessor = JSObject::Cast(holder)->GetProperty(hclass, attr); - if (ShouldCallSetter(receiver, holder, accessor, attr)) { + if (ShouldCallSetter(receiver.GetTaggedValue(), holder, accessor, attr)) { return CallSetter(thread, receiver, value, accessor); } } @@ -475,22 +467,22 @@ JSTaggedValue FastRuntimeStub::SetPropertyByName(JSThread *thread, JSTaggedValue [[maybe_unused]] EcmaHandleScope handle_scope(thread); THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot set readonly property", JSTaggedValue::Exception()); } - if (UNLIKELY(holder != receiver)) { + if (UNLIKELY(holder != receiver.GetTaggedValue())) { break; } - JSObject::Cast(holder)->SetProperty(thread, hclass, attr, value); + JSObject::Cast(holder)->SetProperty(thread, hclass, attr, value.GetTaggedValue()); return JSTaggedValue::Undefined(); } } else { TaggedArray *properties = TaggedArray::Cast(JSObject::Cast(holder)->GetProperties().GetTaggedObject()); ASSERT(properties->IsDictionaryMode()); NameDictionary *dict = NameDictionary::Cast(properties); - int entry = dict->FindEntry(key); + int entry = dict->FindEntry(key.GetTaggedValue()); if (entry != -1) { auto attr = dict->GetAttributes(entry); if (UNLIKELY(attr.IsAccessor())) { auto accessor = dict->GetValue(entry); - if (ShouldCallSetter(receiver, holder, accessor, attr)) { + if (ShouldCallSetter(receiver.GetTaggedValue(), holder, accessor, attr)) { return CallSetter(thread, receiver, value, accessor); } } @@ -498,10 +490,10 @@ JSTaggedValue FastRuntimeStub::SetPropertyByName(JSThread *thread, JSTaggedValue [[maybe_unused]] EcmaHandleScope handle_scope(thread); THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot set readonly property", JSTaggedValue::Exception()); } - if (UNLIKELY(holder != receiver)) { + if (UNLIKELY(holder != receiver.GetTaggedValue())) { break; } - dict->UpdateValue(thread, entry, value); + dict->UpdateValue(thread, entry, value.GetTaggedValue()); return JSTaggedValue::Undefined(); } } @@ -511,42 +503,37 @@ JSTaggedValue FastRuntimeStub::SetPropertyByName(JSThread *thread, JSTaggedValue holder = hclass->GetPrototype(); } while (holder.IsHeapObject()); - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle obj_handle(thread, receiver); - JSHandle key_handle(thread, key); - JSHandle value_handle(thread, value); - - if (UNLIKELY(!JSObject::Cast(receiver)->IsExtensible())) { + if (UNLIKELY(!JSObject::Cast(receiver.GetTaggedValue())->IsExtensible())) { THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot add property in prevent extensions ", JSTaggedValue::Exception()); } - AddPropertyByName(thread, obj_handle, key_handle, value_handle, PropertyAttributes::Default()); + AddPropertyByName(thread, JSHandle::Cast(receiver), key, value, PropertyAttributes::Default()); return JSTaggedValue::Undefined(); } template -JSTaggedValue FastRuntimeStub::SetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index, - JSTaggedValue value) +JSTaggedValue FastRuntimeStub::SetPropertyByIndex(JSThread *thread, JSHandle receiver, uint32_t index, + JSHandle value) { INTERPRETER_TRACE(thread, SetPropertyByIndex); - JSTaggedValue holder = receiver; + JSTaggedValue holder = receiver.GetTaggedValue(); do { auto *hclass = holder.GetTaggedObject()->GetClass(); JSType js_type = hclass->GetObjectType(); if (IsSpecialIndexedObj(js_type)) { if (IsSpecialContainer(js_type)) { - return SetContainerProperty(thread, holder, index, value, js_type); + return SetContainerProperty(thread, holder, index, value.GetTaggedValue(), js_type); } return JSTaggedValue::Hole(); } TaggedArray *elements = TaggedArray::Cast(JSObject::Cast(holder)->GetElements().GetTaggedObject()); if (!hclass->IsDictionaryElement()) { ASSERT(!elements->IsDictionaryMode()); - if (UNLIKELY(holder != receiver)) { + if (UNLIKELY(holder != receiver.GetTaggedValue())) { break; } if (index < elements->GetLength()) { if (!elements->Get(index).IsHole()) { - elements->Set(thread, index, value); + elements->Set(thread, index, value.GetTaggedValue()); return JSTaggedValue::Undefined(); } } @@ -563,28 +550,24 @@ JSTaggedValue FastRuntimeStub::SetPropertyByIndex(JSThread *thread, JSTaggedValu } template -JSTaggedValue FastRuntimeStub::SetPropertyByValue(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key, - JSTaggedValue value) +JSTaggedValue FastRuntimeStub::SetPropertyByValue(JSThread *thread, JSHandle receiver, + JSHandle key, JSHandle value) { INTERPRETER_TRACE(thread, SetPropertyByValue); - if (UNLIKELY(!key.IsNumber() && !key.IsStringOrSymbol())) { + if (UNLIKELY(!key->IsNumber() && !key->IsStringOrSymbol())) { return JSTaggedValue::Hole(); } // fast path - auto index = TryToElementsIndex(key); + auto index = TryToElementsIndex(key.GetTaggedValue()); if (LIKELY(index < JSObject::MAX_ELEMENT_INDEX)) { return SetPropertyByIndex(thread, receiver, index, value); } - if (!key.IsNumber()) { - if (key.IsString() && !EcmaString::Cast(key.GetTaggedObject())->IsInternString()) { + if (!key->IsNumber()) { + if (key->IsString() && !EcmaString::Cast(key->GetTaggedObject())->IsInternString()) { // update string stable [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle receiver_handler(thread, receiver); - JSHandle value_handler(thread, value); - key = JSTaggedValue(thread->GetEcmaVM()->GetFactory()->InternString(JSHandle(thread, key))); - // Maybe moved by GC - receiver = receiver_handler.GetTaggedValue(); - value = value_handler.GetTaggedValue(); + JSHandle new_key(thread, thread->GetEcmaVM()->GetFactory()->InternString(key)); + return FastRuntimeStub::SetPropertyByName(thread, receiver, new_key, value); } return FastRuntimeStub::SetPropertyByName(thread, receiver, key, value); } @@ -640,92 +623,65 @@ JSTaggedValue FastRuntimeStub::FastTypeOf(JSThread *thread, JSTaggedValue obj) return global_const->GetUndefinedString(); } -bool FastRuntimeStub::FastSetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index, - JSTaggedValue value) +bool FastRuntimeStub::FastSetPropertyByIndex(JSThread *thread, JSHandle receiver, uint32_t index, + JSHandle value) { INTERPRETER_TRACE(thread, FastSetPropertyByIndex); JSTaggedValue result = FastRuntimeStub::SetPropertyByIndex(thread, receiver, index, value); if (!result.IsHole()) { return result != JSTaggedValue::Exception(); } - // CSA reports usage of 'receiver' and 'value' after GC in function FastRuntimeStub::SetPropertyByIndex. - // In case the function throws an exception its result will be JSTaggedValue::Exception() we gets in - // the 'if' condition above and return. - // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) - return JSTaggedValue::SetProperty(thread, JSHandle(thread, receiver), index, - // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) - JSHandle(thread, value), true); + return JSTaggedValue::SetProperty(thread, receiver, index, value, true); } -bool FastRuntimeStub::FastSetPropertyByValue(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key, - JSTaggedValue value) +bool FastRuntimeStub::FastSetPropertyByValue(JSThread *thread, JSHandle receiver, + JSHandle key, JSHandle value) { INTERPRETER_TRACE(thread, FastSetPropertyByValue); JSTaggedValue result = FastRuntimeStub::SetPropertyByValue(thread, receiver, key, value); if (!result.IsHole()) { return result != JSTaggedValue::Exception(); } - // CSA reports usage of 'receiver' and 'value' after GC in the function 'SetPropertyByName' called from - // 'SetPropertyByValue'. - // In this case we get in the 'if' condition above and return. - // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) - return JSTaggedValue::SetProperty(thread, JSHandle(thread, receiver), - // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) - JSHandle(thread, key), JSHandle(thread, value), - true); + return JSTaggedValue::SetProperty(thread, receiver, key, value, true); } // must not use for interpreter -JSTaggedValue FastRuntimeStub::FastGetPropertyByName(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key) +JSTaggedValue FastRuntimeStub::FastGetPropertyByName(JSThread *thread, JSHandle receiver, + JSHandle key) { INTERPRETER_TRACE(thread, FastGetPropertyByName); - ASSERT(key.IsStringOrSymbol()); - if (key.IsString() && !EcmaString::Cast(key.GetTaggedObject())->IsInternString()) { - JSHandle receiver_handler(thread, receiver); - key = JSTaggedValue(thread->GetEcmaVM()->GetFactory()->InternString(JSHandle(thread, key))); - // Maybe moved by GC - receiver = receiver_handler.GetTaggedValue(); - } - JSTaggedValue result = FastRuntimeStub::GetPropertyByName(thread, receiver, key); + ASSERT(key->IsStringOrSymbol()); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSMutableHandle new_key(thread, key); + if (key->IsString() && !EcmaString::Cast(key->GetTaggedObject())->IsInternString()) { + new_key.Update(JSTaggedValue(thread->GetEcmaVM()->GetFactory()->InternString(key))); + } + JSTaggedValue result = FastRuntimeStub::GetPropertyByName(thread, receiver, new_key); if (result.IsHole()) { - return JSTaggedValue::GetProperty(thread, JSHandle(thread, receiver), - JSHandle(thread, key)) - .GetValue() - .GetTaggedValue(); + return JSTaggedValue::GetProperty(thread, receiver, new_key).GetValue().GetTaggedValue(); } return result; } -JSTaggedValue FastRuntimeStub::FastGetPropertyByValue(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key) +JSTaggedValue FastRuntimeStub::FastGetPropertyByValue(JSThread *thread, JSHandle receiver, + JSHandle key) { INTERPRETER_TRACE(thread, FastGetPropertyByValue); - JSTaggedValue result = FastRuntimeStub::GetPropertyByValue(thread, &receiver, &key); + JSTaggedValue result = FastRuntimeStub::GetPropertyByValue(thread, receiver, key); if (result.IsHole()) { - // CSA reports usage of 'receiver' and 'key' after GC in the function 'GetPropertyByValue'. - // In case GC is triggered in the function and the objects are moved the function returns - // new addreses of 'receiver' and 'key' via parameters. - // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) - return JSTaggedValue::GetProperty(thread, JSHandle(thread, receiver), - // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) - JSHandle(thread, key)) - .GetValue() - .GetTaggedValue(); + return JSTaggedValue::GetProperty(thread, receiver, key).GetValue().GetTaggedValue(); } return result; } template // UseHole is only for Array::Sort() which requires Hole order -JSTaggedValue FastRuntimeStub::FastGetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index) +JSTaggedValue FastRuntimeStub::FastGetPropertyByIndex(JSThread *thread, JSHandle receiver, + uint32_t index) { INTERPRETER_TRACE(thread, FastGetPropertyByIndex); JSTaggedValue result = FastRuntimeStub::GetPropertyByIndex(thread, receiver, index); if (result.IsHole() && !USE_HOLE) { - // CSA reports usage of 'receiver' after GC in the function 'CallGetter' which is called from - // GetPropertyByIndex. In case we reach CallGetter the result canot by JSTaggedValue::Hole(). - // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) - return JSTaggedValue::GetProperty(thread, JSHandle(thread, receiver), index) - .GetValue() - .GetTaggedValue(); + return JSTaggedValue::GetProperty(thread, receiver, index).GetValue().GetTaggedValue(); } return result; } @@ -1153,36 +1109,36 @@ bool FastRuntimeStub::FastSetProperty(JSThread *thread, JSTaggedValue receiver, may_throw); } -JSTaggedValue FastRuntimeStub::FastGetProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key) +JSTaggedValue FastRuntimeStub::FastGetProperty(JSThread *thread, JSHandle receiver, + JSHandle key) { INTERPRETER_TRACE(thread, FastGetProperty); JSTaggedValue result; - JSHandle receiver_handle(thread, receiver); - JSHandle key_handle(thread, key); - if (receiver.IsJSObject() && !receiver.IsTypedArray() && (key.IsStringOrSymbol())) { + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSMutableHandle new_key(thread, key); + if (receiver->IsJSObject() && !receiver->IsTypedArray() && (key->IsStringOrSymbol())) { uint32_t index = 0; - if (UNLIKELY(JSTaggedValue::ToElementIndex(key, &index))) { - if (FastRuntimeStub::IsSpecialIndexedObjForSet(receiver)) { + if (UNLIKELY(JSTaggedValue::ToElementIndex(key.GetTaggedValue(), &index))) { + if (FastRuntimeStub::IsSpecialIndexedObjForSet(receiver.GetTaggedValue())) { result = JSTaggedValue::Hole(); } else { - result = FastRuntimeStub::GetElement(receiver, index); + result = FastRuntimeStub::GetElement(receiver.GetTaggedValue(), index); } } else { - if (key.IsString()) { - key = JSTaggedValue( - thread->GetEcmaVM()->GetFactory()->InternString(JSHandle(thread, key))); + if (key->IsString()) { + new_key.Update(JSTaggedValue(thread->GetEcmaVM()->GetFactory()->InternString(key))); } - result = FastRuntimeStub::GetPropertyByName(thread, receiver, key); + result = FastRuntimeStub::GetPropertyByName(thread, receiver, new_key); } } if (!result.IsHole()) { if (UNLIKELY(result.IsAccessor())) { - return JSObject::CallGetter(thread, AccessorData::Cast(result.GetHeapObject()), receiver_handle); + return JSObject::CallGetter(thread, AccessorData::Cast(result.GetHeapObject()), receiver); } return result; } - return JSTaggedValue::GetProperty(thread, receiver_handle, key_handle).GetValue().GetTaggedValue(); + return JSTaggedValue::GetProperty(thread, receiver, new_key).GetValue().GetTaggedValue(); } JSTaggedValue FastRuntimeStub::FindOwnProperty(JSThread *thread, JSObject *obj, TaggedArray *properties, diff --git a/runtime/interpreter/fast_runtime_stub.h b/runtime/interpreter/fast_runtime_stub.h index 4df9f2e7b..b4553f692 100644 --- a/runtime/interpreter/fast_runtime_stub.h +++ b/runtime/interpreter/fast_runtime_stub.h @@ -56,7 +56,8 @@ public: static inline bool SetOwnElement(JSThread *thread, JSTaggedValue receiver, uint32_t index, JSTaggedValue value); static inline bool FastSetProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key, JSTaggedValue value, bool may_throw); - static inline JSTaggedValue FastGetProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key); + static inline JSTaggedValue FastGetProperty(JSThread *thread, JSHandle receiver, + JSHandle key); static inline JSTaggedValue FindOwnProperty(JSThread *thread, JSObject *obj, TaggedArray *properties, JSTaggedValue key, PropertyAttributes *attr, uint32_t *index_or_entry); static inline JSTaggedValue FindOwnElement(TaggedArray *elements, uint32_t index, bool is_dict, @@ -70,29 +71,34 @@ public: /* -------------- Common API End, Don't change those interface!!! ----------------- */ template - static inline JSTaggedValue GetPropertyByName(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key); + static inline JSTaggedValue GetPropertyByName(JSThread *thread, JSHandle receiver, + JSHandle key); template - static inline JSTaggedValue GetPropertyByValue(JSThread *thread, JSTaggedValue *receiver, JSTaggedValue *key); + static inline JSTaggedValue GetPropertyByValue(JSThread *thread, JSHandle receiver, + JSHandle key); template - static inline JSTaggedValue GetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index); + static inline JSTaggedValue GetPropertyByIndex(JSThread *thread, JSHandle receiver, uint32_t index); template - static inline JSTaggedValue SetPropertyByName(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key, - JSTaggedValue value); + static inline JSTaggedValue SetPropertyByName(JSThread *thread, JSHandle receiver, + JSHandle key, JSHandle value); template - static inline JSTaggedValue SetPropertyByValue(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key, - JSTaggedValue value); + static inline JSTaggedValue SetPropertyByValue(JSThread *thread, JSHandle receiver, + JSHandle key, JSHandle value); template - static inline JSTaggedValue SetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index, - JSTaggedValue value); + static inline JSTaggedValue SetPropertyByIndex(JSThread *thread, JSHandle receiver, uint32_t index, + JSHandle value); - static inline bool FastSetPropertyByValue(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key, - JSTaggedValue value); - static inline bool FastSetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index, - JSTaggedValue value); - static inline JSTaggedValue FastGetPropertyByName(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key); - static inline JSTaggedValue FastGetPropertyByValue(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key); + static inline bool FastSetPropertyByValue(JSThread *thread, JSHandle receiver, + JSHandle key, JSHandle value); + static inline bool FastSetPropertyByIndex(JSThread *thread, JSHandle receiver, uint32_t index, + JSHandle value); + static inline JSTaggedValue FastGetPropertyByName(JSThread *thread, JSHandle receiver, + JSHandle key); + static inline JSTaggedValue FastGetPropertyByValue(JSThread *thread, JSHandle receiver, + JSHandle key); template - static inline JSTaggedValue FastGetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index); + static inline JSTaggedValue FastGetPropertyByIndex(JSThread *thread, JSHandle receiver, + uint32_t index); static inline PropertyAttributes AddPropertyByName(JSThread *thread, JSHandle obj_handle, JSHandle key_handle, JSHandle value_handle, PropertyAttributes attr); @@ -103,14 +109,14 @@ private: static inline bool IsSpecialReceiverObj(JSType js_type); static inline bool IsSpecialContainer(JSType js_type); static inline uint32_t TryToElementsIndex(JSTaggedValue key); - static inline JSTaggedValue CallGetter(JSThread *thread, JSTaggedValue receiver, JSTaggedValue holder, + static inline JSTaggedValue CallGetter(JSThread *thread, JSHandle receiver, JSTaggedValue holder, JSTaggedValue value); - static inline JSTaggedValue CallSetter(JSThread *thread, JSTaggedValue receiver, JSTaggedValue value, - JSTaggedValue accessor_value); + static inline JSTaggedValue CallSetter(JSThread *thread, JSHandle receiver, + JSHandle value, JSTaggedValue accessor_value); static inline bool ShouldCallSetter(JSTaggedValue receiver, JSTaggedValue holder, JSTaggedValue accessor_value, PropertyAttributes attr); - static inline JSTaggedValue AddPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index, - JSTaggedValue value); + static inline JSTaggedValue AddPropertyByIndex(JSThread *thread, JSHandle receiver, uint32_t index, + JSHandle value); static inline JSTaggedValue GetContainerProperty(JSThread *thread, JSTaggedValue receiver, uint32_t index, JSType js_type); static inline JSTaggedValue SetContainerProperty(JSThread *thread, JSTaggedValue receiver, uint32_t index, diff --git a/runtime/intrinsics-inl.h b/runtime/intrinsics-inl.h index 5a7fcbd64..d0ab0eb6d 100644 --- a/runtime/intrinsics-inl.h +++ b/runtime/intrinsics-inl.h @@ -897,9 +897,6 @@ INLINE_ECMA_INTRINSICS uint64_t Ldglobal(JSThread *thread) INLINE_ECMA_INTRINSICS uint64_t LdObjByValue(JSThread *thread, uint64_t rec, uint64_t pkey, [[maybe_unused]] uint16_t slot_id) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle receiver_handle(thread, JSTaggedValue(rec)); - auto receiver = JSTaggedValue(rec); auto prop_key = JSTaggedValue(pkey); @@ -914,22 +911,25 @@ INLINE_ECMA_INTRINSICS uint64_t LdObjByValue(JSThread *thread, uint64_t rec, uin #endif // fast path + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle receiver_handle(thread, receiver); + JSHandle prop_handle(thread, prop_key); if (LIKELY(receiver.IsHeapObject())) { - res = FastRuntimeStub::GetPropertyByValue(thread, &receiver, &prop_key); + res = FastRuntimeStub::GetPropertyByValue(thread, receiver_handle, prop_handle); if (!res.IsHole()) { return res.GetRawData(); } } // slow path - return SlowRuntimeStub::LdObjByValue(thread, receiver, prop_key, false, JSTaggedValue::Undefined()).GetRawData(); + return SlowRuntimeStub::LdObjByValue(thread, receiver_handle.GetTaggedValue(), prop_handle.GetTaggedValue(), false, + JSTaggedValue::Undefined()) + .GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t StObjByValue(JSThread *thread, uint64_t rec, uint64_t pkey, uint64_t val, [[maybe_unused]] uint16_t slot_id) { - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - auto receiver = JSTaggedValue(rec); auto prop_key = JSTaggedValue(pkey); auto value = JSTaggedValue(val); @@ -944,23 +944,20 @@ INLINE_ECMA_INTRINSICS uint64_t StObjByValue(JSThread *thread, uint64_t rec, uin } #endif + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle receiver_handle(thread, receiver); - JSHandle prop_key_handle(thread, prop_key); + JSHandle prop_handle(thread, prop_key); JSHandle value_handle(thread, value); - if (receiver.IsHeapObject()) { - res = FastRuntimeStub::SetPropertyByValue(thread, receiver, prop_key, value); + res = FastRuntimeStub::SetPropertyByValue(thread, receiver_handle, prop_handle, value_handle); if (!res.IsHole()) { return res.GetRawData(); } } - // slow path - receiver = receiver_handle.GetTaggedValue(); // May be moved by GC - prop_key = prop_key_handle.GetTaggedValue(); // May be moved by GC - value = value_handle.GetTaggedValue(); // May be moved by GC - - return SlowRuntimeStub::StObjByValue(thread, receiver, prop_key, value).GetRawData(); + return SlowRuntimeStub::StObjByValue(thread, receiver_handle.GetTaggedValue(), prop_handle.GetTaggedValue(), + value_handle.GetTaggedValue()) + .GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) @@ -1053,13 +1050,18 @@ INLINE_ECMA_INTRINSICS uint64_t LdObjByName(JSThread *thread, uint32_t string_id } #endif - if (LIKELY(obj.IsHeapObject())) { - res = FastRuntimeStub::GetPropertyByName(thread, obj, prop_key); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle hobj(thread, obj); + JSHandle hprop_key(thread, prop_key); + if (LIKELY(hobj->IsHeapObject())) { + res = FastRuntimeStub::GetPropertyByName(thread, hobj, hprop_key); if (!res.IsHole()) { return res.GetRawData(); } } - return SlowRuntimeStub::LdObjByName(thread, obj, prop_key, false, JSTaggedValue::Undefined()).GetRawData(); + return SlowRuntimeStub::LdObjByName(thread, hobj.GetTaggedValue(), hprop_key.GetTaggedValue(), false, + JSTaggedValue::Undefined()) + .GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) @@ -1081,22 +1083,29 @@ INLINE_ECMA_INTRINSICS uint64_t StObjByName(JSThread *thread, uint32_t string_id } #endif - if (obj.IsHeapObject()) { - res = FastRuntimeStub::SetPropertyByName(thread, obj, prop_key, value); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle hobj(thread, obj); + JSHandle hprop_key(thread, prop_key); + JSHandle hvalue(thread, value); + if (hobj->IsHeapObject()) { + res = FastRuntimeStub::SetPropertyByName(thread, hobj, hprop_key, hvalue); if (!res.IsHole()) { return res.GetRawData(); } } - return SlowRuntimeStub::StObjByName(thread, obj, prop_key, value).GetRawData(); + return SlowRuntimeStub::StObjByName(thread, hobj.GetTaggedValue(), hprop_key.GetTaggedValue(), + hvalue.GetTaggedValue()) + .GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t LdObjByIndex(JSThread *thread, uint32_t idx, uint64_t uobj) { - auto obj = JSTaggedValue(uobj); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle obj(thread, JSTaggedValue(uobj)); // fast path - if (LIKELY(obj.IsHeapObject())) { + if (LIKELY(obj->IsHeapObject())) { JSTaggedValue res = FastRuntimeStub::GetPropertyByIndex(thread, obj, idx); if (!res.IsHole()) { return res.GetRawData(); @@ -1104,24 +1113,26 @@ INLINE_ECMA_INTRINSICS uint64_t LdObjByIndex(JSThread *thread, uint32_t idx, uin } // not meet fast condition or fast path return hole, walk slow path // slow stub not need receiver - return SlowRuntimeStub::LdObjByIndex(thread, obj, idx, false, JSTaggedValue::Undefined()).GetRawData(); + return SlowRuntimeStub::LdObjByIndex(thread, obj.GetTaggedValue(), idx, false, JSTaggedValue::Undefined()) + .GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t StObjByIndex(JSThread *thread, uint32_t idx, uint64_t uobj, uint64_t uval) { - auto obj = JSTaggedValue(uobj); - auto val = JSTaggedValue(uval); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle obj(thread, JSTaggedValue(uobj)); + JSHandle val(thread, JSTaggedValue(uval)); // fast path - if (obj.IsHeapObject()) { + if (obj->IsHeapObject()) { JSTaggedValue res = FastRuntimeStub::SetPropertyByIndex(thread, obj, idx, val); if (!res.IsHole()) { return res.GetRawData(); } } // slow path - return SlowRuntimeStub::StObjByIndex(thread, obj, idx, val).GetRawData(); + return SlowRuntimeStub::StObjByIndex(thread, obj.GetTaggedValue(), idx, val.GetTaggedValue()).GetRawData(); } template bigintOP(JSThread *, JSHandle, JSHandle), bool is_u_left = false, @@ -1762,47 +1773,36 @@ INLINE_ECMA_INTRINSICS uint64_t CreateRegExpWithLiteral(JSThread *thread, uint32 INLINE_ECMA_INTRINSICS uint64_t StOwnByIndex(JSThread *thread, uint64_t object, uint64_t idx, uint64_t val) { [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle obj_handle(thread, JSTaggedValue(object)); - JSHandle value_handle(thread, JSTaggedValue(val)); + JSHandle obj(thread, JSTaggedValue(object)); + JSHandle value(thread, JSTaggedValue(val)); - auto obj = JSTaggedValue(object); - auto value = JSTaggedValue(val); - - if (obj.IsHeapObject() && !obj.IsClassConstructor() && !obj.IsClassPrototype()) { + if (obj->IsHeapObject() && !obj->IsClassConstructor() && !obj->IsClassPrototype()) { JSTaggedValue res = FastRuntimeStub::SetPropertyByIndex(thread, obj, idx, value); if (!res.IsHole()) { return res.GetRawData(); } } - obj = obj_handle.GetTaggedValue(); // Maybe moved by GC - value = value_handle.GetTaggedValue(); // Maybe moved by GC - return SlowRuntimeStub::StOwnByIndex(thread, obj, idx, value).GetRawData(); + return SlowRuntimeStub::StOwnByIndex(thread, obj.GetTaggedValue(), idx, value.GetTaggedValue()).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t StOwnByName(JSThread *thread, uint32_t string_id, uint64_t object, uint64_t val) { [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle obj_handle(thread, JSTaggedValue(object)); - JSHandle value_handle(thread, JSTaggedValue(val)); - - auto obj = obj_handle.GetTaggedValue(); - auto value = value_handle.GetTaggedValue(); - - JSTaggedValue prop = GetConstantPool(thread)->GetObjectFromCache(string_id); + JSHandle obj(thread, JSTaggedValue(object)); + JSHandle value(thread, JSTaggedValue(val)); + JSHandle prop(thread, GetConstantPool(thread)->GetObjectFromCache(string_id)); - if (obj.IsJSObject() && !obj.IsClassConstructor() && !obj.IsClassPrototype()) { + if (obj->IsJSObject() && !obj->IsClassConstructor() && !obj->IsClassPrototype()) { JSTaggedValue res = FastRuntimeStub::SetPropertyByName(thread, obj, prop, value); if (!res.IsHole()) { return res.GetRawData(); } } - obj = obj_handle.GetTaggedValue(); // Maybe moved by GC - value = value_handle.GetTaggedValue(); // Maybe moved by GC - GetConstantPool(thread)->GetObjectFromCache(string_id); // Maybe moved by GC - return SlowRuntimeStub::StOwnByName(thread, obj, prop, value).GetRawData(); + return SlowRuntimeStub::StOwnByName(thread, obj.GetTaggedValue(), prop.GetTaggedValue(), value.GetTaggedValue()) + .GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) @@ -1810,26 +1810,21 @@ INLINE_ECMA_INTRINSICS uint64_t StOwnByValue(JSThread *thread, uint64_t rec, uin { [[maybe_unused]] EcmaHandleScope handle_scope(thread); - auto receiver = JSTaggedValue(rec); - auto prop_key = JSTaggedValue(pkey); - auto value = JSTaggedValue(val); - - JSHandle receiver_handle(thread, receiver); - JSHandle prop_handle(thread, prop_key); - JSHandle value_handle(thread, value); + JSHandle receiver(thread, JSTaggedValue(rec)); + JSHandle prop(thread, JSTaggedValue(pkey)); + JSHandle value(thread, JSTaggedValue(val)); - if (receiver.IsHeapObject() && !receiver.IsClassConstructor() && !receiver.IsClassPrototype()) { - JSTaggedValue res = FastRuntimeStub::SetPropertyByValue(thread, receiver, prop_key, value); - prop_key = prop_handle.GetTaggedValue(); // Maybe moved by GC - value = value_handle.GetTaggedValue(); // Maybe moved by GC + if (receiver->IsHeapObject() && !receiver->IsClassConstructor() && !receiver->IsClassPrototype()) { + JSTaggedValue res = FastRuntimeStub::SetPropertyByValue(thread, receiver, prop, value); if (!res.IsHole()) { - if (value.IsJSFunction()) { - JSFunction::SetFunctionNameNoPrefix(thread, JSFunction::Cast(value.GetHeapObject()), prop_key); + if (value->IsJSFunction()) { + JSFunction::SetFunctionNameNoPrefix(thread, JSFunction::Cast(value.GetTaggedValue().GetHeapObject()), + prop.GetTaggedValue()); } return res.GetRawData(); } } - return SlowRuntimeStub::StOwnByValue(thread, receiver_handle, prop_handle, value_handle).GetRawData(); + return SlowRuntimeStub::StOwnByValue(thread, receiver, prop, value).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) diff --git a/runtime/js_array.cpp b/runtime/js_array.cpp index 012b3d6ad..c01f8ff2a 100644 --- a/runtime/js_array.cpp +++ b/runtime/js_array.cpp @@ -354,27 +354,26 @@ JSHandle JSArray::CreateArrayFromList(JSThread *thread, const JSHandle< JSHandle JSArray::FastGetPropertyByValue(JSThread *thread, const JSHandle &obj, uint32_t index) { - auto result = FastRuntimeStub::FastGetPropertyByIndex(thread, obj.GetTaggedValue(), index); + auto result = FastRuntimeStub::FastGetPropertyByIndex(thread, obj, index); return JSHandle(thread, result); } JSHandle JSArray::FastGetPropertyByValue(JSThread *thread, const JSHandle &obj, const JSHandle &key) { - auto result = FastRuntimeStub::FastGetPropertyByValue(thread, obj.GetTaggedValue(), key.GetTaggedValue()); + auto result = FastRuntimeStub::FastGetPropertyByValue(thread, obj, key); return JSHandle(thread, result); } bool JSArray::FastSetPropertyByValue(JSThread *thread, const JSHandle &obj, uint32_t index, const JSHandle &value) { - return FastRuntimeStub::FastSetPropertyByIndex(thread, obj.GetTaggedValue(), index, value.GetTaggedValue()); + return FastRuntimeStub::FastSetPropertyByIndex(thread, obj, index, value); } bool JSArray::FastSetPropertyByValue(JSThread *thread, const JSHandle &obj, const JSHandle &key, const JSHandle &value) { - return FastRuntimeStub::FastSetPropertyByValue(thread, obj.GetTaggedValue(), key.GetTaggedValue(), - value.GetTaggedValue()); + return FastRuntimeStub::FastSetPropertyByValue(thread, obj, key, value); } } // namespace panda::ecmascript diff --git a/runtime/js_handle.cpp b/runtime/js_handle.cpp new file mode 100644 index 000000000..8a01440a9 --- /dev/null +++ b/runtime/js_handle.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "runtime/include/coretypes/tagged_value.h" +#include "plugins/ecmascript/runtime/js_handle.h" + +namespace panda::ecmascript { +const JSTaggedValue JSPrimitiveHandle::UNDEFINED_VALUE = JSTaggedValue::Undefined(); +const JSTaggedValue JSPrimitiveHandle::NULL_VALUE = JSTaggedValue::Null(); +const JSTaggedValue JSPrimitiveHandle::TRUE_VALUE = JSTaggedValue(true); +const JSTaggedValue JSPrimitiveHandle::FALSE_VALUE = JSTaggedValue(false); +const JSTaggedValue JSPrimitiveHandle::EXCEPTION_VALUE = JSTaggedValue::Exception(); +const JSTaggedValue JSPrimitiveHandle::ZERO_VALUE = JSTaggedValue(0); + +} // namespace panda::ecmascript diff --git a/runtime/js_handle.h b/runtime/js_handle.h index b3096cb08..c454ffef2 100644 --- a/runtime/js_handle.h +++ b/runtime/js_handle.h @@ -128,8 +128,10 @@ public: GetTaggedValue().D(); } -private: +protected: inline explicit JSHandle(const JSTaggedType *slot) : HandleBase(reinterpret_cast(slot)) {} + +private: inline explicit JSHandle(const T *const *slot) : HandleBase(reinterpret_cast(slot)) {} friend class EcmaVM; @@ -249,6 +251,59 @@ private: Span sp_ {}; }; +class JSPrimitiveHandle : public JSHandle { +public: + explicit JSPrimitiveHandle(const JSTaggedValue *value) + : JSHandle(reinterpret_cast(value)) + { + ASSERT(value->IsNumber() || value->IsBoolean() || value->IsException() || value->IsUndefined() || + value->IsNull() || value->IsHole()); + } + + ~JSPrimitiveHandle() = default; + + static JSPrimitiveHandle Undefined() + { + return JSPrimitiveHandle(&UNDEFINED_VALUE); + } + + static JSPrimitiveHandle Null() + { + return JSPrimitiveHandle(&NULL_VALUE); + } + + static JSPrimitiveHandle True() + { + return JSPrimitiveHandle(&TRUE_VALUE); + } + + static JSPrimitiveHandle False() + { + return JSPrimitiveHandle(&FALSE_VALUE); + } + + static JSPrimitiveHandle Exception() + { + return JSPrimitiveHandle(&EXCEPTION_VALUE); + } + + static JSPrimitiveHandle Zero() + { + return JSPrimitiveHandle(&ZERO_VALUE); + } + + DEFAULT_NOEXCEPT_MOVE_SEMANTIC(JSPrimitiveHandle); + DEFAULT_COPY_SEMANTIC(JSPrimitiveHandle); + +private: + const static JSTaggedValue UNDEFINED_VALUE; + const static JSTaggedValue NULL_VALUE; + const static JSTaggedValue TRUE_VALUE; + const static JSTaggedValue FALSE_VALUE; + const static JSTaggedValue EXCEPTION_VALUE; + const static JSTaggedValue ZERO_VALUE; +}; + } // namespace panda::ecmascript #endif // ECMASCRIPT_JSHANDLE_H diff --git a/runtime/js_object.cpp b/runtime/js_object.cpp index 4527c4b34..3052098e8 100644 --- a/runtime/js_object.cpp +++ b/runtime/js_object.cpp @@ -1112,8 +1112,7 @@ bool JSObject::CreateDataProperty(JSThread *thread, const JSHandle &ob { ASSERT_PRINT(obj->IsECMAObject(), "Obj is not a valid object"); ASSERT_PRINT(JSTaggedValue::IsPropertyKey(key), "Key is not a property key"); - auto result = FastRuntimeStub::SetPropertyByValue(thread, obj.GetTaggedValue(), key.GetTaggedValue(), - value.GetTaggedValue()); + auto result = FastRuntimeStub::SetPropertyByValue(thread, JSHandle(obj), key, value); if (!result.IsHole()) { return result != JSTaggedValue::Exception(); } @@ -1125,8 +1124,7 @@ bool JSObject::CreateDataProperty(JSThread *thread, const JSHandle &ob const JSHandle &value) { ASSERT_PRINT(obj->IsECMAObject(), "Obj is not a valid object"); - auto result = - FastRuntimeStub::SetPropertyByIndex(thread, obj.GetTaggedValue(), index, value.GetTaggedValue()); + auto result = FastRuntimeStub::SetPropertyByIndex(thread, JSHandle(obj), index, value); if (!result.IsHole()) { return result != JSTaggedValue::Exception(); } @@ -1174,7 +1172,7 @@ bool JSObject::CreateMethodProperty(JSThread *thread, const JSHandle & JSHandle JSObject::GetMethod(JSThread *thread, const JSHandle &obj, const JSHandle &key) { - JSTaggedValue func = FastRuntimeStub::FastGetProperty(thread, obj.GetTaggedValue(), key.GetTaggedValue()); + JSTaggedValue func = FastRuntimeStub::FastGetProperty(thread, obj, key); if (func.IsUndefined() || func.IsNull()) { return JSHandle(thread, JSTaggedValue::Undefined()); } diff --git a/runtime/js_regexp_iterator.cpp b/runtime/js_regexp_iterator.cpp index 192741d5a..509afbd1a 100644 --- a/runtime/js_regexp_iterator.cpp +++ b/runtime/js_regexp_iterator.cpp @@ -87,9 +87,9 @@ JSTaggedValue JSRegExpIterator::Next(EcmaRuntimeCallInfo *argv) JSObject::GetProperty(thread, regexHandle, lastIndexString).GetValue()); JSTaggedNumber thisIndex = JSTaggedValue::ToLength(thread, getLastIndex); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - uint32_t nextIndex = BuiltinsRegExp::AdvanceStringIndex(inputStr, thisIndex.ToUint32(), fullUnicode); - FastRuntimeStub::FastSetPropertyByValue(thread, regexHandle.GetTaggedValue(), - lastIndexString.GetTaggedValue(), JSTaggedValue(nextIndex)); + JSTaggedValue nextIndex(BuiltinsRegExp::AdvanceStringIndex(inputStr, thisIndex.ToUint32(), fullUnicode)); + FastRuntimeStub::FastSetPropertyByValue(thread, regexHandle, lastIndexString, + JSPrimitiveHandle(&nextIndex)); } // iii. Return ! CreateIterResultObject(match, false). return JSIterator::CreateIterResultObject(thread, matchHandle, false).GetTaggedValue(); diff --git a/subproject_sources.gn b/subproject_sources.gn index 34d3a8ecb..ce83cd9a1 100644 --- a/subproject_sources.gn +++ b/subproject_sources.gn @@ -202,6 +202,7 @@ srcs_runtime = [ "runtime/vmstat/runtime_stat.cpp", "runtime/weak_vector.cpp", "runtime/class_info_extractor.cpp", + "runtime/js_handle.cpp", "runtime/compiler/ecmascript_runtime_interface.cpp", "runtime/tooling/pt_ecmascript_extension.cpp", "runtime/init_icu.cpp", -- Gitee From 2033f1e0a26c0113825707922891a9ff2f00b53a Mon Sep 17 00:00:00 2001 From: Artem Udovichenko Date: Tue, 22 Nov 2022 12:38:20 +0300 Subject: [PATCH 2/2] More handles Change-Id: I7d7250263de6d6bcee959f231616bf411f72c494 --- runtime/builtins/builtins_array.cpp | 2 +- runtime/intrinsics-inl.h | 131 ++++++++++++++-------------- 2 files changed, 66 insertions(+), 67 deletions(-) diff --git a/runtime/builtins/builtins_array.cpp b/runtime/builtins/builtins_array.cpp index 91645134c..84cf7da48 100644 --- a/runtime/builtins/builtins_array.cpp +++ b/runtime/builtins/builtins_array.cpp @@ -2348,7 +2348,7 @@ JSTaggedValue BuiltinsArray::Sort(EcmaRuntimeCallInfo *argv) // 1. Let obj be ToObject(this value). JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, GetThis(argv)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisHandle = JSHandle(thisObjHandle); + JSHandle thisHandle(thisObjHandle); JSHandle callbackFnHandle = GetCallArg(argv, 0); if (!callbackFnHandle->IsUndefined() && !callbackFnHandle->IsCallable()) { diff --git a/runtime/intrinsics-inl.h b/runtime/intrinsics-inl.h index d0ab0eb6d..1f205818d 100644 --- a/runtime/intrinsics-inl.h +++ b/runtime/intrinsics-inl.h @@ -416,14 +416,16 @@ INLINE_ECMA_INTRINSICS void TryStGlobalByValue([[maybe_unused]] JSThread *thread INLINE_ECMA_INTRINSICS uint64_t TryLdGlobalByName(JSThread *thread, uint32_t string_id, [[maybe_unused]] uint16_t slot_id) { + [[maybe_unused]] EcmaHandleScope handle_scope(thread); auto constpool = GetConstantPool(thread); - auto global_obj = GetGlobalObject(thread); - auto prop = constpool->GetObjectFromCache(string_id); + JSHandle global_obj(thread, GetGlobalObject(thread)); + JSHandle prop(thread, constpool->GetObjectFromCache(string_id)); JSTaggedValue result = JSTaggedValue::Hole(); #if ECMASCRIPT_ENABLE_IC if (ICRuntimeStub::HaveICForFunction(thread)) { - result = ICRuntimeStub::LoadGlobalICByName(thread, global_obj, prop, slot_id, true); + result = ICRuntimeStub::LoadGlobalICByName(thread, global_obj.GetTaggedValue(), prop.GetTaggedValue(), slot_id, + true); if (!result.IsHole()) { return result.GetRawData(); } @@ -432,11 +434,11 @@ INLINE_ECMA_INTRINSICS uint64_t TryLdGlobalByName(JSThread *thread, uint32_t str bool found = false; - result = FastRuntimeStub::GetGlobalOwnProperty(global_obj, prop, &found); + result = FastRuntimeStub::GetGlobalOwnProperty(global_obj.GetTaggedValue(), prop.GetTaggedValue(), &found); if (found) { return result.GetRawData(); } - return SlowRuntimeStub::TryLdGlobalByName(thread, global_obj, prop).GetRawData(); + return SlowRuntimeStub::TryLdGlobalByName(thread, global_obj.GetTaggedValue(), prop.GetTaggedValue()).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) @@ -897,13 +899,14 @@ INLINE_ECMA_INTRINSICS uint64_t Ldglobal(JSThread *thread) INLINE_ECMA_INTRINSICS uint64_t LdObjByValue(JSThread *thread, uint64_t rec, uint64_t pkey, [[maybe_unused]] uint16_t slot_id) { - auto receiver = JSTaggedValue(rec); - auto prop_key = JSTaggedValue(pkey); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle receiver(thread, JSTaggedValue(rec)); + JSHandle prop_key(thread, JSTaggedValue(pkey)); JSTaggedValue res = JSTaggedValue::Hole(); #if ECMASCRIPT_ENABLE_IC if (ICRuntimeStub::HaveICForFunction(thread)) { - res = ICRuntimeStub::LoadICByValue(thread, receiver, prop_key, slot_id); + res = ICRuntimeStub::LoadICByValue(thread, receiver.GetTaggedValue(), prop_key.GetTaggedValue(), slot_id); if (LIKELY(!res.IsHole())) { return res.GetRawData(); } @@ -911,17 +914,14 @@ INLINE_ECMA_INTRINSICS uint64_t LdObjByValue(JSThread *thread, uint64_t rec, uin #endif // fast path - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle receiver_handle(thread, receiver); - JSHandle prop_handle(thread, prop_key); - if (LIKELY(receiver.IsHeapObject())) { - res = FastRuntimeStub::GetPropertyByValue(thread, receiver_handle, prop_handle); + if (LIKELY(receiver->IsHeapObject())) { + res = FastRuntimeStub::GetPropertyByValue(thread, receiver, prop_key); if (!res.IsHole()) { return res.GetRawData(); } } // slow path - return SlowRuntimeStub::LdObjByValue(thread, receiver_handle.GetTaggedValue(), prop_handle.GetTaggedValue(), false, + return SlowRuntimeStub::LdObjByValue(thread, receiver.GetTaggedValue(), prop_key.GetTaggedValue(), false, JSTaggedValue::Undefined()) .GetRawData(); } @@ -930,47 +930,48 @@ INLINE_ECMA_INTRINSICS uint64_t LdObjByValue(JSThread *thread, uint64_t rec, uin INLINE_ECMA_INTRINSICS uint64_t StObjByValue(JSThread *thread, uint64_t rec, uint64_t pkey, uint64_t val, [[maybe_unused]] uint16_t slot_id) { - auto receiver = JSTaggedValue(rec); - auto prop_key = JSTaggedValue(pkey); - auto value = JSTaggedValue(val); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle receiver(thread, JSTaggedValue(rec)); + JSHandle prop_key(thread, JSTaggedValue(pkey)); + JSHandle value(thread, JSTaggedValue(val)); JSTaggedValue res = JSTaggedValue::Hole(); #if ECMASCRIPT_ENABLE_IC if (ICRuntimeStub::HaveICForFunction(thread)) { - res = ICRuntimeStub::StoreICByValue(thread, receiver, prop_key, value, slot_id); + res = ICRuntimeStub::StoreICByValue(thread, receiver.GetTaggedValue(), prop_key.GetTaggedValue(), + value.GetTaggedValue(), slot_id); if (LIKELY(!res.IsHole())) { return res.GetRawData(); } } #endif - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle receiver_handle(thread, receiver); - JSHandle prop_handle(thread, prop_key); - JSHandle value_handle(thread, value); - if (receiver.IsHeapObject()) { - res = FastRuntimeStub::SetPropertyByValue(thread, receiver_handle, prop_handle, value_handle); + if (receiver->IsHeapObject()) { + res = FastRuntimeStub::SetPropertyByValue(thread, receiver, prop_key, value); if (!res.IsHole()) { return res.GetRawData(); } } - return SlowRuntimeStub::StObjByValue(thread, receiver_handle.GetTaggedValue(), prop_handle.GetTaggedValue(), - value_handle.GetTaggedValue()) + return SlowRuntimeStub::StObjByValue(thread, receiver.GetTaggedValue(), prop_key.GetTaggedValue(), + value.GetTaggedValue()) .GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t TryStGlobalByName(JSThread *thread, uint32_t string_id, uint64_t value, +INLINE_ECMA_INTRINSICS uint64_t TryStGlobalByName(JSThread *thread, uint32_t string_id, uint64_t val, [[maybe_unused]] uint16_t slot_id) { - JSTaggedValue prop_key = GetConstantPool(thread)->GetObjectFromCache(string_id); - auto global_obj = GetGlobalObject(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle prop_key(thread, GetConstantPool(thread)->GetObjectFromCache(string_id)); + JSHandle global_obj(thread, GetGlobalObject(thread)); + JSHandle value(thread, JSTaggedValue(val)); JSTaggedValue result = JSTaggedValue::Hole(); #if ECMASCRIPT_ENABLE_IC if (ICRuntimeStub::HaveICForFunction(thread)) { - result = ICRuntimeStub::StoreGlobalICByName(thread, global_obj, prop_key, JSTaggedValue(value), slot_id, true); + result = ICRuntimeStub::StoreGlobalICByName(thread, global_obj.GetTaggedValue(), prop_key.GetTaggedValue(), + value.GetTaggedValue(), slot_id, true); if (!result.IsHole()) { return result.GetRawData(); } @@ -979,26 +980,28 @@ INLINE_ECMA_INTRINSICS uint64_t TryStGlobalByName(JSThread *thread, uint32_t str bool found = false; // 2. find from global object - FastRuntimeStub::GetGlobalOwnProperty(global_obj, prop_key, &found); + FastRuntimeStub::GetGlobalOwnProperty(global_obj.GetTaggedValue(), prop_key.GetTaggedValue(), &found); if (!found) { - result = SlowRuntimeStub::ThrowReferenceError(thread, prop_key, " is not defined"); + result = SlowRuntimeStub::ThrowReferenceError(thread, prop_key.GetTaggedValue(), " is not defined"); if (result.IsException()) { return result.GetRawData(); } } - return SlowRuntimeStub::StGlobalVar(thread, prop_key, JSTaggedValue(value)).GetRawData(); + return SlowRuntimeStub::StGlobalVar(thread, prop_key.GetTaggedValue(), value.GetTaggedValue()).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t LdGlobalVar(JSThread *thread, uint32_t string_id, [[maybe_unused]] uint16_t slot_id) { - auto global_obj = thread->GetGlobalObject(); - auto prop_key = GetConstantPool(thread)->GetObjectFromCache(string_id); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle global_obj(thread, thread->GetGlobalObject()); + JSHandle prop_key(thread, GetConstantPool(thread)->GetObjectFromCache(string_id)); JSTaggedValue result = JSTaggedValue::Hole(); #if ECMASCRIPT_ENABLE_IC if (ICRuntimeStub::HaveICForFunction(thread)) { - result = ICRuntimeStub::LoadGlobalICByName(thread, global_obj, prop_key, slot_id); + result = + ICRuntimeStub::LoadGlobalICByName(thread, global_obj.GetTaggedValue(), prop_key.GetTaggedValue(), slot_id); if (!result.IsHole()) { return result.GetRawData(); } @@ -1006,60 +1009,60 @@ INLINE_ECMA_INTRINSICS uint64_t LdGlobalVar(JSThread *thread, uint32_t string_id #endif bool found = false; - result = FastRuntimeStub::GetGlobalOwnProperty(global_obj, prop_key, &found); + result = FastRuntimeStub::GetGlobalOwnProperty(global_obj.GetTaggedValue(), prop_key.GetTaggedValue(), &found); if (found) { return result.GetRawData(); } - return SlowRuntimeStub::LdGlobalVar(thread, global_obj, prop_key).GetRawData(); + return SlowRuntimeStub::LdGlobalVar(thread, global_obj.GetTaggedValue(), prop_key.GetTaggedValue()).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) -INLINE_ECMA_INTRINSICS uint64_t StGlobalVar(JSThread *thread, uint32_t string_id, uint64_t value, +INLINE_ECMA_INTRINSICS uint64_t StGlobalVar(JSThread *thread, uint32_t string_id, uint64_t val, [[maybe_unused]] uint16_t slot_id) { - auto global_obj = thread->GetGlobalObject(); - JSTaggedValue prop = GetConstantPool(thread)->GetObjectFromCache(string_id); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle global_obj(thread, thread->GetGlobalObject()); + JSHandle prop(thread, GetConstantPool(thread)->GetObjectFromCache(string_id)); + JSHandle value(thread, JSTaggedValue(val)); #if ECMASCRIPT_ENABLE_IC if (ICRuntimeStub::HaveICForFunction(thread)) { - JSTaggedValue result = - ICRuntimeStub::StoreGlobalICByName(thread, global_obj, prop, JSTaggedValue(value), slot_id); + JSTaggedValue result = ICRuntimeStub::StoreGlobalICByName( + thread, global_obj.GetTaggedValue(), prop.GetTaggedValue(), value.GetTaggedValue(), slot_id); if (!result.IsHole()) { return result.GetRawData(); } } #endif - return SlowRuntimeStub::StGlobalVar(thread, prop, JSTaggedValue(value)).GetRawData(); + return SlowRuntimeStub::StGlobalVar(thread, prop.GetTaggedValue(), value.GetTaggedValue()).GetRawData(); } // NOLINTNEXTLINE(misc-definitions-in-headers) INLINE_ECMA_INTRINSICS uint64_t LdObjByName(JSThread *thread, uint32_t string_id, uint64_t object, [[maybe_unused]] uint16_t slot_id) { - auto obj = JSTaggedValue(object); - auto prop_key = GetConstantPool(thread)->GetObjectFromCache(string_id); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle obj(thread, JSTaggedValue(object)); + JSHandle prop_key(thread, GetConstantPool(thread)->GetObjectFromCache(string_id)); JSTaggedValue res = JSTaggedValue::Hole(); #if ECMASCRIPT_ENABLE_IC if (ICRuntimeStub::HaveICForFunction(thread)) { - res = ICRuntimeStub::LoadICByName(thread, obj, prop_key, slot_id); + res = ICRuntimeStub::LoadICByName(thread, obj.GetTaggedValue(), prop_key.GetTaggedValue(), slot_id); if (LIKELY(!res.IsHole())) { return res.GetRawData(); } } #endif - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle hobj(thread, obj); - JSHandle hprop_key(thread, prop_key); - if (LIKELY(hobj->IsHeapObject())) { - res = FastRuntimeStub::GetPropertyByName(thread, hobj, hprop_key); + if (LIKELY(obj->IsHeapObject())) { + res = FastRuntimeStub::GetPropertyByName(thread, obj, prop_key); if (!res.IsHole()) { return res.GetRawData(); } } - return SlowRuntimeStub::LdObjByName(thread, hobj.GetTaggedValue(), hprop_key.GetTaggedValue(), false, + return SlowRuntimeStub::LdObjByName(thread, obj.GetTaggedValue(), prop_key.GetTaggedValue(), false, JSTaggedValue::Undefined()) .GetRawData(); } @@ -1068,33 +1071,29 @@ INLINE_ECMA_INTRINSICS uint64_t LdObjByName(JSThread *thread, uint32_t string_id INLINE_ECMA_INTRINSICS uint64_t StObjByName(JSThread *thread, uint32_t string_id, uint64_t object, uint64_t val, [[maybe_unused]] uint16_t slot_id) { - auto obj = JSTaggedValue(object); - auto value = JSTaggedValue(val); - - auto prop_key = GetConstantPool(thread)->GetObjectFromCache(string_id); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle obj(thread, JSTaggedValue(object)); + JSHandle value(thread, JSTaggedValue(val)); + JSHandle prop_key(thread, GetConstantPool(thread)->GetObjectFromCache(string_id)); JSTaggedValue res = JSTaggedValue::Hole(); #if ECMASCRIPT_ENABLE_IC if (ICRuntimeStub::HaveICForFunction(thread)) { - res = ICRuntimeStub::StoreICByName(thread, obj, prop_key, value, slot_id); + res = ICRuntimeStub::StoreICByName(thread, obj.GetTaggedValue(), prop_key.GetTaggedValue(), + value.GetTaggedValue(), slot_id); if (LIKELY(!res.IsHole())) { return res.GetRawData(); } } #endif - [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle hobj(thread, obj); - JSHandle hprop_key(thread, prop_key); - JSHandle hvalue(thread, value); - if (hobj->IsHeapObject()) { - res = FastRuntimeStub::SetPropertyByName(thread, hobj, hprop_key, hvalue); + if (obj->IsHeapObject()) { + res = FastRuntimeStub::SetPropertyByName(thread, obj, prop_key, value); if (!res.IsHole()) { return res.GetRawData(); } } - return SlowRuntimeStub::StObjByName(thread, hobj.GetTaggedValue(), hprop_key.GetTaggedValue(), - hvalue.GetTaggedValue()) + return SlowRuntimeStub::StObjByName(thread, obj.GetTaggedValue(), prop_key.GetTaggedValue(), value.GetTaggedValue()) .GetRawData(); } -- Gitee