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_JSARRAYBUFFER_H 17 #define ECMASCRIPT_JSARRAYBUFFER_H 18 19 #include "ecmascript/js_object.h" 20 21 namespace panda::ecmascript { 22 class JSArrayBuffer final : public JSObject { 23 public: 24 CAST_NO_CHECK(JSArrayBuffer); 25 26 // 6.2.6.2 27 static void CopyDataBlockBytes(JSTaggedValue toBlock, JSTaggedValue fromBlock, int32_t fromIndex, int32_t count); 28 static void CopyDataPointBytes(void *toBuf, void *fromBuf, int32_t fromIndex, int32_t count); 29 30 void Attach(JSThread *thread, uint32_t arrayBufferByteLength, JSTaggedValue arrayBufferData); 31 void Detach(JSThread *thread); 32 IsDetach()33 bool IsDetach() 34 { 35 JSTaggedValue arrayBufferData = GetArrayBufferData(); 36 return arrayBufferData == JSTaggedValue::Null(); 37 } 38 39 static constexpr size_t DATA_OFFSET = JSObject::SIZE; 40 ACCESSORS(ArrayBufferData, DATA_OFFSET, BYTE_LENGTH_OFFSET) 41 ACCESSORS_PRIMITIVE_FIELD(ArrayBufferByteLength, uint32_t, BYTE_LENGTH_OFFSET, BIT_FIELD_OFFSET) 42 ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) 43 DEFINE_ALIGN_SIZE(LAST_OFFSET); 44 45 // define BitField 46 static constexpr size_t SHARED_BITS = 2; 47 FIRST_BIT_FIELD(BitField, Shared, bool, SHARED_BITS) 48 49 DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, DATA_OFFSET, BYTE_LENGTH_OFFSET) 50 DECL_DUMP() 51 }; 52 } // namespace panda::ecmascript 53 54 #endif // ECMASCRIPT_JSARRAYBUFFER_H