• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 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 #include "presets/console_module.h"
17 #if IS_ENABLED(CONSOLE_LOG_OUTPUT)
18 #include "presets/console_log_impl.h"
19 #endif // ENABLED(CONSOLE_LOG_OUTPUT)
20 
21 namespace OHOS {
22 namespace ACELite {
Init()23 void ConsoleModule::Init()
24 {
25     const char * const debug = "debug";
26     const char * const info = "info";
27     const char * const warn = "warn";
28     const char * const log = "log";
29     const char * const error = "error";
30     CreateNamedFunction(debug, LogDebug);
31     CreateNamedFunction(info, LogInfo);
32     CreateNamedFunction(warn, LogWarn);
33     CreateNamedFunction(log, Log);
34     CreateNamedFunction(error, LogError);
35 }
36 
LogDebug(const jerry_value_t func,const jerry_value_t context,const jerry_value_t * args,const jerry_length_t length)37 jerry_value_t ConsoleModule::LogDebug(const jerry_value_t func,
38                                       const jerry_value_t context,
39                                       const jerry_value_t *args,
40                                       const jerry_length_t length)
41 {
42 #if IS_DISABLED(CONSOLE_LOG_OUTPUT)
43     return UNDEFINED;
44 #else
45     return LogNative(LOG_LEVEL_DEBUG, args, length);
46 #endif // DISABLED(CONSOLE_LOG_OUTPUT)
47 }
48 
LogInfo(const jerry_value_t func,const jerry_value_t context,const jerry_value_t * args,const jerry_length_t length)49 jerry_value_t ConsoleModule::LogInfo(const jerry_value_t func,
50                                      const jerry_value_t context,
51                                      const jerry_value_t *args,
52                                      const jerry_length_t length)
53 {
54 #if IS_DISABLED(CONSOLE_LOG_OUTPUT)
55     return UNDEFINED;
56 #else
57     return LogNative(LOG_LEVEL_INFO, args, length);
58 #endif // DISABLED(CONSOLE_LOG_OUTPUT)
59 }
60 
LogWarn(const jerry_value_t func,const jerry_value_t context,const jerry_value_t * args,const jerry_length_t length)61 jerry_value_t ConsoleModule::LogWarn(const jerry_value_t func,
62                                      const jerry_value_t context,
63                                      const jerry_value_t *args,
64                                      const jerry_length_t length)
65 {
66 #if IS_DISABLED(CONSOLE_LOG_OUTPUT)
67     return UNDEFINED;
68 #else
69     return LogNative(LOG_LEVEL_WARN, args, length);
70 #endif // DISABLED(CONSOLE_LOG_OUTPUT)
71 }
72 
Log(const jerry_value_t func,const jerry_value_t context,const jerry_value_t * args,const jerry_length_t length)73 jerry_value_t ConsoleModule::Log(const jerry_value_t func,
74                                  const jerry_value_t context,
75                                  const jerry_value_t *args,
76                                  const jerry_length_t length)
77 {
78 #if IS_DISABLED(CONSOLE_LOG_OUTPUT)
79     return UNDEFINED;
80 #else
81     return LogNative(LOG_LEVEL_NONE, args, length);
82 #endif // DISABLED(CONSOLE_LOG_OUTPUT)
83 }
84 
LogError(const jerry_value_t func,const jerry_value_t context,const jerry_value_t * args,const jerry_length_t length)85 jerry_value_t ConsoleModule::LogError(const jerry_value_t func,
86                                       const jerry_value_t context,
87                                       const jerry_value_t *args,
88                                       const jerry_length_t length)
89 {
90 #if IS_DISABLED(CONSOLE_LOG_OUTPUT)
91     return UNDEFINED;
92 #else
93     return LogNative(LOG_LEVEL_ERR, args, length);
94 #endif // DISABLED(CONSOLE_LOG_OUTPUT)
95 }
96 } // namespace ACELite
97 } // namespace OHOS
98