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 #ifndef OHOS_ACELITE_SAMPLE_MODULE_H
17 #define OHOS_ACELITE_SAMPLE_MODULE_H
18 
19 #include "acelite_config.h"
20 #if (ENABLE_MODULE_REQUIRE_TEST == 1)
21 
22 #include "jsi.h"
23 #include "non_copyable.h"
24 
25 namespace OHOS {
26 namespace ACELite {
27 class SampleModule final : public MemoryHeap {
28 public:
29     ACE_DISALLOW_COPY_AND_MOVE(SampleModule);
SampleModule()30     SampleModule() {}
~SampleModule()31     ~SampleModule() {}
32     static JSIValue TestCallFunc(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum);
33     static JSIValue TestCallback(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum);
34     static JSIValue TestStandardCallback(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum);
35     static JSIValue TestCallbackWithArgs(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum);
36     static JSIValue TestStandardCallbackWithArgs(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum);
37     static JSIValue TestGeneralFunc(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum);
38     static JSIValue Getter(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum);
39     static JSIValue Setter(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum);
40     static void OnDestroy();
41     static void OnTerminate();
42 private:
43     static int8_t counter_; // used for js descriptor test
44 };
45 
InitSampleModule(JSIValue exports)46 void InitSampleModule(JSIValue exports)
47 {
48     JSI::SetModuleAPI(exports, "testCallFunc", SampleModule::TestCallFunc);
49     JSI::SetModuleAPI(exports, "testCallback", SampleModule::TestCallback);
50     JSI::SetModuleAPI(exports, "testStandardCallback", SampleModule::TestStandardCallback);
51     JSI::SetModuleAPI(exports, "testCallbackWithArgs", SampleModule::TestCallbackWithArgs);
52     JSI::SetModuleAPI(exports, "testStandardCallbackWithArgs", SampleModule::TestStandardCallbackWithArgs);
53     JSI::SetModuleAPI(exports, "testGeneralFunc", SampleModule::TestGeneralFunc);
54     JSI::SetOnDestroy(exports, SampleModule::OnDestroy);
55     JSI::SetOnTerminate(exports, SampleModule::OnTerminate);
56 }
57 } // namespace ACELite
58 } // namespace OHOS
59 
60 #endif // ENABLE_MODULE_REQUIRE_TEST
61 
62 #endif // OHOS_ACELITE_SAMPLE_MODULE_H
63