1 /**
2 * Copyright (c) 2021-2024 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 PANDA_PLUGINS_ETS_RUNTIME_STUBS_INL_H
17 #define PANDA_PLUGINS_ETS_RUNTIME_STUBS_INL_H
18
19 #include "plugins/ets/runtime/ets_coroutine.h"
20 #include "plugins/ets/runtime/types/ets_object.h"
21 #include "plugins/ets/runtime/ets_stubs.h"
22
23 namespace ark::ets {
24
EtsReferenceNullish(EtsCoroutine * coro,EtsObject * ref)25 ALWAYS_INLINE inline bool EtsReferenceNullish(EtsCoroutine *coro, EtsObject *ref)
26 {
27 return ref == nullptr || ref == EtsObject::FromCoreType(coro->GetUndefinedObject());
28 }
29
IsRefNullish(EtsCoroutine * coro,EtsObject * ref)30 ALWAYS_INLINE inline bool IsRefNullish(EtsCoroutine *coro, EtsObject *ref)
31 {
32 return ref == nullptr || ref == EtsObject::FromCoreType(coro->GetUndefinedObject());
33 }
34
EtsReferenceEquals(EtsCoroutine * coro,EtsObject * ref1,EtsObject * ref2)35 ALWAYS_INLINE inline bool EtsReferenceEquals(EtsCoroutine *coro, EtsObject *ref1, EtsObject *ref2)
36 {
37 if (UNLIKELY(ref1 == ref2)) {
38 return true;
39 }
40
41 if (IsRefNullish(coro, ref1) || IsRefNullish(coro, ref2)) {
42 return IsRefNullish(coro, ref1) && IsRefNullish(coro, ref2);
43 }
44
45 if (LIKELY(!(ref1->GetClass()->IsValueTyped() && ref2->GetClass()->IsValueTyped()))) {
46 return false;
47 }
48 return EtsValueTypedEquals(coro, ref1, ref2);
49 }
50
51 } // namespace ark::ets
52
53 #endif // PANDA_PLUGINS_ETS_RUNTIME_STUBS_INL_H
54