1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ECMASCRIPT_JSDATAVIEW_H 17 #define ECMASCRIPT_JSDATAVIEW_H 18 19 #include <cstddef> 20 #include <cstdint> 21 22 #include "ecmascript/ecma_macros.h" 23 #include "ecmascript/js_object.h" 24 25 namespace panda::ecmascript { 26 enum class DataViewType : uint8_t { 27 BIGINT64 = 0, BIGUINT64, FLOAT32, FLOAT64, INT8, INT16, INT32, UINT8, UINT16, UINT32, UINT8_CLAMPED 28 }; 29 30 class JSDataView : public JSObject { 31 public: 32 CAST_CHECK(JSDataView, IsDataView); 33 34 static uint32_t GetElementSize(DataViewType type); 35 36 static constexpr size_t DATA_VIEW_OFFSET = JSObject::SIZE; 37 ACCESSORS(DataView, DATA_VIEW_OFFSET, VIEW_ARRAY_BUFFER_OFFSET); 38 ACCESSORS(ViewedArrayBuffer, VIEW_ARRAY_BUFFER_OFFSET, BYTE_LENGTH_OFFSET); 39 ACCESSORS_PRIMITIVE_FIELD(ByteLength, uint32_t, BYTE_LENGTH_OFFSET, BYTE_OFFSET_OFFSET); 40 ACCESSORS_PRIMITIVE_FIELD(ByteOffset, uint32_t, BYTE_OFFSET_OFFSET, LAST_OFFSET); 41 DEFINE_ALIGN_SIZE(LAST_OFFSET); 42 43 DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, DATA_VIEW_OFFSET, BYTE_LENGTH_OFFSET) 44 45 DECL_DUMP() 46 }; 47 } // namespace panda::ecmascript 48 49 #endif // ECMASCRIPT_JSDATAVIEW_H 50