1 /* 2 * Copyright (c) 2023 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_ON_HEAP_H 17 #define ECMASCRIPT_ON_HEAP_H 18 19 #include "ecmascript/js_tagged_value.h" 20 21 namespace panda::ecmascript { 22 enum class OnHeapMode : uint8_t { 23 NONE = 0, 24 ON_HEAP, 25 NOT_ON_HEAP, 26 }; 27 28 class OnHeap { 29 public: IsNone(OnHeapMode mode)30 static bool IsNone(OnHeapMode mode) 31 { 32 return !(mode == OnHeapMode::ON_HEAP || mode == OnHeapMode::NOT_ON_HEAP); 33 } 34 IsOnHeap(OnHeapMode mode)35 static bool IsOnHeap(OnHeapMode mode) 36 { 37 return mode == OnHeapMode::ON_HEAP; 38 } 39 IsNotOnHeap(OnHeapMode mode)40 static bool IsNotOnHeap(OnHeapMode mode) 41 { 42 return mode == OnHeapMode::NOT_ON_HEAP; 43 } 44 Merge(OnHeapMode first,OnHeapMode second)45 static OnHeapMode Merge(OnHeapMode first, OnHeapMode second) 46 { 47 if (IsNone(first) || IsNone(second) || (first != second)) { 48 return OnHeapMode::NONE; 49 } 50 return first; 51 } 52 ToBoolean(OnHeapMode mode)53 static bool ToBoolean(OnHeapMode mode) 54 { 55 ASSERT(!IsNone(mode)); 56 return mode == OnHeapMode::ON_HEAP; 57 } 58 }; 59 } // namespace panda::ecmascript 60 #endif // ECMASCRIPT_ON_HEAP_H 61