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 21namespace panda::ecmascript { 22enum class OnHeapMode : uint8_t { 23 NONE = 0, 24 ON_HEAP, 25 NOT_ON_HEAP, 26}; 27 28class OnHeap { 29public: 30 static bool IsNone(OnHeapMode mode) 31 { 32 return !(mode == OnHeapMode::ON_HEAP || mode == OnHeapMode::NOT_ON_HEAP); 33 } 34 35 static OnHeapMode Merge(OnHeapMode first, OnHeapMode second) 36 { 37 if (IsNone(first) || IsNone(second) || (first != second)) { 38 return OnHeapMode::NONE; 39 } 40 return first; 41 } 42 43 static bool ToBoolean(OnHeapMode mode) 44 { 45 ASSERT(!IsNone(mode)); 46 return mode == OnHeapMode::ON_HEAP; 47 } 48}; 49} // namespace panda::ecmascript 50#endif // ECMASCRIPT_ON_HEAP_H 51