primitive_scope part3

delete JsPrimitiveHandle, directly overload the JsHandle constructor
Signed-off-by: huangzhenghua <huangzhenghua3@huawei.com>
Change-Id: Ifc04212cf2241b9764acbdb76a89ebd0b07fa3dc
This commit is contained in:
huangzhenghua 2024-05-10 12:29:07 +08:00
parent 91e54b81b6
commit 4d68d80c28
3 changed files with 14 additions and 133 deletions

View File

@ -86,6 +86,16 @@ public:
address_ = EcmaHandleScope::NewHandle(const_cast<JSThread *>(thread), value.GetRawData());
}
JSHandle(const JSThread *thread, JSTaggedValue value, bool isPrimitive)
{
if (LIKELY(isPrimitive)) {
address_ = EcmaHandleScope::NewPrimitiveHandle(
const_cast<JSThread *>(thread), value.GetRawData());
return;
}
address_ = EcmaHandleScope::NewHandle(const_cast<JSThread *>(thread), value.GetRawData());
}
JSHandle(const JSThread *thread, const TaggedObject *value)
{
address_ = EcmaHandleScope::NewHandle(const_cast<JSThread *>(thread), JSTaggedValue(value).GetRawData());
@ -234,127 +244,6 @@ public:
*addr = handle.GetTaggedValue();
}
};
template <typename T>
class JSPrimitiveHandle {
public:
inline JSPrimitiveHandle() : address_(reinterpret_cast<uintptr_t>(nullptr)) {}
~JSPrimitiveHandle() = default;
DEFAULT_NOEXCEPT_MOVE_SEMANTIC(JSPrimitiveHandle);
DEFAULT_COPY_SEMANTIC(JSPrimitiveHandle);
JSPrimitiveHandle(const JSThread *thread, JSTaggedValue value)
{
address_ = EcmaHandleScope::NewPrimitiveHandle(
const_cast<JSThread *>(thread), value.GetRawData());
}
JSPrimitiveHandle(const JSThread *thread, const TaggedObject *value)
{
address_ = EcmaHandleScope::NewPrimitiveHandle(
const_cast<JSThread *>(thread), JSTaggedValue(value).GetRawData());
}
inline uintptr_t GetAddress() const
{
return address_;
}
template <typename S>
explicit JSPrimitiveHandle(const JSPrimitiveHandle<S> &handle) : address_(handle.GetAddress()) {}
template <typename S>
inline static JSPrimitiveHandle<T> Cast(const JSPrimitiveHandle<S> &handle)
{
T::Cast(handle.GetTaggedValue().GetTaggedObject());
return JSPrimitiveHandle<T>(handle.GetAddress());
}
inline JSTaggedValue GetTaggedValue() const
{
CHECK_NO_DEREF_HANDLE;
if (GetAddress() == 0U) {
return JSTaggedValue::Undefined();
}
return *(reinterpret_cast<JSTaggedValue *>(GetAddress())); // NOLINT(clang-analyzer-core.NullDereference)
}
inline JSTaggedType GetTaggedType() const
{
CHECK_NO_DEREF_HANDLE;
if (GetAddress() == 0U) {
return JSTaggedValue::Undefined().GetRawData();
}
return *reinterpret_cast<JSTaggedType *>(GetAddress()); // NOLINT(clang-analyzer-core.NullDereference)
}
inline T *operator*() const
{
return T::Cast(GetTaggedValue().GetTaggedObject());
}
inline T *operator->() const
{
return T::Cast(GetTaggedValue().GetTaggedObject());
}
inline bool operator==(const JSPrimitiveHandle<T> &other) const
{
return GetTaggedType() == other.GetTaggedType();
}
inline bool operator!=(const JSPrimitiveHandle<T> &other) const
{
return GetTaggedType() != other.GetTaggedType();
}
inline bool IsEmpty() const
{
return GetAddress() == 0U;
}
template <typename R>
R *GetObject() const
{
return reinterpret_cast<R *>(GetTaggedValue().GetTaggedObject());
}
inline explicit JSPrimitiveHandle(uintptr_t slot) : address_(slot)
{
if (!std::is_convertible<T *, JSTaggedValue *>::value) {
ASSERT(slot != 0);
if ((*reinterpret_cast<JSTaggedValue *>(slot)).IsHeapObject()) {
T::Cast((*reinterpret_cast<JSTaggedValue *>(slot)).GetTaggedObject());
}
}
}
void Dump() const DUMP_API_ATTR
{
GetTaggedValue().D();
}
private:
inline explicit JSPrimitiveHandle(const JSTaggedType *slot) : address_(reinterpret_cast<uintptr_t>(slot)) {}
inline explicit JSPrimitiveHandle(const T *const *slot) : address_(reinterpret_cast<uintptr_t>(slot)) {}
uintptr_t address_; // NOLINT(misc-non-private-member-variables-in-classes)
friend class EcmaVM;
friend class GlobalEnv;
friend class GlobalHandleCollection;
friend class RuntimeStubs;
};
template <>
inline JSTaggedValue *JSPrimitiveHandle<JSTaggedValue>::operator->() const
{
return reinterpret_cast<JSTaggedValue *>(GetAddress());
}
template <>
inline JSTaggedValue *JSPrimitiveHandle<JSTaggedValue>::operator*() const
{
return reinterpret_cast<JSTaggedValue *>(GetAddress());
}
} // namespace panda::ecmascript
#endif // ECMASCRIPT_JSHANDLE_H

