1 /* 2 * Copyright (c) 2021 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 "ecmascript/js_object.h" 20 21 namespace panda::ecmascript { 22 enum class DataViewType : uint8_t { FLOAT32 = 0, FLOAT64, INT8, INT16, INT32, UINT8, UINT16, UINT32, UINT8_CLAMPED }; 23 class JSDataView : public JSObject { 24 public: 25 CAST_CHECK(JSDataView, IsDataView); 26 27 static uint32_t GetElementSize(DataViewType type); 28 29 static constexpr size_t DATA_VIEW_OFFSET = JSObject::SIZE; 30 ACCESSORS(DataView, DATA_VIEW_OFFSET, VIEW_ARRAY_BUFFER_OFFSET); 31 ACCESSORS(ViewedArrayBuffer, VIEW_ARRAY_BUFFER_OFFSET, BYTE_LENGTH_OFFSET); 32 ACCESSORS_PRIMITIVE_FIELD(ByteLength, uint32_t, BYTE_LENGTH_OFFSET, BYTE_OFFSET_OFFSET); 33 ACCESSORS_PRIMITIVE_FIELD(ByteOffset, uint32_t, BYTE_OFFSET_OFFSET, LAST_OFFSET); 34 DEFINE_ALIGN_SIZE(LAST_OFFSET); 35 36 DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, DATA_VIEW_OFFSET, BYTE_LENGTH_OFFSET) 37 38 DECL_DUMP() 39 }; 40 } // namespace panda::ecmascript 41 42 #endif // ECMASCRIPT_JSDATAVIEW_H 43