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/preset_module.h"
17 #include <string.h>
18 #include "ace_log.h"
19
20 namespace OHOS {
21 namespace ACELite {
PresetModule(const char * const name)22 PresetModule::PresetModule(const char * const name)
23 {
24 jerry_value_t globalObject = jerry_get_global_object();
25 moduleName_ = const_cast<char *>(name);
26 if (moduleName_ != nullptr) {
27 module_ = jerry_create_object();
28 JerrySetNamedProperty(globalObject, moduleName_, module_);
29 jerry_release_value(globalObject);
30 } else {
31 module_ = globalObject;
32 }
33 }
34
~PresetModule()35 PresetModule::~PresetModule()
36 {
37 jerry_release_value(module_);
38 }
39
CreateNamedFunction(const char * const funcName,jerry_external_handler_t handler)40 void PresetModule::CreateNamedFunction(const char * const funcName, jerry_external_handler_t handler)
41 {
42 if (funcName == nullptr) {
43 return;
44 }
45 JerrySetFuncProperty(module_, funcName, handler);
46 }
47 } // namespace ACELite
48 } // namespace OHOS
49