From 9a907ba3c3e6ace7960d90f5cd8ec24689bead12 Mon Sep 17 00:00:00 2001 From: wengchangcheng Date: Tue, 25 Jan 2022 18:05:12 +0800 Subject: [PATCH] optimize primitive type ACCESSORS Signed-off-by: wengchangcheng --- ecmascript/accessor_data.h | 25 +- ecmascript/base/typed_array_helper.cpp | 4 +- ecmascript/builtins/builtins_arraybuffer.cpp | 40 +-- ecmascript/builtins/builtins_arraybuffer.h | 20 +- ecmascript/builtins/builtins_dataview.cpp | 43 ++- ecmascript/builtins/builtins_generator.cpp | 4 +- ecmascript/builtins/builtins_map.cpp | 2 +- ecmascript/builtins/builtins_promise.cpp | 40 +-- ecmascript/builtins/builtins_regexp.cpp | 2 +- .../builtins/builtins_string_iterator.cpp | 4 +- ecmascript/builtins/builtins_weak_map.cpp | 2 +- .../builtins/tests/builtins_map_test.cpp | 6 +- .../builtins/tests/builtins_promise_test.cpp | 90 ++--- .../builtins/tests/builtins_set_test.cpp | 4 +- ecmascript/class_info_extractor.cpp | 8 +- ecmascript/class_info_extractor.h | 51 +-- ecmascript/class_linker/program_object-inl.h | 7 - ecmascript/class_linker/program_object.h | 32 +- ecmascript/compiler/stub-inl.h | 6 +- ecmascript/compiler/stub_aot_compiler.cpp | 3 +- ecmascript/dump.cpp | 328 ++++++------------ ecmascript/ecma_macros.h | 180 +++++----- ecmascript/ecma_string.h | 8 +- ecmascript/ecma_vm.h | 7 +- ecmascript/free_object.h | 11 +- ecmascript/generator_helper.cpp | 17 +- ecmascript/generator_helper.h | 10 +- ecmascript/global_dictionary-inl.h | 2 +- ecmascript/global_env_constants.cpp | 3 - ecmascript/global_env_constants.h | 1 - ecmascript/hprof/heap_snapshot.cpp | 4 - ecmascript/hprof/tests/hprof_test.cpp | 1 - ecmascript/ic/proto_change_details.h | 17 +- ecmascript/interpreter/interpreter-inl.h | 38 +- .../interpreter/slow_runtime_helper.cpp | 4 +- ecmascript/interpreter/slow_runtime_stub.cpp | 25 +- ecmascript/js_arguments.h | 1 - ecmascript/js_array_iterator.cpp | 6 +- ecmascript/js_array_iterator.h | 14 +- ecmascript/js_arraybuffer.cpp | 6 +- ecmascript/js_arraybuffer.h | 17 +- ecmascript/js_async_function.cpp | 8 +- ecmascript/js_collator.cpp | 35 +- ecmascript/js_collator.h | 30 +- ecmascript/js_dataview.cpp | 4 +- ecmascript/js_dataview.h | 9 +- ecmascript/js_date_time_format.cpp | 48 +-- ecmascript/js_date_time_format.h | 26 +- ecmascript/js_for_in_iterator.cpp | 8 +- ecmascript/js_for_in_iterator.h | 15 +- ecmascript/js_function.cpp | 6 +- ecmascript/js_function.h | 91 ++--- ecmascript/js_function_extra_info.h | 42 --- ecmascript/js_function_kind.h | 6 +- ecmascript/js_generator_object.cpp | 47 ++- ecmascript/js_generator_object.h | 45 ++- ecmascript/js_hclass.cpp | 18 +- ecmascript/js_hclass.h | 27 +- ecmascript/js_iterator.cpp | 2 +- ecmascript/js_iterator.h | 7 +- ecmascript/js_locale.h | 10 +- ecmascript/js_map_iterator.cpp | 10 +- ecmascript/js_map_iterator.h | 14 +- ecmascript/js_native_pointer.h | 7 +- ecmascript/js_number_format.cpp | 50 +-- ecmascript/js_number_format.h | 49 +-- ecmascript/js_plural_rules.cpp | 20 +- ecmascript/js_plural_rules.h | 19 +- ecmascript/js_promise.cpp | 17 +- ecmascript/js_promise.h | 57 +-- ecmascript/js_proxy.h | 12 +- ecmascript/js_regexp.h | 8 +- ecmascript/js_relative_time_format.cpp | 35 +- ecmascript/js_relative_time_format.h | 20 +- ecmascript/js_serializer.cpp | 24 +- ecmascript/js_set_iterator.cpp | 10 +- ecmascript/js_set_iterator.h | 15 +- ecmascript/js_string_iterator.cpp | 2 +- ecmascript/js_string_iterator.h | 5 +- ecmascript/js_symbol.h | 82 ++--- ecmascript/js_tagged_value-inl.h | 12 +- ecmascript/js_tagged_value.h | 2 - ecmascript/linked_hash_table.cpp | 2 +- ecmascript/mem/machine_code.h | 9 +- ecmascript/mem/object_xray-inl.h | 6 - ecmascript/napi/include/jsnapi.h | 8 +- ecmascript/napi/jsnapi.cpp | 114 ++---- ecmascript/object_factory.cpp | 115 +++--- ecmascript/object_factory.h | 15 +- .../snapshot/mem/snapshot_serialize.cpp | 4 +- ecmascript/stub_module.cpp | 2 +- ecmascript/tagged_array.h | 5 +- ecmascript/tagged_dictionary.cpp | 2 +- ecmascript/tests/dump_test.cpp | 59 ++-- ecmascript/tests/js_array_iterator_test.cpp | 29 +- ecmascript/tests/js_dataview_test.cpp | 24 +- ecmascript/tests/js_function_test.cpp | 1 - ecmascript/tests/js_object_test.cpp | 40 +-- ecmascript/tests/js_promise_test.cpp | 20 +- ecmascript/tests/js_serializer_test.cpp | 13 +- ecmascript/transitions_dictionary.h | 2 +- 101 files changed, 1062 insertions(+), 1455 deletions(-) delete mode 100644 ecmascript/js_function_extra_info.h diff --git a/ecmascript/accessor_data.h b/ecmascript/accessor_data.h index 830c5fd435..81123e1acf 100644 --- a/ecmascript/accessor_data.h +++ b/ecmascript/accessor_data.h @@ -69,10 +69,16 @@ public: DECL_VISIT_OBJECT(GETTER_OFFSET, SIZE) }; +enum class CompletionRecordType : uint8_t { + NORMAL = 0U, + BREAK, + CONTINUE, + RETURN, + THROW +}; + class CompletionRecord final : public Record { public: - enum : uint8_t { NORMAL = 0U, BREAK, CONTINUE, RETURN, THROW }; - static CompletionRecord *Cast(ObjectHeader *object) { ASSERT(JSTaggedValue(object).IsCompletionRecord()); @@ -81,16 +87,21 @@ public: bool IsThrow() const { - return JSTaggedValue::SameValue(this->GetType(), JSTaggedValue(static_cast(THROW))); + return GetType() == CompletionRecordType::THROW; } - static constexpr size_t TYPE_OFFSET = Record::SIZE; - ACCESSORS(Type, TYPE_OFFSET, VALUE_OFFSET); - ACCESSORS(Value, VALUE_OFFSET, SIZE); + static constexpr size_t VALUE_OFFSET = Record::SIZE; + ACCESSORS(Value, VALUE_OFFSET, BIT_FIELD_OFFSET) + ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); + + // define BitField + static constexpr size_t TYPE_BITS = 3; + FIRST_BIT_FIELD(BitField, Type, CompletionRecordType, TYPE_BITS) DECL_DUMP() - DECL_VISIT_OBJECT(TYPE_OFFSET, SIZE) + DECL_VISIT_OBJECT(VALUE_OFFSET, BIT_FIELD_OFFSET) }; } // namespace panda::ecmascript #endif // ECMASCRIPT_ACCESSOR_DATA_H diff --git a/ecmascript/base/typed_array_helper.cpp b/ecmascript/base/typed_array_helper.cpp index dcd4ab8de3..63ef30627e 100644 --- a/ecmascript/base/typed_array_helper.cpp +++ b/ecmascript/base/typed_array_helper.cpp @@ -291,9 +291,7 @@ JSTaggedValue TypedArrayHelper::CreateFromArrayBuffer(EcmaRuntimeCallInfo *argv, THROW_TYPE_ERROR_AND_RETURN(thread, "The srcData is detached buffer.", JSTaggedValue::Exception()); } // 10. Let bufferByteLength be buffer.[[ArrayBufferByteLength]]. - JSTaggedNumber newLengthNum = - JSTaggedNumber::FromIntOrDouble(thread, JSHandle(buffer)->GetArrayBufferByteLength()); - int32_t bufferByteLength = newLengthNum.ToInt32(); + uint32_t bufferByteLength = JSHandle(buffer)->GetArrayBufferByteLength(); // 11. If length is undefined, then // a. If bufferByteLength modulo elementSize ≠ 0, throw a RangeError exception. // b. Let newByteLength be bufferByteLength - offset. diff --git a/ecmascript/builtins/builtins_arraybuffer.cpp b/ecmascript/builtins/builtins_arraybuffer.cpp index 8e82578cd0..cf3f5f8eeb 100644 --- a/ecmascript/builtins/builtins_arraybuffer.cpp +++ b/ecmascript/builtins/builtins_arraybuffer.cpp @@ -98,7 +98,7 @@ JSTaggedValue BuiltinsArrayBuffer::GetByteLength(EcmaRuntimeCallInfo *argv) } JSHandle arrBuf(thisHandle); // 5. Let length be the value of O’s [[ArrayBufferByteLength]] internal slot. - JSTaggedValue length = arrBuf->GetArrayBufferByteLength(); + uint32_t length = arrBuf->GetArrayBufferByteLength(); // 6. Return length. return JSTaggedValue(length); } @@ -128,14 +128,12 @@ JSTaggedValue BuiltinsArrayBuffer::Slice(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "this value IsDetachedBuffer", JSTaggedValue::Exception()); } // 5. Let len be the value of O’s [[ArrayBufferByteLength]] internal slot. - JSTaggedNumber lengthNum = JSTaggedNumber::FromIntOrDouble(thread, arrBuf->GetArrayBufferByteLength()); - RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + int32_t len = arrBuf->GetArrayBufferByteLength(); JSHandle startHandle = GetCallArg(argv, 0); // 6. Let relativeStart be ToInteger(start). JSTaggedNumber relativeStart = JSTaggedValue::ToInteger(thread, startHandle); // 7. ReturnIfAbrupt(relativeStart). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t len = lengthNum.ToInt32(); int32_t start = base::NumberHelper::DoubleInRangeInt32(relativeStart.GetNumber()); int32_t end; int32_t first; @@ -163,7 +161,7 @@ JSTaggedValue BuiltinsArrayBuffer::Slice(EcmaRuntimeCallInfo *argv) last = std::min(end, len); } // 12. Let newLen be max(final-first,0). - int32_t newLen = std::max((last - first), 0); + uint32_t newLen = std::max((last - first), 0); // 13. Let ctor be SpeciesConstructor(O, %ArrayBuffer%). JSHandle defaultConstructor = env->GetArrayBufferFunction(); JSHandle objHandle(thisHandle); @@ -192,8 +190,7 @@ JSTaggedValue BuiltinsArrayBuffer::Slice(EcmaRuntimeCallInfo *argv) } JSHandle newJsArrBuf(newArrBuf); // 20. If the value of new’s [[ArrayBufferByteLength]] internal slot < newLen, throw a TypeError exception. - JSTaggedNumber newLengthNum = JSTaggedNumber::FromIntOrDouble(thread, newJsArrBuf->GetArrayBufferByteLength()); - int32_t newArrBufLen = newLengthNum.ToInt32(); + uint32_t newArrBufLen = newJsArrBuf->GetArrayBufferByteLength(); if (newArrBufLen < newLen) { THROW_TYPE_ERROR_AND_RETURN(thread, "new array buffer length smaller than newlen", JSTaggedValue::Exception()); } @@ -250,7 +247,7 @@ JSTaggedValue BuiltinsArrayBuffer::AllocateArrayBuffer(JSThread *thread, const J // 6. Set obj’s [[ArrayBufferData]] internal slot to block. factory->NewJSArrayBufferData(arrayBuffer, byteLength); // 7. Set obj’s [[ArrayBufferByteLength]] internal slot to byteLength. - arrayBuffer->SetArrayBufferByteLength(thread, JSTaggedValue(static_cast(byteLength))); + arrayBuffer->SetArrayBufferByteLength(static_cast(byteLength)); // 8. Return obj. return arrayBuffer.GetTaggedValue(); } @@ -269,7 +266,7 @@ bool BuiltinsArrayBuffer::IsDetachedBuffer(JSTaggedValue arrayBuffer) // 24.1.1.4 JSTaggedValue BuiltinsArrayBuffer::CloneArrayBuffer(JSThread *thread, const JSHandle &srcBuffer, - int32_t srcByteOffset, JSHandle constructor) + uint32_t srcByteOffset, JSHandle constructor) { BUILTINS_API_TRACE(thread, ArrayBuffer, CloneArrayBuffer); // 1. Assert: Type(srcBuffer) is Object and it has an [[ArrayBufferData]] internal slot. @@ -292,8 +289,7 @@ JSTaggedValue BuiltinsArrayBuffer::CloneArrayBuffer(JSThread *thread, const JSHa } // 4. Let srcLength be the value of srcBuffer’s [[ArrayBufferByteLength]] internal slot. JSHandle arrBuf(srcBuffer); - JSTaggedNumber lengthNumber = JSTaggedNumber::FromIntOrDouble(thread, arrBuf->GetArrayBufferByteLength()); - int32_t srcLen = lengthNumber.ToInt32(); + uint32_t srcLen = arrBuf->GetArrayBufferByteLength(); // 5. Assert: srcByteOffset ≤ srcLength. ASSERT(srcByteOffset <= srcLen); // 6. Let cloneLength be srcLength – srcByteOffset. @@ -320,7 +316,7 @@ JSTaggedValue BuiltinsArrayBuffer::CloneArrayBuffer(JSThread *thread, const JSHa // 24.1.1.5 // NOLINTNEXTLINE(readability-function-size) -JSTaggedValue BuiltinsArrayBuffer::GetValueFromBuffer(JSTaggedValue arrBuf, int32_t byteIndex, DataViewType type, +JSTaggedValue BuiltinsArrayBuffer::GetValueFromBuffer(JSTaggedValue arrBuf, uint32_t byteIndex, DataViewType type, bool littleEndian) { JSArrayBuffer *jsArrayBuffer = JSArrayBuffer::Cast(arrBuf.GetTaggedObject()); @@ -358,7 +354,7 @@ JSTaggedValue BuiltinsArrayBuffer::GetValueFromBuffer(JSTaggedValue arrBuf, int3 } // 24.1.1.6 -JSTaggedValue BuiltinsArrayBuffer::SetValueInBuffer(JSTaggedValue arrBuf, int32_t byteIndex, DataViewType type, +JSTaggedValue BuiltinsArrayBuffer::SetValueInBuffer(JSTaggedValue arrBuf, uint32_t byteIndex, DataViewType type, JSTaggedNumber value, bool littleEndian) { JSArrayBuffer *jsArrayBuffer = JSArrayBuffer::Cast(arrBuf.GetTaggedObject()); @@ -401,11 +397,11 @@ JSTaggedValue BuiltinsArrayBuffer::SetValueInBuffer(JSTaggedValue arrBuf, int32_ } template -void BuiltinsArrayBuffer::SetTypeData(uint8_t *block, T value, int32_t index) +void BuiltinsArrayBuffer::SetTypeData(uint8_t *block, T value, uint32_t index) { - int32_t sizeCount = sizeof(T); + uint32_t sizeCount = sizeof(T); auto *res = reinterpret_cast(&value); - for (int i = 0; i < sizeCount; i++) { + for (uint32_t i = 0; i < sizeCount; i++) { *(block + index + i) = *(res + i); // NOLINT } } @@ -446,7 +442,7 @@ uint64_t BuiltinsArrayBuffer::LittleEndianToBigEndianUint64(uint64_t liValue) } template -JSTaggedValue BuiltinsArrayBuffer::GetValueFromBufferForInteger(uint8_t *block, int32_t byteIndex, bool littleEndian) +JSTaggedValue BuiltinsArrayBuffer::GetValueFromBufferForInteger(uint8_t *block, uint32_t byteIndex, bool littleEndian) { static_assert(std::is_integral_v, "T must be integral"); static_assert(sizeof(T) == size, "Invalid number size"); @@ -470,7 +466,7 @@ JSTaggedValue BuiltinsArrayBuffer::GetValueFromBufferForInteger(uint8_t *block, } template -JSTaggedValue BuiltinsArrayBuffer::GetValueFromBufferForFloat(uint8_t *block, int32_t byteIndex, bool littleEndian) +JSTaggedValue BuiltinsArrayBuffer::GetValueFromBufferForFloat(uint8_t *block, uint32_t byteIndex, bool littleEndian) { static_assert(std::is_same_v || std::is_same_v, "T must be float type"); static_assert(sizeof(T) == size, "Invalid number size"); @@ -500,7 +496,7 @@ JSTaggedValue BuiltinsArrayBuffer::GetValueFromBufferForFloat(uint8_t *block, in } template -void BuiltinsArrayBuffer::SetValueInBufferForByte(double val, uint8_t *block, int32_t byteIndex) +void BuiltinsArrayBuffer::SetValueInBufferForByte(double val, uint8_t *block, uint32_t byteIndex) { static_assert(std::is_same_v || std::is_same_v, "T must be int8/uint8"); T res; @@ -515,7 +511,7 @@ void BuiltinsArrayBuffer::SetValueInBufferForByte(double val, uint8_t *block, in SetTypeData(block, res, byteIndex); } -void BuiltinsArrayBuffer::SetValueInBufferForUint8Clamped(double val, uint8_t *block, int32_t byteIndex) +void BuiltinsArrayBuffer::SetValueInBufferForUint8Clamped(double val, uint8_t *block, uint32_t byteIndex) { uint8_t res; if (std::isnan(val) || val <= 0) { @@ -531,7 +527,7 @@ void BuiltinsArrayBuffer::SetValueInBufferForUint8Clamped(double val, uint8_t *b } template -void BuiltinsArrayBuffer::SetValueInBufferForInteger(double val, uint8_t *block, int32_t byteIndex, bool littleEndian) +void BuiltinsArrayBuffer::SetValueInBufferForInteger(double val, uint8_t *block, uint32_t byteIndex, bool littleEndian) { static_assert(std::is_integral_v, "T must be integral"); static_assert(sizeof(T) >= sizeof(uint16_t), "T must have a size more than uint8"); @@ -559,7 +555,7 @@ void BuiltinsArrayBuffer::SetValueInBufferForInteger(double val, uint8_t *block, } template -void BuiltinsArrayBuffer::SetValueInBufferForFloat(double val, uint8_t *block, int32_t byteIndex, bool littleEndian) +void BuiltinsArrayBuffer::SetValueInBufferForFloat(double val, uint8_t *block, uint32_t byteIndex, bool littleEndian) { static_assert(std::is_same_v || std::is_same_v, "T must be float type"); auto data = static_cast(val); diff --git a/ecmascript/builtins/builtins_arraybuffer.h b/ecmascript/builtins/builtins_arraybuffer.h index 948657be28..0911e9021c 100644 --- a/ecmascript/builtins/builtins_arraybuffer.h +++ b/ecmascript/builtins/builtins_arraybuffer.h @@ -44,14 +44,14 @@ public: // 24.1.1.2 IsDetachedBuffer(arrayBuffer) static bool IsDetachedBuffer(JSTaggedValue arrayBuffer); // 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type, isLittleEndian ) - static JSTaggedValue GetValueFromBuffer(JSTaggedValue arrBuf, int32_t byteIndex, DataViewType type, + static JSTaggedValue GetValueFromBuffer(JSTaggedValue arrBuf, uint32_t byteIndex, DataViewType type, bool littleEndian); // 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value, isLittleEndian ) - static JSTaggedValue SetValueInBuffer(JSTaggedValue arrBuf, int32_t byteIndex, DataViewType type, + static JSTaggedValue SetValueInBuffer(JSTaggedValue arrBuf, uint32_t byteIndex, DataViewType type, JSTaggedNumber value, bool littleEndian); // 24.1.1.4 CloneArrayBuffer( srcBuffer, srcByteOffset [, cloneConstructor] ) static JSTaggedValue CloneArrayBuffer(JSThread *thread, const JSHandle &srcBuffer, - int32_t srcByteOffset, JSHandle constructor); + uint32_t srcByteOffset, JSHandle constructor); // 24.1.1.1 AllocateArrayBuffer(constructor, byteLength) static JSTaggedValue AllocateArrayBuffer(JSThread *thread, const JSHandle &newTarget, double byteLength); @@ -63,24 +63,24 @@ private: static uint64_t LittleEndianToBigEndianUint64(uint64_t liValue); template - static void SetTypeData(uint8_t *block, T value, int32_t index); + static void SetTypeData(uint8_t *block, T value, uint32_t index); template - static JSTaggedValue GetValueFromBufferForInteger(uint8_t *block, int32_t byteIndex, bool littleEndian); + static JSTaggedValue GetValueFromBufferForInteger(uint8_t *block, uint32_t byteIndex, bool littleEndian); template - static JSTaggedValue GetValueFromBufferForFloat(uint8_t *block, int32_t byteIndex, bool littleEndian); + static JSTaggedValue GetValueFromBufferForFloat(uint8_t *block, uint32_t byteIndex, bool littleEndian); template - static void SetValueInBufferForByte(double val, uint8_t *block, int32_t byteIndex); + static void SetValueInBufferForByte(double val, uint8_t *block, uint32_t byteIndex); - static void SetValueInBufferForUint8Clamped(double val, uint8_t *block, int32_t byteIndex); + static void SetValueInBufferForUint8Clamped(double val, uint8_t *block, uint32_t byteIndex); template - static void SetValueInBufferForInteger(double val, uint8_t *block, int32_t byteIndex, bool littleEndian); + static void SetValueInBufferForInteger(double val, uint8_t *block, uint32_t byteIndex, bool littleEndian); template - static void SetValueInBufferForFloat(double val, uint8_t *block, int32_t byteIndex, bool littleEndian); + static void SetValueInBufferForFloat(double val, uint8_t *block, uint32_t byteIndex, bool littleEndian); }; } // namespace panda::ecmascript::builtins diff --git a/ecmascript/builtins/builtins_dataview.cpp b/ecmascript/builtins/builtins_dataview.cpp index 53777aad04..97f6445cb0 100644 --- a/ecmascript/builtins/builtins_dataview.cpp +++ b/ecmascript/builtins/builtins_dataview.cpp @@ -51,24 +51,24 @@ JSTaggedValue BuiltinsDataView::DataViewConstructor(EcmaRuntimeCallInfo *argv) JSTaggedNumber offsetNumber = JSTaggedValue::ToNumber(thread, offsetHandle); // 6. ReturnIfAbrupt(offset). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t offset = base::NumberHelper::DoubleInRangeInt32(offsetNumber.GetNumber()); + int32_t offsetInt = base::NumberHelper::DoubleInRangeInt32(offsetNumber.GetNumber()); // 7. If numberOffset ≠ offset or offset < 0, throw a RangeError exception. - if (offset < 0) { + if (offsetInt < 0) { THROW_RANGE_ERROR_AND_RETURN(thread, "Offset out of range", JSTaggedValue::Exception()); } + uint32_t offset = offsetInt; // 8. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. if (BuiltinsArrayBuffer::IsDetachedBuffer(bufferHandle.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "buffer is Detached Buffer", JSTaggedValue::Exception()); } // 9. Let bufferByteLength be the value of buffer’s [[ArrayBufferByteLength]] internal slot. JSHandle arrBufHandle(bufferHandle); - JSTaggedNumber bufLenNum = JSTaggedNumber::FromIntOrDouble(thread, arrBufHandle->GetArrayBufferByteLength()); - int32_t bufByteLen = bufLenNum.ToInt32(); + uint32_t bufByteLen = arrBufHandle->GetArrayBufferByteLength(); // 10. If offset > bufferByteLength, throw a RangeError exception. if (offset > bufByteLen) { THROW_RANGE_ERROR_AND_RETURN(thread, "offset > bufferByteLength", JSTaggedValue::Exception()); } - int32_t viewByteLen; + uint32_t viewByteLen; JSHandle byteLenHandle = GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD); // 11. If byteLength is undefined, then Let viewByteLength be bufferByteLength – offset. if (byteLenHandle->IsUndefined()) { @@ -96,9 +96,9 @@ JSTaggedValue BuiltinsDataView::DataViewConstructor(EcmaRuntimeCallInfo *argv) // 16. Set O’s [[ViewedArrayBuffer]] internal slot to buffer. dataView->SetViewedArrayBuffer(thread, bufferHandle.GetTaggedValue()); // 17. Set O’s [[ByteLength]] internal slot to viewByteLength. - dataView->SetByteLength(thread, JSTaggedValue(viewByteLen)); + dataView->SetByteLength(viewByteLen); // 18. Set O’s [[ByteOffset]] internal slot to offset. - dataView->SetByteOffset(thread, JSTaggedValue(offset)); + dataView->SetByteOffset(offset); // 19. Return O. return JSTaggedValue(dataView.GetTaggedValue()); } @@ -152,7 +152,7 @@ JSTaggedValue BuiltinsDataView::GetByteLength(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception()); } // 6. Let size be the value of O’s [[ByteLength]] internal slot. - JSTaggedValue size = dataView->GetByteLength(); + uint32_t size = dataView->GetByteLength(); // 7. Return size. return JSTaggedValue(size); } @@ -182,7 +182,7 @@ JSTaggedValue BuiltinsDataView::GetOffset(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception()); } // 6. Let offset be the value of O’s [[ByteOffset]] internal slot. - JSTaggedValue offset = dataView->GetByteOffset(); + uint32_t offset = dataView->GetByteOffset(); // 7. Return offset. return JSTaggedValue(offset); } @@ -317,11 +317,12 @@ JSTaggedValue BuiltinsDataView::GetViewValue(JSThread *thread, const JSHandleGetByteOffset()); - int32_t offset = offsetNum.ToInt32(); + uint32_t offset = dataView->GetByteOffset(); // 11. Let viewSize be the value of view’s [[ByteLength]] internal slot. - JSTaggedNumber viewNum = JSTaggedNumber::FromIntOrDouble(thread, dataView->GetByteLength()); - int32_t size = viewNum.ToInt32(); + uint32_t size = dataView->GetByteLength(); // 12. Let elementSize be the Number value of the Element Size value specified in Table 49 for Element Type type. - int32_t elementSize = JSDataView::GetElementSize(type); + uint32_t elementSize = JSDataView::GetElementSize(type); // 13. If getIndex +elementSize > viewSize, throw a RangeError exception. if (index + elementSize > size) { THROW_RANGE_ERROR_AND_RETURN(thread, "getIndex +elementSize > viewSize", JSTaggedValue::Exception()); } // 14. Let bufferIndex be getIndex + viewOffset. - int32_t bufferIndex = index + offset; + uint32_t bufferIndex = index + offset; // 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). return BuiltinsArrayBuffer::GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian); } @@ -394,19 +393,17 @@ JSTaggedValue BuiltinsDataView::SetViewValue(JSThread *thread, const JSHandleGetByteOffset()); - int32_t offset = offsetNum.ToInt32(); + uint32_t offset = dataView->GetByteOffset(); // 11. Let viewSize be the value of view’s [[ByteLength]] internal slot. - JSTaggedNumber viewNum = JSTaggedNumber::FromIntOrDouble(thread, dataView->GetByteLength()); - int32_t size = viewNum.ToInt32(); + uint32_t size = dataView->GetByteLength(); // 12. Let elementSize be the Number value of the Element Size value specified in Table 49 for Element Type type. - int32_t elementSize = JSDataView::GetElementSize(type); + uint32_t elementSize = JSDataView::GetElementSize(type); // 13. If getIndex +elementSize > viewSize, throw a RangeError exception. if (index + elementSize > size) { THROW_RANGE_ERROR_AND_RETURN(thread, "getIndex +elementSize > viewSize", JSTaggedValue::Exception()); } // 14. Let bufferIndex be getIndex + viewOffset. - int32_t bufferIndex = index + offset; + uint32_t bufferIndex = index + offset; // 15. Return SetValueFromBuffer(buffer, bufferIndex, type, value, isLittleEndian). return BuiltinsArrayBuffer::SetValueInBuffer(buffer, bufferIndex, type, numVal, isLittleEndian); } diff --git a/ecmascript/builtins/builtins_generator.cpp b/ecmascript/builtins/builtins_generator.cpp index 82e5f1297d..34c57121ba 100644 --- a/ecmascript/builtins/builtins_generator.cpp +++ b/ecmascript/builtins/builtins_generator.cpp @@ -64,7 +64,7 @@ JSTaggedValue BuiltinsGenerator::GeneratorPrototypeReturn(EcmaRuntimeCallInfo *a JSHandle value = GetCallArg(argv, 0); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle completionRecord = - factory->NewCompletionRecord(CompletionRecord::RETURN, value); + factory->NewCompletionRecord(CompletionRecordType::RETURN, value); // 3.Return ? GeneratorResumeAbrupt(g, C). JSHandle result = JSGeneratorObject::GeneratorResumeAbrupt(thread, generator, completionRecord); @@ -89,7 +89,7 @@ JSTaggedValue BuiltinsGenerator::GeneratorPrototypeThrow(EcmaRuntimeCallInfo *ar JSHandle exception = GetCallArg(argv, 0); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle completionRecord = - factory->NewCompletionRecord(CompletionRecord::THROW, exception); + factory->NewCompletionRecord(CompletionRecordType::THROW, exception); // 3.Return ? GeneratorResumeAbrupt(g, C). JSHandle result = JSGeneratorObject::GeneratorResumeAbrupt(thread, generator, completionRecord); diff --git a/ecmascript/builtins/builtins_map.cpp b/ecmascript/builtins/builtins_map.cpp index 458ff2cd22..5ffab1f44e 100644 --- a/ecmascript/builtins/builtins_map.cpp +++ b/ecmascript/builtins/builtins_map.cpp @@ -87,7 +87,7 @@ JSTaggedValue BuiltinsMap::MapConstructor(EcmaRuntimeCallInfo *argv) if (!nextValue->IsECMAObject()) { JSHandle typeError = factory->GetJSError(ErrorType::TYPE_ERROR, "nextItem is not Object"); JSHandle record( - factory->NewCompletionRecord(CompletionRecord::THROW, JSHandle(typeError))); + factory->NewCompletionRecord(CompletionRecordType::THROW, JSHandle(typeError))); JSTaggedValue ret = JSIterator::IteratorClose(thread, iter, record).GetTaggedValue(); if (!thread->HasPendingException()) { THROW_NEW_ERROR_AND_RETURN_VALUE(thread, typeError.GetTaggedValue(), ret); diff --git a/ecmascript/builtins/builtins_promise.cpp b/ecmascript/builtins/builtins_promise.cpp index 58242c48b3..b98e86a0ce 100644 --- a/ecmascript/builtins/builtins_promise.cpp +++ b/ecmascript/builtins/builtins_promise.cpp @@ -133,7 +133,7 @@ JSTaggedValue BuiltinsPromise::All(EcmaRuntimeCallInfo *argv) RETURN_REJECT_PROMISE_IF_ABRUPT(thread, itor, capa); // 10. Let iteratorRecord be Record {[[iterator]]: iterator, [[done]]: false}. - JSHandle done(thread, JSTaggedValue::False()); + bool done = false; JSHandle itRecord = factory->NewPromiseIteratorRecord(itor, done); // 11. Let result be PerformPromiseAll(iteratorRecord, C, promiseCapability). JSHandle result = PerformPromiseAll(thread, itRecord, ctor, capa); @@ -142,7 +142,7 @@ JSTaggedValue BuiltinsPromise::All(EcmaRuntimeCallInfo *argv) thread->ClearException(); // a. If iteratorRecord.[[done]] is false, let result be IteratorClose(iterator, result). // b. IfAbruptRejectPromise(result, promiseCapability). - if (itRecord->GetDone().IsFalse()) { + if (!itRecord->GetDone()) { JSHandle closeVal = JSIterator::IteratorClose(thread, itor, JSHandle::Cast(result)); if (closeVal.GetTaggedValue().IsRecord()) { @@ -199,7 +199,7 @@ JSTaggedValue BuiltinsPromise::Race(EcmaRuntimeCallInfo *argv) RETURN_REJECT_PROMISE_IF_ABRUPT(thread, iterator, promiseCapability); // 10. Let iteratorRecord be Record {[[iterator]]: iterator, [[done]]: false}. - JSHandle done(thread, JSTaggedValue::False()); + bool done = false; JSHandle iteratorRecord = factory->NewPromiseIteratorRecord(iterator, done); // 11. Let result be PerformPromiseRace(iteratorRecord, promiseCapability, C). @@ -210,7 +210,7 @@ JSTaggedValue BuiltinsPromise::Race(EcmaRuntimeCallInfo *argv) JSHandle result = PerformPromiseRace(thread, iteratorRecord, promiseCapability, thisValue); if (result->IsThrow()) { thread->ClearException(); - if (iteratorRecord->GetDone().IsFalse()) { + if (!iteratorRecord->GetDone()) { JSHandle value = JSIterator::IteratorClose(thread, iterator, JSHandle::Cast(result)); if (value.GetTaggedValue().IsCompletionRecord()) { @@ -396,8 +396,8 @@ JSTaggedValue BuiltinsPromise::PerformPromiseThen(JSThread *thread, const JSHand rejectReaction->SetPromiseCapability(thread, capability.GetTaggedValue()); rejectReaction->SetHandler(thread, rejected.GetTaggedValue()); - if (JSTaggedValue::SameValue(promise->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::PENDING)))) { + PromiseState state = promise->GetPromiseState(); + if (state == PromiseState::PENDING) { JSHandle fulfillReactions(thread, promise->GetPromiseFulfillReactions()); TaggedQueue *newQueue = TaggedQueue::Push(thread, fulfillReactions, JSHandle::Cast(fulfillReaction)); @@ -406,29 +406,27 @@ JSTaggedValue BuiltinsPromise::PerformPromiseThen(JSThread *thread, const JSHand JSHandle rejectReactions(thread, promise->GetPromiseRejectReactions()); newQueue = TaggedQueue::Push(thread, rejectReactions, JSHandle::Cast(rejectReaction)); promise->SetPromiseRejectReactions(thread, JSTaggedValue(newQueue)); - } else if (JSTaggedValue::SameValue(promise->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::FULFILLED)))) { + } else if (state == PromiseState::FULFILLED) { JSHandle argv = factory->NewTaggedArray(2); // 2: 2 means two args stored in array argv->Set(thread, 0, fulfillReaction.GetTaggedValue()); argv->Set(thread, 1, promise->GetPromiseResult()); JSHandle promiseReactionsJob(env->GetPromiseReactionJob()); job::MicroJobQueue::EnqueueJob(thread, job, job::QueueType::QUEUE_PROMISE, promiseReactionsJob, argv); - } else if (JSTaggedValue::SameValue(promise->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::REJECTED)))) { + } else if (state == PromiseState::REJECTED) { JSHandle argv = factory->NewTaggedArray(2); // 2: 2 means two args stored in array argv->Set(thread, 0, rejectReaction.GetTaggedValue()); argv->Set(thread, 1, promise->GetPromiseResult()); // When a handler is added to a rejected promise for the first time, it is called with its operation // argument set to "handle". - if (!promise->GetPromiseIsHandled().ToBoolean()) { + if (!promise->GetPromiseIsHandled()) { JSHandle reason(thread, JSTaggedValue::Null()); - thread->GetEcmaVM()->PromiseRejectionTracker(promise, reason, ecmascript::PromiseRejectionEvent::HANDLE); + thread->GetEcmaVM()->PromiseRejectionTracker(promise, reason, PromiseRejectionEvent::HANDLE); } JSHandle promiseReactionsJob(env->GetPromiseReactionJob()); job::MicroJobQueue::EnqueueJob(thread, job, job::QueueType::QUEUE_PROMISE, promiseReactionsJob, argv); } - promise->SetPromiseIsHandled(thread, JSTaggedValue::True()); + promise->SetPromiseIsHandled(true); return capability->GetPromise(); } @@ -460,7 +458,7 @@ JSHandle BuiltinsPromise::PerformPromiseAll(JSThread *thread, next.Update(JSIterator::IteratorStep(thread, itor).GetTaggedValue()); // b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. if (thread->HasPendingException()) { - itRecord->SetDone(thread, JSTaggedValue::True()); + itRecord->SetDone(true); next.Update(JSPromise::IfThrowGetThrowValue(thread).GetTaggedValue()); } // c. ReturnIfAbrupt(next). @@ -468,7 +466,7 @@ JSHandle BuiltinsPromise::PerformPromiseAll(JSThread *thread, // d. If next is false, if (next->IsFalse()) { // i. Set iteratorRecord.[[done]] to true. - itRecord->SetDone(thread, JSTaggedValue::True()); + itRecord->SetDone(true); // ii. Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] − 1. remainCnt->SetValue(thread, --JSTaggedNumber(remainCnt->GetValue())); // iii. If remainingElementsCount.[[value]] is 0, @@ -488,14 +486,14 @@ JSHandle BuiltinsPromise::PerformPromiseAll(JSThread *thread, } // iv. Return resultCapability.[[Promise]]. JSHandle resRecord = factory->NewCompletionRecord( - CompletionRecord::NORMAL, JSHandle(thread, capa->GetPromise())); + CompletionRecordType::NORMAL, JSHandle(thread, capa->GetPromise())); return resRecord; } // e. Let nextValue be IteratorValue(next). JSHandle nextVal = JSIterator::IteratorValue(thread, next); // f. If nextValue is an abrupt completion, set iteratorRecord.[[done]] to true. if (thread->HasPendingException()) { - itRecord->SetDone(thread, JSTaggedValue::True()); + itRecord->SetDone(true); nextVal = JSHandle(thread, thread->GetException()); } @@ -574,20 +572,20 @@ JSHandle BuiltinsPromise::PerformPromiseRace(JSThread *thread, while (true) { next.Update(JSIterator::IteratorStep(thread, iterator).GetTaggedValue()); if (thread->HasPendingException()) { - iteratorRecord->SetDone(thread, JSTaggedValue::True()); + iteratorRecord->SetDone(true); next.Update(JSPromise::IfThrowGetThrowValue(thread).GetTaggedValue()); } RETURN_COMPLETION_IF_ABRUPT(thread, next); if (next->IsFalse()) { - iteratorRecord->SetDone(thread, JSTaggedValue::True()); + iteratorRecord->SetDone(true); JSHandle promise(thread, capability->GetPromise()); JSHandle completionRecord = - factory->NewCompletionRecord(CompletionRecord::NORMAL, promise); + factory->NewCompletionRecord(CompletionRecordType::NORMAL, promise); return completionRecord; } JSHandle nextValue = JSIterator::IteratorValue(thread, next); if (thread->HasPendingException()) { - iteratorRecord->SetDone(thread, JSTaggedValue::True()); + iteratorRecord->SetDone(true); nextValue = JSPromise::IfThrowGetThrowValue(thread); } RETURN_COMPLETION_IF_ABRUPT(thread, nextValue); diff --git a/ecmascript/builtins/builtins_regexp.cpp b/ecmascript/builtins/builtins_regexp.cpp index 804cbbea9f..9fde7f4597 100644 --- a/ecmascript/builtins/builtins_regexp.cpp +++ b/ecmascript/builtins/builtins_regexp.cpp @@ -1547,7 +1547,7 @@ JSTaggedValue BuiltinsRegExp::RegExpInitialize(JSThread *thread, const JSHandle< regExpParserCache->SetCache(*patternStrHandle, flagsBits, regexp->GetByteCodeBuffer(), bufferSize); } else { regexp->SetByteCodeBuffer(thread, getCache.first); - regexp->SetLength(thread, JSTaggedValue(static_cast(getCache.second))); + regexp->SetLength(static_cast(getCache.second)); } // 14. Let setStatus be Set(obj, "lastIndex", 0, true). JSHandle lastIndexString = thread->GlobalConstants()->GetHandledLastIndexString(); diff --git a/ecmascript/builtins/builtins_string_iterator.cpp b/ecmascript/builtins/builtins_string_iterator.cpp index cc38dc157f..1a9d050558 100644 --- a/ecmascript/builtins/builtins_string_iterator.cpp +++ b/ecmascript/builtins/builtins_string_iterator.cpp @@ -44,7 +44,7 @@ JSTaggedValue BuiltinsStringIterator::Next(EcmaRuntimeCallInfo *argv) return JSIterator::CreateIterResultObject(thread, string, true).GetTaggedValue(); } // 6. Let position be the value of the [[StringIteratorNextIndex]] internal slot of O. - double position = JSTaggedNumber(thisValue.GetObject()->GetStringIteratorNextIndex()).GetNumber(); + uint32_t position = thisValue.GetObject()->GetStringIteratorNextIndex(); // 7. Let len be the number of elements in s. uint32_t len = string.GetObject()->GetLength(); @@ -87,7 +87,7 @@ JSTaggedValue BuiltinsStringIterator::Next(EcmaRuntimeCallInfo *argv) } // 12. Let resultSize be the number of code units in resultString. // 13. Set the value of the [[StringIteratorNextIndex]] internal slot of O to position+ resultSize. - thisValue.GetObject()->SetStringIteratorNextIndex(thread, JSTaggedValue(position + resultSize)); + thisValue.GetObject()->SetStringIteratorNextIndex(position + resultSize); // 14. Return CreateIterResultObject(resultString, false). return JSIterator::CreateIterResultObject(thread, result, false).GetTaggedValue(); diff --git a/ecmascript/builtins/builtins_weak_map.cpp b/ecmascript/builtins/builtins_weak_map.cpp index 1d81874c6e..4d156d7004 100644 --- a/ecmascript/builtins/builtins_weak_map.cpp +++ b/ecmascript/builtins/builtins_weak_map.cpp @@ -88,7 +88,7 @@ JSTaggedValue BuiltinsWeakMap::WeakMapConstructor(EcmaRuntimeCallInfo *argv) if (!nextValue->IsECMAObject()) { JSHandle typeError = factory->GetJSError(ErrorType::TYPE_ERROR, "nextItem is not Object"); JSHandle record( - factory->NewCompletionRecord(CompletionRecord::THROW, JSHandle(typeError))); + factory->NewCompletionRecord(CompletionRecordType::THROW, JSHandle(typeError))); JSTaggedValue ret = JSIterator::IteratorClose(thread, iter, record).GetTaggedValue(); if (!thread->HasPendingException()) { THROW_NEW_ERROR_AND_RETURN_VALUE(thread, typeError.GetTaggedValue(), ret); diff --git a/ecmascript/builtins/tests/builtins_map_test.cpp b/ecmascript/builtins/tests/builtins_map_test.cpp index dac0e77209..1d7f398e4a 100644 --- a/ecmascript/builtins/tests/builtins_map_test.cpp +++ b/ecmascript/builtins/tests/builtins_map_test.cpp @@ -341,19 +341,19 @@ HWTEST_F_L0(BuiltinsMapTest, GetIterator) JSTaggedValue result = BuiltinsMap::Values(ecmaRuntimeCallInfo.get()); JSHandle iter(thread, result); EXPECT_TRUE(iter->IsJSMapIterator()); - EXPECT_EQ(IterationKind::VALUE, IterationKind(iter->GetIterationKind().GetInt())); + EXPECT_EQ(IterationKind::VALUE, iter->GetIterationKind()); EXPECT_EQ(JSMap::Cast(map.GetTaggedValue().GetTaggedObject())->GetLinkedMap(), iter->GetIteratedMap()); // test Keys() JSTaggedValue result1 = BuiltinsMap::Keys(ecmaRuntimeCallInfo.get()); JSHandle iter1(thread, result1); EXPECT_TRUE(iter1->IsJSMapIterator()); - EXPECT_EQ(IterationKind::KEY, IterationKind(iter1->GetIterationKind().GetInt())); + EXPECT_EQ(IterationKind::KEY, iter1->GetIterationKind()); // test entries() JSTaggedValue result2 = BuiltinsMap::Entries(ecmaRuntimeCallInfo.get()); JSHandle iter2(thread, result2); EXPECT_TRUE(iter2->IsJSMapIterator()); - EXPECT_EQ(IterationKind::KEY_AND_VALUE, IterationKind(iter2->GetIterationKind().GetInt())); + EXPECT_EQ(IterationKind::KEY_AND_VALUE, iter2->GetIterationKind()); } } // namespace panda::test diff --git a/ecmascript/builtins/tests/builtins_promise_test.cpp b/ecmascript/builtins/tests/builtins_promise_test.cpp index d5e7bcb52e..2838c5ebca 100644 --- a/ecmascript/builtins/tests/builtins_promise_test.cpp +++ b/ecmascript/builtins/tests/builtins_promise_test.cpp @@ -144,9 +144,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Reject1) [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); JSTaggedValue result = BuiltinsPromise::Reject(ecmaRuntimeCallInfo1.get()); JSHandle rejectPromise(thread, result); - EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::REJECTED))), - true); + EXPECT_EQ(rejectPromise->GetPromiseState(), PromiseState::REJECTED); EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseResult(), JSTaggedValue(3)), true); } @@ -176,9 +174,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Reject2) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); JSTaggedValue result = BuiltinsPromise::Reject(ecmaRuntimeCallInfo.get()); JSHandle promise1(thread, result); - EXPECT_EQ(JSTaggedValue::SameValue(promise1->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::REJECTED))), - true); + EXPECT_EQ(promise1->GetPromiseState(), PromiseState::REJECTED); EXPECT_EQ(JSTaggedValue::SameValue(promise1->GetPromiseResult(), paramMsg1.GetTaggedValue()), true); /** @@ -193,9 +189,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Reject2) JSTaggedValue result1 = BuiltinsPromise::Reject(ecmaRuntimeCallInfo1.get()); JSHandle promise2(thread, result1); EXPECT_NE(*promise1, *promise2); - EXPECT_EQ(JSTaggedValue::SameValue(promise2->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::REJECTED))), - true); + EXPECT_EQ(promise2->GetPromiseState(), PromiseState::REJECTED); EXPECT_EQ( JSTaggedValue::SameValue(promise2->GetPromiseResult(), JSTaggedValue(promise1.GetTaggedValue().GetRawData())), true); @@ -224,9 +218,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Resolve1) [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); JSTaggedValue result = BuiltinsPromise::Resolve(ecmaRuntimeCallInfo1.get()); JSHandle rejectPromise(thread, result); - EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::FULFILLED))), - true); + EXPECT_EQ(rejectPromise->GetPromiseState(), PromiseState::FULFILLED); EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseResult(), JSTaggedValue(5)), true); } @@ -256,9 +248,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Resolve2) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); JSTaggedValue result = BuiltinsPromise::Reject(ecmaRuntimeCallInfo.get()); JSHandle promise1(thread, result); - EXPECT_EQ(JSTaggedValue::SameValue(promise1->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::REJECTED))), - true); + EXPECT_EQ(promise1->GetPromiseState(), PromiseState::REJECTED); EXPECT_EQ(JSTaggedValue::SameValue(promise1->GetPromiseResult(), paramMsg1.GetTaggedValue()), true); // promise1 Enter Reject() as a parameter. @@ -274,9 +264,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Resolve2) JSTaggedValue result1 = BuiltinsPromise::Resolve(ecmaRuntimeCallInfo1.get()); JSHandle promise2(thread, result1); EXPECT_EQ(*promise1, *promise2); - EXPECT_EQ(JSTaggedValue::SameValue(promise2->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::REJECTED))), - true); + EXPECT_EQ(promise2->GetPromiseState(), PromiseState::REJECTED); EXPECT_EQ(JSTaggedValue::SameValue(promise2->GetPromiseResult(), paramMsg1.GetTaggedValue()), true); } @@ -304,9 +292,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Race1) [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); JSTaggedValue result1 = BuiltinsPromise::Reject(ecmaRuntimeCallInfo1.get()); JSHandle rejectPromise(thread, result1); - EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::REJECTED))), - true); + EXPECT_EQ(rejectPromise->GetPromiseState(), PromiseState::REJECTED); EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseResult(), JSTaggedValue(12345)), true); /** @@ -320,9 +306,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Race1) [[maybe_unused]] auto prevResolve = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); JSTaggedValue result2 = BuiltinsPromise::Resolve(ecmaRuntimeCallInfo2.get()); JSHandle resolvePromise(thread, result2); - EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::FULFILLED))), - true); + EXPECT_EQ(resolvePromise->GetPromiseState(), PromiseState::FULFILLED); EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise->GetPromiseResult(), JSTaggedValue(6789)), true); /** @@ -346,9 +330,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Race1) [[maybe_unused]] auto prev4 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4.get()); JSTaggedValue result4 = BuiltinsPromise::Race(ecmaRuntimeCallInfo4.get()); JSHandle racePromise(thread, result4); - EXPECT_EQ(JSTaggedValue::SameValue(racePromise->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::PENDING))), - true); + EXPECT_EQ(racePromise->GetPromiseState(), PromiseState::PENDING); EXPECT_EQ(racePromise->GetPromiseResult().IsUndefined(), true); } @@ -378,9 +360,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Race2) [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); JSTaggedValue result1 = BuiltinsPromise::Reject(ecmaRuntimeCallInfo1.get()); JSHandle rejectPromise(thread, result1); - EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::REJECTED))), - true); + EXPECT_EQ(rejectPromise->GetPromiseState(), PromiseState::REJECTED); EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseResult(), JSTaggedValue(12345)), true); /** @@ -394,9 +374,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Race2) [[maybe_unused]] auto prevResolve = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); JSTaggedValue result2 = BuiltinsPromise::Resolve(ecmaRuntimeCallInfo2.get()); JSHandle resolvePromise(thread, result2); - EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::FULFILLED))), - true); + EXPECT_EQ(resolvePromise->GetPromiseState(), PromiseState::FULFILLED); EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise->GetPromiseResult(), JSTaggedValue(6789)), true); /** @@ -420,9 +398,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Race2) [[maybe_unused]] auto prev4 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4.get()); JSTaggedValue result4 = BuiltinsPromise::Race(ecmaRuntimeCallInfo4.get()); JSHandle racePromise(thread, result4); - EXPECT_EQ(JSTaggedValue::SameValue(racePromise->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::PENDING))), - true); + EXPECT_EQ(racePromise->GetPromiseState(), PromiseState::PENDING); EXPECT_EQ(racePromise->GetPromiseResult().IsUndefined(), true); /** @@ -440,8 +416,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Race2) JSTaggedValue thenResult = BuiltinsPromise::Then(ecmaRuntimeCallInfo5.get()); JSHandle thenPromise(thread, thenResult); - EXPECT_TRUE(JSTaggedValue::SameValue(thenPromise->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::PENDING)))); + EXPECT_EQ(thenPromise->GetPromiseState(), PromiseState::PENDING); EXPECT_TRUE(thenPromise->GetPromiseResult().IsUndefined()); /** @@ -479,9 +454,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, All) [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); JSTaggedValue result1 = BuiltinsPromise::Resolve(ecmaRuntimeCallInfo1.get()); JSHandle resolvePromise1(thread, result1); - EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise1->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::FULFILLED))), - true); + EXPECT_EQ(resolvePromise1->GetPromiseState(), PromiseState::FULFILLED); EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise1->GetPromiseResult(), JSTaggedValue(111)), true); /** @@ -495,9 +468,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, All) [[maybe_unused]] auto prevResolve = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); JSTaggedValue result2 = BuiltinsPromise::Resolve(ecmaRuntimeCallInfo2.get()); JSHandle resolvePromise2(thread, result2); - EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise2->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::FULFILLED))), - true); + EXPECT_EQ(resolvePromise2->GetPromiseState(), PromiseState::FULFILLED); EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise2->GetPromiseResult(), JSTaggedValue(222)), true); /** @@ -521,9 +492,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, All) [[maybe_unused]] auto prev4 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4.get()); JSTaggedValue result4 = BuiltinsPromise::All(ecmaRuntimeCallInfo4.get()); JSHandle allPromise(thread, result4); - EXPECT_EQ(JSTaggedValue::SameValue(allPromise->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::PENDING))), - true); + EXPECT_EQ(allPromise->GetPromiseState(), PromiseState::PENDING); EXPECT_EQ(allPromise->GetPromiseResult().IsUndefined(), true); /** @@ -541,8 +510,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, All) JSTaggedValue thenResult = BuiltinsPromise::Then(ecmaRuntimeCallInfo5.get()); JSHandle thenPromise(thread, thenResult); - EXPECT_TRUE(JSTaggedValue::SameValue(thenPromise->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::PENDING)))); + EXPECT_EQ(thenPromise->GetPromiseState(), PromiseState::PENDING); EXPECT_TRUE(thenPromise->GetPromiseResult().IsUndefined()); /** @@ -578,9 +546,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Catch) [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); JSTaggedValue result = BuiltinsPromise::Reject(ecmaRuntimeCallInfo1.get()); JSHandle rejectPromise(thread, result); - EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::REJECTED))), - true); + EXPECT_EQ(rejectPromise->GetPromiseState(), PromiseState::REJECTED); EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseResult(), JSTaggedValue(3)), true); /** @@ -596,9 +562,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Catch) JSTaggedValue catchResult = BuiltinsPromise::Catch(ecmaRuntimeCallInfo2.get()); JSHandle catchPromise(thread, catchResult); - EXPECT_EQ(JSTaggedValue::SameValue(catchPromise->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::PENDING))), - true); + EXPECT_EQ(catchPromise->GetPromiseState(), PromiseState::PENDING); EXPECT_EQ(catchPromise->GetPromiseResult().IsUndefined(), true); /** @@ -634,9 +598,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, ThenResolve) [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); JSTaggedValue result = BuiltinsPromise::Resolve(ecmaRuntimeCallInfo1.get()); JSHandle resolvePromise(thread, result); - EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::FULFILLED))), - true); + EXPECT_EQ(resolvePromise->GetPromiseState(), PromiseState::FULFILLED); EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise->GetPromiseResult(), paramMsg.GetTaggedValue()), true); /** @@ -654,9 +616,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, ThenResolve) JSTaggedValue thenResult = BuiltinsPromise::Then(ecmaRuntimeCallInfo2.get()); JSHandle thenPromise(thread, thenResult); - EXPECT_EQ(JSTaggedValue::SameValue(thenPromise->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::PENDING))), - true); + EXPECT_EQ(thenPromise->GetPromiseState(), PromiseState::PENDING); EXPECT_EQ(thenPromise->GetPromiseResult().IsUndefined(), true); /** @@ -692,9 +652,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, ThenReject) [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); JSTaggedValue result = BuiltinsPromise::Reject(ecmaRuntimeCallInfo1.get()); JSHandle rejectPromise(thread, result); - EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::REJECTED))), - true); + EXPECT_EQ(rejectPromise->GetPromiseState(), PromiseState::REJECTED); EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseResult(), paramMsg.GetTaggedValue()), true); /** @@ -712,9 +670,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, ThenReject) JSTaggedValue thenResult = BuiltinsPromise::Then(ecmaRuntimeCallInfo2.get()); JSHandle thenPromise(thread, thenResult); - EXPECT_EQ(JSTaggedValue::SameValue(thenPromise->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::PENDING))), - true); + EXPECT_EQ(thenPromise->GetPromiseState(), PromiseState::PENDING); EXPECT_EQ(thenPromise->GetPromiseResult().IsUndefined(), true); /** * @tc.steps: step3. execute promise queue diff --git a/ecmascript/builtins/tests/builtins_set_test.cpp b/ecmascript/builtins/tests/builtins_set_test.cpp index ccea63173c..e7658f2ba1 100644 --- a/ecmascript/builtins/tests/builtins_set_test.cpp +++ b/ecmascript/builtins/tests/builtins_set_test.cpp @@ -351,13 +351,13 @@ HWTEST_F_L0(BuiltinsSetTest, GetIterator) JSTaggedValue result = BuiltinsSet::Values(ecmaRuntimeCallInfo.get()); JSHandle iter(thread, result); EXPECT_TRUE(iter->IsJSSetIterator()); - EXPECT_EQ(IterationKind::VALUE, IterationKind(iter->GetIterationKind().GetInt())); + EXPECT_EQ(IterationKind::VALUE, IterationKind(iter->GetIterationKind())); EXPECT_EQ(JSSet::Cast(set.GetTaggedValue().GetTaggedObject())->GetLinkedSet(), iter->GetIteratedSet()); // test entrys() JSTaggedValue result2 = BuiltinsSet::Entries(ecmaRuntimeCallInfo.get()); JSHandle iter2(thread, result2); EXPECT_TRUE(iter2->IsJSSetIterator()); - EXPECT_EQ(IterationKind::KEY_AND_VALUE, IterationKind(iter2->GetIterationKind().GetInt())); + EXPECT_EQ(IterationKind::KEY_AND_VALUE, iter2->GetIterationKind()); } } // namespace panda::test diff --git a/ecmascript/class_info_extractor.cpp b/ecmascript/class_info_extractor.cpp index 77be6b2d71..febd3d2c22 100644 --- a/ecmascript/class_info_extractor.cpp +++ b/ecmascript/class_info_extractor.cpp @@ -44,7 +44,7 @@ void ClassInfoExtractor::BuildClassInfoExtractorFromLiteral(JSThread *thread, JS if (UNLIKELY(ExtractAndReturnWhetherWithElements(thread, literal, nonStaticDetail, nonStaticKeys, nonStaticProperties, nonStaticElements))) { - extractor->SetNonStaticWithElements(); + extractor->SetNonStaticWithElements(true); extractor->SetNonStaticElements(thread, nonStaticElements); } } @@ -77,7 +77,7 @@ void ClassInfoExtractor::BuildClassInfoExtractorFromLiteral(JSThread *thread, JS if (UNLIKELY(ExtractAndReturnWhetherWithElements(thread, literal, staticDetail, staticKeys, staticProperties, staticElements))) { - extractor->SetStaticWithElements(); + extractor->SetStaticWithElements(true); extractor->SetStaticElements(thread, staticElements); } } else { @@ -310,7 +310,7 @@ JSHandle ClassHelper::DefineClassTemplate(JSThread *thread, JSHandle } // non-static elements - if (UNLIKELY(extractor->IsNonStaticWithElements())) { + if (UNLIKELY(extractor->GetNonStaticWithElements())) { JSHandle nonStaticElements(thread, extractor->GetNonStaticElements()); ClassHelper::HandleElementsProperties(thread, prototype, nonStaticElements, constantpool); } @@ -338,7 +338,7 @@ JSHandle ClassHelper::DefineClassTemplate(JSThread *thread, JSHandle } // static elements - if (UNLIKELY(extractor->IsStaticWithElements())) { + if (UNLIKELY(extractor->GetStaticWithElements())) { JSHandle staticElements(thread, extractor->GetStaticElements()); ClassHelper::HandleElementsProperties(thread, JSHandle(constructor), staticElements, constantpool); } diff --git a/ecmascript/class_info_extractor.h b/ecmascript/class_info_extractor.h index b2d6f56509..745954d0d6 100644 --- a/ecmascript/class_info_extractor.h +++ b/ecmascript/class_info_extractor.h @@ -42,44 +42,10 @@ public: CAST_CHECK(ClassInfoExtractor, IsClassInfoExtractor); - using NonStaticWithElementsBit = BitField; - using StaticWithElementsBit = NonStaticWithElementsBit::NextFlag; - static void BuildClassInfoExtractorFromLiteral(JSThread *thread, JSHandle &extractor, const JSHandle &literal); - inline void InitializeBitField() - { - SetBitField(0UL); - } - - inline void SetNonStaticWithElements() - { - uint8_t bits = GetBitField(); - uint8_t newVal = NonStaticWithElementsBit::Update(bits, true); - SetBitField(newVal); - } - - inline void SetStaticWithElements() - { - uint8_t bits = GetBitField(); - uint8_t newVal = StaticWithElementsBit::Update(bits, true); - SetBitField(newVal); - } - - inline bool IsNonStaticWithElements() const - { - return NonStaticWithElementsBit::Decode(GetBitField()); - } - - inline bool IsStaticWithElements() const - { - return StaticWithElementsBit::Decode(GetBitField()); - } - - static constexpr size_t BIT_FIELD_OFFSET = TaggedObjectSize(); - SET_GET_PRIMITIVE_FIELD(BitField, uint8_t, BIT_FIELD_OFFSET, CONSTRUCTOR_METHOD_OFFSET) - SET_GET_NATIVE_FIELD(ConstructorMethod, JSMethod, CONSTRUCTOR_METHOD_OFFSET, PROTOTYPE_HCLASS_OFFSET) + static constexpr size_t PROTOTYPE_HCLASS_OFFSET = TaggedObjectSize(); ACCESSORS(PrototypeHClass, PROTOTYPE_HCLASS_OFFSET, NON_STATIC_KEYS_OFFSET) ACCESSORS(NonStaticKeys, NON_STATIC_KEYS_OFFSET, NON_STATIC_PROPERTIES_OFFSET) ACCESSORS(NonStaticProperties, NON_STATIC_PROPERTIES_OFFSET, NON_STATIC_ELEMENTS_OFFSET) @@ -87,9 +53,18 @@ public: ACCESSORS(ConstructorHClass, CONSTRUCTOR_HCLASS_OFFSET, STATIC_KEYS_OFFSET) ACCESSORS(StaticKeys, STATIC_KEYS_OFFSET, STATIC_PROPERTIES_OFFSET) ACCESSORS(StaticProperties, STATIC_PROPERTIES_OFFSET, STATIC_ELEMENTS_OFFSET) - ACCESSORS(StaticElements, STATIC_ELEMENTS_OFFSET, SIZE) - - DECL_VISIT_OBJECT(PROTOTYPE_HCLASS_OFFSET, SIZE) + ACCESSORS(StaticElements, STATIC_ELEMENTS_OFFSET, CONSTRUCTOR_METHOD_OFFSET) + ACCESSORS_NATIVE_FIELD(ConstructorMethod, JSMethod, CONSTRUCTOR_METHOD_OFFSET, BIT_FIELD_OFFSET) + ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); + + // define BitField + static constexpr size_t NON_STATIC_BITS = 1; + static constexpr size_t STATIC_BITS = 1; + FIRST_BIT_FIELD(BitField, NonStaticWithElements, bool, NON_STATIC_BITS) + NEXT_BIT_FIELD(BitField, StaticWithElements, bool, STATIC_BITS, NonStaticWithElements) + + DECL_VISIT_OBJECT(PROTOTYPE_HCLASS_OFFSET, CONSTRUCTOR_METHOD_OFFSET) DECL_DUMP() private: diff --git a/ecmascript/class_linker/program_object-inl.h b/ecmascript/class_linker/program_object-inl.h index 1c235eb625..21dd7ff1f0 100644 --- a/ecmascript/class_linker/program_object-inl.h +++ b/ecmascript/class_linker/program_object-inl.h @@ -21,13 +21,6 @@ namespace panda { namespace ecmascript { -const uint8_t *LexicalFunction::GetInstructions() const -{ - JSTaggedValue inst = GetBytecode(); - void *buffer = JSNativePointer::Cast(inst.GetTaggedObject())->GetExternalPointer(); - return static_cast(buffer); -} - JSTaggedValue ConstantPool::GetObjectFromCache(uint32_t index) const { return Get(index); diff --git a/ecmascript/class_linker/program_object.h b/ecmascript/class_linker/program_object.h index df56dea719..2ecd5a38e6 100644 --- a/ecmascript/class_linker/program_object.h +++ b/ecmascript/class_linker/program_object.h @@ -32,8 +32,9 @@ public: ACCESSORS(Location, LOCATION_OFFSET, CONSTANT_POOL_OFFSET) ACCESSORS(ConstantPool, CONSTANT_POOL_OFFSET, MAIN_FUNCTION_OFFSET) ACCESSORS(MainFunction, MAIN_FUNCTION_OFFSET, METHODS_DATA_OFFSET) - SET_GET_NATIVE_FIELD(MethodsData, JSMethod, METHODS_DATA_OFFSET, NUMBER_METHODS_OFFSET) - SET_GET_PRIMITIVE_FIELD(NumberMethods, uint32_t, NUMBER_METHODS_OFFSET, SIZE); + ACCESSORS_NATIVE_FIELD(MethodsData, JSMethod, METHODS_DATA_OFFSET, NUMBER_METHODS_OFFSET) + ACCESSORS_PRIMITIVE_FIELD(NumberMethods, uint32_t, NUMBER_METHODS_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); inline void FreeMethodData(RegionFactory *factory); @@ -41,33 +42,6 @@ public: DECL_DUMP() }; -class LexicalFunction : public ECMAObject { -public: - DECL_CAST(LexicalFunction) - - uint32_t GetNumVregs() const - { - return static_cast(GetNumberVRegs().GetInt()); - } - - uint32_t GetNumICSlots() const - { - return static_cast(GetNumberICSlots().GetInt()); - } - - inline const uint8_t *GetInstructions() const; - - static constexpr size_t NAME_OFFSET = ECMAObject::SIZE; - ACCESSORS(Name, NAME_OFFSET, NUMBER_VREGS_OFFSET) - ACCESSORS(NumberVRegs, NUMBER_VREGS_OFFSET, NUMBER_IC_SLOTS_OFFSET) - ACCESSORS(NumberICSlots, NUMBER_IC_SLOTS_OFFSET, BYTECODE_OFFSET) - ACCESSORS(Bytecode, BYTECODE_OFFSET, PROGRAM_OFFSET) - ACCESSORS(Program, PROGRAM_OFFSET, SIZE) - - DECL_VISIT_OBJECT(NAME_OFFSET, SIZE) - DECL_DUMP() -}; - class ConstantPool : public TaggedArray { public: static ConstantPool *Cast(ObjectHeader *object) diff --git a/ecmascript/compiler/stub-inl.h b/ecmascript/compiler/stub-inl.h index c444576c3f..9debe599ac 100644 --- a/ecmascript/compiler/stub-inl.h +++ b/ecmascript/compiler/stub-inl.h @@ -1062,8 +1062,10 @@ GateRef Stub::GetPrototypeHandlerHandlerInfo(GateRef object) GateRef Stub::GetHasChanged(GateRef object) { - GateRef hasChangedOffset = GetArchRelateConstant(ProtoChangeMarker::HAS_CHANGED_OFFSET); - return Word64NotEqual(Load(MachineType::UINT64, object, hasChangedOffset), GetWord64Constant(0)); + GateRef bitfieldOffset = GetArchRelateConstant(ProtoChangeMarker::BIT_FIELD_OFFSET); + GateRef bitfield = Load(MachineType::UINT32, object, bitfieldOffset); + GateRef mask = GetInt32Constant(1LLU << (ProtoChangeMarker::HAS_CHANGED_BITS - 1)); + return Word32NotEqual(Word32Or(bitfield, mask), GetInt32Constant(0)); } GateRef Stub::HclassIsPrototypeHandler(GateRef hclass) diff --git a/ecmascript/compiler/stub_aot_compiler.cpp b/ecmascript/compiler/stub_aot_compiler.cpp index 524e30f62f..d0c44083bd 100644 --- a/ecmascript/compiler/stub_aot_compiler.cpp +++ b/ecmascript/compiler/stub_aot_compiler.cpp @@ -157,8 +157,7 @@ void StubAotCompiler::BuildStubModuleAndSave(const std::string &triple, panda::e auto codeSize = assembler.GetCodeSize(); panda::ecmascript::MachineCode *code = reinterpret_cast( new uint64_t[(panda::ecmascript::MachineCode::SIZE + codeSize) / sizeof(uint64_t) + 1]); - code->SetInstructionSizeInBytes(nullptr, panda::ecmascript::JSTaggedValue(codeSize), - panda::ecmascript::SKIP_BARRIER); + code->SetInstructionSizeInBytes(codeSize); assembler.CopyAssemblerToCode(code); diff --git a/ecmascript/dump.cpp b/ecmascript/dump.cpp index 445728c7da..bcdaf7341f 100644 --- a/ecmascript/dump.cpp +++ b/ecmascript/dump.cpp @@ -42,7 +42,6 @@ #include "ecmascript/js_date_time_format.h" #include "ecmascript/js_for_in_iterator.h" #include "ecmascript/js_function.h" -#include "ecmascript/js_function_extra_info.h" #include "ecmascript/js_generator_object.h" #include "ecmascript/js_global_object.h" #include "ecmascript/js_handle.h" @@ -245,10 +244,6 @@ CString JSHClass::DumpJSType(JSType type) return "PrototypeInfo"; case JSType::PROGRAM: return "program"; - case JSType::LEXICAL_FUNCTION: - return "LexicalFunction"; - case JSType::FUNCTION_EXTRA_INFO: - return "FunctionExtraInfo"; case JSType::MACHINE_CODE_OBJECT: return "MachineCode"; case JSType::ECMA_MODULE: @@ -585,12 +580,6 @@ static void DumpObject(JSThread *thread, TaggedObject *obj, std::ostream &os) case JSType::PROGRAM: Program::Cast(obj)->Dump(thread, os); break; - case JSType::LEXICAL_FUNCTION: - LexicalFunction::Cast(obj)->Dump(thread, os); - break; - case JSType::FUNCTION_EXTRA_INFO: - JSFunctionExtraInfo::Cast(obj)->Dump(thread, os); - break; case JSType::MACHINE_CODE_OBJECT: MachineCode::Cast(obj)->Dump(thread, os); break; @@ -941,8 +930,13 @@ void JSFunction::Dump(JSThread *thread, std::ostream &os) const os << " - HomeObject: "; GetHomeObject().D(); os << "\n"; - os << " - FunctionInfoFlag: "; - GetFunctionInfoFlag().D(); + os << " - FunctionKind: " << static_cast(GetFunctionKind()); + os << "\n"; + os << " - Strict: " << GetStrict(); + os << "\n"; + os << " - Resolved: " << GetResolved(); + os << "\n"; + os << " - ThisMode: " << static_cast(GetThisMode()); os << "\n"; os << " - FunctionExtraInfo: "; GetFunctionExtraInfo().D(); @@ -1010,8 +1004,7 @@ void JSForInIterator::Dump(JSThread *thread, std::ostream &os) const os << " - Object : "; GetObject().DumpTaggedValue(thread, os); os << "\n"; - os << " - WasVisited : "; - GetWasVisited().DumpTaggedValue(thread, os); + os << " - WasVisited : " << GetWasVisited(); os << "\n"; os << " - VisitedKeys : "; GetVisitedKeys().DumpTaggedValue(thread, os); @@ -1028,8 +1021,8 @@ void JSMapIterator::Dump(JSThread *thread, std::ostream &os) const os << " - elements: " << std::dec << map->NumberOfElements() << "\n"; os << " - deleted-elements: " << std::dec << map->NumberOfDeletedElements() << "\n"; os << " - capacity: " << std::dec << map->Capacity() << "\n"; - os << " - nextIndex: " << std::dec << GetNextIndex().GetInt() << "\n"; - os << " - IterationKind: " << std::dec << GetIterationKind().GetInt() << "\n"; + os << " - nextIndex: " << std::dec << GetNextIndex() << "\n"; + os << " - IterationKind: " << std::dec << static_cast(GetIterationKind()) << "\n"; JSObject::Dump(thread, os); os << " NumberOfElements() << "]>\n"; @@ -1080,8 +1073,8 @@ void JSSetIterator::Dump(JSThread *thread, std::ostream &os) const os << " - elements: " << std::dec << set->NumberOfElements() << "\n"; os << " - deleted-elements: " << std::dec << set->NumberOfDeletedElements() << "\n"; os << " - capacity: " << std::dec << set->Capacity() << "\n"; - os << " - nextIndex: " << std::dec << GetNextIndex().GetInt() << "\n"; - os << " - IterationKind: " << std::dec << GetIterationKind().GetInt() << "\n"; + os << " - nextIndex: " << std::dec << GetNextIndex() << "\n"; + os << " - IterationKind: " << std::dec << static_cast(GetIterationKind()) << "\n"; JSObject::Dump(thread, os); os << " NumberOfElements() << "]>\n"; @@ -1104,8 +1097,8 @@ void JSArrayIterator::Dump(JSThread *thread, std::ostream &os) const { JSArray *array = JSArray::Cast(GetIteratedArray().GetTaggedObject()); os << " - length: " << std::dec << array->GetArrayLength() << "\n"; - os << " - nextIndex: " << std::dec << GetNextIndex().GetInt() << "\n"; - os << " - IterationKind: " << std::dec << GetIterationKind().GetInt() << "\n"; + os << " - nextIndex: " << std::dec << GetNextIndex() << "\n"; + os << " - IterationKind: " << std::dec << static_cast(GetIterationKind()) << "\n"; JSObject::Dump(thread, os); } @@ -1113,7 +1106,7 @@ void JSStringIterator::Dump(JSThread *thread, std::ostream &os) const { EcmaString *str = EcmaString::Cast(GetIteratedString().GetTaggedObject()); os << " - IteratedString: " << str->GetCString().get() << "\n"; - os << " - StringIteratorNextIndex: " << std::dec << GetStringIteratorNextIndex().GetInt() << "\n"; + os << " - StringIteratorNextIndex: " << std::dec << GetStringIteratorNextIndex() << "\n"; JSObject::Dump(thread, os); } void JSTypedArray::Dump(JSThread *thread, std::ostream &os) const @@ -1133,8 +1126,6 @@ void JSTypedArray::Dump(JSThread *thread, std::ostream &os) const void JSRegExp::Dump(JSThread *thread, std::ostream &os) const { - os << " - LastIndex: "; - GetLastIndex().D(); os << "\n"; os << " - ByteCodeBuffer: "; GetByteCodeBuffer().D(); @@ -1145,8 +1136,7 @@ void JSRegExp::Dump(JSThread *thread, std::ostream &os) const os << " - OriginalFlags: "; GetOriginalFlags().D(); os << "\n"; - os << " - Length: "; - GetLength().D(); + os << " - Length: " << GetLength(); os << "\n"; JSObject::Dump(thread, os); } @@ -1164,13 +1154,9 @@ void JSProxy::Dump(JSThread *thread, std::ostream &os) const void JSSymbol::Dump(JSThread *thread, std::ostream &os) const { - os << " - hash-field: "; - JSTaggedValue hashField = GetHashField(); - hashField.D(); - os << " - flags: "; - JSTaggedValue flags = GetFlags(); - flags.D(); - os << " - description: "; + os << " - hash-field: " << GetHashField(); + os << "\n - flags: " << GetFlags(); + os << "\n - description: "; JSTaggedValue description = GetDescription(); description.D(); } @@ -1396,28 +1382,23 @@ void JSDataView::Dump(JSThread *thread, std::ostream &os) const GetDataView().D(); os << " - buffer: "; GetViewedArrayBuffer().D(); - os << " - byte-length: "; - GetByteLength().D(); - os << " - byte-offset: "; - GetByteOffset().D(); + os << "- byte-length: " << GetByteLength(); + os << "\n - byte-offset: " << GetByteOffset(); } void JSArrayBuffer::Dump(JSThread *thread, std::ostream &os) const { - os << " - byte-length: "; - GetArrayBufferByteLength().D(); + os << " - byte-length: " << GetArrayBufferByteLength(); os << " - buffer-data: "; GetArrayBufferData().D(); - os << " - Shared: "; - GetShared().D(); + os << " - Shared: " << GetShared(); } void PromiseReaction::Dump(JSThread *thread, std::ostream &os) const { os << " - promise-capability: "; GetPromiseCapability().D(); - os << " - type: "; - GetType().D(); + os << " - type: " << static_cast(GetType()); os << " - handler: "; GetHandler().D(); } @@ -1436,8 +1417,7 @@ void PromiseIteratorRecord::Dump(JSThread *thread, std::ostream &os) const { os << " - iterator: "; GetIterator().D(); - os << " - done: "; - GetDone().D(); + os << " - done: " << GetDone(); } void PromiseRecord::Dump(JSThread *thread, std::ostream &os) const @@ -1456,16 +1436,14 @@ void ResolvingFunctionsRecord::Dump(JSThread *thread, std::ostream &os) const void JSPromise::Dump(JSThread *thread, std::ostream &os) const { - os << " - promise-state: "; - GetPromiseState().D(); - os << " - promise-result: "; + os << " - promise-state: " << static_cast(GetPromiseState()); + os << "\n - promise-result: "; GetPromiseResult().D(); os << " - promise-fulfill-reactions: "; GetPromiseFulfillReactions().D(); os << " - promise-reject-reactions: "; GetPromiseRejectReactions().D(); - os << " - promise-is-handled: "; - GetPromiseIsHandled().D(); + os << " - promise-is-handled: " << GetPromiseIsHandled(); JSObject::Dump(thread, os); } @@ -1518,8 +1496,7 @@ void PendingJob::Dump(JSThread *thread, std::ostream &os) const void CompletionRecord::Dump(JSThread *thread, std::ostream &os) const { - os << " - type: "; - GetType().D(); + os << " - type: " << static_cast(GetType()); os << " - value: "; GetValue().D(); } @@ -1635,8 +1612,7 @@ void JSDateTimeFormat::Dump(JSThread *thread, std::ostream &os) const os << " - TimeZone: "; GetTimeZone().D(); os << "\n"; - os << " - HourCycle: "; - GetHourCycle().D(); + os << " - HourCycle: " << static_cast(GetHourCycle()); os << "\n"; os << " - LocaleIcu: "; GetLocaleIcu().D(); @@ -1647,11 +1623,9 @@ void JSDateTimeFormat::Dump(JSThread *thread, std::ostream &os) const os << " - Iso8601: "; GetIso8601().D(); os << "\n"; - os << " - DateStyle: "; - GetDateStyle().D(); + os << " - DateStyle: " << static_cast(GetDateStyle()); os << "\n"; - os << " - TimeStyle: "; - GetTimeStyle().D(); + os << " - TimeStyle: " << static_cast(GetTimeStyle()); os << "\n"; os << " - BoundFormat: "; GetBoundFormat().D(); @@ -1670,11 +1644,9 @@ void JSRelativeTimeFormat::Dump(JSThread *thread, std::ostream &os) const os << " - NumberingSystem: "; GetNumberingSystem().D(); os << "\n"; - os << " - Style: "; - GetStyle().D(); + os << " - Style: " << static_cast(GetStyle()); os << "\n"; - os << " - Numeric: "; - GetNumeric().D(); + os << " - Numeric: " << static_cast(GetNumeric()); os << "\n"; os << " - AvailableLocales: "; GetAvailableLocales().D(); @@ -1691,18 +1663,14 @@ void JSNumberFormat::Dump(JSThread *thread, std::ostream &os) const GetLocale().D(); os << "\n" << " - NumberingSystem: "; GetNumberingSystem().D(); - os << "\n" << " - Style: "; - GetStyle().D(); + os << "\n" << " - Style: " << static_cast(GetStyle()); os << "\n" << " - Currency: "; GetCurrency().D(); - os << "\n" << " - CurrencyDisplay: "; - GetCurrencyDisplay().D(); - os << "\n" << " - CurrencySign: "; - GetCurrencySign().D(); + os << "\n" << " - CurrencyDisplay: " << static_cast(GetCurrencyDisplay()); + os << "\n" << " - CurrencySign: " << static_cast(GetCurrencySign()); os << "\n" << " - Unit: "; GetUnit().D(); - os << "\n" << " - UnitDisplay: "; - GetUnitDisplay().D(); + os << "\n" << " - UnitDisplay: " << static_cast(GetUnitDisplay()); os << "\n" << " - MinimumIntegerDigits: "; GetMinimumIntegerDigits().D(); os << "\n" << " - MinimumFractionDigits: "; @@ -1715,18 +1683,14 @@ void JSNumberFormat::Dump(JSThread *thread, std::ostream &os) const GetMaximumSignificantDigits().D(); os << "\n" << " - UseGrouping: "; GetUseGrouping().D(); - os << "\n" << " - RoundingType: "; - GetUseGrouping().D(); - os << "\n" << " - Notation: "; - GetMinimumIntegerDigits().D(); - os << "\n" << " - CompactDisplay: "; - GetMaximumSignificantDigits().D(); - os << "\n" << " - SignDisplay: "; - GetMinimumFractionDigits().D(); + os << "\n" << " - RoundingType: " << static_cast(GetRoundingType()); + os << "\n" << " - Notation: " << static_cast(GetNotation()); + os << "\n" << " - CompactDisplay: " << static_cast(GetCompactDisplay()); + os << "\n" << " - SignDisplay: " << static_cast(GetSignDisplay()); os << "\n" << " - BoundFormat: "; - GetMaximumFractionDigits().D(); + GetBoundFormat().D(); os << "\n" << " - IcuField: "; - GetMinimumSignificantDigits().D(); + GetIcuField().D(); os << "\n"; JSObject::Dump(thread, os); } @@ -1735,29 +1699,16 @@ void JSCollator::Dump(JSThread *thread, std::ostream &os) const { os << " - IcuField: "; GetIcuField().D(); - os << "\n"; - os << " - Locale: "; + os << "\n - Locale: "; GetLocale().D(); - os << "\n"; - os << " - Usage: "; - GetUsage().D(); - os << "\n"; - os << " - Sensitivity: "; - GetSensitivity().D(); - os << "\n"; - os << " - IgnorePunctuation: "; - GetIgnorePunctuation().D(); - os << "\n"; - os << " - Collation: "; + os << "\n - Usage: " << static_cast(GetUsage()); + os << "\n - Sensitivity: " << static_cast(GetSensitivity()); + os << "\n - IgnorePunctuation: " << GetIgnorePunctuation(); + os << "\n - Collation: "; GetCollation().D(); - os << "\n"; - os << " - Numeric: "; - GetNumeric().D(); - os << "\n"; - os << " - CaseFirst: "; - GetCaseFirst().D(); - os << "\n"; - os << " - BoundCompare: "; + os << "\n - Numeric: " << GetNumeric(); + os << "\n - CaseFirst: " << static_cast(GetCaseFirst()); + os << "\n - BoundCompare: "; GetBoundCompare().D(); os << "\n"; JSObject::Dump(thread, os); @@ -1771,8 +1722,7 @@ void JSPluralRules::Dump(JSThread *thread, std::ostream &os) const os << " - InitializedPluralRules: "; GetInitializedPluralRules().D(); os << "\n"; - os << " - Type: "; - GetType().D(); + os << " - Type: " << static_cast(GetType()); os << "\n"; os << " - MinimumIntegerDigits: "; GetMinimumIntegerDigits().D(); @@ -1789,8 +1739,7 @@ void JSPluralRules::Dump(JSThread *thread, std::ostream &os) const os << " - MaximumSignificantDigits: "; GetMaximumSignificantDigits().D(); os << "\n"; - os << " - RoundingType: "; - GetRoundingType().D(); + os << " - RoundingType: " << static_cast(GetRoundingType()); os << "\n"; os << " - IcuPR: "; GetIcuPR().D(); @@ -1803,17 +1752,15 @@ void JSPluralRules::Dump(JSThread *thread, std::ostream &os) const void JSGeneratorObject::Dump(JSThread *thread, std::ostream &os) const { - os << " - GeneratorState: "; - GetGeneratorState().D(); - os << "\n"; os << " - GeneratorContext: "; GetGeneratorContext().D(); os << "\n"; os << " - ResumeResult: "; GetResumeResult().D(); os << "\n"; - os << " - ResumeMode: "; - GetResumeMode().D(); + os << " - GeneratorState: " << static_cast(GetGeneratorState()); + os << "\n"; + os << " - ResumeMode: " << static_cast(GetResumeMode()); os << "\n"; JSObject::Dump(thread, os); } @@ -1836,18 +1783,16 @@ void GeneratorContext::Dump(JSThread *thread, std::ostream &os) const os << " - Acc: "; GetAcc().D(); os << "\n"; - os << " - NRegs: "; - GetNRegs().D(); - os << "\n"; - os << " - BCOffset: "; - GetBCOffset().D(); - os << "\n"; os << " - GeneratorObject: "; GetGeneratorObject().D(); os << "\n"; os << " - LexicalEnv: "; GetLexicalEnv().D(); os << "\n"; + os << " - NRegs: " << GetNRegs(); + os << "\n"; + os << " - BCOffset: " << GetBCOffset(); + os << "\n"; } void ProtoChangeMarker::Dump(JSThread *thread, std::ostream &os) const @@ -1860,44 +1805,13 @@ void ProtoChangeDetails::Dump(JSThread *thread, std::ostream &os) const os << " - ChangeListener: "; GetChangeListener().D(); os << "\n"; - os << " - RegisterIndex: "; - GetRegisterIndex().D(); - os << "\n"; -} - -void LexicalFunction::Dump(JSThread *thread, std::ostream &os) const -{ - os << " - Name: "; - GetName().D(); - os << "\n"; - os << " - NumberVRegs: "; - GetNumberVRegs().D(); - os << "\n"; - os << " - NumberICSlots: "; - GetNumberICSlots().D(); - os << "\n"; - os << " - Bytecode: "; - GetBytecode().D(); - os << "\n"; - os << " - Program: "; - GetProgram().D(); - os << "\n"; -} - -void JSFunctionExtraInfo::Dump(JSThread *thread, std::ostream &os) const -{ - os << " - Callback: "; - GetCallback().D(); - os << "\n"; - os << " - Data: "; - GetData().D(); + os << " - RegisterIndex: " << GetRegisterIndex(); os << "\n"; } void MachineCode::Dump(JSThread *thread, std::ostream &os) const { - os << " - InstructionSizeInBytes: "; - GetInstructionSizeInBytes().D(); + os << " - InstructionSizeInBytes: " << GetInstructionSizeInBytes(); os << "\n"; } @@ -2145,9 +2059,6 @@ static void DumpObject(JSThread *thread, TaggedObject *obj, case JSType::JS_GENERATOR_CONTEXT: GeneratorContext::Cast(obj)->DumpForSnapshot(thread, vec); return; - case JSType::FUNCTION_EXTRA_INFO: - JSFunctionExtraInfo::Cast(obj)->DumpForSnapshot(thread, vec); - return; case JSType::ECMA_MODULE: EcmaModule::Cast(obj)->DumpForSnapshot(thread, vec); return; @@ -2165,9 +2076,6 @@ static void DumpObject(JSThread *thread, TaggedObject *obj, case JSType::TEMPLATE_MAP: DumpArrayClass(thread, TaggedArray::Cast(obj), vec); return; - case JSType::LEXICAL_FUNCTION: - LexicalFunction::Cast(obj)->DumpForSnapshot(thread, vec); - return; case JSType::GLOBAL_ENV: GlobalEnv::Cast(obj)->DumpForSnapshot(thread, vec); return; @@ -2381,7 +2289,10 @@ void JSFunction::DumpForSnapshot([[maybe_unused]] JSThread *thread, vec.push_back(std::make_pair(CString("ProtoOrDynClass"), GetProtoOrDynClass())); vec.push_back(std::make_pair(CString("LexicalEnv"), GetLexicalEnv())); vec.push_back(std::make_pair(CString("HomeObject"), GetHomeObject())); - vec.push_back(std::make_pair(CString("FunctionInfoFlag"), GetFunctionInfoFlag())); + vec.push_back(std::make_pair(CString("FunctionKind"), JSTaggedValue(static_cast(GetFunctionKind())))); + vec.push_back(std::make_pair(CString("Strict"), JSTaggedValue(GetStrict()))); + vec.push_back(std::make_pair(CString("Resolved"), JSTaggedValue(GetResolved()))); + vec.push_back(std::make_pair(CString("ThisMode"), JSTaggedValue(static_cast(GetThisMode())))); vec.push_back(std::make_pair(CString("FunctionExtraInfo"), GetFunctionExtraInfo())); vec.push_back(std::make_pair(CString("ConstantPool"), GetConstantPool())); vec.push_back(std::make_pair(CString("ProfileTypeInfo"), GetProfileTypeInfo())); @@ -2443,7 +2354,7 @@ void JSForInIterator::DumpForSnapshot([[maybe_unused]] JSThread *thread, std::vector> &vec) const { vec.push_back(std::make_pair(CString("Object"), GetObject())); - vec.push_back(std::make_pair(CString("WasVisited"), GetWasVisited())); + vec.push_back(std::make_pair(CString("WasVisited"), JSTaggedValue(GetWasVisited()))); vec.push_back(std::make_pair(CString("VisitedKeys"), GetVisitedKeys())); vec.push_back(std::make_pair(CString("RemainingKeys"), GetRemainingKeys())); JSObject::DumpForSnapshot(thread, vec); @@ -2454,8 +2365,8 @@ void JSMapIterator::DumpForSnapshot([[maybe_unused]] JSThread *thread, { LinkedHashMap *map = LinkedHashMap::Cast(GetIteratedMap().GetTaggedObject()); map->DumpForSnapshot(thread, vec); - vec.push_back(std::make_pair(CString("NextIndex"), GetNextIndex())); - vec.push_back(std::make_pair(CString("IterationKind"), GetIterationKind())); + vec.push_back(std::make_pair(CString("NextIndex"), JSTaggedValue(GetNextIndex()))); + vec.push_back(std::make_pair(CString("IterationKind"), JSTaggedValue(static_cast(GetIterationKind())))); JSObject::DumpForSnapshot(thread, vec); } @@ -2490,8 +2401,8 @@ void JSSetIterator::DumpForSnapshot([[maybe_unused]] JSThread *thread, { LinkedHashSet *set = LinkedHashSet::Cast(GetIteratedSet().GetTaggedObject()); set->DumpForSnapshot(thread, vec); - vec.push_back(std::make_pair(CString("NextIndex"), GetNextIndex())); - vec.push_back(std::make_pair(CString("IterationKind"), GetIterationKind())); + vec.push_back(std::make_pair(CString("NextIndex"), JSTaggedValue(GetNextIndex()))); + vec.push_back(std::make_pair(CString("IterationKind"), JSTaggedValue(static_cast(GetIterationKind())))); JSObject::DumpForSnapshot(thread, vec); } @@ -2512,8 +2423,8 @@ void JSArrayIterator::DumpForSnapshot([[maybe_unused]] JSThread *thread, { JSArray *array = JSArray::Cast(GetIteratedArray().GetTaggedObject()); array->DumpForSnapshot(thread, vec); - vec.push_back(std::make_pair(CString("NextIndex"), GetNextIndex())); - vec.push_back(std::make_pair(CString("IterationKind"), GetIterationKind())); + vec.push_back(std::make_pair(CString("NextIndex"), JSTaggedValue(GetNextIndex()))); + vec.push_back(std::make_pair(CString("IterationKind"), JSTaggedValue(static_cast(GetIterationKind())))); JSObject::DumpForSnapshot(thread, vec); } @@ -2521,7 +2432,7 @@ void JSStringIterator::DumpForSnapshot([[maybe_unused]] JSThread *thread, std::vector> &vec) const { vec.push_back(std::make_pair(CString("IteratedString"), GetIteratedString())); - vec.push_back(std::make_pair(CString("StringIteratorNextIndex"), GetStringIteratorNextIndex())); + vec.push_back(std::make_pair(CString("StringIteratorNextIndex"), JSTaggedValue(GetStringIteratorNextIndex()))); JSObject::DumpForSnapshot(thread, vec); } @@ -2554,8 +2465,8 @@ void JSProxy::DumpForSnapshot([[maybe_unused]] JSThread *thread, void JSSymbol::DumpForSnapshot([[maybe_unused]] JSThread *thread, std::vector> &vec) const { - vec.push_back(std::make_pair(CString("hash-field"), GetHashField())); - vec.push_back(std::make_pair(CString("flags"), GetFlags())); + vec.push_back(std::make_pair(CString("hash-field"), JSTaggedValue(GetHashField()))); + vec.push_back(std::make_pair(CString("flags"), JSTaggedValue(GetFlags()))); vec.push_back(std::make_pair(CString("description"), GetDescription())); } @@ -2693,24 +2604,24 @@ void JSDataView::DumpForSnapshot([[maybe_unused]] JSThread *thread, { vec.push_back(std::make_pair(CString("data-view"), GetDataView())); vec.push_back(std::make_pair(CString("buffer"), GetViewedArrayBuffer())); - vec.push_back(std::make_pair(CString("byte-length"), GetByteLength())); - vec.push_back(std::make_pair(CString("byte-offset"), GetByteOffset())); + vec.push_back(std::make_pair(CString("byte-length"), JSTaggedValue(GetByteLength()))); + vec.push_back(std::make_pair(CString("byte-offset"), JSTaggedValue(GetByteOffset()))); } void JSArrayBuffer::DumpForSnapshot([[maybe_unused]] JSThread *thread, std::vector> &vec) const { - vec.push_back(std::make_pair(CString("byte-length"), GetArrayBufferByteLength())); vec.push_back(std::make_pair(CString("buffer-data"), GetArrayBufferData())); - vec.push_back(std::make_pair(CString("shared"), GetShared())); + vec.push_back(std::make_pair(CString("byte-length"), JSTaggedValue(GetArrayBufferByteLength()))); + vec.push_back(std::make_pair(CString("shared"), JSTaggedValue(GetShared()))); } void PromiseReaction::DumpForSnapshot([[maybe_unused]] JSThread *thread, std::vector> &vec) const { vec.push_back(std::make_pair(CString("promise-capability"), GetPromiseCapability())); - vec.push_back(std::make_pair(CString("type"), GetType())); vec.push_back(std::make_pair(CString("handler"), GetHandler())); + vec.push_back(std::make_pair(CString("type"), JSTaggedValue(static_cast(GetType())))); } void PromiseCapability::DumpForSnapshot([[maybe_unused]] JSThread *thread, @@ -2725,7 +2636,7 @@ void PromiseIteratorRecord::DumpForSnapshot([[maybe_unused]] JSThread *thread, std::vector> &vec) const { vec.push_back(std::make_pair(CString("iterator"), GetIterator())); - vec.push_back(std::make_pair(CString("done"), GetDone())); + vec.push_back(std::make_pair(CString("done"), JSTaggedValue(GetDone()))); } void PromiseRecord::DumpForSnapshot([[maybe_unused]] JSThread *thread, @@ -2744,11 +2655,11 @@ void ResolvingFunctionsRecord::DumpForSnapshot([[maybe_unused]] JSThread *thread void JSPromise::DumpForSnapshot([[maybe_unused]] JSThread *thread, std::vector> &vec) const { - vec.push_back(std::make_pair(CString("promise-state"), GetPromiseState())); + vec.push_back(std::make_pair(CString("promise-state"), JSTaggedValue(static_cast(GetPromiseState())))); vec.push_back(std::make_pair(CString("promise-result"), GetPromiseResult())); vec.push_back(std::make_pair(CString("promise-fulfill-reactions"), GetPromiseFulfillReactions())); vec.push_back(std::make_pair(CString("promise-reject-reactions"), GetPromiseRejectReactions())); - vec.push_back(std::make_pair(CString("promise-is-handled"), GetPromiseIsHandled())); + vec.push_back(std::make_pair(CString("promise-is-handled"), JSTaggedValue(GetPromiseIsHandled()))); JSObject::DumpForSnapshot(thread, vec); } @@ -2795,8 +2706,8 @@ void PendingJob::DumpForSnapshot([[maybe_unused]] JSThread *thread, void CompletionRecord::DumpForSnapshot([[maybe_unused]] JSThread *thread, std::vector> &vec) const { - vec.push_back(std::make_pair(CString("type"), GetType())); vec.push_back(std::make_pair(CString("value"), GetValue())); + vec.push_back(std::make_pair(CString("type"), JSTaggedValue(static_cast(GetType())))); } void JSProxyRevocFunction::DumpForSnapshot([[maybe_unused]] JSThread *thread, @@ -2879,12 +2790,12 @@ void JSDateTimeFormat::DumpForSnapshot(JSThread *thread, std::vector(GetHourCycle())))); vec.push_back(std::make_pair(CString("LocaleIcu"), GetLocaleIcu())); vec.push_back(std::make_pair(CString("SimpleDateTimeFormatIcu"), GetSimpleDateTimeFormatIcu())); vec.push_back(std::make_pair(CString("Iso8601"), GetIso8601())); - vec.push_back(std::make_pair(CString("DateStyle"), GetDateStyle())); - vec.push_back(std::make_pair(CString("TimeStyle"), GetTimeStyle())); + vec.push_back(std::make_pair(CString("DateStyle"), JSTaggedValue(static_cast(GetDateStyle())))); + vec.push_back(std::make_pair(CString("TimeStyle"), JSTaggedValue(static_cast(GetTimeStyle())))); vec.push_back(std::make_pair(CString("BoundFormat"), GetBoundFormat())); JSObject::DumpForSnapshot(thread, vec); } @@ -2894,8 +2805,8 @@ void JSRelativeTimeFormat::DumpForSnapshot(JSThread *thread, std::vector(GetStyle())))); + vec.push_back(std::make_pair(CString("Numeric"), JSTaggedValue(static_cast(GetNumeric())))); vec.push_back(std::make_pair(CString("AvailableLocales"), GetAvailableLocales())); vec.push_back(std::make_pair(CString("IcuField"), GetIcuField())); JSObject::DumpForSnapshot(thread, vec); @@ -2905,22 +2816,22 @@ void JSNumberFormat::DumpForSnapshot(JSThread *thread, std::vector(GetStyle())))); vec.push_back(std::make_pair(CString("Currency"), GetCurrency())); - vec.push_back(std::make_pair(CString("CurrencyDisplay"), GetCurrencyDisplay())); - vec.push_back(std::make_pair(CString("CurrencySign"), GetCurrencySign())); + vec.push_back(std::make_pair(CString("CurrencyDisplay"), JSTaggedValue(static_cast(GetCurrencyDisplay())))); + vec.push_back(std::make_pair(CString("CurrencySign"), JSTaggedValue(static_cast(GetCurrencySign())))); vec.push_back(std::make_pair(CString("Unit"), GetUnit())); - vec.push_back(std::make_pair(CString("UnitDisplay"), GetUnitDisplay())); + vec.push_back(std::make_pair(CString("UnitDisplay"), JSTaggedValue(static_cast(GetUnitDisplay())))); vec.push_back(std::make_pair(CString("MinimumIntegerDigits"), GetMinimumIntegerDigits())); vec.push_back(std::make_pair(CString("MinimumFractionDigits"), GetMinimumFractionDigits())); vec.push_back(std::make_pair(CString("MaximumFractionDigits"), GetMaximumFractionDigits())); vec.push_back(std::make_pair(CString("MinimumSignificantDigits"), GetMinimumSignificantDigits())); vec.push_back(std::make_pair(CString("MaximumSignificantDigits"), GetMaximumSignificantDigits())); vec.push_back(std::make_pair(CString("UseGrouping"), GetUseGrouping())); - vec.push_back(std::make_pair(CString("RoundingType"), GetRoundingType())); - vec.push_back(std::make_pair(CString("Notation"), GetNotation())); - vec.push_back(std::make_pair(CString("CompactDisplay"), GetCompactDisplay())); - vec.push_back(std::make_pair(CString("SignDisplay"), GetSignDisplay())); + vec.push_back(std::make_pair(CString("RoundingType"), JSTaggedValue(static_cast(GetRoundingType())))); + vec.push_back(std::make_pair(CString("Notation"), JSTaggedValue(static_cast(GetNotation())))); + vec.push_back(std::make_pair(CString("CompactDisplay"), JSTaggedValue(static_cast(GetCompactDisplay())))); + vec.push_back(std::make_pair(CString("SignDisplay"), JSTaggedValue(static_cast(GetSignDisplay())))); vec.push_back(std::make_pair(CString("BoundFormat"), GetBoundFormat())); vec.push_back(std::make_pair(CString("IcuField"), GetIcuField())); JSObject::DumpForSnapshot(thread, vec); @@ -2930,13 +2841,13 @@ void JSCollator::DumpForSnapshot(JSThread *thread, std::vector(GetCaseFirst())))); + vec.push_back(std::make_pair(CString("Usage"), JSTaggedValue(static_cast(GetUsage())))); + vec.push_back(std::make_pair(CString("Sensitivity"), JSTaggedValue(static_cast(GetSensitivity())))); + vec.push_back(std::make_pair(CString("IgnorePunctuation"), JSTaggedValue(GetIgnorePunctuation()))); + vec.push_back(std::make_pair(CString("Numeric"), JSTaggedValue(GetNumeric()))); JSObject::DumpForSnapshot(thread, vec); } @@ -2944,24 +2855,24 @@ void JSPluralRules::DumpForSnapshot(JSThread *thread, std::vector(GetRoundingType())))); vec.push_back(std::make_pair(CString("IcuPR"), GetIcuPR())); vec.push_back(std::make_pair(CString("IcuNF"), GetIcuNF())); + vec.push_back(std::make_pair(CString("Type"), JSTaggedValue(static_cast(GetType())))); JSObject::DumpForSnapshot(thread, vec); } void JSGeneratorObject::DumpForSnapshot(JSThread *thread, std::vector> &vec) const { - vec.push_back(std::make_pair(CString("GeneratorState"), GetGeneratorState())); vec.push_back(std::make_pair(CString("GeneratorContext"), GetGeneratorContext())); vec.push_back(std::make_pair(CString("ResumeResult"), GetResumeResult())); - vec.push_back(std::make_pair(CString("ResumeMode"), GetResumeMode())); + vec.push_back(std::make_pair(CString("GeneratorState"), JSTaggedValue(static_cast(GetGeneratorState())))); + vec.push_back(std::make_pair(CString("ResumeMode"), JSTaggedValue(static_cast(GetResumeMode())))); JSObject::DumpForSnapshot(thread, vec); } @@ -2975,10 +2886,10 @@ void GeneratorContext::DumpForSnapshot(JSThread *thread, std::vector> &vec) const @@ -2989,27 +2900,12 @@ void ProtoChangeMarker::DumpForSnapshot(JSThread *thread, std::vector> &vec) const { vec.push_back(std::make_pair(CString("ChangeListener"), GetChangeListener())); - vec.push_back(std::make_pair(CString("RegisterIndex"), GetRegisterIndex())); -} - -void LexicalFunction::DumpForSnapshot(JSThread *thread, std::vector> &vec) const -{ - vec.push_back(std::make_pair(CString("Name"), GetName())); - vec.push_back(std::make_pair(CString("NumberVRegs"), GetNumberVRegs())); - vec.push_back(std::make_pair(CString("NumberICSlots"), GetNumberICSlots())); - vec.push_back(std::make_pair(CString("Bytecode"), GetBytecode())); - vec.push_back(std::make_pair(CString("Program"), GetProgram())); -} - -void JSFunctionExtraInfo::DumpForSnapshot(JSThread *thread, std::vector> &vec) const -{ - vec.push_back(std::make_pair(CString("Callback"), GetCallback())); - vec.push_back(std::make_pair(CString("Data"), GetData())); + vec.push_back(std::make_pair(CString("RegisterIndex"), JSTaggedValue(GetRegisterIndex()))); } void MachineCode::DumpForSnapshot(JSThread *thread, std::vector> &vec) const { - vec.push_back(std::make_pair(CString("InstructionSizeInBytes"), GetInstructionSizeInBytes())); + vec.push_back(std::make_pair(CString("InstructionSizeInBytes"), JSTaggedValue(GetInstructionSizeInBytes()))); } void EcmaModule::DumpForSnapshot(JSThread *thread, std::vector> &vec) const diff --git a/ecmascript/ecma_macros.h b/ecmascript/ecma_macros.h index 5efea5690e..0eb0e4009e 100644 --- a/ecmascript/ecma_macros.h +++ b/ecmascript/ecma_macros.h @@ -52,20 +52,20 @@ #define GET_VALUE(addr, offset) Barriers::GetDynValue((addr), (offset)) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define SET_VALUE_WITH_BARRIER(thread, addr, offset, value) \ - if (value.IsHeapObject()) { \ - Barriers::SetDynObject(thread, addr, offset, value.GetRawData()); \ - } else { \ - Barriers::SetDynPrimitive(addr, offset, value.GetRawData()); \ +#define SET_VALUE_WITH_BARRIER(thread, addr, offset, value) \ + if ((value).IsHeapObject()) { \ + Barriers::SetDynObject(thread, addr, offset, (value).GetRawData()); \ + } else { \ + Barriers::SetDynPrimitive(addr, offset, (value).GetRawData()); \ } // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define SET_VALUE_PRIMITIVE(addr, offset, value) \ - Barriers::SetDynPrimitive(this, offset, value.GetRawData()) + Barriers::SetDynPrimitive(this, offset, (value).GetRawData()) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define ACCESSORS(name, offset, lastOffset) \ - static constexpr size_t lastOffset = offset + JSTaggedValue::TaggedTypeSize(); \ +#define ACCESSORS(name, offset, endOffset) \ + static constexpr size_t endOffset = (offset) + JSTaggedValue::TaggedTypeSize(); \ JSTaggedValue Get##name() const \ { \ /* Note: We can't statically decide the element type is a primitive or heap object, especially for */ \ @@ -103,53 +103,67 @@ } // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define SET_GET_VOID_FIELD(name, offset, lastOffset) \ - static constexpr size_t lastOffset = offset + JSTaggedValue::TaggedTypeSize(); \ - void Set##name(void *fun) \ - { \ - Barriers::SetDynPrimitive(this, offset, fun); \ - } \ - void *Get##name() const \ - { \ - return Barriers::GetDynValue(this, offset); \ +#define DEFINE_ALIGN_SIZE(offset) \ + static constexpr size_t SIZE = ((offset) + sizeof(JSTaggedType) - 1U) & (~(sizeof(JSTaggedType) - 1U)) + +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define ACCESSORS_FIXED_SIZE_FIELD(name, type, sizeType, offset, endOffset) \ + static_assert(sizeof(type) <= sizeof(sizeType)); \ + static constexpr size_t endOffset = (offset) + sizeof(sizeType); \ + inline void Set##name(type value) \ + { \ + Barriers::SetDynPrimitive(this, offset, value); \ + } \ + inline type Get##name() const \ + { \ + return Barriers::GetDynValue(this, offset); \ } // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define SET_GET_NATIVE_FIELD(name, type, offset, lastOffset) \ - static constexpr size_t lastOffset = offset + JSTaggedValue::TaggedTypeSize(); \ - void Set##name(type *mem) \ - { \ - Barriers::SetDynPrimitive(this, offset, mem); \ - } \ - type *Get##name() const \ - { \ - return Barriers::GetDynValue(this, offset); \ - } \ - size_t Offset##name() const \ - { \ - return offset; \ +#define ACCESSORS_NATIVE_FIELD(name, type, offset, endOffset) \ + ACCESSORS_FIXED_SIZE_FIELD(name, type *, type *, offset, endOffset) + +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define ACCESSORS_PRIMITIVE_FIELD(name, type, offset, endOffset) \ + ACCESSORS_FIXED_SIZE_FIELD(name, type, type, offset, endOffset) + +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define ACCESSORS_BIT_FIELD(name, offset, endOffset) \ + ACCESSORS_FIXED_SIZE_FIELD(name, uint32_t, uint32_t, offset, endOffset) \ + inline void Clear##name() \ + { \ + Set##name(0UL); \ } // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define SET_GET_PRIMITIVE_FIELD(name, type, offset, lastOffset) \ - static constexpr size_t lastOffset = offset + JSTaggedValue::TaggedTypeSize(); \ - void Set##name(type value) \ - { \ - Barriers::SetDynPrimitive(this, offset, value); \ - } \ - type Get##name() const \ - { \ - return Barriers::GetDynValue(this, offset); \ +#define SET_GET_BIT_FIELD(bitFieldName, name, type) \ + inline type Get##name() const \ + { \ + return name##Bits::Decode(Get##bitFieldName()); \ + } \ + inline void Set##name(type t) \ + { \ + Set##bitFieldName(name##Bits::Update(Get##bitFieldName(), t)); \ } +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define FIRST_BIT_FIELD(bitFieldName, name, type, bits) \ + using name##Bits = BitField; \ + SET_GET_BIT_FIELD(bitFieldName, name, type) + +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define NEXT_BIT_FIELD(bitFieldName, name, type, bits, lastName) \ + using name##Bits = lastName##Bits::NextField; \ + SET_GET_BIT_FIELD(bitFieldName, name, type) + #if !defined(NDEBUG) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define DASSERT(cond) assert(cond) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define DASSERT_PRINT(cond, message) \ - if (auto cond_val = cond; UNLIKELY(!(cond_val))) { \ - std::cerr << message << std::endl; \ - ASSERT(#cond &&cond_val); \ +#define DASSERT_PRINT(cond, message) \ + if (auto cond_val = (cond); UNLIKELY(!(cond_val))) { \ + std::cerr << (message) << std::endl; \ + ASSERT(#cond &&cond_val); \ } #else // NDEBUG #define DASSERT(cond) static_cast(0) // NOLINT(cppcoreguidelines-macro-usage) @@ -176,7 +190,7 @@ // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, value) \ do { \ - if (thread->HasPendingException()) { \ + if ((thread)->HasPendingException()) { \ return (value); \ } \ } while (false) @@ -184,7 +198,7 @@ // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread) \ do { \ - if (thread->HasPendingException()) { \ + if ((thread)->HasPendingException()) { \ return JSTaggedValue::Exception(); \ } \ } while (false) @@ -192,7 +206,7 @@ // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define RETURN_HANDLE_IF_ABRUPT_COMPLETION(type, thread) \ do { \ - if (thread->HasPendingException()) { \ + if ((thread)->HasPendingException()) { \ return JSHandle(thread, JSTaggedValue::Exception()); \ } \ } while (false) @@ -203,8 +217,8 @@ // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, value) \ do { \ - if (!thread->HasPendingException()) { \ - thread->SetException(error); \ + if (!(thread)->HasPendingException()) { \ + (thread)->SetException(error); \ } \ return (value); \ } while (false) @@ -280,8 +294,8 @@ // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define THROW_NEW_ERROR_AND_RETURN(thread, error) \ do { \ - if (!thread->HasPendingException()) { \ - thread->SetException(error); \ + if (!(thread)->HasPendingException()) { \ + (thread)->SetException(error); \ } \ return; \ } while (false) @@ -289,7 +303,7 @@ // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define THROW_TYPE_ERROR_AND_RETURN(thread, message, exception) \ do { \ - ObjectFactory *objectFactory = thread->GetEcmaVM()->GetFactory(); \ + ObjectFactory *objectFactory = (thread)->GetEcmaVM()->GetFactory(); \ JSHandle error = objectFactory->GetJSError(ErrorType::TYPE_ERROR, message); \ THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error.GetTaggedValue(), exception); \ } while (false) @@ -297,7 +311,7 @@ // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define THROW_TYPE_ERROR(thread, message) \ do { \ - ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); \ + ObjectFactory *factory = (thread)->GetEcmaVM()->GetFactory(); \ JSHandle error = factory->GetJSError(ErrorType::TYPE_ERROR, message); \ THROW_NEW_ERROR_AND_RETURN(thread, error.GetTaggedValue()); \ } while (false) @@ -305,7 +319,7 @@ // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define THROW_RANGE_ERROR_AND_RETURN(thread, message, exception) \ do { \ - ObjectFactory *objectFactory = thread->GetEcmaVM()->GetFactory(); \ + ObjectFactory *objectFactory = (thread)->GetEcmaVM()->GetFactory(); \ JSHandle error = objectFactory->GetJSError(ErrorType::RANGE_ERROR, message); \ THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error.GetTaggedValue(), exception); \ } while (false) @@ -313,7 +327,7 @@ // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define THROW_RANGE_ERROR(thread, message) \ do { \ - ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); \ + ObjectFactory *factory = (thread)->GetEcmaVM()->GetFactory(); \ JSHandle error = factory->GetJSError(ErrorType::RANGE_ERROR, message); \ THROW_NEW_ERROR_AND_RETURN(thread, error.GetTaggedValue()); \ } while (false) @@ -321,14 +335,14 @@ // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define THROW_URI_ERROR_AND_RETURN(thread, message, exception) \ do { \ - ObjectFactory *objectFactory = thread->GetEcmaVM()->GetFactory(); \ + ObjectFactory *objectFactory = (thread)->GetEcmaVM()->GetFactory(); \ JSHandle error = objectFactory->GetJSError(ErrorType::URI_ERROR, message); \ THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error.GetTaggedValue(), exception); \ } while (false) #define THROW_SYNTAX_ERROR_AND_RETURN(thread, message, exception) \ do { \ - ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); \ + ObjectFactory *factory = (thread)->GetEcmaVM()->GetFactory(); \ JSHandle error = factory->GetJSError(ErrorType::SYNTAX_ERROR, message); \ THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error.GetTaggedValue(), exception); \ } while (false) @@ -336,39 +350,39 @@ // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define RETURN_REJECT_PROMISE_IF_ABRUPT(thread, value, capability) \ do { \ - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); \ - if (value.GetTaggedValue().IsCompletionRecord()) { \ + const GlobalEnvConstants *globalConst = (thread)->GlobalConstants(); \ + if ((value).GetTaggedValue().IsCompletionRecord()) { \ JSHandle record = JSHandle::Cast(value); \ if (record->IsThrow()) { \ - JSHandle reject(thread, capability->GetReject()); \ + JSHandle reject(thread, (capability)->GetReject()); \ JSHandle undefine = globalConst->GetHandledUndefined(); \ - InternalCallParams *arg = thread->GetInternalCallParams(); \ + InternalCallParams *arg = (thread)->GetInternalCallParams(); \ arg->MakeArgv(record->GetValue()); \ JSTaggedValue res = JSFunction::Call(thread, reject, undefine, 1, arg->GetArgv()); \ RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, res); \ - return capability->GetPromise(); \ + return (capability)->GetPromise(); \ } \ } \ - if (thread->HasPendingException()) { \ - thread->ClearException(); \ - JSHandle reject(thread, capability->GetReject()); \ + if ((thread)->HasPendingException()) { \ + (thread)->ClearException(); \ + JSHandle reject(thread, (capability)->GetReject()); \ JSHandle undefined = globalConst->GetHandledUndefined(); \ - InternalCallParams *arg = thread->GetInternalCallParams(); \ + InternalCallParams *arg = (thread)->GetInternalCallParams(); \ arg->MakeArgv(value); \ JSTaggedValue res = JSFunction::Call(thread, reject, undefined, 1, arg->GetArgv()); \ RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, res); \ - return capability->GetPromise(); \ + return (capability)->GetPromise(); \ } \ } while (false) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define RETURN_COMPLETION_IF_ABRUPT(thread, value) \ - do { \ - if (thread->HasPendingException()) { \ - JSHandle completionRecord = \ - factory->NewCompletionRecord(CompletionRecord::THROW, value); \ - return (completionRecord); \ - } \ +#define RETURN_COMPLETION_IF_ABRUPT(thread, value) \ + do { \ + if ((thread)->HasPendingException()) { \ + JSHandle completionRecord = \ + factory->NewCompletionRecord(CompletionRecordType::THROW, value); \ + return (completionRecord); \ + } \ } while (false) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) @@ -412,8 +426,8 @@ VisitObjects(visitor); \ /* visit in object fields */ \ auto objSize = this->GetClass()->GetObjectSize(); \ - if (objSize > (END_OFFSET)) { \ - visitor(this, ObjectSlot(ToUintPtr(this) + (END_OFFSET)), ObjectSlot(ToUintPtr(this) + objSize)); \ + if (objSize > SIZE) { \ + visitor(this, ObjectSlot(ToUintPtr(this) + SIZE), ObjectSlot(ToUintPtr(this) + objSize)); \ } \ } \ void VisitObjects(const EcmaObjectRangeVisitor &visitor) \ @@ -484,18 +498,18 @@ #endif // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define CHECK_DUMP_FILEDS(begin, end, num) \ - LOG_IF(num != (end - begin) / JSTaggedValue::TaggedTypeSize(), FATAL, RUNTIME) \ +#define CHECK_DUMP_FILEDS(begin, end, num) \ + LOG_IF((num) != ((end) - (begin)) / JSTaggedValue::TaggedTypeSize(), FATAL, RUNTIME) \ << "Fileds in obj are not in dump list. "; -#define CHECK_OBJECT_SIZE(size) \ - if (size == 0) { \ - LOG(FATAL, ECMASCRIPT) << __func__ << " Line: " << __LINE__ << " objectSize is " << size; \ +#define CHECK_OBJECT_SIZE(size) \ + if ((size) == 0) { \ + LOG(FATAL, ECMASCRIPT) << __func__ << " Line: " << __LINE__ << " objectSize is " << (size); \ } -#define CHECK_REGION_END(begin, end) \ - if (begin > end) { \ - LOG(FATAL, ECMASCRIPT) << __func__ << " Line: " << __LINE__ << " begin: " << begin << " end: " << end; \ +#define CHECK_REGION_END(begin, end) \ + if ((begin) > (end)) { \ + LOG(FATAL, ECMASCRIPT) << __func__ << " Line: " << __LINE__ << " begin: " << (begin) << " end: " << (end); \ } #endif // ECMASCRIPT_ECMA_MACROS_H diff --git a/ecmascript/ecma_string.h b/ecmascript/ecma_string.h index 6655826136..9842563dea 100644 --- a/ecmascript/ecma_string.h +++ b/ecmascript/ecma_string.h @@ -262,11 +262,11 @@ public: static constexpr size_t MIX_LENGTH_OFFSET = TaggedObjectSize(); // In last bit of mix_length we store if this string is compressed or not. - SET_GET_PRIMITIVE_FIELD(MixLength, uint32_t, MIX_LENGTH_OFFSET, HASHCODE_OFFSET); - SET_GET_PRIMITIVE_FIELD(RawHashcode, uint32_t, HASHCODE_OFFSET, DATA_OFFSET); + ACCESSORS_PRIMITIVE_FIELD(MixLength, uint32_t, MIX_LENGTH_OFFSET, HASHCODE_OFFSET) + ACCESSORS_PRIMITIVE_FIELD(RawHashcode, uint32_t, HASHCODE_OFFSET, SIZE) // DATA_OFFSET: the string data stored after the string header. // Data can be stored in utf8 or utf16 form according to compressed bit. - static constexpr size_t SIZE = DATA_OFFSET; // Empty String size + static constexpr size_t DATA_OFFSET = SIZE; // DATA_OFFSET equal to Empty String size private: void SetLength(uint32_t length, bool compressed = false) @@ -321,6 +321,8 @@ private: template static int32_t IndexOf(Span &lhsSp, Span &rhsSp, int32_t pos, int32_t max); }; + +static_assert((EcmaString::DATA_OFFSET % static_cast(MemAlignment::MEM_ALIGN_OBJECT)) == 0); } // namespace ecmascript } // namespace panda #endif // ECMASCRIPT_STRING_H diff --git a/ecmascript/ecma_vm.h b/ecmascript/ecma_vm.h index b88fcbabbf..2b6258f378 100644 --- a/ecmascript/ecma_vm.h +++ b/ecmascript/ecma_vm.h @@ -56,7 +56,7 @@ class JSNativePointer; class Program; class RegExpExecResultCache; class JSPromise; -enum class PromiseRejectionEvent : uint32_t; +enum class PromiseRejectionEvent : uint8_t; namespace job { class MicroJobQueue; } // namespace job @@ -71,7 +71,7 @@ class EcmaModule; using HostPromiseRejectionTracker = void (*)(const EcmaVM* vm, const JSHandle promise, const JSHandle reason, - const PromiseRejectionEvent operation, + PromiseRejectionEvent operation, void* data); using PromiseRejectCallback = void (*)(void* info); @@ -387,12 +387,13 @@ public: } void PromiseRejectionTracker(const JSHandle &promise, - const JSHandle &reason, const PromiseRejectionEvent operation) + const JSHandle &reason, PromiseRejectionEvent operation) { if (hostPromiseRejectionTracker_ != nullptr) { hostPromiseRejectionTracker_(this, promise, reason, operation, data_); } } + protected: bool CheckEntrypointSignature([[maybe_unused]] Method *entrypoint) override { diff --git a/ecmascript/free_object.h b/ecmascript/free_object.h index 27eb1edf92..30506080b3 100644 --- a/ecmascript/free_object.h +++ b/ecmascript/free_object.h @@ -47,7 +47,7 @@ public: inline void SetAvailable(uint32_t size) { if (size >= SIZE) { - SetSize(JSTaggedValue(size)); + SetSize(size); } } @@ -57,7 +57,7 @@ public: if (hclass != nullptr && (hclass->IsFreeObjectWithOneField() || hclass->IsFreeObjectWithNoneField())) { return hclass->GetObjectSize(); } - return GetSize().GetInt(); + return GetSize(); } inline bool IsFreeObject() const @@ -68,8 +68,11 @@ public: } static constexpr size_t NEXT_OFFSET = TaggedObjectSize(); - SET_GET_NATIVE_FIELD(Next, FreeObject, NEXT_OFFSET, SIZE_OFFSET); - ACCESSORS(Size, SIZE_OFFSET, SIZE); + ACCESSORS_FIXED_SIZE_FIELD(Next, FreeObject *, JSTaggedType, NEXT_OFFSET, SIZE_OFFSET) + ACCESSORS_FIXED_SIZE_FIELD(Size, uint32_t, JSTaggedType, SIZE_OFFSET, SIZE) }; + +static_assert((FreeObject::SIZE % static_cast(MemAlignment::MEM_ALIGN_OBJECT)) == 0); } // namespace panda::ecmascript + #endif // ECMASCRIPT_MEM_FREE_OBJECT_H diff --git a/ecmascript/generator_helper.cpp b/ecmascript/generator_helper.cpp index f8970929d6..78c4391dec 100644 --- a/ecmascript/generator_helper.cpp +++ b/ecmascript/generator_helper.cpp @@ -24,9 +24,9 @@ JSHandle GeneratorHelper::Next(JSThread *thread, const JSHandle genObject(thread, genContext->GetGeneratorObject()); - genObject->SetGeneratorState(thread, JSTaggedValue(static_cast(JSGeneratorState::EXECUTING))); - genObject->SetResumeMode(thread, JSTaggedValue(static_cast(GeneratorResumeMode::NEXT))); genObject->SetResumeResult(thread, value); + genObject->SetGeneratorState(JSGeneratorState::EXECUTING); + genObject->SetResumeMode(GeneratorResumeMode::NEXT); JSTaggedValue next = EcmaInterpreter::GeneratorReEnterInterpreter(thread, genContext); JSHandle nextValue(thread, next); @@ -34,7 +34,7 @@ JSHandle GeneratorHelper::Next(JSThread *thread, const JSHandleIsSuspendYield()) { return JSHandle::Cast(nextValue); } - genObject->SetGeneratorState(thread, JSTaggedValue(static_cast(JSGeneratorState::COMPLETED))); + genObject->SetGeneratorState(JSGeneratorState::COMPLETED); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSObject, thread); return JSIterator::CreateIterResultObject(thread, nextValue, true); } @@ -43,14 +43,14 @@ JSHandle GeneratorHelper::Return(JSThread *thread, const JSHandle genObject(thread, genContext->GetGeneratorObject()); - genObject->SetResumeMode(thread, JSTaggedValue(static_cast(GeneratorResumeMode::RETURN))); + genObject->SetResumeMode(GeneratorResumeMode::RETURN); genObject->SetResumeResult(thread, value); JSTaggedValue res = EcmaInterpreter::GeneratorReEnterInterpreter(thread, genContext); JSHandle returnValue(thread, res); // change state to completed if (genObject->IsExecuting()) { - genObject->SetGeneratorState(thread, JSTaggedValue(static_cast(JSGeneratorState::COMPLETED))); + genObject->SetGeneratorState(JSGeneratorState::COMPLETED); } RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSObject, thread); return JSIterator::CreateIterResultObject(thread, returnValue, true); @@ -60,7 +60,7 @@ JSHandle GeneratorHelper::Throw(JSThread *thread, const JSHandle genObject(thread, genContext->GetGeneratorObject()); - genObject->SetResumeMode(thread, JSTaggedValue(static_cast(GeneratorResumeMode::THROW))); + genObject->SetResumeMode(GeneratorResumeMode::THROW); genObject->SetResumeResult(thread, value); JSTaggedValue res = EcmaInterpreter::GeneratorReEnterInterpreter(thread, genContext); @@ -71,14 +71,13 @@ JSHandle GeneratorHelper::Throw(JSThread *thread, const JSHandleSetGeneratorState(thread, JSTaggedValue(static_cast(JSGeneratorState::COMPLETED))); + genObject->SetGeneratorState(JSGeneratorState::COMPLETED); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSObject, thread); return JSIterator::CreateIterResultObject(thread, throwValue, true); } // main->foo -void GeneratorHelper::ChangeGenContext(JSThread *thread, const JSHandle &genContext, - [[maybe_unused]] C2IBridge *c2i) +void GeneratorHelper::ChangeGenContext(JSThread *thread, const JSHandle &genContext) { JSThread *jsThread = thread; EcmaInterpreter::ChangeGenContext(jsThread, genContext); diff --git a/ecmascript/generator_helper.h b/ecmascript/generator_helper.h index f6ad6616ce..fbbb2ecc08 100644 --- a/ecmascript/generator_helper.h +++ b/ecmascript/generator_helper.h @@ -22,14 +22,6 @@ #include "ecmascript/js_handle.h" namespace panda::ecmascript { -enum class GeneratorResumeMode { - RETURN = 0, - THROW, - NEXT, -}; - -using C2IBridge = std::array; // 4: means array length - class GeneratorHelper { public: static JSHandle Next(JSThread *thread, const JSHandle &genContext, JSTaggedValue value); @@ -39,7 +31,7 @@ public: static JSHandle Throw(JSThread *thread, const JSHandle &genContext, JSTaggedValue value); - static void ChangeGenContext(JSThread *thread, const JSHandle &genContext, C2IBridge *c2i); + static void ChangeGenContext(JSThread *thread, const JSHandle &genContext); static void ResumeContext(JSThread *thread); }; } // namespace panda::ecmascript diff --git a/ecmascript/global_dictionary-inl.h b/ecmascript/global_dictionary-inl.h index f843df6fd8..aaac2b4638 100644 --- a/ecmascript/global_dictionary-inl.h +++ b/ecmascript/global_dictionary-inl.h @@ -28,7 +28,7 @@ int GlobalDictionary::Hash(const JSTaggedValue &key) if (key.IsHeapObject()) { if (key.IsSymbol()) { auto symbolString = JSSymbol::Cast(key.GetTaggedObject()); - return static_cast(symbolString->GetHashField()).GetInt(); + return symbolString->GetHashField(); } if (key.IsString()) { auto keyString = EcmaString::Cast(key.GetTaggedObject()); diff --git a/ecmascript/global_env_constants.cpp b/ecmascript/global_env_constants.cpp index 7e7ff51fdc..524dc98fd4 100644 --- a/ecmascript/global_env_constants.cpp +++ b/ecmascript/global_env_constants.cpp @@ -128,9 +128,6 @@ void GlobalEnvConstants::InitRootsClass([[maybe_unused]] JSThread *thread, JSHCl factory->NewEcmaDynClass(dynClassClass, TransitionHandler::SIZE, JSType::TRANSITION_HANDLER).GetTaggedValue()); SetConstant(ConstantIndex::PROPERTY_BOX_CLASS_INDEX, factory->NewEcmaDynClass(dynClassClass, PropertyBox::SIZE, JSType::PROPERTY_BOX).GetTaggedValue()); - SetConstant(ConstantIndex::FUNCTION_EXTRA_INFO_INDEX, - factory->NewEcmaDynClass(dynClassClass, JSFunctionExtraInfo::SIZE, JSType::FUNCTION_EXTRA_INFO) - .GetTaggedValue()); SetConstant(ConstantIndex::PROGRAM_CLASS_INDEX, factory->NewEcmaDynClass(dynClassClass, Program::SIZE, JSType::PROGRAM).GetTaggedValue()); SetConstant(ConstantIndex::ECMA_MODULE_CLASS_INDEX, diff --git a/ecmascript/global_env_constants.h b/ecmascript/global_env_constants.h index dd1e716f82..25515971d2 100644 --- a/ecmascript/global_env_constants.h +++ b/ecmascript/global_env_constants.h @@ -59,7 +59,6 @@ class JSThread; V(JSTaggedValue, PrototypeHandlerClass, PROTOTYPE_HANDLER_CLASS_INDEX, ecma_roots_class) \ V(JSTaggedValue, TransitionHandlerClass, TRANSITION_HANDLER_CLASS_INDEX, ecma_roots_class) \ V(JSTaggedValue, PropertyBoxClass, PROPERTY_BOX_CLASS_INDEX, ecma_roots_class) \ - V(JSTaggedValue, FunctionExtraInfoClass, FUNCTION_EXTRA_INFO_INDEX, ecma_roots_class) \ V(JSTaggedValue, ProgramClass, PROGRAM_CLASS_INDEX, ecma_roots_class) \ V(JSTaggedValue, EcmaModuleClass, ECMA_MODULE_CLASS_INDEX, ecma_roots_class) \ V(JSTaggedValue, JSProxyCallableClass, JS_PROXY_CALLABLE_CLASS_INDEX, ecma_roots_class) \ diff --git a/ecmascript/hprof/heap_snapshot.cpp b/ecmascript/hprof/heap_snapshot.cpp index 66090b6d46..86f69bc55e 100644 --- a/ecmascript/hprof/heap_snapshot.cpp +++ b/ecmascript/hprof/heap_snapshot.cpp @@ -315,8 +315,6 @@ CString *HeapSnapShot::GenerateNodeName(JSThread *thread, TaggedObject *entry) return GetString("AccessorData"); case JSType::INTERNAL_ACCESSOR: return GetString("InternalAccessor"); - case JSType::FUNCTION_EXTRA_INFO: - return GetString("FunctionExtraInfo"); case JSType::MICRO_JOB_QUEUE: return GetString("MicroJobQueue"); case JSType::PENDING_JOB: @@ -348,8 +346,6 @@ CString *HeapSnapShot::GenerateNodeName(JSThread *thread, TaggedObject *entry) return GetString("TemplateMap"); case JSType::PROGRAM: return GetString("Program"); - case JSType::LEXICAL_FUNCTION: - return GetString("LexicalFunction"); case JSType::MACHINE_CODE_OBJECT: return GetString("MachineCode"); default: diff --git a/ecmascript/hprof/tests/hprof_test.cpp b/ecmascript/hprof/tests/hprof_test.cpp index 1bb33b6a54..c50ebee7fc 100644 --- a/ecmascript/hprof/tests/hprof_test.cpp +++ b/ecmascript/hprof/tests/hprof_test.cpp @@ -43,7 +43,6 @@ #include "ecmascript/js_date_time_format.h" #include "ecmascript/js_for_in_iterator.h" #include "ecmascript/js_function.h" -#include "ecmascript/js_function_extra_info.h" #include "ecmascript/js_generator_object.h" #include "ecmascript/js_global_object.h" #include "ecmascript/js_handle.h" diff --git a/ecmascript/ic/proto_change_details.h b/ecmascript/ic/proto_change_details.h index 91022c74fe..8ce9905be1 100644 --- a/ecmascript/ic/proto_change_details.h +++ b/ecmascript/ic/proto_change_details.h @@ -25,16 +25,20 @@ namespace panda { namespace ecmascript { class ProtoChangeMarker : public TaggedObject { public: - - using HasChangedField = BitField; static ProtoChangeMarker *Cast(ObjectHeader *object) { ASSERT(JSTaggedValue(object).IsProtoChangeMarker()); return static_cast(object); } - static constexpr size_t HAS_CHANGED_OFFSET = TaggedObjectSize(); - SET_GET_PRIMITIVE_FIELD(HasChanged, bool, HAS_CHANGED_OFFSET, SIZE); + static constexpr size_t BIT_FIELD_OFFSET = TaggedObjectSize(); + ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); + + // define BitField + static constexpr size_t HAS_CHANGED_BITS = 1; + FIRST_BIT_FIELD(BitField, HasChanged, bool, HAS_CHANGED_BITS); + DECL_DUMP() }; @@ -49,9 +53,10 @@ public: static constexpr size_t CHANGE_LISTENER_OFFSET = TaggedObjectSize(); ACCESSORS(ChangeListener, CHANGE_LISTENER_OFFSET, REGISTER_INDEX_OFFSET); - ACCESSORS(RegisterIndex, REGISTER_INDEX_OFFSET, SIZE); + ACCESSORS_PRIMITIVE_FIELD(RegisterIndex, uint32_t, REGISTER_INDEX_OFFSET, LAST_OFFSET); + DEFINE_ALIGN_SIZE(LAST_OFFSET); - DECL_VISIT_OBJECT(CHANGE_LISTENER_OFFSET, SIZE) + DECL_VISIT_OBJECT(CHANGE_LISTENER_OFFSET, REGISTER_INDEX_OFFSET) DECL_DUMP() }; diff --git a/ecmascript/interpreter/interpreter-inl.h b/ecmascript/interpreter/interpreter-inl.h index 72605fda6b..fead227777 100644 --- a/ecmascript/interpreter/interpreter-inl.h +++ b/ecmascript/interpreter/interpreter-inl.h @@ -422,7 +422,7 @@ JSTaggedValue EcmaInterpreter::GeneratorReEnterInterpreter(JSThread *thread, JSH breakState->base.type = FrameType::INTERPRETER_FRAME; // create new frame and resume sp and pc - uint32_t nregs = context->GetNRegs().GetInt(); + uint32_t nregs = context->GetNRegs(); size_t newFrameSize = FRAME_STATE_SIZE + nregs; // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic JSTaggedType *newSp = breakSp - newFrameSize; @@ -434,10 +434,9 @@ JSTaggedValue EcmaInterpreter::GeneratorReEnterInterpreter(JSThread *thread, JSH newSp[i] = regsArray->Get(i).GetRawData(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) } JSTaggedValue constpool = func->GetConstantPool(); - JSTaggedValue pcOffset = context->GetBCOffset(); - // pc = first_inst + offset + size(Opcode::SUSPENDGENERATOR_IMM8_V8_V8) + uint32_t pcOffset = context->GetBCOffset(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - const uint8_t *resumePc = method->GetBytecodeArray() + static_cast(pcOffset.GetInt()) + + const uint8_t *resumePc = method->GetBytecodeArray() + pcOffset + BytecodeInstruction::Size(BytecodeInstruction::Format::PREF_V8_V8); InterpretedFrame *state = GET_FRAME(newSp); @@ -486,7 +485,7 @@ void EcmaInterpreter::ChangeGenContext(JSThread *thread, JSHandlebase.type = FrameType::INTERPRETER_FRAME; // create new frame and resume sp and pc - uint32_t nregs = context->GetNRegs().GetInt(); + uint32_t nregs = context->GetNRegs(); size_t newFrameSize = FRAME_STATE_SIZE + nregs; // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic @@ -499,10 +498,9 @@ void EcmaInterpreter::ChangeGenContext(JSThread *thread, JSHandleGet(i).GetRawData(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) } JSTaggedValue constpool = func->GetConstantPool(); - JSTaggedValue pcOffset = context->GetBCOffset(); - // pc = first_inst + offset + uint32_t pcOffset = context->GetBCOffset(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - const uint8_t *pc = method->GetBytecodeArray() + static_cast(pcOffset.GetInt()); + const uint8_t *pc = method->GetBytecodeArray() + pcOffset; InterpretedFrame *state = GET_FRAME(newSp); state->pc = pc; @@ -1300,7 +1298,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool LOG_INST() << "intrinsics::getresumemode"; uint16_t vs = READ_INST_8_1(); JSGeneratorObject *obj = JSGeneratorObject::Cast(GET_VREG_VALUE(vs).GetTaggedObject()); - SET_ACC(obj->GetResumeMode()); + SET_ACC(JSTaggedValue(static_cast(obj->GetResumeMode()))); DISPATCH(BytecodeInstruction::Format::PREF_V8); } HANDLE_OPCODE(HANDLE_GETITERATOR_PREF) { @@ -1893,14 +1891,14 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool << " v" << v0; JSFunction *result = JSFunction::Cast(constpool->GetObjectFromCache(methodId).GetTaggedObject()); ASSERT(result != nullptr); - if (result->IsResolved()) { + if (result->GetResolved()) { SAVE_PC(); auto res = SlowRuntimeStub::DefinefuncDyn(thread, result); INTERPRETER_RETURN_IF_ABRUPT(res); result = JSFunction::Cast(res.GetTaggedObject()); result->SetConstantPool(thread, JSTaggedValue(constpool)); } else { - result->SetResolved(thread); + result->SetResolved(true); } result->SetPropertyInlinedProps(thread, JSFunction::LENGTH_INLINE_PROPERTY_INDEX, JSTaggedValue(length)); @@ -1919,7 +1917,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool << " v" << v0; JSFunction *result = JSFunction::Cast(constpool->GetObjectFromCache(methodId).GetTaggedObject()); ASSERT(result != nullptr); - if (result->IsResolved()) { + if (result->GetResolved()) { SAVE_ACC(); SAVE_PC(); auto res = SlowRuntimeStub::DefineNCFuncDyn(thread, result); @@ -1929,7 +1927,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool RESTORE_ACC(); homeObject = GET_ACC(); } else { - result->SetResolved(thread); + result->SetResolved(true); } result->SetPropertyInlinedProps(thread, JSFunction::LENGTH_INLINE_PROPERTY_INDEX, JSTaggedValue(length)); @@ -1949,7 +1947,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool << " v" << v0; JSFunction *result = JSFunction::Cast(constpool->GetObjectFromCache(methodId).GetTaggedObject()); ASSERT(result != nullptr); - if (result->IsResolved()) { + if (result->GetResolved()) { SAVE_PC(); auto res = SlowRuntimeStub::DefineMethod(thread, result, homeObject); INTERPRETER_RETURN_IF_ABRUPT(res); @@ -1957,7 +1955,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool result->SetConstantPool(thread, JSTaggedValue(constpool)); } else { result->SetHomeObject(thread, homeObject); - result->SetResolved(thread); + result->SetResolved(true); } result->SetPropertyInlinedProps(thread, JSFunction::LENGTH_INLINE_PROPERTY_INDEX, JSTaggedValue(length)); @@ -2591,14 +2589,14 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool << " v" << v0; JSFunction *result = JSFunction::Cast(constpool->GetObjectFromCache(methodId).GetTaggedObject()); ASSERT(result != nullptr); - if (result->IsResolved()) { + if (result->GetResolved()) { SAVE_PC(); auto res = SlowRuntimeStub::DefineGeneratorFunc(thread, result); INTERPRETER_RETURN_IF_ABRUPT(res); result = JSFunction::Cast(res.GetTaggedObject()); result->SetConstantPool(thread, JSTaggedValue(constpool)); } else { - result->SetResolved(thread); + result->SetResolved(true); } result->SetPropertyInlinedProps(thread, JSFunction::LENGTH_INLINE_PROPERTY_INDEX, JSTaggedValue(length)); @@ -2615,14 +2613,14 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool << " v" << v0; JSFunction *result = JSFunction::Cast(constpool->GetObjectFromCache(methodId).GetTaggedObject()); ASSERT(result != nullptr); - if (result->IsResolved()) { + if (result->GetResolved()) { SAVE_PC(); auto res = SlowRuntimeStub::DefineAsyncFunc(thread, result); INTERPRETER_RETURN_IF_ABRUPT(res); result = JSFunction::Cast(res.GetTaggedObject()); result->SetConstantPool(thread, JSTaggedValue(constpool)); } else { - result->SetResolved(thread); + result->SetResolved(true); } result->SetPropertyInlinedProps(thread, JSFunction::LENGTH_INLINE_PROPERTY_INDEX, JSTaggedValue(length)); @@ -3404,7 +3402,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool JSTaggedValue res; SAVE_PC(); - if (LIKELY(!classTemplate->IsResolved())) { + if (LIKELY(!classTemplate->GetResolved())) { res = SlowRuntimeStub::ResolveClass(thread, JSTaggedValue(classTemplate), literalBuffer, proto, lexenv, constpool); } else { diff --git a/ecmascript/interpreter/slow_runtime_helper.cpp b/ecmascript/interpreter/slow_runtime_helper.cpp index 02363321bf..528d5132fd 100644 --- a/ecmascript/interpreter/slow_runtime_helper.cpp +++ b/ecmascript/interpreter/slow_runtime_helper.cpp @@ -94,9 +94,9 @@ void SlowRuntimeHelper::SaveFrameToContext(JSThread *thread, JSHandleSetMethod(thread, frameHandler.GetFunction()); context->SetAcc(thread, frameHandler.GetAcc()); - context->SetNRegs(thread, JSTaggedValue(nregs)); - context->SetBCOffset(thread, JSTaggedValue(frameHandler.GetBytecodeOffset())); context->SetLexicalEnv(thread, thread->GetCurrentLexenv()); + context->SetNRegs(nregs); + context->SetBCOffset(frameHandler.GetBytecodeOffset()); } JSTaggedValue ConstructGeneric(JSThread *thread, JSHandle ctor, JSHandle newTgt, diff --git a/ecmascript/interpreter/slow_runtime_stub.cpp b/ecmascript/interpreter/slow_runtime_stub.cpp index ac87931cb7..b2f0231df8 100644 --- a/ecmascript/interpreter/slow_runtime_stub.cpp +++ b/ecmascript/interpreter/slow_runtime_stub.cpp @@ -101,7 +101,7 @@ JSTaggedValue SlowRuntimeStub::AsyncFunctionEnter(JSThread *thread) JSHandle promiseObject = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(promiseFunc), promiseFunc)); - promiseObject->SetPromiseState(thread, JSTaggedValue(static_cast(PromiseStatus::PENDING))); + promiseObject->SetPromiseState(PromiseState::PENDING); // 2. create asyncfuncobj JSHandle asyncFuncObj = factory->NewJSAsyncFuncObject(); asyncFuncObj->SetPromise(thread, promiseObject); @@ -110,7 +110,7 @@ JSTaggedValue SlowRuntimeStub::AsyncFunctionEnter(JSThread *thread) context->SetGeneratorObject(thread, asyncFuncObj); // change state to EXECUTING - asyncFuncObj->SetGeneratorState(thread, JSTaggedValue(static_cast(JSGeneratorState::EXECUTING))); + asyncFuncObj->SetGeneratorState(JSGeneratorState::EXECUTING); asyncFuncObj->SetGeneratorContext(thread, context); // 3. return asyncfuncobj @@ -584,7 +584,7 @@ JSTaggedValue SlowRuntimeStub::CreateGeneratorObj(JSThread *thread, JSTaggedValu context->SetGeneratorObject(thread, obj.GetTaggedValue()); // change state to SUSPENDED_START - obj->SetGeneratorState(thread, JSTaggedValue(static_cast(JSGeneratorState::SUSPENDED_START))); + obj->SetGeneratorState(JSGeneratorState::SUSPENDED_START); obj->SetGeneratorContext(thread, context); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -604,8 +604,7 @@ JSTaggedValue SlowRuntimeStub::SuspendGenerator(JSThread *thread, JSTaggedValue // change state to SuspendedYield if (generatorObjectHandle->IsExecuting()) { - generatorObjectHandle->SetGeneratorState(thread, - JSTaggedValue(static_cast(JSGeneratorState::SUSPENDED_YIELD))); + generatorObjectHandle->SetGeneratorState(JSGeneratorState::SUSPENDED_YIELD); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return valueHandle.GetTaggedValue(); } @@ -949,10 +948,10 @@ JSTaggedValue SlowRuntimeStub::CloseIterator(JSThread *thread, JSTaggedValue ite JSHandle record; if (thread->HasPendingException()) { record = JSHandle(factory->NewCompletionRecord( - CompletionRecord::THROW, JSHandle(thread, thread->GetException()))); + CompletionRecordType::THROW, JSHandle(thread, thread->GetException()))); } else { JSHandle undefinedVal = globalConst->GetHandledUndefined(); - record = JSHandle(factory->NewCompletionRecord(CompletionRecord::NORMAL, undefinedVal)); + record = JSHandle(factory->NewCompletionRecord(CompletionRecordType::NORMAL, undefinedVal)); } JSHandle result = JSIterator::IteratorClose(thread, iterHandle, record); if (result->IsCompletionRecord()) { @@ -1226,11 +1225,11 @@ JSTaggedValue SlowRuntimeStub::DefineGetterSetterByValue(JSThread *thread, JSTag !(objHandle.GetTaggedValue().IsClassPrototype() || objHandle.GetTaggedValue().IsClassConstructor()); PropertyDescriptor desc(thread, true, enumerable, true); if (!getterHandle->IsUndefined()) { - JSHandle::Cast(getterHandle)->SetFunctionKind(thread, FunctionKind::GETTER_FUNCTION); + JSHandle::Cast(getterHandle)->SetFunctionKind(FunctionKind::GETTER_FUNCTION); desc.SetGetter(getterHandle); } if (!setterHandle->IsUndefined()) { - JSHandle::Cast(setterHandle)->SetFunctionKind(thread, FunctionKind::SETTER_FUNCTION); + JSHandle::Cast(setterHandle)->SetFunctionKind(FunctionKind::SETTER_FUNCTION); desc.SetSetter(setterHandle); } JSObject::DefineOwnProperty(thread, objHandle, propKey, desc); @@ -1806,7 +1805,7 @@ JSTaggedValue SlowRuntimeStub::ResolveClass(JSThread *thread, JSTaggedValue ctor } } - cls->SetResolved(thread); + cls->SetResolved(true); return cls.GetTaggedValue(); } @@ -1883,17 +1882,17 @@ JSTaggedValue SlowRuntimeStub::SetClassInheritanceRelationship(JSThread *thread, JSHandle parentPrototype; // hole means parent is not present if (parent->IsHole()) { - JSHandle::Cast(cls)->SetFunctionKind(thread, FunctionKind::CLASS_CONSTRUCTOR); + JSHandle::Cast(cls)->SetFunctionKind(FunctionKind::CLASS_CONSTRUCTOR); parentPrototype = env->GetObjectFunctionPrototype(); parent.Update(env->GetFunctionPrototype().GetTaggedValue()); } else if (parent->IsNull()) { - JSHandle::Cast(cls)->SetFunctionKind(thread, FunctionKind::DERIVED_CONSTRUCTOR); + JSHandle::Cast(cls)->SetFunctionKind(FunctionKind::DERIVED_CONSTRUCTOR); parentPrototype = JSHandle(thread, JSTaggedValue::Null()); parent.Update(env->GetFunctionPrototype().GetTaggedValue()); } else if (!parent->IsConstructor()) { return ThrowTypeError(thread, "parent class is not constructor"); } else { - JSHandle::Cast(cls)->SetFunctionKind(thread, FunctionKind::DERIVED_CONSTRUCTOR); + JSHandle::Cast(cls)->SetFunctionKind(FunctionKind::DERIVED_CONSTRUCTOR); parentPrototype = JSTaggedValue::GetProperty(thread, parent, globalConst->GetHandledPrototypeString()).GetValue(); if (!parentPrototype->IsECMAObject() && !parentPrototype->IsNull()) { diff --git a/ecmascript/js_arguments.h b/ecmascript/js_arguments.h index 05c68e73b6..c04ed12b40 100644 --- a/ecmascript/js_arguments.h +++ b/ecmascript/js_arguments.h @@ -59,7 +59,6 @@ public: // 9.4.4.6 CreateUnmappedArgumentsObject(argumentsList) // 9.4.4.7 CreateMappedArgumentsObject ( func, formals, argumentsList, env ) - // ACCESSORS(JSTaggedValue, Length, LENGTH_OFFSET) static constexpr size_t PARAMETER_MAP_OFFSET = JSObject::SIZE; ACCESSORS(ParameterMap, PARAMETER_MAP_OFFSET, SIZE) diff --git a/ecmascript/js_array_iterator.cpp b/ecmascript/js_array_iterator.cpp index 7ded4229d8..eef1b208c3 100644 --- a/ecmascript/js_array_iterator.cpp +++ b/ecmascript/js_array_iterator.cpp @@ -47,9 +47,9 @@ JSTaggedValue JSArrayIterator::Next(EcmaRuntimeCallInfo *argv) return JSIterator::CreateIterResultObject(thread, undefinedHandle, true).GetTaggedValue(); } // 6.Let index be O.[[ArrayLikeNextIndex]]. - uint32_t index = iter->GetNextIndex().GetInt(); + uint32_t index = iter->GetNextIndex(); // 7.Let itemKind be O.[[ArrayLikeIterationKind]]. - IterationKind itemKind = IterationKind(iter->GetIterationKind().GetInt()); + IterationKind itemKind = iter->GetIterationKind(); uint32_t length; // 8. If a has a [[TypedArrayName]] internal slot, then @@ -71,7 +71,7 @@ JSTaggedValue JSArrayIterator::Next(EcmaRuntimeCallInfo *argv) return JSIterator::CreateIterResultObject(thread, undefinedHandle, true).GetTaggedValue(); } // 11.Set O.[[ArrayLikeNextIndex]] to index + 1. - iter->SetNextIndex(thread, JSTaggedValue(index + 1)); + iter->SetNextIndex(index + 1); // 12.If itemKind is key, return CreateIterResultObject(index, false). JSHandle key(thread, JSTaggedValue(index)); if (itemKind == IterationKind::KEY) { diff --git a/ecmascript/js_array_iterator.h b/ecmascript/js_array_iterator.h index 77e7d84371..db3d5be877 100644 --- a/ecmascript/js_array_iterator.h +++ b/ecmascript/js_array_iterator.h @@ -16,8 +16,8 @@ #ifndef ECMASCRIPT_JS_ARRAY_ITERATOR_H #define ECMASCRIPT_JS_ARRAY_ITERATOR_H -#include "js_iterator.h" -#include "js_object.h" +#include "ecmascript/js_iterator.h" +#include "ecmascript/js_object.h" namespace panda::ecmascript { class JSArrayIterator : public JSObject { @@ -28,11 +28,15 @@ public: static constexpr size_t ITERATED_ARRAY_OFFSET = JSObject::SIZE; ACCESSORS(IteratedArray, ITERATED_ARRAY_OFFSET, NEXT_INDEX_OFFSET) - ACCESSORS(NextIndex, NEXT_INDEX_OFFSET, ITERATION_KIND_OFFSET) - ACCESSORS(IterationKind, ITERATION_KIND_OFFSET, SIZE) + ACCESSORS_PRIMITIVE_FIELD(NextIndex, uint32_t, NEXT_INDEX_OFFSET, BIT_FIELD_OFFSET) + ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); - DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, ITERATED_ARRAY_OFFSET, SIZE) + // define BitField + static constexpr size_t ITERATION_KIND_BITS = 2; + FIRST_BIT_FIELD(BitField, IterationKind, IterationKind, ITERATION_KIND_BITS) + DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, ITERATED_ARRAY_OFFSET, NEXT_INDEX_OFFSET) DECL_DUMP() }; } // namespace panda::ecmascript diff --git a/ecmascript/js_arraybuffer.cpp b/ecmascript/js_arraybuffer.cpp index af3dd367ac..8745db2b69 100644 --- a/ecmascript/js_arraybuffer.cpp +++ b/ecmascript/js_arraybuffer.cpp @@ -35,10 +35,10 @@ void JSArrayBuffer::CopyDataBlockBytes(JSTaggedValue toBlock, JSTaggedValue from } } -void JSArrayBuffer::Attach(JSThread *thread, JSTaggedValue arrayBufferByteLength, JSTaggedValue arrayBufferData) +void JSArrayBuffer::Attach(JSThread *thread, uint32_t arrayBufferByteLength, JSTaggedValue arrayBufferData) { ASSERT(arrayBufferData.IsNativePointer()); - SetArrayBufferByteLength(thread, arrayBufferByteLength); + SetArrayBufferByteLength(arrayBufferByteLength); SetArrayBufferData(thread, arrayBufferData); EcmaVM *vm = thread->GetEcmaVM(); vm->PushToArrayDataList(JSNativePointer::Cast(arrayBufferData.GetHeapObject())); @@ -59,6 +59,6 @@ void JSArrayBuffer::Detach(JSThread *thread) jsNativePointer->Destroy(); SetArrayBufferData(thread, JSTaggedValue::Null()); - SetArrayBufferByteLength(thread, JSTaggedValue(0)); + SetArrayBufferByteLength(0); } } // namespace panda::ecmascript diff --git a/ecmascript/js_arraybuffer.h b/ecmascript/js_arraybuffer.h index 60f6302a3f..085e361654 100644 --- a/ecmascript/js_arraybuffer.h +++ b/ecmascript/js_arraybuffer.h @@ -26,7 +26,7 @@ public: // 6.2.6.2 static void CopyDataBlockBytes(JSTaggedValue toBlock, JSTaggedValue fromBlock, int32_t fromIndex, int32_t count); - void Attach(JSThread *thread, JSTaggedValue arrayBufferByteLength, JSTaggedValue arrayBufferData); + void Attach(JSThread *thread, uint32_t arrayBufferByteLength, JSTaggedValue arrayBufferData); void Detach(JSThread *thread); bool IsDetach() @@ -35,13 +35,18 @@ public: return arrayBufferData == JSTaggedValue::Null(); } - static constexpr size_t ARRAY_BUFFER_BYTE_LENGTH_OFFSET = JSObject::SIZE; - ACCESSORS(ArrayBufferByteLength, ARRAY_BUFFER_BYTE_LENGTH_OFFSET, ARRAY_BUFFER_DATA_OFFSET) - ACCESSORS(ArrayBufferData, ARRAY_BUFFER_DATA_OFFSET, ARRAY_BUFFER_SHARED_OFFSET) - ACCESSORS(Shared, ARRAY_BUFFER_SHARED_OFFSET, SIZE) + static constexpr size_t DATA_OFFSET = JSObject::SIZE; + ACCESSORS(ArrayBufferData, DATA_OFFSET, BYTE_LENGTH_OFFSET) + ACCESSORS_PRIMITIVE_FIELD(ArrayBufferByteLength, uint32_t, BYTE_LENGTH_OFFSET, BIT_FIELD_OFFSET) + ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); + // define BitField + static constexpr size_t SHARED_BITS = 2; + FIRST_BIT_FIELD(BitField, Shared, bool, SHARED_BITS) + + DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, DATA_OFFSET, BYTE_LENGTH_OFFSET) DECL_DUMP() - DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, ARRAY_BUFFER_BYTE_LENGTH_OFFSET, SIZE) }; } // namespace panda::ecmascript diff --git a/ecmascript/js_async_function.cpp b/ecmascript/js_async_function.cpp index 7a36ed2e18..31b766874e 100644 --- a/ecmascript/js_async_function.cpp +++ b/ecmascript/js_async_function.cpp @@ -67,7 +67,7 @@ void JSAsyncFunction::AsyncFunctionAwait(JSThread *thread, const JSHandle tcap = JSPromise::NewPromiseCapability(thread, JSHandle::Cast(env->GetPromiseFunction())); - JSHandle(thread, tcap->GetPromise())->SetPromiseIsHandled(thread, JSTaggedValue::Undefined()); + JSHandle(thread, tcap->GetPromise())->SetPromiseIsHandled(true); // 10.Perform ! PerformPromiseThen(promiseCapability.[[Promise]], onFulfilled, onRejected, throwawayCapability). JSHandle promise(thread, pcap->GetPromise()); @@ -89,8 +89,7 @@ JSHandle JSAsyncAwaitStatusFunction::AsyncFunctionAwaitFulfilled( JSHandle asyncCtxt(thread, func->GetAsyncContext()); // 2.Let prevContext be the running execution context. - C2IBridge c2i; - GeneratorHelper::ChangeGenContext(thread, asyncCtxt, &c2i); + GeneratorHelper::ChangeGenContext(thread, asyncCtxt); // 3.Suspend prevContext. // 4.Push asyncContext onto the execution context stack; asyncContext is now the running execution context. // 5.Resume the suspended evaluation of asyncContext using NormalCompletion(value) as the result of the @@ -111,8 +110,7 @@ JSHandle JSAsyncAwaitStatusFunction::AsyncFunctionAwaitRejected( JSHandle asyncCtxt(thread, func->GetAsyncContext()); // 2.Let prevContext be the running execution context. - C2IBridge c2i; - GeneratorHelper::ChangeGenContext(thread, asyncCtxt, &c2i); + GeneratorHelper::ChangeGenContext(thread, asyncCtxt); // 3.Suspend prevContext. // 4.Push asyncContext onto the execution context stack; asyncContext is now the running execution context. // 5.Resume the suspended evaluation of asyncContext using Completion{[[Type]]: throw, diff --git a/ecmascript/js_collator.cpp b/ecmascript/js_collator.cpp index 83f62dcd2c..fe10e30d9d 100644 --- a/ecmascript/js_collator.cpp +++ b/ecmascript/js_collator.cpp @@ -91,8 +91,7 @@ JSHandle JSCollator::InitializeCollator(JSThread *thread, const JSHa {UsageOption::SORT, UsageOption::SEARCH}, {"sort", "search"}, UsageOption::SORT); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSCollator, thread); - JSHandle usageValue(thread, JSTaggedValue(static_cast(usage))); - collator->SetUsage(thread, usageValue); + collator->SetUsage(usage); // 5. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). auto matcher = JSLocale::GetOptionOfString( @@ -123,17 +122,15 @@ JSHandle JSCollator::InitializeCollator(JSThread *thread, const JSHa bool foundNumeric = JSLocale::GetOptionOfBool(thread, optionsObject, globalConst->GetHandledNumericString(), false, &numeric); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSCollator, thread); - JSHandle numericValue(thread, JSTaggedValue(numeric)); - collator->SetNumeric(thread, numericValue); + collator->SetNumeric(numeric); // 14. Let caseFirst be ? GetOption(options, "caseFirst", "string", « "upper", "lower", "false" », undefined). - auto caseFirst = JSLocale::GetOptionOfString( + CaseFirstOption caseFirst = JSLocale::GetOptionOfString( thread, optionsObject, globalConst->GetHandledCaseFirstString(), {CaseFirstOption::UPPER, CaseFirstOption::LOWER, CaseFirstOption::FALSE_OPTION}, {"upper", "lower", "false"}, CaseFirstOption::UNDEFINED); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSCollator, thread); - JSHandle caseFirstValue(thread, JSTaggedValue(static_cast(caseFirst))); - collator->SetCaseFirst(thread, caseFirstValue); + collator->SetCaseFirst(caseFirst); // 16. Let relevantExtensionKeys be %Collator%.[[RelevantExtensionKeys]]. std::set relevantExtensionKeys = {"co", "kn", "kf"}; @@ -204,8 +201,7 @@ JSHandle JSCollator::InitializeCollator(JSThread *thread, const JSHa if (extensionIter != r.extensions.end()) { ASSERT(icuCollator.get() != nullptr); bool found = (extensionIter->second == "true"); - JSHandle isNumeric(thread, JSTaggedValue(found)); - collator->SetNumeric(thread, isNumeric); + collator->SetNumeric(found); icuCollator.get()->setAttribute(UCOL_NUMERIC_COLLATION, found ? UCOL_ON : UCOL_OFF, status); ASSERT(U_SUCCESS(status)); } @@ -226,8 +222,7 @@ JSHandle JSCollator::InitializeCollator(JSThread *thread, const JSHa auto mapIter = caseFirstMap.find(extensionIter->second); if (mapIter != caseFirstMap.end()) { icuCollator.get()->setAttribute(UCOL_CASE_FIRST, OptionToUColAttribute(mapIter->second), status); - JSHandle caseFirstValue(thread, JSTaggedValue(static_cast(mapIter->second))); - collator->SetCaseFirst(thread, caseFirstValue); + collator->SetCaseFirst(mapIter->second); } else { icuCollator.get()->setAttribute(UCOL_CASE_FIRST, OptionToUColAttribute(CaseFirstOption::UNDEFINED), status); @@ -238,7 +233,7 @@ JSHandle JSCollator::InitializeCollator(JSThread *thread, const JSHa // 24. Let sensitivity be ? GetOption(options, "sensitivity", "string", « "base", "accent", "case", "variant" », // undefined). - auto sensitivity = JSLocale::GetOptionOfString( + SensitivityOption sensitivity = JSLocale::GetOptionOfString( thread, optionsObject, globalConst->GetHandledSensitivityString(), {SensitivityOption::BASE, SensitivityOption::ACCENT, SensitivityOption::CASE, SensitivityOption::VARIANT}, {"base", "accent", "case", "variant"}, SensitivityOption::UNDEFINED); @@ -251,8 +246,7 @@ JSHandle JSCollator::InitializeCollator(JSThread *thread, const JSHa sensitivity = SensitivityOption::VARIANT; } } - JSHandle sensitivityValue(thread, JSTaggedValue(static_cast(sensitivity))); - collator->SetSensitivity(thread, sensitivityValue); + collator->SetSensitivity(sensitivity); // Trans SensitivityOption to Icu strength option switch (sensitivity) { @@ -280,8 +274,7 @@ JSHandle JSCollator::InitializeCollator(JSThread *thread, const JSHa bool ignorePunctuation = false; JSLocale::GetOptionOfBool(thread, optionsObject, globalConst->GetHandledIgnorePunctuationString(), false, &ignorePunctuation); - JSHandle ignorePunctuationValue(thread, JSTaggedValue(ignorePunctuation)); - collator->SetIgnorePunctuation(thread, ignorePunctuationValue); + collator->SetIgnorePunctuation(ignorePunctuation); if (ignorePunctuation) { status = U_ZERO_ERROR; icuCollator->setAttribute(UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, status); @@ -385,17 +378,17 @@ JSHandle JSCollator::ResolvedOptions(JSThread *thread, const JSHandle< JSObject::CreateDataPropertyOrThrow(thread, options, property, locale); // [[Usage]] - UsageOption usageOption = static_cast(collator->GetUsage().GetNumber()); + UsageOption usageOption = collator->GetUsage(); JSHandle usageValue = OptionsToEcmaString(thread, usageOption); JSObject::CreateDataProperty(thread, options, globalConst->GetHandledUsageString(), usageValue); // [[Sensitivity]] - auto sentivityOption = static_cast(collator->GetSensitivity().GetNumber()); + auto sentivityOption = collator->GetSensitivity(); JSHandle sensitivityValue = OptionsToEcmaString(thread, sentivityOption); JSObject::CreateDataProperty(thread, options, globalConst->GetHandledSensitivityString(), sensitivityValue); // [[IgnorePunctuation]] - JSHandle ignorePunctuationValue(thread, collator->GetIgnorePunctuation()); + JSHandle ignorePunctuationValue(thread, JSTaggedValue(collator->GetIgnorePunctuation())); JSObject::CreateDataProperty(thread, options, globalConst->GetHandledIgnorePunctuationString(), ignorePunctuationValue); @@ -407,11 +400,11 @@ JSHandle JSCollator::ResolvedOptions(JSThread *thread, const JSHandle< JSObject::CreateDataProperty(thread, options, globalConst->GetHandledCollationString(), collationValue); // [[Numeric]] - JSHandle numericValue(thread, collator->GetNumeric()); + JSHandle numericValue(thread, JSTaggedValue(collator->GetNumeric())); JSObject::CreateDataProperty(thread, options, globalConst->GetHandledNumericString(), numericValue); // [[CaseFirst]] - CaseFirstOption caseFirstOption = static_cast(collator->GetCaseFirst().GetNumber()); + CaseFirstOption caseFirstOption = collator->GetCaseFirst(); // In Ecma402 spec, caseFirst is an optional property so we set it to Upper when input is undefined // the requirement maybe change in the future JSHandle caseFirstValue = OptionsToEcmaString(thread, caseFirstOption); diff --git a/ecmascript/js_collator.h b/ecmascript/js_collator.h index b4d5ff10da..6322d0329e 100644 --- a/ecmascript/js_collator.h +++ b/ecmascript/js_collator.h @@ -37,19 +37,27 @@ public: CAST_CHECK(JSCollator, IsJSCollator); static constexpr size_t ICU_FIELD_OFFSET = JSObject::SIZE; - // icu field. ACCESSORS(IcuField, ICU_FIELD_OFFSET, LOCALE_OFFSET) - ACCESSORS(Locale, LOCALE_OFFSET, USAGE_OFFSET) - ACCESSORS(Usage, USAGE_OFFSET, SENSITIVITY_OFFSET) - ACCESSORS(Sensitivity, SENSITIVITY_OFFSET, IGNORE_PUNCTUATION_OFFSET) - ACCESSORS(IgnorePunctuation, IGNORE_PUNCTUATION_OFFSET, COLLATION_OFFSET) - ACCESSORS(Collation, COLLATION_OFFSET, NUMERIC_OFFSET) - ACCESSORS(Numeric, NUMERIC_OFFSET, CASE_FIRST_OFFSET) - ACCESSORS(CaseFirst, CASE_FIRST_OFFSET, BOUND_COMPARE_OFFSET) - ACCESSORS(BoundCompare, BOUND_COMPARE_OFFSET, SIZE) - - DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, ICU_FIELD_OFFSET, SIZE) + ACCESSORS(Locale, LOCALE_OFFSET, COLLATION_OFFSET) + ACCESSORS(Collation, COLLATION_OFFSET, BOUND_COMPARE_OFFSET) + ACCESSORS(BoundCompare, BOUND_COMPARE_OFFSET, BIT_FIELD_OFFSET) + ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); + + // define BitField + static constexpr size_t USAGE_BITS = 2; + static constexpr size_t CASE_FIRST_BITS = 3; + static constexpr size_t SENSITIVITY_BITS = 3; + static constexpr size_t IGNORE_PUNCTUATION_BITS = 1; + static constexpr size_t NUMERIC_BITS = 1; + FIRST_BIT_FIELD(BitField, Usage, UsageOption, USAGE_BITS) + NEXT_BIT_FIELD(BitField, CaseFirst, CaseFirstOption, CASE_FIRST_BITS, Usage) + NEXT_BIT_FIELD(BitField, Sensitivity, SensitivityOption, SENSITIVITY_BITS, CaseFirst) + NEXT_BIT_FIELD(BitField, IgnorePunctuation, bool, IGNORE_PUNCTUATION_BITS, Sensitivity) + NEXT_BIT_FIELD(BitField, Numeric, bool, NUMERIC_BITS, IgnorePunctuation) + + DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, ICU_FIELD_OFFSET, BIT_FIELD_OFFSET) DECL_DUMP() icu::Collator *GetIcuCollator() const diff --git a/ecmascript/js_dataview.cpp b/ecmascript/js_dataview.cpp index 8636a33b62..8293f80a41 100644 --- a/ecmascript/js_dataview.cpp +++ b/ecmascript/js_dataview.cpp @@ -16,9 +16,9 @@ #include "ecmascript/js_dataview.h" namespace panda::ecmascript { -int32_t JSDataView::GetElementSize(DataViewType type) +uint32_t JSDataView::GetElementSize(DataViewType type) { - int32_t size; + uint32_t size; switch (type) { case DataViewType::INT8: case DataViewType::UINT8: diff --git a/ecmascript/js_dataview.h b/ecmascript/js_dataview.h index 9d48627096..25fe200414 100644 --- a/ecmascript/js_dataview.h +++ b/ecmascript/js_dataview.h @@ -24,15 +24,16 @@ class JSDataView : public JSObject { public: CAST_CHECK(JSDataView, IsDataView); - static int32_t GetElementSize(DataViewType type); + static uint32_t GetElementSize(DataViewType type); static constexpr size_t DATA_VIEW_OFFSET = JSObject::SIZE; ACCESSORS(DataView, DATA_VIEW_OFFSET, VIEW_ARRAY_BUFFER_OFFSET); ACCESSORS(ViewedArrayBuffer, VIEW_ARRAY_BUFFER_OFFSET, BYTE_LENGTH_OFFSET); - ACCESSORS(ByteLength, BYTE_LENGTH_OFFSET, BYTE_OFFSET_OFFSET); - ACCESSORS(ByteOffset, BYTE_OFFSET_OFFSET, SIZE); + ACCESSORS_PRIMITIVE_FIELD(ByteLength, uint32_t, BYTE_LENGTH_OFFSET, BYTE_OFFSET_OFFSET); + ACCESSORS_PRIMITIVE_FIELD(ByteOffset, uint32_t, BYTE_OFFSET_OFFSET, LAST_OFFSET); + DEFINE_ALIGN_SIZE(LAST_OFFSET); - DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, DATA_VIEW_OFFSET, SIZE) + DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, DATA_VIEW_OFFSET, BYTE_LENGTH_OFFSET) DECL_DUMP() }; diff --git a/ecmascript/js_date_time_format.cpp b/ecmascript/js_date_time_format.cpp index 6d98d01441..7dd472dae6 100644 --- a/ecmascript/js_date_time_format.cpp +++ b/ecmascript/js_date_time_format.cpp @@ -402,7 +402,7 @@ JSHandle JSDateTimeFormat::InitializeDateTimeFormat(JSThread * {DateTimeStyleOption::FULL, DateTimeStyleOption::LONG, DateTimeStyleOption::MEDIUM, DateTimeStyleOption::SHORT}, {"full", "long", "medium", "short"}, DateTimeStyleOption::UNDEFINED); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSDateTimeFormat, thread); - dateTimeFormat->SetDateStyle(thread, JSTaggedValue(static_cast(dateStyle))); + dateTimeFormat->SetDateStyle(dateStyle); // Let timeStyle be ? GetOption(options, "string", «"full", "long", "medium", "short"», undefined). // Set dateTimeFormat.[[timeStyle]] @@ -411,7 +411,7 @@ JSHandle JSDateTimeFormat::InitializeDateTimeFormat(JSThread * {DateTimeStyleOption::FULL, DateTimeStyleOption::LONG, DateTimeStyleOption::MEDIUM, DateTimeStyleOption::SHORT}, {"full", "long", "medium", "short"}, DateTimeStyleOption::UNDEFINED); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSDateTimeFormat, thread); - dateTimeFormat->SetTimeStyle(thread, JSTaggedValue(static_cast(timeStyle))); + dateTimeFormat->SetTimeStyle(timeStyle); HourCycleOption dtfHourCycle = HourCycleOption::UNDEFINED; @@ -426,7 +426,7 @@ JSHandle JSDateTimeFormat::InitializeDateTimeFormat(JSThread * } // Set dateTimeFormat.[[hourCycle]]. - dateTimeFormat->SetHourCycle(thread, JSTaggedValue(static_cast(dtfHourCycle))); + dateTimeFormat->SetHourCycle(dtfHourCycle); // Set dateTimeFormat.[[icuLocale]]. JSDateTimeFormat::SetIcuLocale(thread, dateTimeFormat, icuLocale, JSDateTimeFormat::FreeIcuLocale); @@ -715,21 +715,21 @@ JSHandle JSDateTimeFormat::UnwrapDateTimeFormat(JSThread *thread, return dateTimeFormat; } -JSHandle ToHourCycleEcmaString(JSThread *thread, int32_t hc) +JSHandle ToHourCycleEcmaString(JSThread *thread, HourCycleOption hc) { JSMutableHandle result(thread, JSTaggedValue::Undefined()); auto globalConst = thread->GlobalConstants(); switch (hc) { - case static_cast(HourCycleOption::H11): + case HourCycleOption::H11: result.Update(globalConst->GetHandledH11String().GetTaggedValue()); break; - case static_cast(HourCycleOption::H12): + case HourCycleOption::H12: result.Update(globalConst->GetHandledH12String().GetTaggedValue()); break; - case static_cast(HourCycleOption::H23): + case HourCycleOption::H23: result.Update(globalConst->GetHandledH23String().GetTaggedValue()); break; - case static_cast(HourCycleOption::H24): + case HourCycleOption::H24: result.Update(globalConst->GetHandledH24String().GetTaggedValue()); break; default: @@ -738,21 +738,21 @@ JSHandle ToHourCycleEcmaString(JSThread *thread, int32_t hc) return result; } -JSHandle ToDateTimeStyleEcmaString(JSThread *thread, int32_t style) +JSHandle ToDateTimeStyleEcmaString(JSThread *thread, DateTimeStyleOption style) { JSMutableHandle result(thread, JSTaggedValue::Undefined()); auto globalConst = thread->GlobalConstants(); switch (style) { - case static_cast(DateTimeStyleOption::FULL): + case DateTimeStyleOption::FULL: result.Update(globalConst->GetHandledFullString().GetTaggedValue()); break; - case static_cast(DateTimeStyleOption::LONG): + case DateTimeStyleOption::LONG: result.Update(globalConst->GetHandledLongString().GetTaggedValue()); break; - case static_cast(DateTimeStyleOption::MEDIUM): + case DateTimeStyleOption::MEDIUM: result.Update(globalConst->GetHandledMediumString().GetTaggedValue()); break; - case static_cast(DateTimeStyleOption::SHORT): + case DateTimeStyleOption::SHORT: result.Update(globalConst->GetHandledShortString().GetTaggedValue()); break; default: @@ -836,10 +836,10 @@ void JSDateTimeFormat::ResolvedOptions(JSThread *thread, const JSHandle hcValue; - HourCycleOption hc = static_cast(dateTimeFormat->GetHourCycle().GetInt()); + HourCycleOption hc = dateTimeFormat->GetHourCycle(); if (hc != HourCycleOption::UNDEFINED) { property = globalConst->GetHandledHourCycleString(); - hcValue = ToHourCycleEcmaString(thread, dateTimeFormat->GetHourCycle().GetInt()); + hcValue = ToHourCycleEcmaString(thread, dateTimeFormat->GetHourCycle()); JSObject::CreateDataPropertyOrThrow(thread, options, property, hcValue); if (hc == HourCycleOption::H11 || hc == HourCycleOption::H12) { JSHandle trueValue(thread, JSTaggedValue::True()); @@ -856,8 +856,8 @@ void JSDateTimeFormat::ResolvedOptions(JSThread *thread, const JSHandletoPattern(patternUnicode); std::string pattern; patternUnicode.toUTF8String(pattern); - if (dateTimeFormat->GetDateStyle() == JSTaggedValue(static_cast(DateTimeStyleOption::UNDEFINED)) && - dateTimeFormat->GetTimeStyle() == JSTaggedValue(static_cast(DateTimeStyleOption::UNDEFINED))) { + if (dateTimeFormat->GetDateStyle() == DateTimeStyleOption::UNDEFINED && + dateTimeFormat->GetTimeStyle() == DateTimeStyleOption::UNDEFINED) { for (const auto &item : BuildIcuPatternDescs()) { // fractionalSecondsDigits need to be added before timeZoneName. if (item.property == "timeZoneName") { @@ -879,14 +879,14 @@ void JSDateTimeFormat::ResolvedOptions(JSThread *thread, const JSHandleGetDateStyle() != JSTaggedValue(static_cast(DateTimeStyleOption::UNDEFINED))) { + if (dateTimeFormat->GetDateStyle() != DateTimeStyleOption::UNDEFINED) { property = globalConst->GetHandledDateStyleString(); - hcValue = ToDateTimeStyleEcmaString(thread, dateTimeFormat->GetDateStyle().GetInt()); + hcValue = ToDateTimeStyleEcmaString(thread, dateTimeFormat->GetDateStyle()); JSObject::CreateDataPropertyOrThrow(thread, options, property, hcValue); } - if (dateTimeFormat->GetTimeStyle() != JSTaggedValue(static_cast(DateTimeStyleOption::UNDEFINED))) { + if (dateTimeFormat->GetTimeStyle() != DateTimeStyleOption::UNDEFINED) { property = globalConst->GetHandledTimeStyleString(); - hcValue = ToDateTimeStyleEcmaString(thread, dateTimeFormat->GetTimeStyle().GetInt()); + hcValue = ToDateTimeStyleEcmaString(thread, dateTimeFormat->GetTimeStyle()); JSObject::CreateDataPropertyOrThrow(thread, options, property, hcValue); } } @@ -1347,11 +1347,11 @@ std::string JSDateTimeFormat::ConstructGMTTimeZoneID(const std::string &input) return ""; } -std::string JSDateTimeFormat::ToHourCycleString(int32_t hc) +std::string JSDateTimeFormat::ToHourCycleString(HourCycleOption hc) { auto mapIter = std::find_if(TO_HOUR_CYCLE_MAP.begin(), TO_HOUR_CYCLE_MAP.end(), [hc](const std::map::value_type item) { - return static_cast(item.second) == hc; + return item.second == hc; }); if (mapIter != TO_HOUR_CYCLE_MAP.end()) { return mapIter->first; @@ -1439,7 +1439,7 @@ std::unique_ptr JSDateTimeFormat::ConstructDateInterval { icu::SimpleDateFormat *icuSimpleDateFormat = dtf->GetIcuSimpleDateFormat(); icu::Locale locale = *(dtf->GetIcuLocale()); - std::string hcString = ToHourCycleString(dtf->GetHourCycle().GetInt()); + std::string hcString = ToHourCycleString(dtf->GetHourCycle()); UErrorCode status = U_ZERO_ERROR; // Sets the Unicode value for a Unicode keyword. if (!hcString.empty()) { diff --git a/ecmascript/js_date_time_format.h b/ecmascript/js_date_time_format.h index aee98deda6..2768a6016d 100644 --- a/ecmascript/js_date_time_format.h +++ b/ecmascript/js_date_time_format.h @@ -89,20 +89,26 @@ public: CAST_CHECK(JSDateTimeFormat, IsJSDateTimeFormat); static constexpr size_t LOCALE_OFFSET = JSObject::SIZE; - ACCESSORS(Locale, LOCALE_OFFSET, CALENDAR_OFFSET) ACCESSORS(Calendar, CALENDAR_OFFSET, NUMBER_STRING_SYSTEM_OFFSET) ACCESSORS(NumberingSystem, NUMBER_STRING_SYSTEM_OFFSET, TIME_ZONE_OFFSET) - ACCESSORS(TimeZone, TIME_ZONE_OFFSET, HOUR_CYCLE_OFFSET) - ACCESSORS(HourCycle, HOUR_CYCLE_OFFSET, LOCALE_ICU_OFFSET) + ACCESSORS(TimeZone, TIME_ZONE_OFFSET, LOCALE_ICU_OFFSET) ACCESSORS(LocaleIcu, LOCALE_ICU_OFFSET, SIMPLE_DATE_TIME_FORMAT_ICU_OFFSET) ACCESSORS(SimpleDateTimeFormatIcu, SIMPLE_DATE_TIME_FORMAT_ICU_OFFSET, ISO8601_OFFSET) - ACCESSORS(Iso8601, ISO8601_OFFSET, DATE_STYLE_OFFSET) - ACCESSORS(DateStyle, DATE_STYLE_OFFSET, TIME_STYLE_OFFSET) - ACCESSORS(TimeStyle, TIME_STYLE_OFFSET, BOUND_FORMAT_OFFSET) - ACCESSORS(BoundFormat, BOUND_FORMAT_OFFSET, SIZE) - - DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, LOCALE_OFFSET, SIZE) + ACCESSORS(Iso8601, ISO8601_OFFSET, BOUND_FORMAT_OFFSET) + ACCESSORS(BoundFormat, BOUND_FORMAT_OFFSET, BIT_FIELD_OFFSET) + ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); + + // define BitField + static constexpr size_t HONOR_CYCLE_BITS = 3; + static constexpr size_t DATE_STYLE_BITS = 3; + static constexpr size_t TIME_STYLE_BITS = 3; + FIRST_BIT_FIELD(BitField, HourCycle, HourCycleOption, HONOR_CYCLE_BITS) + NEXT_BIT_FIELD(BitField, DateStyle, DateTimeStyleOption, DATE_STYLE_BITS, HourCycle) + NEXT_BIT_FIELD(BitField, TimeStyle, DateTimeStyleOption, TIME_STYLE_BITS, DateStyle) + + DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, LOCALE_OFFSET, BIT_FIELD_OFFSET) DECL_DUMP() icu::Locale *GetIcuLocale() const; @@ -156,7 +162,7 @@ private: static HourCycleOption OptionToHourCycle(UDateFormatHourCycle hc); - static std::string ToHourCycleString(int32_t hc); + static std::string ToHourCycleString(HourCycleOption hc); static std::unique_ptr ConstructTimeZone(const std::string &timezone); diff --git a/ecmascript/js_for_in_iterator.cpp b/ecmascript/js_for_in_iterator.cpp index fccb34509d..ce98a5ea93 100644 --- a/ecmascript/js_for_in_iterator.cpp +++ b/ecmascript/js_for_in_iterator.cpp @@ -183,7 +183,7 @@ void JSForInIterator::FastGetAllEnumKeys(const JSThread *thread, const JSHandle< } } it->SetRemainingKeys(thread, remaining); - it->SetWasVisited(thread, JSTaggedValue::True()); + it->SetWasVisited(true); } void JSForInIterator::SlowGetAllEnumKeys(JSThread *thread, const JSHandle &it, @@ -203,7 +203,7 @@ void JSForInIterator::SlowGetAllEnumKeys(JSThread *thread, const JSHandleSetRemainingKeys(thread, remaining); it->SetVisitedKeys(thread, visited); - it->SetWasVisited(thread, JSTaggedValue::True()); + it->SetWasVisited(true); } std::pair JSForInIterator::NextInternal(JSThread *thread, const JSHandle &it) @@ -215,7 +215,7 @@ std::pair JSForInIterator::NextInternal(JSThread *thread, c if (object->IsNull() || object->IsUndefined()) { return std::make_pair(JSTaggedValue::Undefined(), true); } - if (it->GetWasVisited().IsFalse()) { + if (!it->GetWasVisited()) { if (object->IsJSObject() && notModiObjProto) { FastGetAllEnumKeys(thread, it, object); } else { @@ -258,7 +258,7 @@ std::pair JSForInIterator::NextInternal(JSThread *thread, c } JSTaggedValue proto = JSHandle::Cast(object)->GetPrototype(thread); it->SetObject(thread, proto); - it->SetWasVisited(thread, JSTaggedValue::False()); + it->SetWasVisited(false); } } diff --git a/ecmascript/js_for_in_iterator.h b/ecmascript/js_for_in_iterator.h index f3e8b83790..7ae9453f81 100644 --- a/ecmascript/js_for_in_iterator.h +++ b/ecmascript/js_for_in_iterator.h @@ -39,16 +39,17 @@ public: const JSHandle &object); static constexpr size_t OBJECT_OFFSET = JSObject::SIZE; - - ACCESSORS(Object, OBJECT_OFFSET, WAS_VISITED_OFFSET) - - ACCESSORS(WasVisited, WAS_VISITED_OFFSET, VISITED_KEYS_OFFSET) - + ACCESSORS(Object, OBJECT_OFFSET, VISITED_KEYS_OFFSET) ACCESSORS(VisitedKeys, VISITED_KEYS_OFFSET, REMAINING_KEYS_OFFSET) + ACCESSORS(RemainingKeys, REMAINING_KEYS_OFFSET, BIT_FIELD_OFFSET) + ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); - ACCESSORS(RemainingKeys, REMAINING_KEYS_OFFSET, SIZE) + // define BitField + static constexpr size_t WAS_VISITED_BITS = 3; + FIRST_BIT_FIELD(BitField, WasVisited, bool, WAS_VISITED_BITS) - DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, OBJECT_OFFSET, SIZE) + DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, OBJECT_OFFSET, BIT_FIELD_OFFSET) DECL_DUMP() }; } // namespace panda::ecmascript diff --git a/ecmascript/js_function.cpp b/ecmascript/js_function.cpp index 56351f89a1..3273746e50 100644 --- a/ecmascript/js_function.cpp +++ b/ecmascript/js_function.cpp @@ -43,14 +43,16 @@ void JSFunction::InitializeJSFunction(JSThread *thread, const JSHandleSetProtoOrDynClass(thread, JSTaggedValue::Hole(), SKIP_BARRIER); func->SetHomeObject(thread, JSTaggedValue::Undefined(), SKIP_BARRIER); func->SetLexicalEnv(thread, JSTaggedValue::Undefined(), SKIP_BARRIER); func->SetConstantPool(thread, JSTaggedValue::Undefined(), SKIP_BARRIER); func->SetProfileTypeInfo(thread, JSTaggedValue::Undefined(), SKIP_BARRIER); func->SetFunctionExtraInfo(thread, JSTaggedValue::Undefined()); - func->SetFunctionInfoFlag(thread, JSTaggedValue(flag)); + func->SetFunctionKind(kind); + func->SetStrict(strict); + func->SetThisMode(thisMode); + func->SetResolved(false); auto globalConst = thread->GlobalConstants(); if (HasPrototype(kind)) { diff --git a/ecmascript/js_function.h b/ecmascript/js_function.h index fd30c23499..0ce1dc9571 100644 --- a/ecmascript/js_function.h +++ b/ecmascript/js_function.h @@ -19,7 +19,6 @@ #include "ecmascript/accessor_data.h" #include "ecmascript/ecma_macros.h" #include "ecmascript/ecma_runtime_call_info.h" -#include "ecmascript/js_function_extra_info.h" #include "ecmascript/js_object-inl.h" #include "ecmascript/lexical_env.h" @@ -47,11 +46,14 @@ public: } static constexpr size_t METHOD_OFFSET = JSObject::SIZE; - SET_GET_NATIVE_FIELD(Method, JSMethod, METHOD_OFFSET, SIZE) + ACCESSORS_NATIVE_FIELD(Method, JSMethod, METHOD_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, SIZE, SIZE) }; +static_assert((JSFunctionBase::SIZE % static_cast(MemAlignment::MEM_ALIGN_OBJECT)) == 0); + class JSFunction : public JSFunctionBase { public: static constexpr int LENGTH_OF_INLINE_PROPERTIES = 3; @@ -170,78 +172,34 @@ public: return kind == FunctionKind::DERIVED_CONSTRUCTOR; } - inline void SetFunctionKind(const JSThread *thread, FunctionKind kind) - { - JSTaggedType oldValue = GetFunctionInfoFlag().GetRawData(); - SetFunctionInfoFlag(thread, JSTaggedValue(FunctionKindBit::Update(oldValue, kind))); - } - - inline void SetStrict(const JSThread *thread, bool flag) - { - JSTaggedType oldValue = GetFunctionInfoFlag().GetRawData(); - SetFunctionInfoFlag(thread, JSTaggedValue(StrictBit::Update(oldValue, flag))); - } - - inline void SetResolved(const JSThread *thread) - { - TaggedType oldValue = GetFunctionInfoFlag().GetRawData(); - SetFunctionInfoFlag(thread, JSTaggedValue(ResolvedBit::Update(oldValue, true))); - } - - inline bool IsResolved() const - { - return ResolvedBit::Decode(GetFunctionInfoFlag().GetInt()); - } - - inline void SetFunctionMode(const JSThread *thread, FunctionMode mode) - { - JSTaggedType oldValue = GetFunctionInfoFlag().GetRawData(); - SetFunctionInfoFlag(thread, JSTaggedValue(ThisModeBit::Update(oldValue, mode))); - } - - inline FunctionKind GetFunctionKind() const - { - return FunctionKindBit::Decode(GetFunctionInfoFlag().GetInt()); - } - - inline bool IsStrict() const - { - return StrictBit::Decode(GetFunctionInfoFlag().GetInt()); - } - - inline FunctionMode GetFunctionMode() const - { - return ThisModeBit::Decode(GetFunctionInfoFlag().GetInt()); - } - inline static bool IsArrowFunction(FunctionKind kind) { - return (kind >= ARROW_FUNCTION) && (kind <= ASYNC_ARROW_FUNCTION); + return (kind >= FunctionKind::ARROW_FUNCTION) && (kind <= FunctionKind::ASYNC_ARROW_FUNCTION); } inline static bool IsClassConstructor(FunctionKind kind) { - return (kind == CLASS_CONSTRUCTOR) || (kind == DERIVED_CONSTRUCTOR); + return (kind == FunctionKind::CLASS_CONSTRUCTOR) || (kind == FunctionKind::DERIVED_CONSTRUCTOR); } inline static bool IsConstructorKind(FunctionKind kind) { - return (kind >= BUILTIN_PROXY_CONSTRUCTOR) && (kind <= DERIVED_CONSTRUCTOR); + return (kind >= FunctionKind::BUILTIN_PROXY_CONSTRUCTOR) && (kind <= FunctionKind::DERIVED_CONSTRUCTOR); } inline static bool IsBuiltinConstructor(FunctionKind kind) { - return kind >= BUILTIN_PROXY_CONSTRUCTOR && kind <= BUILTIN_CONSTRUCTOR; + return kind >= FunctionKind::BUILTIN_PROXY_CONSTRUCTOR && kind <= FunctionKind::BUILTIN_CONSTRUCTOR; } inline static bool HasPrototype(FunctionKind kind) { - return kind >= BUILTIN_CONSTRUCTOR && kind <= GENERATOR_FUNCTION; + return kind >= FunctionKind::BUILTIN_CONSTRUCTOR && kind <= FunctionKind::GENERATOR_FUNCTION; } inline static bool HasAccessor(FunctionKind kind) { - return kind >= NORMAL_FUNCTION && kind <= ASYNC_FUNCTION; + return kind >= FunctionKind::NORMAL_FUNCTION && kind <= FunctionKind::ASYNC_FUNCTION; } inline bool IsClassConstructor() const @@ -264,23 +222,26 @@ public: static constexpr size_t PROTO_OR_DYNCLASS_OFFSET = JSFunctionBase::SIZE; ACCESSORS(ProtoOrDynClass, PROTO_OR_DYNCLASS_OFFSET, LEXICAL_ENV_OFFSET) ACCESSORS(LexicalEnv, LEXICAL_ENV_OFFSET, HOME_OBJECT_OFFSET) - ACCESSORS(HomeObject, HOME_OBJECT_OFFSET, FUNCTION_INFO_FLAG_OFFSET) - ACCESSORS(FunctionInfoFlag, FUNCTION_INFO_FLAG_OFFSET, FUNCTION_EXTRA_INFO_OFFSET) + ACCESSORS(HomeObject, HOME_OBJECT_OFFSET, FUNCTION_EXTRA_INFO_OFFSET) ACCESSORS(FunctionExtraInfo, FUNCTION_EXTRA_INFO_OFFSET, CONSTANT_POOL_OFFSET) ACCESSORS(ConstantPool, CONSTANT_POOL_OFFSET, PROFILE_TYPE_INFO_OFFSET) - ACCESSORS(ProfileTypeInfo, PROFILE_TYPE_INFO_OFFSET, SIZE) - - static constexpr uint32_t FUNCTION_KIND_BIT_NUM = 5; - using FunctionKindBit = BitField; - using StrictBit = FunctionKindBit::NextFlag; - - using ResolvedBit = StrictBit::NextFlag; - using ThisModeBit = ResolvedBit::NextField; // 2: means this flag occupies two digits. - + ACCESSORS(ProfileTypeInfo, PROFILE_TYPE_INFO_OFFSET, BIT_FIELD_OFFSET) + ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); + + // define BitField + static constexpr uint32_t FUNCTION_KIND_BITS = 4; + static constexpr uint32_t STRICT_BITS = 1; + static constexpr uint32_t RESOLVED_BITS = 1; + static constexpr uint32_t THIS_MODE_BITS = 2; + FIRST_BIT_FIELD(BitField, FunctionKind, FunctionKind, FUNCTION_KIND_BITS) + NEXT_BIT_FIELD(BitField, Strict, bool, STRICT_BITS, FunctionKind) + NEXT_BIT_FIELD(BitField, Resolved, bool, RESOLVED_BITS, Strict) + NEXT_BIT_FIELD(BitField, ThisMode, FunctionMode, THIS_MODE_BITS, Resolved) + + DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSFunctionBase, PROTO_OR_DYNCLASS_OFFSET, BIT_FIELD_OFFSET) DECL_DUMP() - DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSFunctionBase, PROTO_OR_DYNCLASS_OFFSET, SIZE) - private: static JSHandle GetOrCreateDerivedJSHClass(JSThread *thread, JSHandle derived, JSHandle constructor, diff --git a/ecmascript/js_function_extra_info.h b/ecmascript/js_function_extra_info.h deleted file mode 100644 index 364048917c..0000000000 --- a/ecmascript/js_function_extra_info.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2021 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. - */ - -#ifndef ECMASCRIPT_JS_FUNCTION_INFO_H -#define ECMASCRIPT_JS_FUNCTION_INFO_H - -#include "utils/bit_field.h" -#include "ecmascript/ecma_macros.h" -#include "ecmascript/ecma_string.h" -#include "js_tagged_value-inl.h" -#include "js_function_kind.h" - -namespace panda::ecmascript { -class JSFunctionExtraInfo : public TaggedObject { -public: - static JSFunctionExtraInfo *Cast(ObjectHeader *object) - { - ASSERT(JSTaggedValue(object).IsJSFunctionExtraInfo()); - return static_cast(object); - } - - static constexpr size_t CALL_BACK_OFFSET = TaggedObjectSize(); - ACCESSORS(Callback, CALL_BACK_OFFSET, DATA_OFFSET); - ACCESSORS(Data, DATA_OFFSET, SIZE); - - DECL_VISIT_OBJECT(CALL_BACK_OFFSET, SIZE) - DECL_DUMP() -}; -} // namespace panda::ecmascript -#endif diff --git a/ecmascript/js_function_kind.h b/ecmascript/js_function_kind.h index 53c535a3c4..bfb424bb19 100644 --- a/ecmascript/js_function_kind.h +++ b/ecmascript/js_function_kind.h @@ -19,7 +19,7 @@ #include namespace panda::ecmascript { -enum FunctionKind : uint8_t { +enum class FunctionKind : uint8_t { NORMAL_FUNCTION = 0, // BEGIN arrow functions ARROW_FUNCTION, @@ -35,9 +35,9 @@ enum FunctionKind : uint8_t { BASE_CONSTRUCTOR, // BEGIN default constructors DEFAULT_BASE_CONSTRUCTOR, - // END base constructors // BEGIN class constructors CLASS_CONSTRUCTOR, + // END base constructors // END default constructors DERIVED_CONSTRUCTOR, // END class constructors @@ -53,7 +53,7 @@ enum FunctionKind : uint8_t { LAST_FUNCTION_KIND, }; -enum FunctionMode : uint8_t { +enum class FunctionMode : uint8_t { LEXICAL, STRICT, GLOBAL, diff --git a/ecmascript/js_generator_object.cpp b/ecmascript/js_generator_object.cpp index e835b0f9a0..c46409ef94 100644 --- a/ecmascript/js_generator_object.cpp +++ b/ecmascript/js_generator_object.cpp @@ -19,24 +19,24 @@ #include "js_tagged_value-inl.h" namespace panda::ecmascript { -JSTaggedValue JSGeneratorObject::GeneratorValidate(JSThread *thread, const JSHandle &obj) +JSGeneratorState JSGeneratorObject::GeneratorValidate(JSThread *thread, const JSHandle &obj) { // 1.Perform ? RequireInternalSlot(generator, [[GeneratorState]]). // 2.Assert: generator also has a [[GeneratorContext]] internal slot. if (!obj->IsECMAObject()) { - THROW_TYPE_ERROR_AND_RETURN(thread, "", JSTaggedValue::Undefined()); + THROW_TYPE_ERROR_AND_RETURN(thread, "", JSGeneratorState::UNDEFINED); } JSHandle toObj = JSTaggedValue::ToObject(thread, obj); if (!toObj->IsGeneratorObject()) { - THROW_TYPE_ERROR_AND_RETURN(thread, "", JSTaggedValue::Undefined()); + THROW_TYPE_ERROR_AND_RETURN(thread, "", JSGeneratorState::UNDEFINED); } // 3.Let state be generator.[[GeneratorState]]. JSHandle generator(thread, JSGeneratorObject::Cast(*(toObj))); - JSTaggedValue state = generator->GetGeneratorState(); + JSGeneratorState state = generator->GetGeneratorState(); // 4.If state is executing, throw a TypeError exception. - if (state == JSTaggedValue(static_cast(JSGeneratorState::EXECUTING))) { - THROW_TYPE_ERROR_AND_RETURN(thread, "", JSTaggedValue::Undefined()); + if (state == JSGeneratorState::EXECUTING) { + THROW_TYPE_ERROR_AND_RETURN(thread, "", JSGeneratorState::UNDEFINED); } // 5.Return state. return state; @@ -47,18 +47,18 @@ JSHandle JSGeneratorObject::GeneratorResume(JSThread *thread, const JS { // 1.Let state be ? GeneratorValidate(generator). JSHandle gen(thread, generator.GetTaggedValue()); - JSTaggedValue state = GeneratorValidate(thread, gen); + JSGeneratorState state = GeneratorValidate(thread, gen); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSObject, thread); // 2.If state is completed, return CreateIterResultObject(undefined, true). - if (state == JSTaggedValue(static_cast(JSGeneratorState::COMPLETED))) { + if (state == JSGeneratorState::COMPLETED) { JSHandle valueHandle(thread, JSTaggedValue::Undefined()); return JSIterator::CreateIterResultObject(thread, valueHandle, true); } // 3.Assert: state is either suspendedStart or suspendedYield. - ASSERT_PRINT(state == JSTaggedValue(static_cast(JSGeneratorState::SUSPENDED_START)) || - state == JSTaggedValue(static_cast(JSGeneratorState::SUSPENDED_YIELD)), + ASSERT_PRINT(state == JSGeneratorState::SUSPENDED_START || + state == JSGeneratorState::SUSPENDED_YIELD, "state is neither suspendedStart nor suspendedYield"); // 4.Let genContext be generator.[[GeneratorContext]]. @@ -68,11 +68,10 @@ JSHandle JSGeneratorObject::GeneratorResume(JSThread *thread, const JS // 6.Suspend methodContext. // 7.Set generator.[[GeneratorState]] to executing. - generator->SetGeneratorState(thread, JSTaggedValue(static_cast(JSGeneratorState::EXECUTING))); + generator->SetGeneratorState(JSGeneratorState::EXECUTING); // 8.Push genContext onto the execution context stack; genContext is now the running execution context. - C2IBridge c2i; - GeneratorHelper::ChangeGenContext(thread, genContext, &c2i); + GeneratorHelper::ChangeGenContext(thread, genContext); // 9.Resume the suspended evaluation of genContext using NormalCompletion(value) as the result of the operation // that suspended it. Let result be the value returned by the resumed computation. @@ -90,7 +89,7 @@ JSHandle JSGeneratorObject::GeneratorResumeAbrupt(JSThread *thread, { // 1.Let state be ? GeneratorValidate(generator). JSHandle gen(thread, generator.GetTaggedValue()); - JSTaggedValue state = GeneratorValidate(thread, gen); + JSGeneratorState state = GeneratorValidate(thread, gen); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSObject, thread); // 2.If state is suspendedStart, then @@ -98,27 +97,26 @@ JSHandle JSGeneratorObject::GeneratorResumeAbrupt(JSThread *thread, // b.Once a generator enters the completed state it never leaves it and its associated execution context is // never resumed. Any execution state associated with generator can be discarded at this point. // c.Set state to completed. - if (state == JSTaggedValue(static_cast(JSGeneratorState::SUSPENDED_START))) { - generator->SetGeneratorState(thread, JSTaggedValue(static_cast(JSGeneratorState::COMPLETED))); - state = JSTaggedValue(static_cast(JSGeneratorState::COMPLETED)); + if (state == JSGeneratorState::SUSPENDED_START) { + state = JSGeneratorState::COMPLETED; + generator->SetGeneratorState(state); } // 3.If state is completed, then // a.If abruptCompletion.[[Type]] is return, then // i.Return CreateIterResultObject(abruptCompletion.[[Value]], true). // b.Return Completion(abruptCompletion). - if (state == JSTaggedValue(static_cast(JSGeneratorState::COMPLETED))) { + if (state == JSGeneratorState::COMPLETED) { JSHandle valueHandle(thread, abruptCompletion->GetValue()); JSHandle result = JSIterator::CreateIterResultObject(thread, valueHandle, true); - if (abruptCompletion->GetType() == JSTaggedValue(static_cast(CompletionRecord::RETURN))) { + if (abruptCompletion->GetType() == CompletionRecordType::RETURN) { return result; } THROW_NEW_ERROR_AND_RETURN_VALUE(thread, valueHandle.GetTaggedValue(), result); } // 4.Assert: state is suspendedYield. - ASSERT_PRINT(state == JSTaggedValue(static_cast(JSGeneratorState::SUSPENDED_YIELD)), - "state is not suspendedYield"); + ASSERT_PRINT(state == JSGeneratorState::SUSPENDED_YIELD, "state is not suspendedYield"); // 5.Let genContext be generator.[[GeneratorContext]]. JSHandle genContext(thread, generator->GetGeneratorContext()); @@ -127,11 +125,10 @@ JSHandle JSGeneratorObject::GeneratorResumeAbrupt(JSThread *thread, // 7.Suspend methodContext. // 8.Set generator.[[GeneratorState]] to executing. - generator->SetGeneratorState(thread, JSTaggedValue(static_cast(JSGeneratorState::EXECUTING))); + generator->SetGeneratorState(JSGeneratorState::EXECUTING); // 9.Push genContext onto the execution context stack; genContext is now the running execution context. - C2IBridge c2i; - GeneratorHelper::ChangeGenContext(thread, genContext, &c2i); + GeneratorHelper::ChangeGenContext(thread, genContext); // 10.Resume the suspended evaluation of genContext using abruptCompletion as the result of the operation that // suspended it. Let result be the completion record returned by the resumed computation. @@ -139,7 +136,7 @@ JSHandle JSGeneratorObject::GeneratorResumeAbrupt(JSThread *thread, // methodContext is the currently running execution context. // 12.Return Completion(result). JSHandle result; - if (abruptCompletion->GetType() == JSTaggedValue(static_cast(CompletionRecord::RETURN))) { + if (abruptCompletion->GetType() == CompletionRecordType::RETURN) { result = GeneratorHelper::Return(thread, genContext, abruptCompletion->GetValue()); } else { result = GeneratorHelper::Throw(thread, genContext, abruptCompletion->GetValue()); diff --git a/ecmascript/js_generator_object.h b/ecmascript/js_generator_object.h index f33531e7cc..15326c79c9 100644 --- a/ecmascript/js_generator_object.h +++ b/ecmascript/js_generator_object.h @@ -20,13 +20,19 @@ namespace panda { namespace ecmascript { -enum class JSGeneratorState { +enum class JSGeneratorState : uint8_t { UNDEFINED = 0, SUSPENDED_START, SUSPENDED_YIELD, EXECUTING, COMPLETED, }; +enum class GeneratorResumeMode : uint8_t { + RETURN = 0, + THROW, + NEXT, + UNDEFINED +}; class GeneratorContext : TaggedObject { public: @@ -35,13 +41,14 @@ public: static constexpr size_t GENERATOR_REGS_ARRAY_OFFSET = TaggedObjectSize(); ACCESSORS(RegsArray, GENERATOR_REGS_ARRAY_OFFSET, GENERATOR_METHOD_OFFSET) ACCESSORS(Method, GENERATOR_METHOD_OFFSET, GENERATOR_ACC_OFFSET) - ACCESSORS(Acc, GENERATOR_ACC_OFFSET, GENERATOR_NREGS_OFFSET) - ACCESSORS(NRegs, GENERATOR_NREGS_OFFSET, GENERATOR_BC_OFFSET_OFFSET) - ACCESSORS(BCOffset, GENERATOR_BC_OFFSET_OFFSET, GENERATOR_GENERATOR_OBJECT_OFFSET) + ACCESSORS(Acc, GENERATOR_ACC_OFFSET, GENERATOR_GENERATOR_OBJECT_OFFSET) ACCESSORS(GeneratorObject, GENERATOR_GENERATOR_OBJECT_OFFSET, GENERATOR_LEXICALENV_OFFSET) - ACCESSORS(LexicalEnv, GENERATOR_LEXICALENV_OFFSET, SIZE) + ACCESSORS(LexicalEnv, GENERATOR_LEXICALENV_OFFSET, GENERATOR_NREGS_OFFSET) + ACCESSORS_PRIMITIVE_FIELD(NRegs, uint32_t, GENERATOR_NREGS_OFFSET, GENERATOR_BC_OFFSET_OFFSET) + ACCESSORS_PRIMITIVE_FIELD(BCOffset, uint32_t, GENERATOR_BC_OFFSET_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); - DECL_VISIT_OBJECT(GENERATOR_REGS_ARRAY_OFFSET, SIZE) + DECL_VISIT_OBJECT(GENERATOR_REGS_ARRAY_OFFSET, GENERATOR_NREGS_OFFSET) DECL_DUMP() }; @@ -49,14 +56,23 @@ class JSGeneratorObject : public JSObject { public: CAST_CHECK(JSGeneratorObject, IsGeneratorObject); - static constexpr size_t GENERATOR_STATE_OFFSET = JSObject::SIZE; - ACCESSORS(GeneratorState, GENERATOR_STATE_OFFSET, GENERATOR_CONTEXT_OFFSET) + static constexpr size_t GENERATOR_CONTEXT_OFFSET = JSObject::SIZE; ACCESSORS(GeneratorContext, GENERATOR_CONTEXT_OFFSET, GENERATOR_RESUME_RESULT_OFFSET) - ACCESSORS(ResumeResult, GENERATOR_RESUME_RESULT_OFFSET, GENERATOR_RESUME_MODE_OFFSET) - ACCESSORS(ResumeMode, GENERATOR_RESUME_MODE_OFFSET, SIZE) + ACCESSORS(ResumeResult, GENERATOR_RESUME_RESULT_OFFSET, BIT_FIELD_OFFSET) + ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); + + // define BitField + static constexpr size_t GENERATOE_STATE_BITS = 3; + static constexpr size_t RESUME_MODE_BITS = 3; + FIRST_BIT_FIELD(BitField, GeneratorState, JSGeneratorState, GENERATOE_STATE_BITS) + NEXT_BIT_FIELD(BitField, ResumeMode, GeneratorResumeMode, RESUME_MODE_BITS, GeneratorState) + + DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, GENERATOR_CONTEXT_OFFSET, BIT_FIELD_OFFSET) + DECL_DUMP() // 26.4.3.2 GeneratorValidate(generator) - static JSTaggedValue GeneratorValidate(JSThread *thread, const JSHandle &obj); + static JSGeneratorState GeneratorValidate(JSThread *thread, const JSHandle &obj); // 26.4.3.3 GeneratorResume(generator, value) static JSHandle GeneratorResume(JSThread *thread, const JSHandle &generator, @@ -68,16 +84,13 @@ public: inline bool IsSuspendYield() const { - return GetGeneratorState() == JSTaggedValue(static_cast(JSGeneratorState::SUSPENDED_YIELD)); + return GetGeneratorState() == JSGeneratorState::SUSPENDED_YIELD; } inline bool IsExecuting() const { - return GetGeneratorState() == JSTaggedValue(static_cast(JSGeneratorState::EXECUTING)); + return GetGeneratorState() == JSGeneratorState::EXECUTING; } - - DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, GENERATOR_STATE_OFFSET, SIZE) - DECL_DUMP() }; class JSAsyncFuncObject : public JSGeneratorObject { diff --git a/ecmascript/js_hclass.cpp b/ecmascript/js_hclass.cpp index e32641a3ca..4e9f869106 100644 --- a/ecmascript/js_hclass.cpp +++ b/ecmascript/js_hclass.cpp @@ -359,7 +359,7 @@ void JSHClass::RegisterOnProtoChain(const JSThread *thread, const JSHandleGetRegisterIndex() != JSTaggedValue(ProtoChangeDetails::UNREGISTERED)) { + if (userDetails->GetRegisterIndex() != ProtoChangeDetails::UNREGISTERED) { return; } @@ -376,14 +376,14 @@ void JSHClass::RegisterOnProtoChain(const JSThread *thread, const JSHandle(thread, protoHandle->GetJSHClass())); JSTaggedValue listeners = protoDetails->GetChangeListener(); JSHandle listenersHandle; - if (listeners == JSTaggedValue(0)) { + if (listeners.IsUndefined()) { listenersHandle = JSHandle(ChangeListener::Create(thread)); } else { listenersHandle = JSHandle(thread, listeners); } uint32_t registerIndex = 0; JSHandle newListeners = ChangeListener::Add(thread, listenersHandle, user, ®isterIndex); - userDetails->SetRegisterIndex(thread, JSTaggedValue(registerIndex)); + userDetails->SetRegisterIndex(registerIndex); protoDetails->SetChangeListener(thread, newListeners.GetTaggedValue()); userDetails = protoDetails; user = JSHandle(thread, protoHandle->GetJSHClass()); @@ -399,11 +399,11 @@ bool JSHClass::UnregisterOnProtoChain(const JSThread *thread, const JSHandleGetPrototype().IsECMAObject()) { JSTaggedValue listeners = ProtoChangeDetails::Cast(jshclass->GetProtoChangeDetails().GetTaggedObject())->GetChangeListener(); - return listeners != JSTaggedValue(0); + return !listeners.IsUndefined(); } JSHandle currentDetails = GetProtoChangeDetails(thread, jshclass); - uint32_t index = currentDetails->GetRegisterIndex().GetArrayLength(); - if (JSTaggedValue(index) == JSTaggedValue(ProtoChangeDetails::UNREGISTERED)) { + uint32_t index = currentDetails->GetRegisterIndex(); + if (index == ProtoChangeDetails::UNREGISTERED) { return false; } JSTaggedValue proto = jshclass->GetPrototype(); @@ -411,7 +411,7 @@ bool JSHClass::UnregisterOnProtoChain(const JSThread *thread, const JSHandleGetJSHClass()->GetProtoChangeDetails(); ASSERT(protoDetailsValue.IsProtoChangeDetails()); JSTaggedValue listenersValue = ProtoChangeDetails::Cast(protoDetailsValue.GetTaggedObject())->GetChangeListener(); - ASSERT(listenersValue != JSTaggedValue(0)); + ASSERT(!listenersValue.IsUndefined()); JSHandle listeners(thread, listenersValue.GetTaggedObject()); ASSERT(listeners->Get(index) == jshclass.GetTaggedValue()); listeners->Delete(thread, index); @@ -473,11 +473,11 @@ void JSHClass::RefreshUsers(const JSThread *thread, const JSHandle &ol bool onceRegistered = UnregisterOnProtoChain(thread, oldHclass); newHclass->SetProtoChangeDetails(thread, oldHclass->GetProtoChangeDetails()); - oldHclass->SetProtoChangeDetails(thread, JSTaggedValue(0)); + oldHclass->SetProtoChangeDetails(thread, JSTaggedValue::Undefined()); if (onceRegistered) { if (newHclass->GetProtoChangeDetails().IsProtoChangeDetails()) { ProtoChangeDetails::Cast(newHclass->GetProtoChangeDetails().GetTaggedObject()) - ->SetRegisterIndex(thread, JSTaggedValue(ProtoChangeDetails::UNREGISTERED)); + ->SetRegisterIndex(ProtoChangeDetails::UNREGISTERED); } RegisterOnProtoChain(thread, newHclass); } diff --git a/ecmascript/js_hclass.h b/ecmascript/js_hclass.h index b48b34650b..230cb302f4 100644 --- a/ecmascript/js_hclass.h +++ b/ecmascript/js_hclass.h @@ -148,7 +148,6 @@ class ProtoChangeDetails; PROTOTYPE_INFO, /* ////////////////////////////////////////////////////////////////////////////-PADDING */ \ TEMPLATE_MAP, /* ////////////////////////////////////////////////////////////////////////////-PADDING */ \ PROGRAM, /* /////////////////////////////////////////////////////////////////////////////////-PADDING */ \ - LEXICAL_FUNCTION, /* ////////////////////////////////////////////////////////////////////////-PADDING */ \ \ PROMISE_CAPABILITY, /* JS_RECORD_BEGIN //////////////////////////////////////////////////////////////////// */ \ PROMISE_RECORD, /* ////////////////////////////////////////////////////////////////////////////-PADDING */ \ @@ -157,7 +156,6 @@ class ProtoChangeDetails; PROMISE_ITERATOR_RECORD, /* ////////////////////////////////////////////////////////////////////-PADDING */ \ MICRO_JOB_QUEUE, /* /////////////////////////////////////////////////////////////////////////////-PADDING */ \ PENDING_JOB, /* /////////////////////////////////////////////////////////////////////////////-PADDING */ \ - FUNCTION_EXTRA_INFO, /* ////////////////////////////////////////////////////////////////////////-PADDING */ \ COMPLETION_RECORD, /* JS_RECORD_END /////////////////////////////////////////////////////////////////////// */ \ MACHINE_CODE_OBJECT, \ ECMA_MODULE, /* ///////////////////////////////////////////////////////////////////////////////////-PADDING */ \ @@ -499,11 +497,6 @@ public: return GetObjectType() == JSType::JS_PROMISE_ALL_RESOLVE_ELEMENT_FUNCTION; } - inline bool IsJSFunctionExtraInfo() const - { - return GetObjectType() == JSType::FUNCTION_EXTRA_INFO; - } - inline bool IsMicroJobQueue() const { return GetObjectType() == JSType::MICRO_JOB_QUEUE; @@ -709,11 +702,6 @@ public: return GetObjectType() == JSType::CLASS_INFO_EXTRACTOR; } - inline bool IsLexicalFunction() const - { - return GetObjectType() == JSType::LEXICAL_FUNCTION; - } - inline bool IsCallable() const { uint32_t bits = GetBitField(); @@ -881,7 +869,7 @@ public: inline void SetIsDictionaryElement(bool value) { - JSTaggedType newVal = DictionaryElementBits::Update(GetBitField(), value); + uint32_t newVal = DictionaryElementBits::Update(GetBitField(), value); SetBitField(newVal); } inline bool IsDictionaryElement() const @@ -890,7 +878,7 @@ public: } inline void SetIsStableElements(bool value) { - JSTaggedType newVal = IsStableElementsBit::Update(GetBitField(), value); + uint32_t newVal = IsStableElementsBit::Update(GetBitField(), value); SetBitField(newVal); } inline bool IsStableElements() const @@ -1011,16 +999,17 @@ public: JSTaggedValue GetAccessor(const JSTaggedValue &key); - static constexpr size_t BIT_FIELD_OFFSET = TaggedObjectSize(); - SET_GET_PRIMITIVE_FIELD(BitField, uint32_t, BIT_FIELD_OFFSET, BIT_FIELD1_OFFSET); - SET_GET_PRIMITIVE_FIELD(BitField1, uint32_t, BIT_FIELD1_OFFSET, PROTOTYPE_OFFSET); + static constexpr size_t PROTOTYPE_OFFSET = TaggedObjectSize(); ACCESSORS(Proto, PROTOTYPE_OFFSET, LAYOUT_OFFSET); ACCESSORS(Layout, LAYOUT_OFFSET, TRANSTIONS_OFFSET); ACCESSORS(Transitions, TRANSTIONS_OFFSET, PARENT_OFFSET); ACCESSORS(Parent, PARENT_OFFSET, VALIDITY_CELL_OFFSET); ACCESSORS(ProtoChangeMarker, VALIDITY_CELL_OFFSET, PROTOTYPE_INFO_OFFSET); ACCESSORS(ProtoChangeDetails, PROTOTYPE_INFO_OFFSET, ENUM_CACHE_OFFSET); - ACCESSORS(EnumCache, ENUM_CACHE_OFFSET, SIZE); + ACCESSORS(EnumCache, ENUM_CACHE_OFFSET, BIT_FIELD_OFFSET); + ACCESSORS_PRIMITIVE_FIELD(BitField, uint32_t, BIT_FIELD_OFFSET, BIT_FIELD1_OFFSET); + ACCESSORS_PRIMITIVE_FIELD(BitField1, uint32_t, BIT_FIELD1_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); void SetPrototype(const JSThread *thread, JSTaggedValue proto); void SetPrototype(const JSThread *thread, const JSHandle &proto); @@ -1032,7 +1021,7 @@ public: static CString DumpJSType(JSType type); - DECL_VISIT_OBJECT(PROTOTYPE_OFFSET, SIZE); + DECL_VISIT_OBJECT(PROTOTYPE_OFFSET, BIT_FIELD_OFFSET); private: static inline void AddTransitions(const JSThread *thread, const JSHandle &parent, diff --git a/ecmascript/js_iterator.cpp b/ecmascript/js_iterator.cpp index 8ba9a3a871..9d87af0dc1 100644 --- a/ecmascript/js_iterator.cpp +++ b/ecmascript/js_iterator.cpp @@ -30,7 +30,7 @@ JSTaggedValue JSIterator::IteratorCloseAndReturn(JSThread *thread, const JSHandl ASSERT(thread->HasPendingException()); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSTaggedValue exception = thread->GetException(); - JSHandle record = JSHandle(factory->NewCompletionRecord(CompletionRecord::THROW, + JSHandle record = JSHandle(factory->NewCompletionRecord(CompletionRecordType::THROW, JSHandle(thread, exception))); JSHandle result = JSIterator::IteratorClose(thread, iter, record); if (result->IsCompletionRecord()) { diff --git a/ecmascript/js_iterator.h b/ecmascript/js_iterator.h index 5c44fd0f23..e816cd362d 100644 --- a/ecmascript/js_iterator.h +++ b/ecmascript/js_iterator.h @@ -20,7 +20,12 @@ #include "tagged_array-inl.h" namespace panda::ecmascript { -enum class IterationKind { KEY = 0, VALUE, KEY_AND_VALUE }; +enum class IterationKind : uint8_t { + KEY = 0, + VALUE, + KEY_AND_VALUE +}; + class JSIterator final { public: static JSTaggedValue IteratorCloseAndReturn(JSThread *thread, const JSHandle &iter, diff --git a/ecmascript/js_locale.h b/ecmascript/js_locale.h index e50929e77d..1aecc53f2f 100644 --- a/ecmascript/js_locale.h +++ b/ecmascript/js_locale.h @@ -62,6 +62,8 @@ enum class LocaleType : uint8_t { CURRENCY_PREFIX, CURRENCY_SUFFIX, }; + +enum class TypeOption : uint8_t { CARDINAL = 0x01, ORDINAL, EXCEPTION }; enum class RoundingType : uint8_t { FRACTIONDIGITS = 0x01, SIGNIFICANTDIGITS, COMPACTROUNDING, EXCEPTION }; enum class NotationOption : uint8_t { STANDARD = 0x01, SCIENTIFIC, ENGINEERING, COMPACT, EXCEPTION }; @@ -570,7 +572,7 @@ public: // 11. If mnsd is not undefined or mxsd is not undefined, then if (!mnsd->IsUndefined() || !mxsd->IsUndefined()) { // a. Set intlObj.[[RoundingType]] to significantDigits. - intlObj->SetRoundingType(thread, JSTaggedValue(static_cast(RoundingType::SIGNIFICANTDIGITS))); + intlObj->SetRoundingType(RoundingType::SIGNIFICANTDIGITS); // b. Let mnsd be ? DefaultNumberOption(mnsd, 1, 21, 1). mnsd = JSHandle( thread, JSTaggedValue(JSLocale::DefaultNumberOption(thread, mnsd, 1, MAX_DIGITS, 1))); @@ -585,7 +587,7 @@ public: if (!mnfd->IsUndefined() || !mxfd->IsUndefined()) { // 12. Else if mnfd is not undefined or mxfd is not undefined, then // a. Set intlObj.[[RoundingType]] to fractionDigits. - intlObj->SetRoundingType(thread, JSTaggedValue(static_cast(RoundingType::FRACTIONDIGITS))); + intlObj->SetRoundingType(RoundingType::FRACTIONDIGITS); if (!mxfd->IsUndefined()) { JSTaggedValue mxfdValue = JSTaggedValue(JSLocale::DefaultNumberOption(thread, mxfd, 0, MAX_FRACTION_DIGITS, mxfdDefault)); @@ -608,11 +610,11 @@ public: } else if (notation == NotationOption::COMPACT) { // 13. Else if notation is "compact", then // a. Set intlObj.[[RoundingType]] to compactRounding. - intlObj->SetRoundingType(thread, JSTaggedValue(static_cast(RoundingType::COMPACTROUNDING))); + intlObj->SetRoundingType(RoundingType::COMPACTROUNDING); } else { // 14. else, // a.Set intlObj.[[RoundingType]] to fractionDigits. - intlObj->SetRoundingType(thread, JSTaggedValue(static_cast(RoundingType::FRACTIONDIGITS))); + intlObj->SetRoundingType(RoundingType::FRACTIONDIGITS); // b.Set intlObj.[[MinimumFractionDigits]] to mnfdDefault. intlObj->SetMinimumFractionDigits(thread, JSTaggedValue(mnfdDefault)); // c.Set intlObj.[[MaximumFractionDigits]] to mxfdDefault. diff --git a/ecmascript/js_map_iterator.cpp b/ecmascript/js_map_iterator.cpp index 3ba579cec2..d7f6afc596 100644 --- a/ecmascript/js_map_iterator.cpp +++ b/ecmascript/js_map_iterator.cpp @@ -42,8 +42,8 @@ JSTaggedValue JSMapIterator::Next(EcmaRuntimeCallInfo *argv) JSHandle iteratedMap(thread, iter->GetIteratedMap()); // 5.Let index be O.[[MapNextIndex]]. - int index = iter->GetNextIndex().GetInt(); - IterationKind itemKind = IterationKind(iter->GetIterationKind().GetInt()); + int index = iter->GetNextIndex(); + IterationKind itemKind = iter->GetIterationKind(); // 7.If m is undefined, return CreateIterResultObject(undefined, true). if (iteratedMap->IsUndefined()) { return JSIterator::CreateIterResultObject(thread, undefinedHandle, true).GetTaggedValue(); @@ -55,7 +55,7 @@ JSTaggedValue JSMapIterator::Next(EcmaRuntimeCallInfo *argv) while (index < totalElements) { JSTaggedValue key = map->GetKey(index); if (!key.IsHole()) { - iter->SetNextIndex(thread, JSTaggedValue(index + 1)); + iter->SetNextIndex(index + 1); keyHandle.Update(key); // If itemKind is key, let result be e.[[Key]] if (itemKind == IterationKind::KEY) { @@ -92,7 +92,7 @@ void JSMapIterator::Update(const JSThread *thread) if (map->GetNextTable().IsHole()) { return; } - int index = GetNextIndex().GetInt(); + int index = GetNextIndex(); JSTaggedValue nextTable = map->GetNextTable(); while (!nextTable.IsHole()) { index -= map->GetDeletedElementsAt(index); @@ -100,7 +100,7 @@ void JSMapIterator::Update(const JSThread *thread) nextTable = map->GetNextTable(); } SetIteratedMap(thread, JSTaggedValue(map)); - SetNextIndex(thread, JSTaggedValue(index)); + SetNextIndex(index); } JSHandle JSMapIterator::CreateMapIterator(JSThread *thread, const JSHandle &obj, diff --git a/ecmascript/js_map_iterator.h b/ecmascript/js_map_iterator.h index 8669ed7189..8a11bb6e3a 100644 --- a/ecmascript/js_map_iterator.h +++ b/ecmascript/js_map_iterator.h @@ -16,8 +16,8 @@ #ifndef ECMASCRIPT_JS_MAP_ITERATOR_H #define ECMASCRIPT_JS_MAP_ITERATOR_H -#include "js_iterator.h" -#include "js_object.h" +#include "ecmascript/js_iterator.h" +#include "ecmascript/js_object.h" namespace panda::ecmascript { class JSMapIterator : public JSObject { @@ -35,11 +35,15 @@ public: static constexpr size_t ITERATED_MAP_OFFSET = JSObject::SIZE; ACCESSORS(IteratedMap, ITERATED_MAP_OFFSET, NEXT_INDEX_OFFSET); - ACCESSORS(NextIndex, NEXT_INDEX_OFFSET, ITERATION_KIND_OFFSET); - ACCESSORS(IterationKind, ITERATION_KIND_OFFSET, SIZE); + ACCESSORS_PRIMITIVE_FIELD(NextIndex, uint32_t, NEXT_INDEX_OFFSET, BIT_FIELD_OFFSET) + ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); - DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, ITERATED_MAP_OFFSET, SIZE) + // define BitField + static constexpr size_t ITERATION_KIND_BITS = 2; + FIRST_BIT_FIELD(BitField, IterationKind, IterationKind, ITERATION_KIND_BITS) + DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, ITERATED_MAP_OFFSET, NEXT_INDEX_OFFSET) DECL_DUMP() }; } // namespace panda::ecmascript diff --git a/ecmascript/js_native_pointer.h b/ecmascript/js_native_pointer.h index f061d555b9..5d89aa9e7f 100644 --- a/ecmascript/js_native_pointer.h +++ b/ecmascript/js_native_pointer.h @@ -46,9 +46,10 @@ public: } static constexpr size_t POINTER_OFFSET = TaggedObjectSize(); - SET_GET_VOID_FIELD(ExternalPointer, POINTER_OFFSET, DELETER_OFFSET); - SET_GET_PRIMITIVE_FIELD(Deleter, DeleteEntryPoint, DELETER_OFFSET, DATA_OFFSET); - SET_GET_VOID_FIELD(Data, DATA_OFFSET, SIZE); + ACCESSORS_NATIVE_FIELD(ExternalPointer, void, POINTER_OFFSET, DELETER_OFFSET); + ACCESSORS_PRIMITIVE_FIELD(Deleter, DeleteEntryPoint, DELETER_OFFSET, DATA_OFFSET) + ACCESSORS_NATIVE_FIELD(Data, void, DATA_OFFSET, LAST_OFFSET); + DEFINE_ALIGN_SIZE(LAST_OFFSET); private: inline void DeleteExternalPointer() diff --git a/ecmascript/js_number_format.cpp b/ecmascript/js_number_format.cpp index d6c52cbc5f..b89a256750 100644 --- a/ecmascript/js_number_format.cpp +++ b/ecmascript/js_number_format.cpp @@ -265,8 +265,7 @@ FractionDigitsOption SetNumberFormatUnitOptions(JSThread *thread, RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, fractionDigitsOption); // 4. Set intlObj.[[Style]] to style. - JSHandle styleValue(thread, JSTaggedValue(static_cast(style))); - numberFormat->SetStyle(thread, styleValue); + numberFormat->SetStyle(style); // 5. Let currency be ? GetOption(options, "currency", "string", undefined, undefined). property = globalConst->GetHandledCurrencyString(); @@ -302,8 +301,7 @@ FractionDigitsOption SetNumberFormatUnitOptions(JSThread *thread, CurrencyDisplayOption::NAME}, {"code", "symbol", "narrowSymbol", "name"}, CurrencyDisplayOption::SYMBOL); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, fractionDigitsOption); - JSHandle currencyDisplayValue(thread, JSTaggedValue(static_cast(currencyDisplay))); - numberFormat->SetCurrencyDisplay(thread, currencyDisplayValue); + numberFormat->SetCurrencyDisplay(currencyDisplay); // 9. Let currencySign be ? GetOption(options, "currencySign", "string", « "standard", "accounting" », "standard"). property = globalConst->GetHandledCurrencySignString(); @@ -311,8 +309,7 @@ FractionDigitsOption SetNumberFormatUnitOptions(JSThread *thread, thread, optionsObject, property, {CurrencySignOption::STANDARD, CurrencySignOption::ACCOUNTING}, {"standard", "accounting"}, CurrencySignOption::STANDARD); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, fractionDigitsOption); - JSHandle currencySignValue(thread, JSTaggedValue(static_cast(currencySign))); - numberFormat->SetCurrencySign(thread, currencySignValue); + numberFormat->SetCurrencySign(currencySign); // 10. Let unit be ? GetOption(options, "unit", "string", undefined, undefined). property = globalConst->GetHandledUnitString(); @@ -347,8 +344,7 @@ FractionDigitsOption SetNumberFormatUnitOptions(JSThread *thread, thread, optionsObject, property, {UnitDisplayOption::SHORT, UnitDisplayOption::NARROW, UnitDisplayOption::LONG}, {"short", "narrow", "long"}, UnitDisplayOption::SHORT); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, fractionDigitsOption); - JSHandle unitDisplayValue(thread, JSTaggedValue(static_cast(unitDisplay))); - numberFormat->SetUnitDisplay(thread, unitDisplayValue); + numberFormat->SetUnitDisplay(unitDisplay); // 14. If style is "currency", then // a. Let currency be the result of converting currency to upper case as specified in 6.1. @@ -522,8 +518,7 @@ void JSNumberFormat::InitializeNumberFormat(JSThread *thread, const JSHandleGetUnitDisplay(); - UnitDisplayOption unitDisplay = static_cast(unitDisplayValue.GetInt()); + UnitDisplayOption unitDisplay = numberFormat->GetUnitDisplay(); // Trans unitDisplay option to ICU display option UNumberUnitWidth uNumberUnitWidth; @@ -544,8 +539,7 @@ void JSNumberFormat::InitializeNumberFormat(JSThread *thread, const JSHandleGetStyle(); - StyleOption style = static_cast(styleValue.GetInt()); + StyleOption style = numberFormat->GetStyle(); if (style == StyleOption::PERCENT) { icuNumberFormatter = icuNumberFormatter.unit(icu::MeasureUnit::getPercent()) .scale(icu::number::Scale::powerOfTen(2)); // means 10^2 @@ -559,8 +553,7 @@ void JSNumberFormat::InitializeNumberFormat(JSThread *thread, const JSHandle notationValue(thread, JSTaggedValue(static_cast(notation))); - numberFormat->SetNotation(thread, notationValue); + numberFormat->SetNotation(notation); // 21. Perform ? SetNumberFormatDigitOptions(numberFormat, options, mnfdDefault, mxfdDefault, notation). JSLocale::SetNumberFormatDigitOptions(thread, numberFormat, JSHandle::Cast(optionsObject), @@ -572,8 +565,7 @@ void JSNumberFormat::InitializeNumberFormat(JSThread *thread, const JSHandle( thread, optionsObject, property, {CompactDisplayOption::SHORT, CompactDisplayOption::LONG}, {"short", "long"}, CompactDisplayOption::SHORT); - JSHandle compactDisplayValue(thread, JSTaggedValue(static_cast(compactDisplay))); - numberFormat->SetCompactDisplay(thread, compactDisplayValue); + numberFormat->SetCompactDisplay(compactDisplay); // Trans NotationOption to ICU Noation and set to icuNumberFormatter if (notation == NotationOption::COMPACT) { @@ -623,15 +615,13 @@ void JSNumberFormat::InitializeNumberFormat(JSThread *thread, const JSHandle signDisplayValue(thread, JSTaggedValue(static_cast(signDisplay))); - numberFormat->SetSignDisplay(thread, signDisplayValue); + numberFormat->SetSignDisplay(signDisplay); // 27. Set numberFormat.[[SignDisplay]] to signDisplay. // The default sign in ICU is UNUM_SIGN_AUTO which is mapped from // SignDisplay::AUTO and CurrencySign::STANDARD so we can skip setting // under that values for optimization. - JSTaggedValue currencySignValue = numberFormat->GetCurrencySign(); - CurrencySignOption currencySign = static_cast(currencySignValue.GetInt()); + CurrencySignOption currencySign = numberFormat->GetCurrencySign(); // Trans SignDisPlayOption to ICU UNumberSignDisplay and set to icuNumberFormatter switch (signDisplay) { @@ -719,7 +709,7 @@ void GroupToParts(JSThread *thread, const icu::number::FormattedNumber &formatte } ASSERT(x.IsNumber()); - StyleOption styleOption = static_cast(numberFormat->GetStyle().GetInt()); + StyleOption styleOption = numberFormat->GetStyle(); icu::ConstrainedFieldPosition cfpo; // Set constrainCategory to UFIELD_CATEGORY_NUMBER which is specified for UNumberFormatFields @@ -909,7 +899,7 @@ void JSNumberFormat::ResolvedOptions(JSThread *thread, const JSHandle(numberFormat->GetStyle().GetInt()); + StyleOption style = numberFormat->GetStyle(); property = globalConst->GetHandledStyleString(); JSHandle styleString = OptionToEcmaString(thread, style); JSObject::CreateDataPropertyOrThrow(thread, options, property, styleString); @@ -926,14 +916,13 @@ void JSNumberFormat::ResolvedOptions(JSThread *thread, const JSHandleGetHandledCurrencyDisplayString(); - CurrencyDisplayOption currencyDisplay = - static_cast(numberFormat->GetCurrencyDisplay().GetInt()); + CurrencyDisplayOption currencyDisplay = numberFormat->GetCurrencyDisplay(); JSHandle currencyDisplayString = OptionToEcmaString(thread, currencyDisplay); JSObject::CreateDataPropertyOrThrow(thread, options, property, currencyDisplayString); // [[CurrencySign]] property = globalConst->GetHandledCurrencySignString(); - CurrencySignOption currencySign = static_cast(numberFormat->GetCurrencySign().GetInt()); + CurrencySignOption currencySign = numberFormat->GetCurrencySign(); JSHandle currencySignString = OptionToEcmaString(thread, currencySign); JSObject::CreateDataPropertyOrThrow(thread, options, property, currencySignString); } @@ -947,7 +936,7 @@ void JSNumberFormat::ResolvedOptions(JSThread *thread, const JSHandleGetHandledUnitDisplayString(); - UnitDisplayOption unitDisplay = static_cast(numberFormat->GetUnitDisplay().GetInt()); + UnitDisplayOption unitDisplay = numberFormat->GetUnitDisplay(); JSHandle unitDisplayString = OptionToEcmaString(thread, unitDisplay); JSObject::CreateDataPropertyOrThrow(thread, options, property, unitDisplayString); } @@ -956,7 +945,7 @@ void JSNumberFormat::ResolvedOptions(JSThread *thread, const JSHandle minimumIntegerDigits(thread, numberFormat->GetMinimumIntegerDigits()); JSObject::CreateDataPropertyOrThrow(thread, options, property, minimumIntegerDigits); - RoundingType roundingType = static_cast(numberFormat->GetRoundingType().GetInt()); + RoundingType roundingType = numberFormat->GetRoundingType(); if (roundingType == RoundingType::SIGNIFICANTDIGITS) { // [[MinimumSignificantDigits]] property = globalConst->GetHandledMinimumSignificantDigitsString(); @@ -984,7 +973,7 @@ void JSNumberFormat::ResolvedOptions(JSThread *thread, const JSHandleGetHandledNotationString(); - NotationOption notation = static_cast(numberFormat->GetNotation().GetInt()); + NotationOption notation = numberFormat->GetNotation(); JSHandle notationString = OptionToEcmaString(thread, notation); JSObject::CreateDataPropertyOrThrow(thread, options, property, notationString); @@ -992,15 +981,14 @@ void JSNumberFormat::ResolvedOptions(JSThread *thread, const JSHandleGetHandledCompactDisplayString(); - CompactDisplayOption compactDisplay = - static_cast(numberFormat->GetCompactDisplay().GetInt()); + CompactDisplayOption compactDisplay = numberFormat->GetCompactDisplay(); JSHandle compactDisplayString = OptionToEcmaString(thread, compactDisplay); JSObject::CreateDataPropertyOrThrow(thread, options, property, compactDisplayString); } // [[SignDisplay]] property = globalConst->GetHandledSignDisplayString(); - SignDisplayOption signDisplay = static_cast(numberFormat->GetSignDisplay().GetInt()); + SignDisplayOption signDisplay = numberFormat->GetSignDisplay(); JSHandle signDisplayString = OptionToEcmaString(thread, signDisplay); JSObject::CreateDataPropertyOrThrow(thread, options, property, signDisplayString); } diff --git a/ecmascript/js_number_format.h b/ecmascript/js_number_format.h index e577eccce7..6c55f1e053 100644 --- a/ecmascript/js_number_format.h +++ b/ecmascript/js_number_format.h @@ -54,31 +54,40 @@ public: CAST_CHECK(JSNumberFormat, IsJSNumberFormat); static constexpr size_t LOCALE_OFFSET = JSObject::SIZE; - ACCESSORS(Locale, LOCALE_OFFSET, NUMBER_STRING_SYSTEM_OFFSET) - ACCESSORS(NumberingSystem, NUMBER_STRING_SYSTEM_OFFSET, STYLE_OFFSET) - ACCESSORS(Style, STYLE_OFFSET, CURRENCY_OFFSET) - ACCESSORS(Currency, CURRENCY_OFFSET, CURRENCY_DISPLAY_OFFSET) - ACCESSORS(CurrencyDisplay, CURRENCY_DISPLAY_OFFSET, CURRENCY_SIGN_OFFSET) - ACCESSORS(CurrencySign, CURRENCY_SIGN_OFFSET, UNIT_OFFSET) - ACCESSORS(Unit, UNIT_OFFSET, UNIT_DISPLAY_OFFSET) - ACCESSORS(UnitDisplay, UNIT_DISPLAY_OFFSET, MINIMUM_INTEGER_DIGITS_OFFSET) + ACCESSORS(NumberingSystem, NUMBER_STRING_SYSTEM_OFFSET, CURRENCY_OFFSET) + ACCESSORS(Currency, CURRENCY_OFFSET, UNIT_OFFSET) + ACCESSORS(Unit, UNIT_OFFSET, MINIMUM_INTEGER_DIGITS_OFFSET) ACCESSORS(MinimumIntegerDigits, MINIMUM_INTEGER_DIGITS_OFFSET, MINIMUM_FRACTION_DIGITS_OFFSET) ACCESSORS(MinimumFractionDigits, MINIMUM_FRACTION_DIGITS_OFFSET, MAXIMUM_FRACTION_DIGITS_OFFSET) ACCESSORS(MaximumFractionDigits, MAXIMUM_FRACTION_DIGITS_OFFSET, MININUM_SIGNIFICANT_DIGITS_OFFSET) ACCESSORS(MinimumSignificantDigits, MININUM_SIGNIFICANT_DIGITS_OFFSET, MAXINUM_SIGNIFICANT_DIGITS_OFFSET) ACCESSORS(MaximumSignificantDigits, MAXINUM_SIGNIFICANT_DIGITS_OFFSET, USER_GROUPING_OFFSET) - ACCESSORS(UseGrouping, USER_GROUPING_OFFSET, ROUNDING_TYPE_OFFSET) - ACCESSORS(RoundingType, ROUNDING_TYPE_OFFSET, NOTATION_OFFSET) - ACCESSORS(Notation, NOTATION_OFFSET, COMPACT_DISPLAY_OFFSET) - ACCESSORS(CompactDisplay, COMPACT_DISPLAY_OFFSET, SIGN_DISPLAY_OFFSET) - ACCESSORS(SignDisplay, SIGN_DISPLAY_OFFSET, ICU_NUMBER_FORMAT_OFFSET) - ACCESSORS(BoundFormat, ICU_NUMBER_FORMAT_OFFSET, BOUND_FORMAT_OFFSET) - - // icu field. - ACCESSORS(IcuField, BOUND_FORMAT_OFFSET, SIZE) - - DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, LOCALE_OFFSET, SIZE) + ACCESSORS(UseGrouping, USER_GROUPING_OFFSET, BOUND_FORMAT_OFFSET) + ACCESSORS(BoundFormat, BOUND_FORMAT_OFFSET, ICU_FIELD_OFFSET) + ACCESSORS(IcuField, ICU_FIELD_OFFSET, BIT_FIELD_OFFSET) + ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); + + // define BitField + static constexpr size_t STYLE_BITS = 3; + static constexpr size_t CURRENCY_SIGN_BITS = 2; + static constexpr size_t CURRENCY_DISPLAY_BITS = 3; + static constexpr size_t UNIT_DISPLAY_BITS = 3; + static constexpr size_t SIGN_DISPLAY_BITS = 3; + static constexpr size_t COMPACT_DISPLAY_BITS = 2; + static constexpr size_t NOTATION_BITS = 3; + static constexpr size_t ROUNDING_TYPE_BITS = 3; + FIRST_BIT_FIELD(BitField, Style, StyleOption, STYLE_BITS) + NEXT_BIT_FIELD(BitField, CurrencySign, CurrencySignOption, CURRENCY_SIGN_BITS, Style) + NEXT_BIT_FIELD(BitField, CurrencyDisplay, CurrencyDisplayOption, CURRENCY_DISPLAY_BITS, CurrencySign) + NEXT_BIT_FIELD(BitField, UnitDisplay, UnitDisplayOption, UNIT_DISPLAY_BITS, CurrencyDisplay) + NEXT_BIT_FIELD(BitField, SignDisplay, SignDisplayOption, SIGN_DISPLAY_BITS, UnitDisplay) + NEXT_BIT_FIELD(BitField, CompactDisplay, CompactDisplayOption, COMPACT_DISPLAY_BITS, SignDisplay) + NEXT_BIT_FIELD(BitField, Notation, NotationOption, NOTATION_BITS, CompactDisplay) + NEXT_BIT_FIELD(BitField, RoundingType, RoundingType, ROUNDING_TYPE_BITS, Notation) + + DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, LOCALE_OFFSET, BIT_FIELD_OFFSET) DECL_DUMP() icu::number::LocalizedNumberFormatter *GetIcuCallTarget() const @@ -137,7 +146,7 @@ public: int maximumFractionDigits = formatter->GetMaximumFractionDigits().GetInt(); // If roundingtype is "compact-rounding" return ICU formatter - auto roundingType = static_cast(formatter->GetRoundingType().GetInt()); + RoundingType roundingType = formatter->GetRoundingType(); if (roundingType == RoundingType::COMPACTROUNDING) { return icuNumberformatter; } diff --git a/ecmascript/js_plural_rules.cpp b/ecmascript/js_plural_rules.cpp index d6b1fdfb79..f368eca023 100644 --- a/ecmascript/js_plural_rules.cpp +++ b/ecmascript/js_plural_rules.cpp @@ -21,8 +21,6 @@ #include "ecmascript/js_number_format.h" namespace panda::ecmascript { -enum class TypeOption : uint8_t { CARDINAL = 0x01, ORDINAL, EXCEPTION }; - constexpr int32_t STRING_SEPARATOR_LENGTH = 4; icu::number::LocalizedNumberFormatter *JSPluralRules::GetIcuNumberFormatter() const @@ -181,13 +179,7 @@ JSHandle JSPluralRules::InitializePluralRules(JSThread *thread, RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSPluralRules, thread); // set pluralRules.[[type]] to type - JSHandle typeValue; - if (type == TypeOption::CARDINAL) { - typeValue = globalConst->GetHandledCardinalString(); - } else { - typeValue = globalConst->GetHandledOrdinalString(); - } - pluralRules->SetType(thread, typeValue.GetTaggedValue()); + pluralRules->SetType(type); // Let r be ResolveLocale(%PluralRules%.[[AvailableLocales]], requestedLocales, opt, // %PluralRules%.[[RelevantExtensionKeys]], localeData). @@ -316,7 +308,13 @@ void JSPluralRules::ResolvedOptions(JSThread *thread, const JSHandle::Cast(globalConst->GetHandledTypeString()); - PropertyDescriptor typeDesc(thread, JSHandle(thread, pluralRules->GetType()), true, true, true); + JSHandle typeValue; + if (pluralRules->GetType() == TypeOption::CARDINAL) { + typeValue = globalConst->GetHandledCardinalString(); + } else { + typeValue = globalConst->GetHandledOrdinalString(); + } + PropertyDescriptor typeDesc(thread, typeValue, true, true, true); JSObject::DefineOwnProperty(thread, options, property, typeDesc); // [[MinimumIntegerDigits]] @@ -324,7 +322,7 @@ void JSPluralRules::ResolvedOptions(JSThread *thread, const JSHandle minimumIntegerDigits(thread, pluralRules->GetMinimumIntegerDigits()); JSObject::CreateDataPropertyOrThrow(thread, options, property, minimumIntegerDigits); - RoundingType roundingType = static_cast(pluralRules->GetRoundingType().GetInt()); + RoundingType roundingType = pluralRules->GetRoundingType(); if (roundingType == RoundingType::SIGNIFICANTDIGITS) { // [[MinimumSignificantDigits]] property = globalConst->GetHandledMinimumSignificantDigitsString(); diff --git a/ecmascript/js_plural_rules.h b/ecmascript/js_plural_rules.h index d97f6f72d1..873be7daf0 100644 --- a/ecmascript/js_plural_rules.h +++ b/ecmascript/js_plural_rules.h @@ -32,20 +32,25 @@ public: CAST_CHECK(JSPluralRules, IsJSPluralRules); static constexpr size_t LOCALE_OFFSET = JSObject::SIZE; - ACCESSORS(Locale, LOCALE_OFFSET, INITIALIZED_PLURAL_RULES) - ACCESSORS(InitializedPluralRules, INITIALIZED_PLURAL_RULES, TYPE_OFFSET) - ACCESSORS(Type, TYPE_OFFSET, MININUM_INTEGER_DIGITS_OFFSET) + ACCESSORS(InitializedPluralRules, INITIALIZED_PLURAL_RULES, MININUM_INTEGER_DIGITS_OFFSET) ACCESSORS(MinimumIntegerDigits, MININUM_INTEGER_DIGITS_OFFSET, MINIMUM_FRACTION_DIGITS_OFFSET) ACCESSORS(MinimumFractionDigits, MINIMUM_FRACTION_DIGITS_OFFSET, MAXIMUM_FRACTION_DIGITS_OFFSET) ACCESSORS(MaximumFractionDigits, MAXIMUM_FRACTION_DIGITS_OFFSET, MININUM_SIGNIFICANT_DIGITS_OFFSET) ACCESSORS(MinimumSignificantDigits, MININUM_SIGNIFICANT_DIGITS_OFFSET, MAXINUM_SIGNIFICANT_DIGITS_OFFSET) - ACCESSORS(MaximumSignificantDigits, MAXINUM_SIGNIFICANT_DIGITS_OFFSET, ROUDING_TYPE_OFFSET) - ACCESSORS(RoundingType, ROUDING_TYPE_OFFSET, ICU_PLURAL_RULES_OFFSET) + ACCESSORS(MaximumSignificantDigits, MAXINUM_SIGNIFICANT_DIGITS_OFFSET, ICU_PLURAL_RULES_OFFSET) ACCESSORS(IcuPR, ICU_PLURAL_RULES_OFFSET, ICU_NUMBER_FORMAT_OFFSET) - ACCESSORS(IcuNF, ICU_NUMBER_FORMAT_OFFSET, SIZE) + ACCESSORS(IcuNF, ICU_NUMBER_FORMAT_OFFSET, BIT_FIELD_OFFSET) + ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); + + // define BitField + static constexpr size_t ROUDING_TYPE_BITS = 3; + static constexpr size_t TYPE_BITS = 2; + FIRST_BIT_FIELD(BitField, RoundingType, RoundingType, ROUDING_TYPE_BITS) + NEXT_BIT_FIELD(BitField, Type, TypeOption, TYPE_BITS, RoundingType) - DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, LOCALE_OFFSET, SIZE) + DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, LOCALE_OFFSET, BIT_FIELD_OFFSET) DECL_DUMP() icu::number::LocalizedNumberFormatter *GetIcuNumberFormatter() const; diff --git a/ecmascript/js_promise.cpp b/ecmascript/js_promise.cpp index c2a13893ec..fbf6abaf8f 100644 --- a/ecmascript/js_promise.cpp +++ b/ecmascript/js_promise.cpp @@ -63,10 +63,7 @@ JSTaggedValue JSPromise::FulfillPromise(JSThread *thread, const JSHandleGlobalConstants(); // 1. Assert: the value of promise's [[PromiseState]] internal slot is "pending". - JSHandle handleStatus(thread, promise->GetPromiseState()); - ASSERT_PRINT(JSTaggedValue::SameValue(handleStatus.GetTaggedValue(), - JSTaggedValue(static_cast(PromiseStatus::PENDING))), - "FulfillPromise: state must be pending"); + ASSERT_PRINT(promise->GetPromiseState() == PromiseState::PENDING, "FulfillPromise: state must be pending"); // 2. Let reactions be the value of promise's [[PromiseFulfillReactions]] internal slot. JSHandle reactions(thread, promise->GetPromiseFulfillReactions()); // 3. Set the value of promise's [[PromiseResult]] internal slot to value. @@ -76,7 +73,7 @@ JSTaggedValue JSPromise::FulfillPromise(JSThread *thread, const JSHandleSetPromiseRejectReactions(thread, globalConst->GetHandledUndefined()); // 6. Set the value of promise's [[PromiseState]] internal slot to "fulfilled". - promise->SetPromiseState(thread, JSTaggedValue(static_cast(PromiseStatus::FULFILLED))); + promise->SetPromiseState(PromiseState::FULFILLED); // 7. Return TriggerPromiseReactions(reactions, reason). return TriggerPromiseReactions(thread, reactions, value); } @@ -143,11 +140,7 @@ JSTaggedValue JSPromise::RejectPromise(JSThread *thread, const JSHandleGlobalConstants(); // 1. Assert: the value of promise's [[PromiseState]] internal slot is "pending". - JSHandle handleStatus(thread, promise->GetPromiseState()); - - ASSERT_PRINT(JSTaggedValue::SameValue(handleStatus.GetTaggedValue(), - JSTaggedValue(static_cast(PromiseStatus::PENDING))), - "RejectPromise: state must be pending"); + ASSERT_PRINT(promise->GetPromiseState() == PromiseState::PENDING, "RejectPromise: state must be pending"); // 2. Let reactions be the value of promise's [[PromiseRejectReactions]] internal slot. JSHandle reactions(thread, TaggedQueue::Cast(promise->GetPromiseRejectReactions().GetTaggedObject())); // 3. Set the value of promise's [[PromiseResult]] internal slot to reason. @@ -157,9 +150,9 @@ JSTaggedValue JSPromise::RejectPromise(JSThread *thread, const JSHandleSetPromiseRejectReactions(thread, globalConst->GetHandledUndefined()); // 6. Set the value of promise's [[PromiseState]] internal slot to "rejected". - promise->SetPromiseState(thread, JSTaggedValue(static_cast(PromiseStatus::REJECTED))); + promise->SetPromiseState(PromiseState::REJECTED); // 7. When a promise is rejected without any handlers, it is called with its operation argument set to "reject". - if (!promise->GetPromiseIsHandled().ToBoolean()) { + if (!promise->GetPromiseIsHandled()) { thread->GetEcmaVM()->PromiseRejectionTracker(promise, reason, PromiseRejectionEvent::REJECT); } // 8. Return TriggerPromiseReactions(reactions, reason). diff --git a/ecmascript/js_promise.h b/ecmascript/js_promise.h index f382c9af29..de24f4749d 100644 --- a/ecmascript/js_promise.h +++ b/ecmascript/js_promise.h @@ -16,31 +16,35 @@ #ifndef ECMASCRIPT_PROMISE_H #define ECMASCRIPT_PROMISE_H -#include "js_object.h" +#include "ecmascript/accessor_data.h" #include "ecmascript/js_function.h" -#include "ecmascript/tagged_queue.h" -#include "ecmascript/tagged_queue-inl.h" +#include "ecmascript/js_object.h" #include "ecmascript/js_tagged_value.h" -#include "ecmascript/accessor_data.h" #include "ecmascript/js_tagged_value-inl.h" +#include "ecmascript/tagged_queue.h" +#include "ecmascript/tagged_queue-inl.h" namespace panda::ecmascript { -enum class PromiseStatus : uint32_t { PENDING = 0, FULFILLED, REJECTED }; -enum class PromiseType : uint32_t { RESOLVE = 0, REJECT }; -enum class PromiseRejectionEvent : uint32_t { REJECT = 0, HANDLE }; +enum class PromiseState : uint8_t { PENDING = 0, FULFILLED, REJECTED }; +enum class PromiseType : uint8_t { RESOLVE = 0, REJECT }; +enum class PromiseRejectionEvent : uint8_t { REJECT = 0, HANDLE }; class PromiseReaction final : public Record { public: CAST_CHECK(PromiseReaction, IsPromiseReaction); static constexpr size_t PROMISE_CAPABILITY_OFFSET = Record::SIZE; - ACCESSORS(PromiseCapability, PROMISE_CAPABILITY_OFFSET, TYPE_OFFSET); - ACCESSORS(Type, TYPE_OFFSET, HANDLER_OFFSET); - ACCESSORS(Handler, HANDLER_OFFSET, SIZE); + ACCESSORS(PromiseCapability, PROMISE_CAPABILITY_OFFSET, HANDLER_OFFSET) + ACCESSORS(Handler, HANDLER_OFFSET, BIT_FIELD_OFFSET) + ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); - DECL_DUMP() + // define BitField + static constexpr size_t TYPE_BITS = 1; + FIRST_BIT_FIELD(BitField, Type, PromiseType, TYPE_BITS) - DECL_VISIT_OBJECT(PROMISE_CAPABILITY_OFFSET, SIZE) + DECL_VISIT_OBJECT(PROMISE_CAPABILITY_OFFSET, BIT_FIELD_OFFSET) + DECL_DUMP() }; class PromiseCapability final : public Record { @@ -62,12 +66,16 @@ public: CAST_CHECK(PromiseIteratorRecord, IsPromiseIteratorRecord); static constexpr size_t ITERATOR_OFFSET = Record::SIZE; - ACCESSORS(Iterator, ITERATOR_OFFSET, DONE_OFFSET); - ACCESSORS(Done, DONE_OFFSET, SIZE); + ACCESSORS(Iterator, ITERATOR_OFFSET, BIT_FIELD_OFFSET); + ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); - DECL_DUMP() + // define BitField + static constexpr size_t DONE_BITS = 1; + FIRST_BIT_FIELD(BitField, Done, bool, DONE_BITS) - DECL_VISIT_OBJECT(ITERATOR_OFFSET, SIZE) + DECL_VISIT_OBJECT(ITERATOR_OFFSET, BIT_FIELD_OFFSET) + DECL_DUMP() }; class PromiseRecord final : public Record { @@ -122,16 +130,21 @@ public: static JSHandle IfThrowGetThrowValue(JSThread *thread); - static constexpr size_t PROMISE_STATE_OFFSET = JSObject::SIZE; - ACCESSORS(PromiseState, PROMISE_STATE_OFFSET, PROMISE_RESULT_OFFSET); + static constexpr size_t PROMISE_RESULT_OFFSET = JSObject::SIZE; ACCESSORS(PromiseResult, PROMISE_RESULT_OFFSET, PROMISE_FULFILL_REACTIONS_OFFSET); ACCESSORS(PromiseFulfillReactions, PROMISE_FULFILL_REACTIONS_OFFSET, PROMISE_REJECT_REACTIONS_OFFSET); - ACCESSORS(PromiseRejectReactions, PROMISE_REJECT_REACTIONS_OFFSET, PROMISE_IS_HANDLED_OFFSET); - ACCESSORS(PromiseIsHandled, PROMISE_IS_HANDLED_OFFSET, SIZE); + ACCESSORS(PromiseRejectReactions, PROMISE_REJECT_REACTIONS_OFFSET, BIT_FIELD_OFFSET); + ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); - DECL_DUMP() + // define BitField + static constexpr size_t PROMISE_STATE_BITS = 2; + static constexpr size_t PROMISE_IS_HANDLED_BITS = 1; + FIRST_BIT_FIELD(BitField, PromiseState, PromiseState, PROMISE_STATE_BITS) + NEXT_BIT_FIELD(BitField, PromiseIsHandled, bool, PROMISE_IS_HANDLED_BITS, PromiseState) - DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, PROMISE_STATE_OFFSET, SIZE) + DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, PROMISE_RESULT_OFFSET, BIT_FIELD_OFFSET) + DECL_DUMP() }; } // namespace panda::ecmascript diff --git a/ecmascript/js_proxy.h b/ecmascript/js_proxy.h index 9297a214f1..e2ad451010 100644 --- a/ecmascript/js_proxy.h +++ b/ecmascript/js_proxy.h @@ -91,15 +91,17 @@ public: static JSTaggedValue ConstructInternal(JSThread *thread, const JSHandle &proxy, uint32_t argc, const JSTaggedType argv[], const JSHandle &newTarget); - static constexpr size_t METHOD_OFFSET = ECMAObject::SIZE; - SET_GET_NATIVE_FIELD(Method, JSMethod, METHOD_OFFSET, TARGET_OFFSET) + bool IsArray(JSThread *thread) const; + + static constexpr size_t TARGET_OFFSET = ECMAObject::SIZE; ACCESSORS(Target, TARGET_OFFSET, HANDLER_OFFSET) + ACCESSORS(Handler, HANDLER_OFFSET, METHOD_OFFSET) + ACCESSORS_NATIVE_FIELD(Method, JSMethod, METHOD_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); - ACCESSORS(Handler, HANDLER_OFFSET, SIZE) - bool IsArray(JSThread *thread) const; DECL_DUMP() - DECL_VISIT_OBJECT(TARGET_OFFSET, SIZE) + DECL_VISIT_OBJECT(TARGET_OFFSET, METHOD_OFFSET) }; } // namespace panda::ecmascript diff --git a/ecmascript/js_regexp.h b/ecmascript/js_regexp.h index 47fb41a016..b2452ca596 100644 --- a/ecmascript/js_regexp.h +++ b/ecmascript/js_regexp.h @@ -26,14 +26,14 @@ class JSRegExp : public JSObject { public: CAST_CHECK(JSRegExp, IsJSRegExp); - static constexpr size_t LAST_INDEX_OFFSET = JSObject::SIZE; - ACCESSORS(LastIndex, LAST_INDEX_OFFSET, REGEXP_BYTE_CODE_OFFSET); + static constexpr size_t REGEXP_BYTE_CODE_OFFSET = JSObject::SIZE; ACCESSORS(ByteCodeBuffer, REGEXP_BYTE_CODE_OFFSET, ORIGINAL_SOURCE_OFFSET) ACCESSORS(OriginalSource, ORIGINAL_SOURCE_OFFSET, ORIGINAL_FLAGS_OFFSET) ACCESSORS(OriginalFlags, ORIGINAL_FLAGS_OFFSET, LENGTH_OFFSET) - ACCESSORS(Length, LENGTH_OFFSET, SIZE) + ACCESSORS_PRIMITIVE_FIELD(Length, uint32_t, LENGTH_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); - DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, LAST_INDEX_OFFSET, SIZE) + DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, REGEXP_BYTE_CODE_OFFSET, LENGTH_OFFSET) DECL_DUMP() }; diff --git a/ecmascript/js_relative_time_format.cpp b/ecmascript/js_relative_time_format.cpp index 316a9137a0..d8d3c9fc2e 100644 --- a/ecmascript/js_relative_time_format.cpp +++ b/ecmascript/js_relative_time_format.cpp @@ -20,9 +20,6 @@ #include "unicode/unum.h" namespace panda::ecmascript { -enum class StyleOption : uint8_t { LONG = 0x01, SHORT, NARROW, EXCEPTION }; -enum class NumericOption : uint8_t { ALWAYS = 0x01, AUTO, EXCEPTION }; - // 14.1.1 InitializeRelativeTimeFormat ( relativeTimeFormat, locales, options ) JSHandle JSRelativeTimeFormat::InitializeRelativeTimeFormat( JSThread *thread, const JSHandle &relativeTimeFormat, const JSHandle &locales, @@ -106,14 +103,13 @@ JSHandle JSRelativeTimeFormat::InitializeRelativeTimeForma // 16. Let s be ? GetOption(options, "style", "string", «"long", "short", "narrow"», "long"). property = JSHandle::Cast(globalConst->GetHandledStyleString()); - StyleOption styleOption = JSLocale::GetOptionOfString(thread, rtfOptions, property, - {StyleOption::LONG, StyleOption::SHORT, StyleOption::NARROW}, - {"long", "short", "narrow"}, StyleOption::LONG); + RelativeStyleOption styleOption = JSLocale::GetOptionOfString(thread, rtfOptions, property, + {RelativeStyleOption::LONG, RelativeStyleOption::SHORT, RelativeStyleOption::NARROW}, + {"long", "short", "narrow"}, RelativeStyleOption::LONG); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSRelativeTimeFormat, thread); // 17. Set relativeTimeFormat.[[Style]] to s. - JSTaggedValue styleValue(static_cast(styleOption)); - relativeTimeFormat->SetStyle(thread, JSHandle(thread, styleValue)); + relativeTimeFormat->SetStyle(styleOption); // 18. Let numeric be ? GetOption(options, "numeric", "string", ?"always", "auto"?, "always"). property = JSHandle::Cast(globalConst->GetHandledNumericString()); @@ -123,8 +119,7 @@ JSHandle JSRelativeTimeFormat::InitializeRelativeTimeForma RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSRelativeTimeFormat, thread); // 19. Set relativeTimeFormat.[[Numeric]] to numeric. - JSTaggedValue numericValue(static_cast(numericOption)); - relativeTimeFormat->SetNumeric(thread, JSHandle(thread, numericValue)); + relativeTimeFormat->SetNumeric(numericOption); // 20. Let relativeTimeFormat.[[NumberFormat]] be ! Construct(%NumberFormat%, « locale »). icu::NumberFormat *icuNumberFormat = icu::NumberFormat::createInstance(icuLocale, UNUM_DECIMAL, status); @@ -133,16 +128,16 @@ JSHandle JSRelativeTimeFormat::InitializeRelativeTimeForma THROW_RANGE_ERROR_AND_RETURN(thread, "icu Number Format Error", relativeTimeFormat); } - // Trans StyleOption to ICU Style + // Trans RelativeStyleOption to ICU Style UDateRelativeDateTimeFormatterStyle uStyle; switch (styleOption) { - case StyleOption::LONG: + case RelativeStyleOption::LONG: uStyle = UDAT_STYLE_LONG; break; - case StyleOption::SHORT: + case RelativeStyleOption::SHORT: uStyle = UDAT_STYLE_SHORT; break; - case StyleOption::NARROW: + case RelativeStyleOption::NARROW: uStyle = UDAT_STYLE_NARROW; break; default: @@ -264,7 +259,7 @@ icu::FormattedRelativeDateTime GetIcuFormatted(JSThread *thread, THROW_RANGE_ERROR_AND_RETURN(thread, "", icu::FormattedRelativeDateTime()); } UErrorCode status = U_ZERO_ERROR; - NumericOption numeric = static_cast(relativeTimeFormat->GetNumeric().GetNumber()); + NumericOption numeric = relativeTimeFormat->GetNumeric(); icu::FormattedRelativeDateTime formatted; switch (numeric) { @@ -487,13 +482,13 @@ void JSRelativeTimeFormat::ResolvedOptions(JSThread *thread, const JSHandle::Cast(globalConst->GetHandledStyleString()); - StyleOption style = static_cast(relativeTimeFormat->GetStyle().GetNumber()); + RelativeStyleOption style = relativeTimeFormat->GetStyle(); JSHandle styleValue; - if (style == StyleOption::LONG) { + if (style == RelativeStyleOption::LONG) { styleValue = globalConst->GetHandledLongString(); - } else if (style == StyleOption::SHORT) { + } else if (style == RelativeStyleOption::SHORT) { styleValue = globalConst->GetHandledShortString(); - } else if (style == StyleOption::NARROW) { + } else if (style == RelativeStyleOption::NARROW) { styleValue = globalConst->GetHandledNarrowString(); } PropertyDescriptor styleDesc(thread, styleValue, true, true, true); @@ -501,7 +496,7 @@ void JSRelativeTimeFormat::ResolvedOptions(JSThread *thread, const JSHandle::Cast(globalConst->GetHandledNumericString()); - NumericOption numeric = static_cast(relativeTimeFormat->GetNumeric().GetNumber()); + NumericOption numeric = relativeTimeFormat->GetNumeric(); JSHandle numericValue; if (numeric == NumericOption::ALWAYS) { numericValue = globalConst->GetHandledAlwaysString(); diff --git a/ecmascript/js_relative_time_format.h b/ecmascript/js_relative_time_format.h index 4418cc3a0e..64060b22d1 100644 --- a/ecmascript/js_relative_time_format.h +++ b/ecmascript/js_relative_time_format.h @@ -34,23 +34,29 @@ #include "ecmascript/object_factory.h" namespace panda::ecmascript { +enum class RelativeStyleOption : uint8_t { LONG = 0x01, SHORT, NARROW, EXCEPTION }; +enum class NumericOption : uint8_t { ALWAYS = 0x01, AUTO, EXCEPTION }; + class JSRelativeTimeFormat : public JSObject { public: CAST_CHECK(JSRelativeTimeFormat, IsJSRelativeTimeFormat); static constexpr size_t LOCALE_OFFSET = JSObject::SIZE; - ACCESSORS(Locale, LOCALE_OFFSET, INITIALIZED_RELATIVE_TIME_FORMAT) ACCESSORS(InitializedRelativeTimeFormat, INITIALIZED_RELATIVE_TIME_FORMAT, NUMBERING_SYSTEM_OFFSET) - ACCESSORS(NumberingSystem, NUMBERING_SYSTEM_OFFSET, STYLE_OFFSET) - ACCESSORS(Style, STYLE_OFFSET, NUMERIC_OFFSET) - ACCESSORS(Numeric, NUMERIC_OFFSET, AVAILABLE_LOCALES_OFFSET) + ACCESSORS(NumberingSystem, NUMBERING_SYSTEM_OFFSET, AVAILABLE_LOCALES_OFFSET) ACCESSORS(AvailableLocales, AVAILABLE_LOCALES_OFFSET, ICU_FIELD_OFFSET) + ACCESSORS(IcuField, ICU_FIELD_OFFSET, BIT_FIELD_OFFSET) // icu field + ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); - // icu field - ACCESSORS(IcuField, ICU_FIELD_OFFSET, SIZE) + // define BitField + static constexpr size_t STYLE_BITS = 3; + static constexpr size_t NUMERIC_BITS = 2; + FIRST_BIT_FIELD(BitField, Style, RelativeStyleOption, STYLE_BITS) + NEXT_BIT_FIELD(BitField, Numeric, NumericOption, NUMERIC_BITS, Style) - DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, LOCALE_OFFSET, SIZE) + DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, LOCALE_OFFSET, BIT_FIELD_OFFSET) DECL_DUMP() // 14.1.1 InitializeRelativeTimeFormat ( relativeTimeFormat, locales, options ) diff --git a/ecmascript/js_serializer.cpp b/ecmascript/js_serializer.cpp index 1563712e17..1b20621da2 100644 --- a/ecmascript/js_serializer.cpp +++ b/ecmascript/js_serializer.cpp @@ -492,7 +492,7 @@ bool JSSerializer::WriteJSRegExp(const JSHandle &value) bufferSize_ = oldSize; return false; } - uint32_t bufferSize = static_cast(regExp->GetLength().GetInt()); + uint32_t bufferSize = regExp->GetLength(); if (!WriteLength(bufferSize)) { bufferSize_ = oldSize; return false; @@ -592,14 +592,14 @@ bool JSSerializer::WriteJSArrayBuffer(const JSHandle &value) } // Write Accessors(ArrayBufferByteLength) - JSTaggedValue taggedLength = arrayBuffer->GetArrayBufferByteLength(); - if (!WriteRawData(&taggedLength, sizeof(JSTaggedValue))) { + uint32_t arrayLength = arrayBuffer->GetArrayBufferByteLength(); + if (!WriteInt(arrayLength)) { bufferSize_ = oldSize; return false; } // write Accessor shared which indicate the C memeory is shared - bool shared = arrayBuffer->GetShared().ToBoolean(); + bool shared = arrayBuffer->GetShared(); if (!WriteBoolean(shared)) { bufferSize_ = oldSize; return false; @@ -614,11 +614,10 @@ bool JSSerializer::WriteJSArrayBuffer(const JSHandle &value) return false; } } else { - uint32_t byteLength = JSTaggedNumber(taggedLength).ToUint32(); // Write Accessors(ArrayBufferData) which is a pointer to a DynBuffer JSHandle np(thread_, arrayBuffer->GetArrayBufferData()); void *buffer = np->GetExternalPointer(); - if (!WriteRawData(buffer, byteLength)) { + if (!WriteRawData(buffer, arrayLength)) { bufferSize_ = oldSize; return false; } @@ -1204,8 +1203,8 @@ JSHandle JSDeserializer::ReadJSArrayBuffer() { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); // read access length - JSTaggedValue taggedLength; - if (!ReadJSTaggedValue(&taggedLength)) { + uint32_t arrayLength; + if (!ReadInt(&arrayLength)) { return JSHandle(); } // read access shared @@ -1215,24 +1214,23 @@ JSHandle JSDeserializer::ReadJSArrayBuffer() } // create jsarraybuffer JSHandle arrayBufferTag; - uint32_t byteLength = JSTaggedNumber(taggedLength).ToUint32(); if (shared) { uint64_t *bufferAddr = (uint64_t*)GetBuffer(sizeof(uint64_t)); void* bufferData = ToVoidPtr(*bufferAddr); - JSHandle arrayBuffer = factory->NewJSArrayBuffer(bufferData, byteLength, nullptr, nullptr); + JSHandle arrayBuffer = factory->NewJSArrayBuffer(bufferData, arrayLength, nullptr, nullptr); arrayBufferTag = JSHandle::Cast(arrayBuffer); referenceMap_.insert(std::pair(objectId_++, arrayBufferTag)); } else { - void *fromBuffer = GetBuffer(byteLength); + void *fromBuffer = GetBuffer(arrayLength); if (fromBuffer == nullptr) { return arrayBufferTag; } - JSHandle arrayBuffer = factory->NewJSArrayBuffer(byteLength); + JSHandle arrayBuffer = factory->NewJSArrayBuffer(arrayLength); arrayBufferTag = JSHandle::Cast(arrayBuffer); referenceMap_.insert(std::pair(objectId_++, arrayBufferTag)); JSHandle np(thread_, arrayBuffer->GetArrayBufferData()); void *toBuffer = np->GetExternalPointer(); - if (memcpy_s(toBuffer, byteLength, fromBuffer, byteLength) != EOK) { + if (memcpy_s(toBuffer, arrayLength, fromBuffer, arrayLength) != EOK) { UNREACHABLE(); } } diff --git a/ecmascript/js_set_iterator.cpp b/ecmascript/js_set_iterator.cpp index c1530c6b12..4aac723bd5 100644 --- a/ecmascript/js_set_iterator.cpp +++ b/ecmascript/js_set_iterator.cpp @@ -43,8 +43,8 @@ JSTaggedValue JSSetIterator::Next(EcmaRuntimeCallInfo *argv) JSHandle iteratedSet(thread, iter->GetIteratedSet()); // 5.Let index be O.[[SetNextIndex]]. - int index = iter->GetNextIndex().GetInt(); - IterationKind itemKind = IterationKind(iter->GetIterationKind().GetInt()); + int index = iter->GetNextIndex(); + IterationKind itemKind = iter->GetIterationKind(); // 7.If s is undefined, return CreateIterResultObject(undefined, true). if (iteratedSet->IsUndefined()) { return JSIterator::CreateIterResultObject(thread, undefinedHandle, true).GetTaggedValue(); @@ -54,7 +54,7 @@ JSTaggedValue JSSetIterator::Next(EcmaRuntimeCallInfo *argv) while (index < totalElements) { if (!set->GetKey(index).IsHole()) { - iter->SetNextIndex(thread, JSTaggedValue(index + 1)); + iter->SetNextIndex(index + 1); JSHandle key(thread, set->GetKey(index)); // If itemKind is value if (itemKind == IterationKind::VALUE || itemKind == IterationKind::KEY) { @@ -86,7 +86,7 @@ void JSSetIterator::Update(const JSThread *thread) if (set->GetNextTable().IsHole()) { return; } - int index = GetNextIndex().GetInt(); + int index = GetNextIndex(); JSTaggedValue nextTable = set->GetNextTable(); while (!nextTable.IsHole()) { index -= set->GetDeletedElementsAt(index); @@ -94,7 +94,7 @@ void JSSetIterator::Update(const JSThread *thread) nextTable = set->GetNextTable(); } SetIteratedSet(thread, JSTaggedValue(set)); - SetNextIndex(thread, JSTaggedValue(index)); + SetNextIndex(index); } JSHandle JSSetIterator::CreateSetIterator(JSThread *thread, const JSHandle &obj, diff --git a/ecmascript/js_set_iterator.h b/ecmascript/js_set_iterator.h index dec9aa2666..8dad73f884 100644 --- a/ecmascript/js_set_iterator.h +++ b/ecmascript/js_set_iterator.h @@ -16,8 +16,8 @@ #ifndef ECMASCRIPT_JS_SET_ITERATOR_H #define ECMASCRIPT_JS_SET_ITERATOR_H -#include "js_object.h" -#include "js_iterator.h" +#include "ecmascript/js_object.h" +#include "ecmascript/js_iterator.h" namespace panda::ecmascript { class JSSetIterator : public JSObject { @@ -33,10 +33,15 @@ public: static constexpr size_t ITERATED_SET_OFFSET = JSObject::SIZE; ACCESSORS(IteratedSet, ITERATED_SET_OFFSET, NEXT_INDEX_OFFSET); - ACCESSORS(NextIndex, NEXT_INDEX_OFFSET, ITERATION_KIND_OFFSET); - ACCESSORS(IterationKind, ITERATION_KIND_OFFSET, SIZE); + ACCESSORS_PRIMITIVE_FIELD(NextIndex, uint32_t, NEXT_INDEX_OFFSET, BIT_FIELD_OFFSET) + ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); - DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, ITERATED_SET_OFFSET, SIZE) + // define BitField + static constexpr size_t ITERATION_KIND_BITS = 2; + FIRST_BIT_FIELD(BitField, IterationKind, IterationKind, ITERATION_KIND_BITS) + + DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, ITERATED_SET_OFFSET, NEXT_INDEX_OFFSET) DECL_DUMP() }; diff --git a/ecmascript/js_string_iterator.cpp b/ecmascript/js_string_iterator.cpp index ba383067e5..26c8a09aee 100644 --- a/ecmascript/js_string_iterator.cpp +++ b/ecmascript/js_string_iterator.cpp @@ -35,7 +35,7 @@ JSHandle JSStringIterator::CreateStringIterator(const JSThread // 3. Set iterator’s [[IteratedString]] internal slot to string. // 4. Set iterator’s [[StringIteratorNextIndex]] internal slot to 0. iterator->SetIteratedString(thread, string); - iterator->SetStringIteratorNextIndex(thread, JSTaggedValue(0)); + iterator->SetStringIteratorNextIndex(0); return iterator; } } // namespace panda::ecmascript diff --git a/ecmascript/js_string_iterator.h b/ecmascript/js_string_iterator.h index b2e19cfdd9..66f12fd119 100644 --- a/ecmascript/js_string_iterator.h +++ b/ecmascript/js_string_iterator.h @@ -31,9 +31,10 @@ public: static constexpr size_t ITERATED_STRING_OFFSET = JSObject::SIZE; ACCESSORS(IteratedString, ITERATED_STRING_OFFSET, STRING_ITERATOR_NEXT_INDEX_OFFSET) - ACCESSORS(StringIteratorNextIndex, STRING_ITERATOR_NEXT_INDEX_OFFSET, SIZE) + ACCESSORS_PRIMITIVE_FIELD(StringIteratorNextIndex, uint32_t, STRING_ITERATOR_NEXT_INDEX_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); - DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, ITERATED_STRING_OFFSET, SIZE) + DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, ITERATED_STRING_OFFSET, STRING_ITERATOR_NEXT_INDEX_OFFSET) DECL_DUMP() }; } // namespace ecmascript diff --git a/ecmascript/js_symbol.h b/ecmascript/js_symbol.h index 9fa2f74854..2be3e2d7c4 100644 --- a/ecmascript/js_symbol.h +++ b/ecmascript/js_symbol.h @@ -23,12 +23,12 @@ namespace panda { namespace ecmascript { class JSSymbol : public TaggedObject { public: - static constexpr uint64_t IS_PRIVATE = 1U << 0U; - static constexpr uint64_t IS_WELL_KNOWN_SYMBOL = 1U << 1U; - static constexpr uint64_t IS_IN_PUBLIC_SYMBOL_TABLE = 1U << 2U; - static constexpr uint64_t IS_INTERESTING_SYMBOL = 1U << 3U; - static constexpr uint64_t IS_PRIVATE_NAME = 1U << 4U; - static constexpr uint64_t IS_PRIVATE_BRAND = 1U << 5U; + static constexpr uint32_t IS_PRIVATE = 1U << 0U; + static constexpr uint32_t IS_WELL_KNOWN_SYMBOL = 1U << 1U; + static constexpr uint32_t IS_IN_PUBLIC_SYMBOL_TABLE = 1U << 2U; + static constexpr uint32_t IS_INTERESTING_SYMBOL = 1U << 3U; + static constexpr uint32_t IS_PRIVATE_NAME = 1U << 4U; + static constexpr uint32_t IS_PRIVATE_BRAND = 1U << 5U; static constexpr int SYMBOL_HAS_INSTANCE_TYPE = 0; static constexpr int SYMBOL_TO_PRIMITIVE_TYPE = 1; @@ -50,91 +50,52 @@ public: bool IsPrivate() const { - JSTaggedValue flags = this->GetFlags(); - ASSERT(flags.IsInteger()); - return (flags.GetRawData() & IS_PRIVATE) != 0U; + return (GetFlags() & IS_PRIVATE) != 0U; } void SetPrivate(const JSThread *thread) { - JSTaggedValue flags = this->GetFlags(); - if (flags.IsUndefined()) { - SetFlags(thread, JSTaggedValue(IS_PRIVATE)); - return; - } - SetFlags(thread, JSTaggedValue(flags.GetRawData() | IS_PRIVATE)); + SetFlags(GetFlags() | IS_PRIVATE); } bool IsWellKnownSymbol() const { - JSTaggedValue flags = this->GetFlags(); - ASSERT(flags.IsInteger()); - return (flags.GetRawData() & IS_WELL_KNOWN_SYMBOL) != 0U; + return (GetFlags() & IS_WELL_KNOWN_SYMBOL) != 0U; } void SetWellKnownSymbol(const JSThread *thread) { - JSTaggedValue flags = this->GetFlags(); - if (flags.IsUndefined()) { - SetFlags(thread, JSTaggedValue(static_cast(IS_WELL_KNOWN_SYMBOL))); - return; - } - flags = JSTaggedValue(static_cast(flags.GetRawData() | IS_WELL_KNOWN_SYMBOL)); - SetFlags(thread, flags); + SetFlags(GetFlags() | IS_WELL_KNOWN_SYMBOL); } bool IsInPublicSymbolTable() const { - JSTaggedValue flags = this->GetFlags(); - ASSERT(flags.IsInteger()); - return (flags.GetRawData() & IS_IN_PUBLIC_SYMBOL_TABLE) != 0U; + return (GetFlags() & IS_IN_PUBLIC_SYMBOL_TABLE) != 0U; } void SetInPublicSymbolTable(const JSThread *thread) { - JSTaggedValue flags = this->GetFlags(); - if (flags.IsUndefined()) { - SetFlags(thread, JSTaggedValue(static_cast(IS_IN_PUBLIC_SYMBOL_TABLE))); - return; - } - flags = JSTaggedValue(static_cast(flags.GetRawData() | IS_IN_PUBLIC_SYMBOL_TABLE)); - SetFlags(thread, flags); + SetFlags(GetFlags() | IS_IN_PUBLIC_SYMBOL_TABLE); } bool IsInterestingSymbol() const { - JSTaggedValue flags = this->GetFlags(); - ASSERT(flags.IsInteger()); - return (flags.GetRawData() & IS_INTERESTING_SYMBOL) != 0U; + return (GetFlags() & IS_INTERESTING_SYMBOL) != 0U; } void SetInterestingSymbol(const JSThread *thread) { - JSTaggedValue flags = this->GetFlags(); - if (flags.IsUndefined()) { - SetFlags(thread, JSTaggedValue(static_cast(IS_INTERESTING_SYMBOL))); - return; - } - flags = JSTaggedValue(static_cast(flags.GetRawData() | IS_INTERESTING_SYMBOL)); - SetFlags(thread, flags); + SetFlags(GetFlags() | IS_INTERESTING_SYMBOL); } bool IsPrivateNameSymbol() const { - JSTaggedValue flags = this->GetFlags(); - ASSERT(flags.IsInteger()); - return (flags.GetRawData() & IS_PRIVATE_NAME) != 0U; + return (GetFlags() & IS_PRIVATE_NAME) != 0U; } void SetPrivateNameSymbol(const JSThread *thread) { - JSTaggedValue flags = this->GetFlags(); - if (flags.IsUndefined()) { - SetFlags(thread, JSTaggedValue(static_cast(IS_PRIVATE_NAME))); - return; - } - flags = JSTaggedValue(static_cast(flags.GetRawData() | IS_PRIVATE_NAME)); - SetFlags(thread, flags); + SetFlags(GetFlags() | IS_PRIVATE_NAME); } static bool Equal(const JSSymbol &src, const JSSymbol &dst) @@ -148,14 +109,15 @@ public: } public: - static constexpr size_t HASHFIELD_OFFSET = TaggedObjectSize(); - ACCESSORS(HashField, HASHFIELD_OFFSET, FLAGS_OFFSET) - ACCESSORS(Flags, FLAGS_OFFSET, DESCRIPTION_OFFSET) - ACCESSORS(Description, DESCRIPTION_OFFSET, SIZE) + static constexpr size_t DESCRIPTION_OFFSET = TaggedObjectSize(); + ACCESSORS(Description, DESCRIPTION_OFFSET, HASHFIELD_OFFSET) + ACCESSORS_PRIMITIVE_FIELD(HashField, uint32_t, HASHFIELD_OFFSET, FLAGS_OFFSET) + ACCESSORS_PRIMITIVE_FIELD(Flags, uint32_t, FLAGS_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); DECL_DUMP() - DECL_VISIT_OBJECT(HASHFIELD_OFFSET, SIZE) + DECL_VISIT_OBJECT(DESCRIPTION_OFFSET, HASHFIELD_OFFSET) }; } // namespace ecmascript } // namespace panda diff --git a/ecmascript/js_tagged_value-inl.h b/ecmascript/js_tagged_value-inl.h index a1137e7780..b5897f1339 100644 --- a/ecmascript/js_tagged_value-inl.h +++ b/ecmascript/js_tagged_value-inl.h @@ -437,11 +437,6 @@ inline bool JSTaggedValue::IsProgram() const return IsHeapObject() && GetTaggedObject()->GetClass()->IsProgram(); } -inline bool JSTaggedValue::IsLexicalFunction() const -{ - return IsHeapObject() && GetTaggedObject()->GetClass()->IsLexicalFunction(); -} - inline bool JSTaggedValue::IsJSPromiseExecutorFunction() const { return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSPromiseExecutorFunction(); @@ -527,11 +522,6 @@ inline bool JSTaggedValue::IsJSError() const return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSError(); } -inline bool JSTaggedValue::IsJSFunctionExtraInfo() const -{ - return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSFunctionExtraInfo(); -} - inline bool JSTaggedValue::IsMicroJobQueue() const { return IsHeapObject() && GetTaggedObject()->GetClass()->IsMicroJobQueue(); @@ -970,7 +960,7 @@ inline uint32_t JSTaggedValue::GetKeyHashCode() const return EcmaString::Cast(GetTaggedObject())->GetHashcode(); } - return static_cast(JSSymbol::Cast(GetTaggedObject())->GetHashField().GetInt()); + return JSSymbol::Cast(GetTaggedObject())->GetHashField(); } } // namespace panda::ecmascript #endif // ECMASCRIPT_TAGGED_VALUE__INL_H diff --git a/ecmascript/js_tagged_value.h b/ecmascript/js_tagged_value.h index f64bbadcc7..ae8c1bec2d 100644 --- a/ecmascript/js_tagged_value.h +++ b/ecmascript/js_tagged_value.h @@ -291,7 +291,6 @@ public: bool IsRecord() const; bool IsPromiseReaction() const; bool IsProgram() const; - bool IsLexicalFunction() const; bool IsJSPromiseReactionFunction() const; bool IsJSPromiseExecutorFunction() const; bool IsJSPromiseAllResolveElementFunction() const; @@ -302,7 +301,6 @@ public: bool IsCompletionRecord() const; bool IsDataView() const; bool IsTemplateMap() const; - bool IsJSFunctionExtraInfo() const; bool IsMicroJobQueue() const; bool IsPendingJob() const; bool IsJSLocale() const; diff --git a/ecmascript/linked_hash_table.cpp b/ecmascript/linked_hash_table.cpp index 8a94a07ba9..520c9d1577 100644 --- a/ecmascript/linked_hash_table.cpp +++ b/ecmascript/linked_hash_table.cpp @@ -275,7 +275,7 @@ int LinkedHash::Hash(JSTaggedValue key) } if (key.IsSymbol()) { auto symbolString = JSSymbol::Cast(key.GetHeapObject()); - return static_cast(symbolString->GetHashField()).GetInt(); + return symbolString->GetHashField(); } if (key.IsString()) { auto keyString = reinterpret_cast(key.GetHeapObject()); diff --git a/ecmascript/mem/machine_code.h b/ecmascript/mem/machine_code.h index ad4217cd26..3b7c31e8af 100644 --- a/ecmascript/mem/machine_code.h +++ b/ecmascript/mem/machine_code.h @@ -33,8 +33,9 @@ public: } static constexpr size_t INS_SIZE_OFFSET = TaggedObjectSize(); - ACCESSORS(InstructionSizeInBytes, INS_SIZE_OFFSET, DATA_OFFSET); - static constexpr size_t SIZE = DATA_OFFSET; + ACCESSORS_PRIMITIVE_FIELD(InstructionSizeInBytes, uint32_t, INS_SIZE_OFFSET, LAST_OFFSET); + DEFINE_ALIGN_SIZE(LAST_OFFSET); + static constexpr size_t DATA_OFFSET = SIZE; DECL_DUMP() @@ -50,7 +51,7 @@ public: return; } if (memcpy_s(reinterpret_cast(this->GetDataOffsetAddress()), - this->GetInstructionSizeInBytes().GetInt(), stackMapData, codeLength) != EOK) { + this->GetInstructionSizeInBytes(), stackMapData, codeLength) != EOK) { LOG_ECMA_MEM(ERROR) << "memcpy fail in creating new code object "; return; } @@ -68,7 +69,7 @@ public: size_t GetMachineCodeObjectSize(void) { - return SIZE + this->GetInstructionSizeInBytes().GetInt(); + return SIZE + this->GetInstructionSizeInBytes(); } }; } // namespace ecmascript diff --git a/ecmascript/mem/object_xray-inl.h b/ecmascript/mem/object_xray-inl.h index 1e6a52a782..6c557efdd8 100644 --- a/ecmascript/mem/object_xray-inl.h +++ b/ecmascript/mem/object_xray-inl.h @@ -253,9 +253,6 @@ void ObjectXRay::VisitObjectBody(TaggedObject *object, JSHClass *klass, const Ec case JSType::PENDING_JOB: job::PendingJob::Cast(object)->VisitRangeSlot(visitor); break; - case JSType::FUNCTION_EXTRA_INFO: - JSFunctionExtraInfo::Cast(object)->VisitRangeSlot(visitor); - break; case JSType::COMPLETION_RECORD: CompletionRecord::Cast(object)->VisitRangeSlot(visitor); break; @@ -265,9 +262,6 @@ void ObjectXRay::VisitObjectBody(TaggedObject *object, JSHClass *klass, const Ec case JSType::PROGRAM: Program::Cast(object)->VisitRangeSlot(visitor); break; - case JSType::LEXICAL_FUNCTION: - LexicalFunction::Cast(object)->VisitRangeSlot(visitor); - break; case JSType::JS_INTL: JSIntl::Cast(object)->VisitRangeSlot(visitor); break; diff --git a/ecmascript/napi/include/jsnapi.h b/ecmascript/napi/include/jsnapi.h index 8422f4a72d..65d8e32453 100755 --- a/ecmascript/napi/include/jsnapi.h +++ b/ecmascript/napi/include/jsnapi.h @@ -602,10 +602,10 @@ public: class PUBLIC_API DataViewRef : public ObjectRef { public: - static Local New(const EcmaVM *vm, Local arrayBuffer, int32_t byteOffset, - int32_t byteLength); - int32_t ByteLength(); - int32_t ByteOffset(); + static Local New(const EcmaVM *vm, Local arrayBuffer, uint32_t byteOffset, + uint32_t byteLength); + uint32_t ByteLength(); + uint32_t ByteOffset(); Local GetArrayBuffer(const EcmaVM *vm); }; diff --git a/ecmascript/napi/jsnapi.cpp b/ecmascript/napi/jsnapi.cpp index 17179f1d9f..30b4180b0a 100755 --- a/ecmascript/napi/jsnapi.cpp +++ b/ecmascript/napi/jsnapi.cpp @@ -69,7 +69,6 @@ using ecmascript::JSDataView; using ecmascript::JSDate; using ecmascript::JSFunction; using ecmascript::JSFunctionBase; -using ecmascript::JSFunctionExtraInfo; using ecmascript::JSHClass; using ecmascript::JSMap; using ecmascript::JSMethod; @@ -829,9 +828,8 @@ Local FunctionRef::New(EcmaVM *vm, FunctionCallback nativeFunc, voi ObjectFactory *factory = vm->GetFactory(); JSHandle env = vm->GetGlobalEnv(); JSHandle current(factory->NewJSFunction(env, reinterpret_cast(Callback::RegisterCallback))); - JSHandle funcCallback = factory->NewJSNativePointer(reinterpret_cast(nativeFunc)); - JSHandle dataCaddress = factory->NewJSNativePointer(data); - JSHandle extraInfo(factory->NewFunctionExtraInfo(funcCallback, dataCaddress)); + JSHandle extraInfo = + factory->NewJSNativePointer(reinterpret_cast(nativeFunc), nullptr, data); current->SetFunctionExtraInfo(thread, extraInfo.GetTaggedValue()); return JSNApiHelper::ToLocal(JSHandle(current)); } @@ -842,10 +840,9 @@ Local FunctionRef::New(EcmaVM *vm, FunctionCallback nativeFunc, Del ObjectFactory *factory = vm->GetFactory(); JSHandle env = vm->GetGlobalEnv(); JSHandle current(factory->NewJSFunction(env, reinterpret_cast(Callback::RegisterCallback))); - JSHandle funcCallback = factory->NewJSNativePointer(reinterpret_cast(nativeFunc)); - JSHandle dataCaddress = factory->NewJSNativePointer(data, deleter, nullptr); - vm->PushToArrayDataList(*dataCaddress); - JSHandle extraInfo(factory->NewFunctionExtraInfo(funcCallback, dataCaddress)); + JSHandle extraInfo = + factory->NewJSNativePointer(reinterpret_cast(nativeFunc), deleter, data); + vm->PushToArrayDataList(*extraInfo); current->SetFunctionExtraInfo(thread, extraInfo.GetTaggedValue()); return JSNApiHelper::ToLocal(JSHandle(current)); } @@ -856,10 +853,9 @@ Local FunctionRef::NewWithProperty(EcmaVM *vm, FunctionCallback nat ObjectFactory *factory = vm->GetFactory(); JSHandle env = vm->GetGlobalEnv(); JSHandle current = - factory->NewJSFunction(env, reinterpret_cast(Callback::RegisterCallbackWithProperty)); - JSHandle funcCallback = factory->NewJSNativePointer(reinterpret_cast(nativeFunc)); - JSHandle dataCaddress = factory->NewJSNativePointer(data); - JSHandle extraInfo(factory->NewFunctionExtraInfo(funcCallback, dataCaddress)); + factory->NewJSFunction(env, reinterpret_cast(Callback::RegisterCallbackWithProperty)); + JSHandle extraInfo = + factory->NewJSNativePointer(reinterpret_cast(nativeFunc), nullptr, data); current->SetFunctionExtraInfo(thread, extraInfo.GetTaggedValue()); return JSNApiHelper::ToLocal(JSHandle(current)); } @@ -881,15 +877,11 @@ Local FunctionRef::NewClassFunction(EcmaVM *vm, FunctionCallbackWit current->SetPropertyInlinedProps(thread, JSFunction::CLASS_PROTOTYPE_INLINE_PROPERTY_INDEX, accessor.GetTaggedValue()); - JSHandle funcCallback = factory->NewJSNativePointer(reinterpret_cast(nativeFunc)); - JSHandle dataCaddress(thread, JSTaggedValue::Undefined()); - if (deleter == nullptr) { - dataCaddress = factory->NewJSNativePointer(data); - } else { - dataCaddress = factory->NewJSNativePointer(data, deleter, nullptr); - vm->PushToArrayDataList(*dataCaddress); + JSHandle extraInfo = + factory->NewJSNativePointer(reinterpret_cast(nativeFunc), deleter, data); + if (deleter != nullptr) { + vm->PushToArrayDataList(*extraInfo); } - JSHandle extraInfo(factory->NewFunctionExtraInfo(funcCallback, dataCaddress)); current->SetFunctionExtraInfo(thread, extraInfo.GetTaggedValue()); JSHandle clsPrototype = JSFunction::NewJSFunctionPrototype(thread, factory, current); @@ -1165,13 +1157,8 @@ Local ArrayBufferRef::New( int32_t ArrayBufferRef::ByteLength(const EcmaVM *vm) { - JSThread *thread = vm->GetJSThread(); JSHandle arrayBuffer(JSNApiHelper::ToJSHandle(this)); - JSHandle length(thread, arrayBuffer->GetArrayBufferByteLength()); - if (!length->IsNumber()) { - return 0; - } - return length->GetNumber(); + return arrayBuffer->GetArrayBufferByteLength(); } void *ArrayBufferRef::GetBuffer() @@ -1187,7 +1174,7 @@ void *ArrayBufferRef::GetBuffer() // ---------------------------------- DataView ----------------------------------- Local DataViewRef::New( - const EcmaVM *vm, Local arrayBuffer, int32_t byteOffset, int32_t byteLength) + const EcmaVM *vm, Local arrayBuffer, uint32_t byteOffset, uint32_t byteLength) { JSThread *thread = vm->GetJSThread(); ObjectFactory *factory = vm->GetFactory(); @@ -1198,24 +1185,16 @@ Local DataViewRef::New( return JSNApiHelper::ToLocal(JSHandle(dataView)); } -int32_t DataViewRef::ByteLength() +uint32_t DataViewRef::ByteLength() { JSHandle dataView(JSNApiHelper::ToJSHandle(this)); - JSTaggedValue length = dataView->GetByteLength(); - if (!length.IsNumber()) { - return 0; - } - return length.GetNumber(); + return dataView->GetByteLength(); } -int32_t DataViewRef::ByteOffset() +uint32_t DataViewRef::ByteOffset() { JSHandle dataView(JSNApiHelper::ToJSHandle(this)); - JSTaggedValue offset = dataView->GetByteOffset(); - if (!offset.IsNumber()) { - return 0; - } - return offset.GetNumber(); + return dataView->GetByteOffset(); } Local DataViewRef::GetArrayBuffer(const EcmaVM *vm) @@ -1407,10 +1386,10 @@ JSTaggedValue Callback::RegisterCallback(ecmascript::EcmaRuntimeCallInfo *info) } JSHandle function(constructor); JSHandle extraInfoValue(thread, function->GetFunctionExtraInfo()); - if (!extraInfoValue->IsJSFunctionExtraInfo()) { + if (!extraInfoValue->IsJSNativePointer()) { return JSTaggedValue::False(); } - JSHandle extraInfo(extraInfoValue); + JSHandle extraInfo(extraInfoValue); // vm Region *region = Region::ObjectAddressToRange(extraInfo.GetTaggedValue().GetTaggedObject()); if (region == nullptr) { @@ -1418,18 +1397,9 @@ JSTaggedValue Callback::RegisterCallback(ecmascript::EcmaRuntimeCallInfo *info) } EcmaVM *vm = region->GetHeap()->GetEcmaVM(); // data - JSHandle data(thread, extraInfo->GetData()); - if (!data->IsHeapObject()) { - return JSTaggedValue::False(); - } - JSHandle dataObj(data); + void *data = extraInfo->GetData(); // callBack - JSHandle callBack(thread, extraInfo->GetCallback()); - if (!callBack->IsHeapObject()) { - return JSTaggedValue::False(); - } - JSHandle callBackObj(callBack); - FunctionCallback nativeFunc = (reinterpret_cast(callBackObj->GetExternalPointer())); + FunctionCallback nativeFunc = reinterpret_cast(extraInfo->GetExternalPointer()); // this JSHandle thisValue(BuiltinsBase::GetThis(info)); @@ -1445,7 +1415,7 @@ JSTaggedValue Callback::RegisterCallback(ecmascript::EcmaRuntimeCallInfo *info) JSNApiHelper::ToLocal(thisValue), arguments.data(), arguments.size(), - dataObj->GetExternalPointer()); + data); return JSNApiHelper::ToJSHandle(result).GetTaggedValue(); } @@ -1459,10 +1429,10 @@ JSTaggedValue Callback::RegisterCallbackWithProperty(ecmascript::EcmaRuntimeCall } JSHandle function(constructor); JSHandle extraInfoValue(thread, function->GetFunctionExtraInfo()); - if (!extraInfoValue->IsJSFunctionExtraInfo()) { + if (!extraInfoValue->IsJSNativePointer()) { return JSTaggedValue::False(); } - JSHandle extraInfo(extraInfoValue); + JSHandle extraInfo(extraInfoValue); // vm Region *region = Region::ObjectAddressToRange(extraInfo.GetTaggedValue().GetTaggedObject()); if (region == nullptr) { @@ -1470,18 +1440,9 @@ JSTaggedValue Callback::RegisterCallbackWithProperty(ecmascript::EcmaRuntimeCall } EcmaVM *vm = region->GetHeap()->GetEcmaVM(); // data - JSHandle data(thread, extraInfo->GetData()); - if (!data->IsHeapObject()) { - return JSTaggedValue::False(); - } - JSHandle dataObj(data); + void *data = extraInfo->GetData(); // callBack - JSHandle callBack(thread, extraInfo->GetCallback()); - if (!callBack->IsHeapObject()) { - return JSTaggedValue::False(); - } - JSHandle callBackObj(callBack); - FunctionCallback nativeFunc = (reinterpret_cast(callBackObj->GetExternalPointer())); + FunctionCallback nativeFunc = reinterpret_cast(extraInfo->GetExternalPointer()); // constructor JSHandle thisValue(BuiltinsBase::GetConstructor(info)); @@ -1497,7 +1458,7 @@ JSTaggedValue Callback::RegisterCallbackWithProperty(ecmascript::EcmaRuntimeCall JSNApiHelper::ToLocal(thisValue), arguments.data(), arguments.size(), - dataObj->GetExternalPointer()); + data); return JSNApiHelper::ToJSHandle(result).GetTaggedValue(); } @@ -1511,10 +1472,10 @@ JSTaggedValue Callback::RegisterCallbackWithNewTarget(ecmascript::EcmaRuntimeCal } JSHandle function(constructor); JSHandle extraInfoValue(thread, function->GetFunctionExtraInfo()); - if (!extraInfoValue->IsJSFunctionExtraInfo()) { + if (!extraInfoValue->IsJSNativePointer()) { return JSTaggedValue::False(); } - JSHandle extraInfo(extraInfoValue); + JSHandle extraInfo(extraInfoValue); // vm Region *region = Region::ObjectAddressToRange(extraInfo.GetTaggedValue().GetTaggedObject()); if (region == nullptr) { @@ -1522,19 +1483,10 @@ JSTaggedValue Callback::RegisterCallbackWithNewTarget(ecmascript::EcmaRuntimeCal } EcmaVM *vm = region->GetHeap()->GetEcmaVM(); // data - JSHandle data(thread, extraInfo->GetData()); - if (!data->IsHeapObject()) { - return JSTaggedValue::False(); - } - JSHandle dataObj(data); + void *data = extraInfo->GetData(); // callBack - JSHandle callBack(thread, extraInfo->GetCallback()); - if (!callBack->IsHeapObject()) { - return JSTaggedValue::False(); - } - JSHandle callBackObj(callBack); FunctionCallbackWithNewTarget nativeFunc = - (reinterpret_cast(callBackObj->GetExternalPointer())); + reinterpret_cast(extraInfo->GetExternalPointer()); // newTarget JSHandle newTarget(BuiltinsBase::GetNewTarget(info)); @@ -1554,7 +1506,7 @@ JSTaggedValue Callback::RegisterCallbackWithNewTarget(ecmascript::EcmaRuntimeCal JSNApiHelper::ToLocal(newTarget), arguments.data(), arguments.size(), - dataObj->GetExternalPointer()); + data); return JSNApiHelper::ToJSHandle(result).GetTaggedValue(); } diff --git a/ecmascript/object_factory.cpp b/ecmascript/object_factory.cpp index e7dd9e0f0d..00076aaee6 100644 --- a/ecmascript/object_factory.cpp +++ b/ecmascript/object_factory.cpp @@ -151,7 +151,6 @@ void ObjectFactory::ObtainRootClass([[maybe_unused]] const JSHandle & JSHClass::Cast(globalConst->GetPromiseResolvingFunctionsRecordClass().GetTaggedObject()); transitionHandlerClass_ = JSHClass::Cast(globalConst->GetTransitionHandlerClass().GetTaggedObject()); prototypeHandlerClass_ = JSHClass::Cast(globalConst->GetPrototypeHandlerClass().GetTaggedObject()); - functionExtraInfo_ = JSHClass::Cast(globalConst->GetFunctionExtraInfoClass().GetTaggedObject()); jsRealmClass_ = JSHClass::Cast(globalConst->GetJSRealmClass().GetTaggedObject()); machineCodeClass_ = JSHClass::Cast(globalConst->GetMachineCodeClass().GetTaggedObject()); classInfoExtractorHClass_ = JSHClass::Cast(globalConst->GetClassInfoExtractorHClass().GetTaggedObject()); @@ -206,7 +205,7 @@ JSHandle ObjectFactory::NewJSArrayBuffer(int32_t length) JSHandle constructor(env->GetArrayBufferFunction()); JSHandle newTarget(constructor); JSHandle arrayBuffer(NewJSObjectByConstructor(constructor, newTarget)); - arrayBuffer->SetArrayBufferByteLength(thread_, JSTaggedValue(length)); + arrayBuffer->SetArrayBufferByteLength(length); if (length > 0) { auto newData = vm_->GetRegionFactory()->AllocateBuffer(length); if (memset_s(newData, length, 0, length) != EOK) { @@ -216,7 +215,7 @@ JSHandle ObjectFactory::NewJSArrayBuffer(int32_t length) JSHandle pointer = NewJSNativePointer(newData, RegionFactory::FreeBufferFunc, vm_->GetRegionFactory()); arrayBuffer->SetArrayBufferData(thread_, pointer.GetTaggedValue()); - arrayBuffer->SetShared(thread_, JSTaggedValue::False()); + arrayBuffer->ClearBitField(); vm_->PushToArrayDataList(*pointer); } return arrayBuffer; @@ -231,24 +230,20 @@ JSHandle ObjectFactory::NewJSArrayBuffer(void *buffer, int32_t le JSHandle newTarget(constructor); JSHandle arrayBuffer(NewJSObjectByConstructor(constructor, newTarget)); length = buffer == nullptr ? 0 : length; - arrayBuffer->SetArrayBufferByteLength(thread_, JSTaggedValue(length)); + arrayBuffer->SetArrayBufferByteLength(length); if (length > 0) { JSHandle pointer = NewJSNativePointer(buffer, deleter, data); arrayBuffer->SetArrayBufferData(thread_, pointer.GetTaggedValue()); - arrayBuffer->SetShared(thread_, JSTaggedValue(share)); + arrayBuffer->SetShared(share); vm_->PushToArrayDataList(*pointer); } return arrayBuffer; } -JSHandle ObjectFactory::NewJSDataView(JSHandle buffer, int32_t offset, int32_t length) +JSHandle ObjectFactory::NewJSDataView(JSHandle buffer, uint32_t offset, uint32_t length) { - JSTaggedValue arrayLength = buffer->GetArrayBufferByteLength(); - if (!arrayLength.IsNumber()) { - THROW_TYPE_ERROR_AND_RETURN(thread_, "ArrayBuffer length error", - JSHandle(thread_, JSTaggedValue::Undefined())); - } - if (offset + length > arrayLength.GetNumber()) { + uint32_t arrayLength = buffer->GetArrayBufferByteLength(); + if (arrayLength - offset < length) { THROW_TYPE_ERROR_AND_RETURN(thread_, "offset or length error", JSHandle(thread_, JSTaggedValue::Undefined())); } @@ -259,8 +254,8 @@ JSHandle ObjectFactory::NewJSDataView(JSHandle buffer JSHandle arrayBuffer(NewJSObjectByConstructor(constructor, newTarget)); arrayBuffer->SetDataView(thread_, JSTaggedValue::True()); arrayBuffer->SetViewedArrayBuffer(thread_, buffer.GetTaggedValue()); - arrayBuffer->SetByteLength(thread_, JSTaggedValue(length)); - arrayBuffer->SetByteOffset(thread_, JSTaggedValue(offset)); + arrayBuffer->SetByteLength(length); + arrayBuffer->SetByteOffset(offset); return arrayBuffer; } @@ -284,7 +279,7 @@ void ObjectFactory::NewJSRegExpByteCodeData(const JSHandle ®exp, vo JSHandle pointer = NewJSNativePointer(newBuffer, RegionFactory::FreeBufferFunc, vm_->GetRegionFactory()); regexp->SetByteCodeBuffer(thread_, pointer.GetTaggedValue()); - regexp->SetLength(thread_, JSTaggedValue(static_cast(size))); + regexp->SetLength(static_cast(size)); // push uint8_t* to ecma array_data_list vm_->PushToArrayDataList(*pointer); @@ -526,9 +521,9 @@ JSHandle ObjectFactory::NewJSForinIterator(const JSHandle it = JSHandle::Cast(NewJSObject(dynclass)); it->SetObject(thread_, obj); - it->SetWasVisited(thread_, JSTaggedValue::False()); it->SetVisitedKeys(thread_, env->GetEmptyTaggedQueue()); it->SetRemainingKeys(thread_, env->GetEmptyTaggedQueue()); + it->ClearBitField(); return it; } @@ -767,7 +762,7 @@ JSHandle ObjectFactory::NewJSObjectByConstructor(const JSHandleSetByteCodeBuffer(thread_, JSTaggedValue::Undefined()); JSRegExp::Cast(*obj)->SetOriginalSource(thread_, JSTaggedValue::Undefined()); JSRegExp::Cast(*obj)->SetOriginalFlags(thread_, JSTaggedValue(0)); - JSRegExp::Cast(*obj)->SetLength(thread_, JSTaggedValue(0)); + JSRegExp::Cast(*obj)->SetLength(0); break; case JSType::JS_PRIMITIVE_REF: JSPrimitiveRef::Cast(*obj)->SetValue(thread_, JSTaggedValue::Undefined()); @@ -785,33 +780,33 @@ JSHandle ObjectFactory::NewJSObjectByConstructor(const JSHandleSetLinkedSet(thread_, JSTaggedValue::Undefined()); break; case JSType::JS_GENERATOR_OBJECT: - JSGeneratorObject::Cast(*obj)->SetGeneratorState(thread_, JSTaggedValue::Undefined()); JSGeneratorObject::Cast(*obj)->SetGeneratorContext(thread_, JSTaggedValue::Undefined()); JSGeneratorObject::Cast(*obj)->SetResumeResult(thread_, JSTaggedValue::Undefined()); - JSGeneratorObject::Cast(*obj)->SetResumeMode(thread_, JSTaggedValue::Undefined()); + JSGeneratorObject::Cast(*obj)->SetGeneratorState(JSGeneratorState::UNDEFINED); + JSGeneratorObject::Cast(*obj)->SetResumeMode(GeneratorResumeMode::UNDEFINED); break; case JSType::JS_STRING_ITERATOR: - JSStringIterator::Cast(*obj)->SetStringIteratorNextIndex(thread_, JSTaggedValue(0)); + JSStringIterator::Cast(*obj)->SetStringIteratorNextIndex(0); JSStringIterator::Cast(*obj)->SetIteratedString(thread_, JSTaggedValue::Undefined()); break; case JSType::JS_ARRAY_BUFFER: - JSArrayBuffer::Cast(*obj)->SetArrayBufferByteLength(thread_, JSTaggedValue(0)); JSArrayBuffer::Cast(*obj)->SetArrayBufferData(thread_, JSTaggedValue::Undefined()); + JSArrayBuffer::Cast(*obj)->SetArrayBufferByteLength(0); + JSArrayBuffer::Cast(*obj)->ClearBitField(); break; case JSType::JS_PROMISE: - JSPromise::Cast(*obj)->SetPromiseState(thread_, - JSTaggedValue(static_cast(PromiseStatus::PENDING))); + JSPromise::Cast(*obj)->SetPromiseState(PromiseState::PENDING); JSPromise::Cast(*obj)->SetPromiseResult(thread_, JSTaggedValue::Undefined()); JSPromise::Cast(*obj)->SetPromiseRejectReactions(thread_, GetEmptyTaggedQueue().GetTaggedValue()); JSPromise::Cast(*obj)->SetPromiseFulfillReactions(thread_, GetEmptyTaggedQueue().GetTaggedValue()); - JSPromise::Cast(*obj)->SetPromiseIsHandled(thread_, JSTaggedValue::Undefined()); + JSPromise::Cast(*obj)->SetPromiseIsHandled(false); break; case JSType::JS_DATA_VIEW: JSDataView::Cast(*obj)->SetDataView(thread_, JSTaggedValue(false)); JSDataView::Cast(*obj)->SetViewedArrayBuffer(thread_, JSTaggedValue::Undefined()); - JSDataView::Cast(*obj)->SetByteLength(thread_, JSTaggedValue(0)); - JSDataView::Cast(*obj)->SetByteOffset(thread_, JSTaggedValue(0)); + JSDataView::Cast(*obj)->SetByteLength(0); + JSDataView::Cast(*obj)->SetByteOffset(0); break; case JSType::JS_ARRAY_LIST: JSArrayList::Cast(*obj)->SetLength(thread_, JSTaggedValue(0)); @@ -1127,12 +1122,12 @@ JSHandle ObjectFactory::NewJSAsyncFuncObject() return asyncFuncObject; } -JSHandle ObjectFactory::NewCompletionRecord(uint8_t type, JSHandle value) +JSHandle ObjectFactory::NewCompletionRecord(CompletionRecordType type, JSHandle value) { NewObjectHook(); TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(completionRecordClass_); JSHandle obj(thread_, header); - obj->SetType(thread_, JSTaggedValue(static_cast(type))); + obj->SetType(type); obj->SetValue(thread_, value); return obj; } @@ -1145,10 +1140,10 @@ JSHandle ObjectFactory::NewGeneratorContext() obj->SetRegsArray(thread_, JSTaggedValue::Undefined()); obj->SetMethod(thread_, JSTaggedValue::Undefined()); obj->SetAcc(thread_, JSTaggedValue::Undefined()); - obj->SetNRegs(thread_, JSTaggedValue::Undefined()); - obj->SetBCOffset(thread_, JSTaggedValue::Undefined()); obj->SetGeneratorObject(thread_, JSTaggedValue::Undefined()); obj->SetLexicalEnv(thread_, JSTaggedValue::Undefined()); + obj->SetNRegs(0); + obj->SetBCOffset(0); return obj; } @@ -1233,9 +1228,8 @@ JSHandle ObjectFactory::NewJSSymbol() TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(symbolClass_); JSHandle obj(thread_, JSSymbol::Cast(header)); obj->SetDescription(thread_, JSTaggedValue::Undefined()); - obj->SetFlags(thread_, JSTaggedValue(0)); - auto result = JSTaggedValue(static_cast(SymbolTable::Hash(obj.GetTaggedValue()))); - obj->SetHashField(thread_, result); + obj->SetFlags(0); + obj->SetHashField(SymbolTable::Hash(obj.GetTaggedValue())); return obj; } @@ -1251,11 +1245,10 @@ JSHandle ObjectFactory::NewPrivateNameSymbol(const JSHandle obj(thread_, JSSymbol::Cast(header)); - obj->SetFlags(thread_, JSTaggedValue(0)); + obj->SetFlags(0); obj->SetPrivateNameSymbol(thread_); obj->SetDescription(thread_, name); - auto result = JSTaggedValue(static_cast(SymbolTable::Hash(name.GetTaggedValue()))); - obj->SetHashField(thread_, result); + obj->SetHashField(SymbolTable::Hash(name.GetTaggedValue())); return obj; } @@ -1264,11 +1257,10 @@ JSHandle ObjectFactory::NewWellKnownSymbol(const JSHandle obj(thread_, JSSymbol::Cast(header)); - obj->SetFlags(thread_, JSTaggedValue(0)); + obj->SetFlags(0); obj->SetWellKnownSymbol(thread_); obj->SetDescription(thread_, name); - auto result = JSTaggedValue(static_cast(SymbolTable::Hash(name.GetTaggedValue()))); - obj->SetHashField(thread_, result); + obj->SetHashField(SymbolTable::Hash(name.GetTaggedValue())); return obj; } @@ -1277,10 +1269,9 @@ JSHandle ObjectFactory::NewPublicSymbol(const JSHandle NewObjectHook(); TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(symbolClass_); JSHandle obj(thread_, JSSymbol::Cast(header)); - obj->SetFlags(thread_, JSTaggedValue(0)); + obj->SetFlags(0); obj->SetDescription(thread_, name); - auto result = JSTaggedValue(static_cast(SymbolTable::Hash(name.GetTaggedValue()))); - obj->SetHashField(thread_, result); + obj->SetHashField(SymbolTable::Hash(name.GetTaggedValue())); return obj; } @@ -1371,18 +1362,17 @@ JSHandle ObjectFactory::NewPromiseReaction() JSHandle obj(thread_, header); obj->SetPromiseCapability(thread_, JSTaggedValue::Undefined()); obj->SetHandler(thread_, JSTaggedValue::Undefined()); - obj->SetType(thread_, JSTaggedValue::Undefined()); + obj->SetType(PromiseType::RESOLVE); return obj; } -JSHandle ObjectFactory::NewPromiseIteratorRecord(const JSHandle &itor, - const JSHandle &done) +JSHandle ObjectFactory::NewPromiseIteratorRecord(const JSHandle &itor, bool done) { NewObjectHook(); TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(promiseIteratorRecordClass_); JSHandle obj(thread_, header); obj->SetIterator(thread_, itor.GetTaggedValue()); - obj->SetDone(thread_, done.GetTaggedValue()); + obj->SetDone(done); return obj; } @@ -1407,17 +1397,6 @@ JSHandle ObjectFactory::NewPendingJob(const JSHandle ObjectFactory::NewFunctionExtraInfo(const JSHandle &callBack, - const JSHandle &data) -{ - NewObjectHook(); - TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(functionExtraInfo_); - JSHandle obj(thread_, header); - obj->SetCallback(thread_, callBack.GetTaggedValue()); - obj->SetData(thread_, data.GetTaggedValue()); - return obj; -} - JSHandle ObjectFactory::NewJSProxy(const JSHandle &target, const JSHandle &handler) { @@ -1767,7 +1746,7 @@ JSHandle ObjectFactory::NewProtoChangeMarker() NewObjectHook(); TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(protoChangeMarkerClass_); JSHandle marker(thread_, header); - marker->SetHasChanged(false); + marker->ClearBitField(); return marker; } @@ -1776,8 +1755,8 @@ JSHandle ObjectFactory::NewProtoChangeDetails() NewObjectHook(); TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(protoChangeDetailsClass_); JSHandle protoInfo(thread_, header); - protoInfo->SetChangeListener(thread_, JSTaggedValue(0)); - protoInfo->SetRegisterIndex(thread_, JSTaggedValue(ProtoChangeDetails::UNREGISTERED)); + protoInfo->SetChangeListener(thread_, JSTaggedValue::Undefined()); + protoInfo->SetRegisterIndex(ProtoChangeDetails::UNREGISTERED); return protoInfo; } @@ -1836,8 +1815,8 @@ JSHandle ObjectFactory::NewJSSetIterator(const JSHandle &s JSHandle iter(NewJSObject(dynHandle)); iter->GetJSHClass()->SetExtensible(true); iter->SetIteratedSet(thread_, set->GetLinkedSet()); - iter->SetNextIndex(thread_, JSTaggedValue(0)); - iter->SetIterationKind(thread_, JSTaggedValue(static_cast(kind))); + iter->SetNextIndex(0); + iter->SetIterationKind(kind); return iter; } @@ -1849,8 +1828,8 @@ JSHandle ObjectFactory::NewJSMapIterator(const JSHandle &m JSHandle iter(NewJSObject(dynHandle)); iter->GetJSHClass()->SetExtensible(true); iter->SetIteratedMap(thread_, map->GetLinkedMap()); - iter->SetNextIndex(thread_, JSTaggedValue(0)); - iter->SetIterationKind(thread_, JSTaggedValue(static_cast(kind))); + iter->SetNextIndex(0); + iter->SetIterationKind(kind); return iter; } @@ -1862,8 +1841,8 @@ JSHandle ObjectFactory::NewJSArrayIterator(const JSHandle iter(NewJSObject(dynHandle)); iter->GetJSHClass()->SetExtensible(true); iter->SetIteratedArray(thread_, array); - iter->SetNextIndex(thread_, JSTaggedValue(0)); - iter->SetIterationKind(thread_, JSTaggedValue(static_cast(kind))); + iter->SetNextIndex(0); + iter->SetIterationKind(kind); return iter; } @@ -2034,7 +2013,7 @@ JSHandle ObjectFactory::NewMachineCodeObject(size_t length, const u NewObjectHook(); TaggedObject *obj = heapHelper_.AllocateMachineCodeSpaceObject(machineCodeClass_, length + MachineCode::SIZE); MachineCode *code = MachineCode::Cast(obj); - code->SetInstructionSizeInBytes(thread_, JSTaggedValue(static_cast(length))); + code->SetInstructionSizeInBytes(static_cast(length)); if (data != nullptr) { code->SetData(data, length); } @@ -2047,7 +2026,7 @@ JSHandle ObjectFactory::NewClassInfoExtractor(JSMethod *ctor NewObjectHook(); TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(classInfoExtractorHClass_); JSHandle obj(thread_, header); - obj->InitializeBitField(); + obj->ClearBitField(); obj->SetConstructorMethod(ctorMethod); JSHandle emptyArray = EmptyArray(); obj->SetPrototypeHClass(thread_, JSTaggedValue::Undefined()); diff --git a/ecmascript/object_factory.h b/ecmascript/object_factory.h index fd4f1c91d1..c13019e824 100644 --- a/ecmascript/object_factory.h +++ b/ecmascript/object_factory.h @@ -73,7 +73,6 @@ class JSAsyncFunction; class PromiseRecord; class JSLocale; class ResolvingFunctionsRecord; -class JSFunctionExtraInfo; class EcmaVM; class Heap; class ConstantPool; @@ -97,8 +96,9 @@ class ProfileTypeInfo; class MachineCode; class ClassInfoExtractor; +enum class CompletionRecordType : uint8_t; enum class PrimitiveType : uint8_t; -enum class IterationKind; +enum class IterationKind : uint8_t; using ErrorType = base::ErrorType; using base::ErrorType; @@ -200,16 +200,12 @@ public: JSHandle NewResolvingFunctionsRecord(); - JSHandle NewPromiseIteratorRecord(const JSHandle &itor, - const JSHandle &done); + JSHandle NewPromiseIteratorRecord(const JSHandle &itor, bool done); JSHandle NewMicroJobQueue(); JSHandle NewPendingJob(const JSHandle &func, const JSHandle &argv); - JSHandle NewFunctionExtraInfo(const JSHandle &callBack, - const JSHandle &data); - JSHandle NewJSArray(); JSHandle NewJSProxy(const JSHandle &target, const JSHandle &handler); @@ -272,7 +268,7 @@ public: JSHandle NewJSArrayIterator(const JSHandle &array, IterationKind kind); - JSHandle NewCompletionRecord(uint8_t type, JSHandle value); + JSHandle NewCompletionRecord(CompletionRecordType type, JSHandle value); JSHandle NewGeneratorContext(); @@ -297,7 +293,7 @@ public: JSHandle NewJSArrayBuffer(void *buffer, int32_t length, const DeleteEntryPoint &deleter, void *data, bool share = false); - JSHandle NewJSDataView(JSHandle buffer, int32_t offset, int32_t length); + JSHandle NewJSDataView(JSHandle buffer, uint32_t offset, uint32_t length); void NewJSRegExpByteCodeData(const JSHandle ®exp, void *buffer, size_t size); @@ -406,7 +402,6 @@ private: JSHClass *jsNativePointerClass_ {nullptr}; JSHClass *transitionHandlerClass_ {nullptr}; JSHClass *prototypeHandlerClass_ {nullptr}; - JSHClass *functionExtraInfo_ {nullptr}; JSHClass *jsRealmClass_ {nullptr}; JSHClass *programClass_ {nullptr}; JSHClass *machineCodeClass_ {nullptr}; diff --git a/ecmascript/snapshot/mem/snapshot_serialize.cpp b/ecmascript/snapshot/mem/snapshot_serialize.cpp index 4e5971310b..2bc9b73ad0 100644 --- a/ecmascript/snapshot/mem/snapshot_serialize.cpp +++ b/ecmascript/snapshot/mem/snapshot_serialize.cpp @@ -1037,7 +1037,7 @@ void SnapShotSerialize::JSFunctionBaseSerialize(TaggedObject *objectHeader, uint // method auto functionBase = static_cast(objectHeader); - size_t methodOffset = functionBase->OffsetMethod(); + size_t methodOffset = JSFunctionBase::METHOD_OFFSET; auto nativePointer = reinterpret_cast(functionBase->GetMethod()); SetObjectSlotField(snapshotObj, methodOffset, NativePointerToSlotBit(nativePointer).GetValue()); @@ -1065,7 +1065,7 @@ void SnapShotSerialize::JSProxySerialize(TaggedObject *objectHeader, uintptr_t s // method auto jsproxy = static_cast(objectHeader); - size_t methodOffset = jsproxy->OffsetMethod(); + size_t methodOffset = JSProxy::METHOD_OFFSET; auto nativePointer = reinterpret_cast(jsproxy->GetMethod()); SetObjectSlotField(snapshotObj, methodOffset, NativePointerToSlotBit(nativePointer).GetValue()); diff --git a/ecmascript/stub_module.cpp b/ecmascript/stub_module.cpp index 4410018aeb..93a8ea25f2 100644 --- a/ecmascript/stub_module.cpp +++ b/ecmascript/stub_module.cpp @@ -25,7 +25,7 @@ void StubModule::Save(const std::string &filename) /* write stub entries offset */ modulefile.write(reinterpret_cast(fastStubEntries_.data()), sizeof(uint64_t) * (kungfu::FAST_STUB_MAXCOUNT)); - int codeSize = code_->GetInstructionSizeInBytes().GetInt(); + int codeSize = code_->GetInstructionSizeInBytes(); /* write host code section start addr */ modulefile.write(reinterpret_cast(&hostCodeSectionAddr_), sizeof(hostCodeSectionAddr_)); /* write stackmap offset */ diff --git a/ecmascript/tagged_array.h b/ecmascript/tagged_array.h index 5b247c07e0..aea22d70e9 100644 --- a/ecmascript/tagged_array.h +++ b/ecmascript/tagged_array.h @@ -84,8 +84,9 @@ public: inline void Trim(JSThread *thread, uint32_t newLength); static constexpr size_t LENGTH_OFFSET = TaggedObjectSize(); - SET_GET_PRIMITIVE_FIELD(Length, uint32_t, LENGTH_OFFSET, DATA_OFFSET); - static constexpr size_t SIZE = DATA_OFFSET; // Empty Array size + ACCESSORS_PRIMITIVE_FIELD(Length, uint32_t, LENGTH_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); + static constexpr size_t DATA_OFFSET = SIZE; // DATA_OFFSET equal to Empty Array size DECL_VISIT_ARRAY(DATA_OFFSET, GetLength()); diff --git a/ecmascript/tagged_dictionary.cpp b/ecmascript/tagged_dictionary.cpp index 3eff690db8..82ea3e3976 100644 --- a/ecmascript/tagged_dictionary.cpp +++ b/ecmascript/tagged_dictionary.cpp @@ -23,7 +23,7 @@ int NameDictionary::Hash(const JSTaggedValue &key) JSTaggedValue jsKey(key); if (jsKey.IsSymbol()) { auto symbolString = JSSymbol::Cast(key.GetTaggedObject()); - return static_cast(symbolString->GetHashField()).GetInt(); + return symbolString->GetHashField(); } if (jsKey.IsString()) { auto keyString = reinterpret_cast(key.GetTaggedObject()); diff --git a/ecmascript/tests/dump_test.cpp b/ecmascript/tests/dump_test.cpp index 4eb270982f..e890642570 100644 --- a/ecmascript/tests/dump_test.cpp +++ b/ecmascript/tests/dump_test.cpp @@ -42,7 +42,6 @@ #include "ecmascript/js_date_time_format.h" #include "ecmascript/js_for_in_iterator.h" #include "ecmascript/js_function.h" -#include "ecmascript/js_function_extra_info.h" #include "ecmascript/js_generator_object.h" #include "ecmascript/js_global_object.h" #include "ecmascript/js_handle.h" @@ -263,7 +262,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) break; } case JSType::JS_REG_EXP: { - CHECK_DUMP_FILEDS(JSObject::SIZE, JSRegExp::SIZE, 5) + CHECK_DUMP_FILEDS(JSObject::SIZE, JSRegExp::SIZE, 4) NEW_OBJECT_AND_DUMP(JSRegExp, JS_REG_EXP) break; } @@ -317,21 +316,21 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) break; } case JSType::JS_MAP_ITERATOR: { - CHECK_DUMP_FILEDS(JSObject::SIZE, JSMapIterator::SIZE, 3) + CHECK_DUMP_FILEDS(JSObject::SIZE, JSMapIterator::SIZE, 2) JSHandle jsMapIter = factory->NewJSMapIterator(NewJSMap(thread, factory, proto), IterationKind::KEY); DUMP_FOR_HANDLE(jsMapIter) break; } case JSType::JS_SET_ITERATOR: { - CHECK_DUMP_FILEDS(JSObject::SIZE, JSSetIterator::SIZE, 3) + CHECK_DUMP_FILEDS(JSObject::SIZE, JSSetIterator::SIZE, 2) JSHandle jsSetIter = factory->NewJSSetIterator(NewJSSet(thread, factory, proto), IterationKind::KEY); DUMP_FOR_HANDLE(jsSetIter) break; } case JSType::JS_ARRAY_ITERATOR: { - CHECK_DUMP_FILEDS(JSObject::SIZE, JSArrayIterator::SIZE, 3) + CHECK_DUMP_FILEDS(JSObject::SIZE, JSArrayIterator::SIZE, 2) JSHandle arrayIter = factory->NewJSArrayIterator(JSHandle::Cast(factory->NewJSArray()), IterationKind::KEY); DUMP_FOR_HANDLE(arrayIter) @@ -354,42 +353,42 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) break; } case JSType::JS_DATE_TIME_FORMAT: { - CHECK_DUMP_FILEDS(JSObject::SIZE, JSDateTimeFormat::SIZE, 11) + CHECK_DUMP_FILEDS(JSObject::SIZE, JSDateTimeFormat::SIZE, 9) NEW_OBJECT_AND_DUMP(JSDateTimeFormat, JS_DATE_TIME_FORMAT) break; } case JSType::JS_RELATIVE_TIME_FORMAT: { - CHECK_DUMP_FILEDS(JSObject::SIZE, JSRelativeTimeFormat::SIZE, 7) + CHECK_DUMP_FILEDS(JSObject::SIZE, JSRelativeTimeFormat::SIZE, 6) NEW_OBJECT_AND_DUMP(JSRelativeTimeFormat, JS_RELATIVE_TIME_FORMAT) break; } case JSType::JS_NUMBER_FORMAT: { - CHECK_DUMP_FILEDS(JSObject::SIZE, JSNumberFormat::SIZE, 20) + CHECK_DUMP_FILEDS(JSObject::SIZE, JSNumberFormat::SIZE, 13) NEW_OBJECT_AND_DUMP(JSNumberFormat, JS_NUMBER_FORMAT) break; } case JSType::JS_COLLATOR: { - CHECK_DUMP_FILEDS(JSObject::SIZE, JSCollator::SIZE, 9) + CHECK_DUMP_FILEDS(JSObject::SIZE, JSCollator::SIZE, 5) NEW_OBJECT_AND_DUMP(JSCollator, JS_COLLATOR) break; } case JSType::JS_PLURAL_RULES: { - CHECK_DUMP_FILEDS(JSObject::SIZE, JSPluralRules::SIZE, 11) + CHECK_DUMP_FILEDS(JSObject::SIZE, JSPluralRules::SIZE, 10) NEW_OBJECT_AND_DUMP(JSPluralRules, JS_PLURAL_RULES) break; } case JSType::JS_ARRAY_BUFFER: { - CHECK_DUMP_FILEDS(JSObject::SIZE, JSArrayBuffer::SIZE, 3) + CHECK_DUMP_FILEDS(JSObject::SIZE, JSArrayBuffer::SIZE, 2) NEW_OBJECT_AND_DUMP(JSArrayBuffer, JS_ARRAY_BUFFER) break; } case JSType::JS_PROMISE: { - CHECK_DUMP_FILEDS(JSObject::SIZE, JSPromise::SIZE, 5) + CHECK_DUMP_FILEDS(JSObject::SIZE, JSPromise::SIZE, 4) NEW_OBJECT_AND_DUMP(JSPromise, JS_PROMISE) break; } case JSType::JS_DATA_VIEW: { - CHECK_DUMP_FILEDS(JSObject::SIZE, JSDataView::SIZE, 4) + CHECK_DUMP_FILEDS(JSObject::SIZE, JSDataView::SIZE, 3) NEW_OBJECT_AND_DUMP(JSDataView, JS_DATA_VIEW) break; } @@ -399,7 +398,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) break; } case JSType::JS_GENERATOR_OBJECT: { - CHECK_DUMP_FILEDS(JSObject::SIZE, JSGeneratorObject::SIZE, 4) + CHECK_DUMP_FILEDS(JSObject::SIZE, JSGeneratorObject::SIZE, 3) NEW_OBJECT_AND_DUMP(JSGeneratorObject, JS_GENERATOR_OBJECT) break; } @@ -448,7 +447,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) break; } case JSType::HCLASS: { - CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), JSHClass::SIZE, 9) + CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), JSHClass::SIZE, 8) JSHandle hclass = factory->NewEcmaDynClass(JSHClass::SIZE, JSType::HCLASS, proto); DUMP_FOR_HANDLE(hclass) break; @@ -488,13 +487,13 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) break; } case JSType::SYMBOL: { - CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), JSSymbol::SIZE, 3) + CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), JSSymbol::SIZE, 2) JSHandle symbol = factory->NewJSSymbol(); DUMP_FOR_HANDLE(symbol) break; } case JSType::JS_GENERATOR_CONTEXT: { - CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), GeneratorContext::SIZE, 7) + CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), GeneratorContext::SIZE, 6) JSHandle genContext = factory->NewGeneratorContext(); DUMP_FOR_HANDLE(genContext) break; @@ -535,16 +534,15 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) break; } case JSType::PROGRAM: { +#ifdef PANDA_TARGET_64 CHECK_DUMP_FILEDS(ECMAObject::SIZE, Program::SIZE, 5) +#else + CHECK_DUMP_FILEDS(ECMAObject::SIZE, Program::SIZE, 4) +#endif JSHandle program = factory->NewProgram(); DUMP_FOR_HANDLE(program) break; } - case JSType::LEXICAL_FUNCTION: { - CHECK_DUMP_FILEDS(ECMAObject::SIZE, LexicalFunction::SIZE, 5) - // unused - break; - } case JSType::PROMISE_CAPABILITY: { CHECK_DUMP_FILEDS(Record::SIZE, PromiseCapability::SIZE, 3) JSHandle promiseCapa = factory->NewPromiseCapability(); @@ -572,7 +570,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) case JSType::PROMISE_ITERATOR_RECORD: { CHECK_DUMP_FILEDS(Record::SIZE, PromiseIteratorRecord::SIZE, 2) JSHandle emptyObj(thread, NewJSObject(thread, factory, globalEnv).GetTaggedValue()); - JSHandle promiseIter = factory->NewPromiseIteratorRecord(emptyObj, emptyObj); + JSHandle promiseIter = factory->NewPromiseIteratorRecord(emptyObj, false); DUMP_FOR_HANDLE(promiseIter) break; } @@ -590,17 +588,10 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) DUMP_FOR_HANDLE(pendingJob) break; } - case JSType::FUNCTION_EXTRA_INFO: { - CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), JSFunctionExtraInfo::SIZE, 2) - JSHandle funcExtraClass(thread, - JSHClass::Cast(globalConst->GetFunctionExtraInfoClass().GetTaggedObject())); - JSHandle funcInfo(thread, factory->NewDynObject(funcExtraClass)); - DUMP_FOR_HANDLE(funcInfo) - break; - } case JSType::COMPLETION_RECORD: { CHECK_DUMP_FILEDS(Record::SIZE, CompletionRecord::SIZE, 2) - JSHandle comRecord = factory->NewCompletionRecord(0, globalEnv->GetEmptyArray()); + JSHandle comRecord = + factory->NewCompletionRecord(CompletionRecordType::NORMAL, globalEnv->GetEmptyArray()); DUMP_FOR_HANDLE(comRecord) break; } @@ -617,7 +608,11 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) break; } case JSType::CLASS_INFO_EXTRACTOR: { +#ifdef PANDA_TARGET_64 CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), ClassInfoExtractor::SIZE, 10) +#else + CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), ClassInfoExtractor::SIZE, 9) +#endif JSHandle classInfoExtractor = factory->NewClassInfoExtractor(nullptr); DUMP_FOR_HANDLE(classInfoExtractor) break; diff --git a/ecmascript/tests/js_array_iterator_test.cpp b/ecmascript/tests/js_array_iterator_test.cpp index 34c06534a5..c776b0c481 100644 --- a/ecmascript/tests/js_array_iterator_test.cpp +++ b/ecmascript/tests/js_array_iterator_test.cpp @@ -122,15 +122,13 @@ HWTEST_F_L0(JSArrayIteratorTest, SetNextIndex) // Call "SetNextIndex" function through "NewJSArrayIterator" function of "object_factory.cpp". JSHandle handleJSArrayIter = factory->NewJSArrayIterator(handleJSObjectTaggedArray, IterationKind::KEY); - EXPECT_EQ(handleJSArrayIter->GetNextIndex().GetNumber(), 0); + EXPECT_EQ(handleJSArrayIter->GetNextIndex(), 0); int testQuantity = 100; for (int i = 1; i <= testQuantity; i++) { - JSHandle handleTagValNextIndex(thread, JSTaggedValue(i)); - // Call "SetNextIndex" function in this HWTEST_F_L0. - handleJSArrayIter->SetNextIndex(thread, handleTagValNextIndex); - EXPECT_EQ(handleJSArrayIter->GetNextIndex().GetNumber(), i); + handleJSArrayIter->SetNextIndex(i); + EXPECT_EQ(handleJSArrayIter->GetNextIndex(), i); } } @@ -153,26 +151,23 @@ HWTEST_F_L0(JSArrayIteratorTest, SetIterationKind) for (int i = 0; i < numArray; i++) { handleTaggedArray->Set(thread, i, JSTaggedValue(array[i])); } - JSHandle handleTagVal0(thread, JSTaggedValue(0)); - JSHandle handleTagVal1(thread, JSTaggedValue(1)); - JSHandle handleTagVal2(thread, JSTaggedValue(2)); JSHandle handleJSObjectTaggedArray(JSArray::CreateArrayFromList(thread, handleTaggedArray)); // Call "SetIterationKind" function through "NewJSArrayIterator" function of "object_factory.cpp". JSHandle handleJSArrayIter = factory->NewJSArrayIterator(handleJSObjectTaggedArray, IterationKind::KEY); - EXPECT_EQ(handleJSArrayIter->GetIterationKind().GetNumber(), 0); + EXPECT_EQ(handleJSArrayIter->GetIterationKind(), IterationKind::KEY); handleJSArrayIter = factory->NewJSArrayIterator(handleJSObjectTaggedArray, IterationKind::VALUE); - EXPECT_EQ(handleJSArrayIter->GetIterationKind().GetNumber(), 1); + EXPECT_EQ(handleJSArrayIter->GetIterationKind(), IterationKind::VALUE); handleJSArrayIter = factory->NewJSArrayIterator(handleJSObjectTaggedArray, IterationKind::KEY_AND_VALUE); - EXPECT_EQ(handleJSArrayIter->GetIterationKind().GetNumber(), 2); + EXPECT_EQ(handleJSArrayIter->GetIterationKind(), IterationKind::KEY_AND_VALUE); // Call "SetIterationKind" function in this HWTEST_F_L0. - handleJSArrayIter->SetIterationKind(thread, handleTagVal0); - EXPECT_EQ(handleJSArrayIter->GetIterationKind().GetNumber(), 0); - handleJSArrayIter->SetIterationKind(thread, handleTagVal1); - EXPECT_EQ(handleJSArrayIter->GetIterationKind().GetNumber(), 1); - handleJSArrayIter->SetIterationKind(thread, handleTagVal2); - EXPECT_EQ(handleJSArrayIter->GetIterationKind().GetNumber(), 2); + handleJSArrayIter->SetIterationKind(IterationKind::KEY); + EXPECT_EQ(handleJSArrayIter->GetIterationKind(), IterationKind::KEY); + handleJSArrayIter->SetIterationKind(IterationKind::VALUE); + EXPECT_EQ(handleJSArrayIter->GetIterationKind(), IterationKind::VALUE); + handleJSArrayIter->SetIterationKind(IterationKind::KEY_AND_VALUE); + EXPECT_EQ(handleJSArrayIter->GetIterationKind(), IterationKind::KEY_AND_VALUE); } } // namespace panda::ecmascript diff --git a/ecmascript/tests/js_dataview_test.cpp b/ecmascript/tests/js_dataview_test.cpp index 2c15663205..d4291e15e3 100644 --- a/ecmascript/tests/js_dataview_test.cpp +++ b/ecmascript/tests/js_dataview_test.cpp @@ -89,7 +89,7 @@ HWTEST_F_L0(JSDataViewTest, SetDataView) JSHandle handleTagValFuncArrayBuf(handleFuncArrayBuf); JSHandle handleArrayBuf( factory->NewJSObjectByConstructor(handleFuncArrayBuf, handleTagValFuncArrayBuf)); - handleArrayBuf->SetArrayBufferByteLength(thread, JSTaggedValue(lengthDataArrayBuf)); + handleArrayBuf->SetArrayBufferByteLength(lengthDataArrayBuf); // Call "SetDataView" function through "NewJSDataView" function of "object_factory.cpp" JSHandle handleDataView = factory->NewJSDataView(handleArrayBuf, offsetDataView, @@ -126,8 +126,8 @@ HWTEST_F_L0(JSDataViewTest, SetViewedArrayBuffer) factory->NewJSObjectByConstructor(handleFuncArrayBuf, handleTagValFuncArrayBuf)); JSHandle handleArrayBuf2( factory->NewJSObjectByConstructor(handleFuncArrayBuf, handleTagValFuncArrayBuf)); - handleArrayBuf1->SetArrayBufferByteLength(thread, JSTaggedValue(lengthDataArrayBuf1)); - handleArrayBuf2->SetArrayBufferByteLength(thread, JSTaggedValue(lengthDataArrayBuf2)); + handleArrayBuf1->SetArrayBufferByteLength(lengthDataArrayBuf1); + handleArrayBuf2->SetArrayBufferByteLength(lengthDataArrayBuf2); // Call "SetViewedArrayBuffer" function through "NewJSDataView" function of "object_factory.cpp" JSHandle handleDataView = factory->NewJSDataView(handleArrayBuf1, offsetDataView, @@ -163,19 +163,18 @@ HWTEST_F_L0(JSDataViewTest, SetByteLength) int32_t offsetDataView = 4; int32_t lengthDataView1 = 4; int32_t lengthDataView2 = 2; - JSHandle handleTagValLengthDataView2(thread, JSTaggedValue(lengthDataView2)); JSHandle handleArrayBuf( factory->NewJSObjectByConstructor(handleFuncArrayBuf, handleTagValFuncArrayBuf)); - handleArrayBuf->SetArrayBufferByteLength(thread, JSTaggedValue(lengthDataArrayBuf)); + handleArrayBuf->SetArrayBufferByteLength(lengthDataArrayBuf); // Call "SetByteLength" function through "NewJSDataView" function of "object_factory.cpp" JSHandle handleDataView = factory->NewJSDataView(handleArrayBuf, offsetDataView, lengthDataView1); - EXPECT_EQ(handleDataView->GetByteLength().GetNumber(), lengthDataView1); + EXPECT_EQ(handleDataView->GetByteLength(), lengthDataView1); // Call "SetByteLength" function in this HWTEST_F_L0. - handleDataView->SetByteLength(thread, handleTagValLengthDataView2); - EXPECT_EQ(handleDataView->GetByteLength().GetNumber(), lengthDataView2); + handleDataView->SetByteLength(lengthDataView2); + EXPECT_EQ(handleDataView->GetByteLength(), lengthDataView2); } /* @@ -197,18 +196,17 @@ HWTEST_F_L0(JSDataViewTest, SetByteOffset) int32_t offsetDataView1 = 4; int32_t offsetDataView2 = 6; int32_t lengthDataView = 2; - JSHandle handleTagValOffsetDataView2(thread, JSTaggedValue(offsetDataView2)); JSHandle handleArrayBuf( factory->NewJSObjectByConstructor(handleFuncArrayBuf1, handleTagValFuncArrayBuf1)); - handleArrayBuf->SetArrayBufferByteLength(thread, JSTaggedValue(lengthDataArrayBuf)); + handleArrayBuf->SetArrayBufferByteLength(lengthDataArrayBuf); // Call "SetByteOffset" function through "NewJSDataView" function of "object_factory.cpp" JSHandle handleDataView = factory->NewJSDataView(handleArrayBuf, offsetDataView1, lengthDataView); - EXPECT_EQ(handleDataView->GetByteOffset().GetNumber(), offsetDataView1); + EXPECT_EQ(handleDataView->GetByteOffset(), offsetDataView1); // Call "SetByteOffset" function in this HWTEST_F_L0. - handleDataView->SetByteOffset(thread, handleTagValOffsetDataView2); - EXPECT_EQ(handleDataView->GetByteOffset().GetNumber(), offsetDataView2); + handleDataView->SetByteOffset(offsetDataView2); + EXPECT_EQ(handleDataView->GetByteOffset(), offsetDataView2); } } // namespace panda::ecmascript diff --git a/ecmascript/tests/js_function_test.cpp b/ecmascript/tests/js_function_test.cpp index 2dff3f98d5..2f19d6b538 100644 --- a/ecmascript/tests/js_function_test.cpp +++ b/ecmascript/tests/js_function_test.cpp @@ -19,7 +19,6 @@ #include "ecmascript/ecma_vm.h" #include "ecmascript/global_env.h" #include "ecmascript/internal_call_params.h" -#include "ecmascript/js_function_extra_info.h" #include "ecmascript/js_handle.h" #include "ecmascript/js_hclass.h" #include "ecmascript/js_object-inl.h" diff --git a/ecmascript/tests/js_object_test.cpp b/ecmascript/tests/js_object_test.cpp index 1300618805..a4b42adff4 100644 --- a/ecmascript/tests/js_object_test.cpp +++ b/ecmascript/tests/js_object_test.cpp @@ -1035,11 +1035,11 @@ HWTEST_F_L0(JSObjectTest, EnableProtoChangeMarker) JSTaggedValue protoDetails1 = obj1Dynclass->GetProtoChangeDetails(); EXPECT_TRUE(protoDetails1.IsProtoChangeDetails()); JSTaggedValue listeners1 = ProtoChangeDetails::Cast(protoDetails1.GetTaggedObject())->GetChangeListener(); - EXPECT_TRUE(listeners1 != JSTaggedValue(0)); + EXPECT_TRUE(listeners1 != JSTaggedValue::Undefined()); JSTaggedValue listeners2 = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetChangeListener(); - EXPECT_TRUE(listeners2 == JSTaggedValue(0)); - JSTaggedValue index = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetRegisterIndex(); - JSTaggedValue listenersResult = ChangeListener::Cast(listeners1.GetTaggedObject())->Get(index.GetArrayLength()); + EXPECT_TRUE(listeners2 == JSTaggedValue::Undefined()); + uint32_t index = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetRegisterIndex(); + JSTaggedValue listenersResult = ChangeListener::Cast(listeners1.GetTaggedObject())->Get(index); EXPECT_TRUE(listenersResult == obj2Dynclass.GetTaggedValue()); } @@ -1107,8 +1107,8 @@ HWTEST_F_L0(JSObjectTest, BuildRegisterTree) JSHandle listeners1(thread, listeners1Value.GetTaggedObject()); JSTaggedValue protoDetails2 = obj2Dynclass->GetProtoChangeDetails(); EXPECT_TRUE(protoDetails2.IsProtoChangeDetails()); - JSTaggedValue index2 = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetRegisterIndex(); - EXPECT_TRUE(listeners1->Get(index2.GetArrayLength()) == obj2Dynclass.GetTaggedValue()); + uint32_t index2 = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetRegisterIndex(); + EXPECT_TRUE(listeners1->Get(index2) == obj2Dynclass.GetTaggedValue()); JSTaggedValue listeners2Value = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetChangeListener(); EXPECT_TRUE(listeners2Value != JSTaggedValue(0)); @@ -1117,10 +1117,10 @@ HWTEST_F_L0(JSObjectTest, BuildRegisterTree) JSTaggedValue protoDetails6 = obj6Dynclass->GetProtoChangeDetails(); EXPECT_TRUE(protoDetails4.IsProtoChangeDetails()); EXPECT_TRUE(protoDetails6.IsProtoChangeDetails()); - JSTaggedValue index4 = ProtoChangeDetails::Cast(protoDetails4.GetTaggedObject())->GetRegisterIndex(); - EXPECT_TRUE(listeners2->Get(index4.GetArrayLength()) == obj4Dynclass.GetTaggedValue()); - JSTaggedValue index6 = ProtoChangeDetails::Cast(protoDetails6.GetTaggedObject())->GetRegisterIndex(); - EXPECT_TRUE(listeners2->Get(index6.GetArrayLength()) == obj6Dynclass.GetTaggedValue()); + uint32_t index4 = ProtoChangeDetails::Cast(protoDetails4.GetTaggedObject())->GetRegisterIndex(); + EXPECT_TRUE(listeners2->Get(index4) == obj4Dynclass.GetTaggedValue()); + uint32_t index6 = ProtoChangeDetails::Cast(protoDetails6.GetTaggedObject())->GetRegisterIndex(); + EXPECT_TRUE(listeners2->Get(index6) == obj6Dynclass.GetTaggedValue()); EXPECT_TRUE(listeners1->GetEnd() == 1); EXPECT_TRUE(listeners2->GetEnd() == 2); @@ -1187,8 +1187,8 @@ HWTEST_F_L0(JSObjectTest, NoticeThroughChain) EXPECT_TRUE(protoDetails2.IsProtoChangeDetails()); JSTaggedValue listeners2Value = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetChangeListener(); EXPECT_TRUE(listeners2Value != JSTaggedValue(0)); - JSTaggedValue index2 = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetRegisterIndex(); - EXPECT_TRUE(listeners1->Get(index2.GetArrayLength()) == JSTaggedValue::Hole()); + uint32_t index2 = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetRegisterIndex(); + EXPECT_TRUE(listeners1->Get(index2) == JSTaggedValue::Hole()); JSTaggedValue obj6Marker = obj6Dynclass->GetProtoChangeMarker(); EXPECT_TRUE(obj6Marker.IsProtoChangeMarker()); @@ -1278,15 +1278,15 @@ HWTEST_F_L0(JSObjectTest, ChangeProtoAndNoticeTheChain) JSTaggedValue listeners3 = ProtoChangeDetails::Cast(protoDetails3.GetTaggedObject())->GetChangeListener(); EXPECT_TRUE(listeners3 != JSTaggedValue(0)); - JSTaggedValue index2 = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetRegisterIndex(); - JSTaggedValue index3 = ProtoChangeDetails::Cast(protoDetails3.GetTaggedObject())->GetRegisterIndex(); - JSTaggedValue index4 = ProtoChangeDetails::Cast(protoDetails4.GetTaggedObject())->GetRegisterIndex(); - JSTaggedValue index6 = ProtoChangeDetails::Cast(protoDetails6.GetTaggedObject())->GetRegisterIndex(); + uint32_t index2 = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetRegisterIndex(); + uint32_t index3 = ProtoChangeDetails::Cast(protoDetails3.GetTaggedObject())->GetRegisterIndex(); + uint32_t index4 = ProtoChangeDetails::Cast(protoDetails4.GetTaggedObject())->GetRegisterIndex(); + uint32_t index6 = ProtoChangeDetails::Cast(protoDetails6.GetTaggedObject())->GetRegisterIndex(); - JSTaggedValue result2 = ChangeListener::Cast(listeners3.GetTaggedObject())->Get(index2.GetArrayLength()); - JSTaggedValue result3 = ChangeListener::Cast(listeners1.GetTaggedObject())->Get(index3.GetArrayLength()); - JSTaggedValue result4 = ChangeListener::Cast(listeners2.GetTaggedObject())->Get(index4.GetArrayLength()); - JSTaggedValue result6 = ChangeListener::Cast(listeners2.GetTaggedObject())->Get(index6.GetArrayLength()); + JSTaggedValue result2 = ChangeListener::Cast(listeners3.GetTaggedObject())->Get(index2); + JSTaggedValue result3 = ChangeListener::Cast(listeners1.GetTaggedObject())->Get(index3); + JSTaggedValue result4 = ChangeListener::Cast(listeners2.GetTaggedObject())->Get(index4); + JSTaggedValue result6 = ChangeListener::Cast(listeners2.GetTaggedObject())->Get(index6); EXPECT_TRUE(result2 == obj2Dynclass.GetTaggedValue()); EXPECT_TRUE(result3 == obj3Dynclass.GetTaggedValue()); diff --git a/ecmascript/tests/js_promise_test.cpp b/ecmascript/tests/js_promise_test.cpp index 4ffbb4c791..d143ce42fa 100644 --- a/ecmascript/tests/js_promise_test.cpp +++ b/ecmascript/tests/js_promise_test.cpp @@ -79,9 +79,7 @@ HWTEST_F_L0(JSPromiseTest, NewPromiseCapability) JSHandle capbility = JSPromise::NewPromiseCapability(thread, promise); JSHandle newPromise(thread, capbility->GetPromise()); - EXPECT_EQ(JSTaggedValue::SameValue(newPromise->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::PENDING))), - true); + EXPECT_EQ(newPromise->GetPromiseState(), PromiseState::PENDING); JSHandle resolve(thread, capbility->GetResolve()); JSHandle reject(thread, capbility->GetReject()); @@ -101,9 +99,7 @@ HWTEST_F_L0(JSPromiseTest, FullFillPromise) JSHandle promise = env->GetPromiseFunction(); JSHandle capbility = JSPromise::NewPromiseCapability(thread, promise); JSHandle newPromise(thread, capbility->GetPromise()); - EXPECT_EQ(JSTaggedValue::SameValue(newPromise->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::PENDING))), - true); + EXPECT_EQ(newPromise->GetPromiseState(), PromiseState::PENDING); EXPECT_EQ(newPromise->GetPromiseResult().IsUndefined(), true); JSHandle resolve(thread, capbility->GetResolve()); @@ -111,9 +107,7 @@ HWTEST_F_L0(JSPromiseTest, FullFillPromise) InternalCallParams *arguments = thread->GetInternalCallParams(); arguments->MakeArgv(JSTaggedValue(33)); JSFunction::Call(thread, resolve, undefined, 1, arguments->GetArgv()); - EXPECT_EQ(JSTaggedValue::SameValue(newPromise->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::FULFILLED))), - true); + EXPECT_EQ(newPromise->GetPromiseState(), PromiseState::FULFILLED); EXPECT_EQ(JSTaggedValue::SameValue(newPromise->GetPromiseResult(), JSTaggedValue(33)), true); } @@ -124,9 +118,7 @@ HWTEST_F_L0(JSPromiseTest, RejectPromise) JSHandle promise = env->GetPromiseFunction(); JSHandle capbility = JSPromise::NewPromiseCapability(thread, promise); JSHandle newPromise(thread, capbility->GetPromise()); - EXPECT_EQ(JSTaggedValue::SameValue(newPromise->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::PENDING))), - true); + EXPECT_EQ(newPromise->GetPromiseState(), PromiseState::PENDING); EXPECT_EQ(newPromise->GetPromiseResult().IsUndefined(), true); JSHandle reject(thread, capbility->GetReject()); @@ -134,9 +126,7 @@ HWTEST_F_L0(JSPromiseTest, RejectPromise) InternalCallParams *arguments = thread->GetInternalCallParams(); arguments->MakeArgv(JSTaggedValue(44)); JSFunction::Call(thread, reject, undefined, 1, arguments->GetArgv()); - EXPECT_EQ(JSTaggedValue::SameValue(newPromise->GetPromiseState(), - JSTaggedValue(static_cast(PromiseStatus::REJECTED))), - true); + EXPECT_EQ(newPromise->GetPromiseState(), PromiseState::REJECTED); EXPECT_EQ(JSTaggedValue::SameValue(newPromise->GetPromiseResult(), JSTaggedValue(44)), true); } } // namespace panda::test diff --git a/ecmascript/tests/js_serializer_test.cpp b/ecmascript/tests/js_serializer_test.cpp index 3b0b95e71a..2ea201619f 100644 --- a/ecmascript/tests/js_serializer_test.cpp +++ b/ecmascript/tests/js_serializer_test.cpp @@ -344,8 +344,7 @@ public: EXPECT_TRUE(!res.IsEmpty()) << "[Empty] Deserialize JSArrayBuffer fail"; EXPECT_TRUE(res->IsArrayBuffer()) << "[NotJSArrayBuffer] Deserialize JSArrayBuffer fail"; JSHandle resJSArrayBuffer = JSHandle::Cast(res); - JSTaggedValue resTaggedLength = resJSArrayBuffer->GetArrayBufferByteLength(); - int32_t resByteLength = static_cast(resTaggedLength.GetInt()); + int32_t resByteLength = resJSArrayBuffer->GetArrayBufferByteLength(); EXPECT_TRUE(resByteLength == byteLength) << "Not Same ByteLength"; // 10 : test case JSHandle bufferData(thread, originArrayBuffer->GetArrayBufferData()); @@ -429,9 +428,9 @@ public: // check arrayBuffer JSHandle resJSArrayBuffer(viewedArrayBuffer); JSHandle originArrayBuffer(thread, originTypedArray->GetViewedArrayBuffer()); - JSTaggedValue resTaggedLength = resJSArrayBuffer->GetArrayBufferByteLength(); - JSTaggedValue originTaggedLength = originArrayBuffer->GetArrayBufferByteLength(); - EXPECT_TRUE(resTaggedLength.GetInt() == originTaggedLength.GetInt()) << "Not same viewedBuffer length"; + uint32_t resTaggedLength = resJSArrayBuffer->GetArrayBufferByteLength(); + uint32_t originTaggedLength = originArrayBuffer->GetArrayBufferByteLength(); + EXPECT_TRUE(resTaggedLength == originTaggedLength) << "Not same viewedBuffer length"; JSHandle bufferData(thread, originArrayBuffer->GetArrayBufferData()); JSHandle np = JSHandle::Cast(bufferData); void *buffer = np->GetExternalPointer(); @@ -819,7 +818,7 @@ HWTEST_F_L0(JSSerializerTest, SerializeJSArrayBuffer) JSHandle jsArrayBuffer(thread, CreateJSArrayBuffer(thread)); int32_t byteLength = 10; thread->GetEcmaVM()->GetFactory()->NewJSArrayBufferData(jsArrayBuffer, byteLength); - jsArrayBuffer->SetArrayBufferByteLength(thread, JSTaggedValue(static_cast(byteLength))); + jsArrayBuffer->SetArrayBufferByteLength(byteLength); JSHandle obj = JSHandle(jsArrayBuffer); BuiltinsArrayBuffer::SetValueInBuffer(obj.GetTaggedValue(), 1, DataViewType::UINT8, JSTaggedNumber(7), true); BuiltinsArrayBuffer::SetValueInBuffer(obj.GetTaggedValue(), 3, DataViewType::UINT8, JSTaggedNumber(17), true); @@ -913,7 +912,7 @@ JSArrayBuffer *CreateTestJSArrayBuffer(JSThread *thread) JSHandle jsArrayBuffer(thread, CreateJSArrayBuffer(thread)); int32_t byteLength = 10; thread->GetEcmaVM()->GetFactory()->NewJSArrayBufferData(jsArrayBuffer, byteLength); - jsArrayBuffer->SetArrayBufferByteLength(thread, JSTaggedValue(static_cast(byteLength))); + jsArrayBuffer->SetArrayBufferByteLength(byteLength); JSHandle obj = JSHandle(jsArrayBuffer); // 7 : test case BuiltinsArrayBuffer::SetValueInBuffer(obj.GetTaggedValue(), 1, DataViewType::UINT8, JSTaggedNumber(7), true); diff --git a/ecmascript/transitions_dictionary.h b/ecmascript/transitions_dictionary.h index de8fb6b98d..bf7f9c2172 100644 --- a/ecmascript/transitions_dictionary.h +++ b/ecmascript/transitions_dictionary.h @@ -49,7 +49,7 @@ public: if (key.IsString()) { hash = EcmaString::Cast(key.GetTaggedObject())->GetHashcode(); } else if (key.IsSymbol()) { - hash = static_cast(JSSymbol::Cast(key.GetTaggedObject())->GetHashField()).GetInt(); + hash = JSSymbol::Cast(key.GetTaggedObject())->GetHashField(); } int metaDataHash = metaData.IsInt() ? metaData.GetInt() : static_cast(metaData.GetRawData()); return hash + metaDataHash; -- Gitee