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 FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JS_EXECUTION_SCOPE_DEFINES_H
17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JS_EXECUTION_SCOPE_DEFINES_H
18 
19 #ifdef USE_ARK_ENGINE
20 #define JAVASCRIPT_EXECUTION_SCOPE(exec) \
21     panda::LocalScope socpe(exec.vm_);
22 #define JAVASCRIPT_EXECUTION_SCOPE_STATIC                                                                \
23     auto runtime = std::static_pointer_cast<ArkJSRuntime>(JsiDeclarativeEngineInstance::GetCurrentRuntime()); \
24     panda::LocalScope socpe(runtime->GetEcmaVm());
25 #define CHECK_JAVASCRIPT_SCOPE_AND_RETURN                             \
26     if (JsiDeclarativeEngineInstance::GetCurrentRuntime() == nullptr) \
27         return;
28 #define CHECK_JAVASCRIPT_SCOPE(exec, ...)                                               \
29     if (JsiDeclarativeEngineInstance::GetCurrentRuntime() == nullptr || exec.vm_ == nullptr) \
30         return __VA_ARGS__;
31 #define JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(exec, ...) \
32     CHECK_JAVASCRIPT_SCOPE(exec, __VA_ARGS__)            \
33     JAVASCRIPT_EXECUTION_SCOPE(exec)
34 #else
35 #define JAVASCRIPT_EXECUTION_SCOPE(exec)
36 #define JAVASCRIPT_EXECUTION_SCOPE_STATIC
37 #define CHECK_JAVASCRIPT_SCOPE_AND_RETURN
38 #define JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(exec, ...)
39 #endif
40 
41 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JS_EXECUTION_SCOPE_DEFINES_H
42