• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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                 bool transferWithNativeAreaAllocator = false);
32     void Detach(JSThread *thread, bool transferWithNativeAreaAllocator = false);
33 
IsDetach()34     bool IsDetach()
35     {
36         JSTaggedValue arrayBufferData = GetArrayBufferData();
37         return arrayBufferData.IsNull();
38     }
39 
40     static constexpr size_t DATA_OFFSET = JSObject::SIZE;
41     ACCESSORS(ArrayBufferData, DATA_OFFSET, BYTE_LENGTH_OFFSET)
42     ACCESSORS_PRIMITIVE_FIELD(ArrayBufferByteLength, uint32_t, BYTE_LENGTH_OFFSET, BIT_FIELD_OFFSET)
43     ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET)
44     DEFINE_ALIGN_SIZE(LAST_OFFSET);
45 
46     // define BitField
47     static constexpr size_t SHARED_BITS = 1;
48     static constexpr size_t WITH_NATIVE_AREA_ALLOCATOR_BITS = 1;
49 
50     FIRST_BIT_FIELD(BitField, Shared, bool, SHARED_BITS)
51     NEXT_BIT_FIELD(BitField, WithNativeAreaAllocator, bool, WITH_NATIVE_AREA_ALLOCATOR_BITS, Shared)
52 
53     DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, DATA_OFFSET, BYTE_LENGTH_OFFSET)
54     DECL_DUMP()
55 };
56 }  // namespace panda::ecmascript
57 
58 #endif  // ECMASCRIPT_JSARRAYBUFFER_H