View File

@ -192,8 +192,6 @@ using ecmascript::base::NumberHelper;
template <typename T>
using JSHandle = ecmascript::JSHandle<T>;
template <typename T>
using JSPrimitiveHandle = ecmascript::JSPrimitiveHandle<T>;
template <typename T>
using JSMutableHandle = ecmascript::JSMutableHandle<T>;
using PathHelper = ecmascript::base::PathHelper;
@ -900,7 +898,7 @@ Local<NumberRef> NumberRef::New(const EcmaVM *vm, double input)
if (std::isnan(input)) {
input = ecmascript::base::NAN_VALUE;
}
JSPrimitiveHandle<JSTaggedValue> number(thread, JSTaggedValue(input));
JSHandle<JSTaggedValue> number(thread, JSTaggedValue(input), true);
return JSNApiHelper::ToLocal<NumberRef>(number);
}
@ -909,7 +907,7 @@ Local<NumberRef> NumberRef::New(const EcmaVM *vm, int32_t input)
// Omit exception check because ark calls here may not
// cause side effect even pending exception exists.
CROSS_THREAD_CHECK(vm);
JSPrimitiveHandle<JSTaggedValue> number(thread, JSTaggedValue(input));
JSHandle<JSTaggedValue> number(thread, JSTaggedValue(input), true);
return JSNApiHelper::ToLocal<NumberRef>(number);
}
@ -918,7 +916,7 @@ Local<NumberRef> NumberRef::New(const EcmaVM *vm, uint32_t input)
// Omit exception check because ark calls here may not
// cause side effect even pending exception exists.
CROSS_THREAD_CHECK(vm);
JSPrimitiveHandle<JSTaggedValue> number(thread, JSTaggedValue(input));
JSHandle<JSTaggedValue> number(thread, JSTaggedValue(input), true);
return JSNApiHelper::ToLocal<NumberRef>(number);
}
@ -927,7 +925,7 @@ Local<NumberRef> NumberRef::New(const EcmaVM *vm, int64_t input)
// Omit exception check because ark calls here may not
// cause side effect even pending exception exists.
CROSS_THREAD_CHECK(vm);
JSPrimitiveHandle<JSTaggedValue> number(thread, JSTaggedValue(input));
JSHandle<JSTaggedValue> number(thread, JSTaggedValue(input), true);
return JSNApiHelper::ToLocal<NumberRef>(number);
}

View File

@ -121,12 +121,6 @@ public:
return Local<T>(from.GetAddress());
}
template<typename T>
static inline Local<T> ToLocal(ecmascript::JSPrimitiveHandle<ecmascript::JSTaggedValue> from)
{
return Local<T>(from.GetAddress());
}
static inline ecmascript::JSTaggedValue ToJSTaggedValue(JSValueRef *from)
{
ASSERT(from != nullptr);