• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 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
16const etsVm = require('lib/module/ets_interop_js_napi');
17
18const num = 1;
19const string = 'string';
20const bool = true;
21const arr = [];
22const obj = {};
23
24function isObject(variable) {
25	return variable !== null && typeof variable === 'object' && !Array.isArray(variable);
26}
27
28// NOTE #1835 #17769 set "true" when literal types and optional methods are fully fixed
29const FIXES_IMPLEMENTED = false;
30
31const MODULE_PATH = 'Linterface_method/test/ETSGLOBAL;';
32
33const AnyTypeMethodClass = etsVm.getClass('Linterface_method/test/AnyTypeMethodClass;');
34const createInterfaceClassAnyTypeMethod = etsVm.getFunction(MODULE_PATH, 'create_interface_class_any_type_method');
35
36const UnionTypeMethodClass = etsVm.getClass('Linterface_method/test/UnionTypeMethodClass;');
37const createInterfaceClassUnionTypeMethod = etsVm.getFunction(MODULE_PATH, 'create_interface_class_union_type_method');
38
39const TupleTypeMethodClass = etsVm.getClass('Linterface_method/test/TupleTypeMethodClass;');
40const createInterfaceClassTupleTypeMethod = etsVm.getFunction(MODULE_PATH, 'create_interface_class_tuple_type_method');
41
42const SubsetByRefClass = etsVm.getClass('Linterface_method/test/SubsetByRefClass;');
43const subsetByRefInterface = etsVm.getFunction('Linterface_method/test/ETSGLOBAL;', 'subset_by_ref_interface');
44const callSubsetByRefInterfaceFromEts = etsVm.getFunction(MODULE_PATH, 'call_subset_by_ref_interface_from_ets');
45
46const SubsetByValueClass = etsVm.getClass('Linterface_method/test/SubsetByValueClass;');
47const createSubsetByValueClassFromEts = etsVm.getFunction(MODULE_PATH, 'create_subset_by_value_class_from_ets');
48
49getExtras = () => ({
50	WithOptionalMethodClass: etsVm.getClass('Linterface_method/test/WithOptionalMethodClass;'),
51	createClassWithOptionalMethod: etsVm.getFunction('Linterface_method/test/ETSGLOBAL;', 'create_class_with_optional_method'),
52	WithoutOptionalMethodClass: etsVm.getClass('Linterface_method/test/TupleClass;'),
53	createClassWOOptionals: getFunction('Linterface_method/test/ETSGLOBAL;', 'create_class_without_optional_method'),
54	optionalArg: etsVm.getFunction('Linterface_method/test/ETSGLOBAL;', 'optional_arg'),
55	optionalArgArray: etsVm.getFunction('Linterface_method/test/ETSGLOBAL;', 'optional_arg_array'),
56	LiteralValueMethodClass: etsVm.getClass('Linterface_method/test/LiteralValueMethodClass;'),
57	etsFnInterfaceLiteralValueClass: 'create_interface_literal_value_class_from_ets',
58	createInterfaceLiteralValueClassFromEts: etsVm.getFunction(MODULE_PATH, etsFnInterfaceLiteralValueClass),
59});
60
61const exposedValues = {
62	num,
63	string,
64	bool,
65	arr,
66	obj,
67	isObject,
68	AnyTypeMethodClass,
69	createInterfaceClassAnyTypeMethod,
70	UnionTypeMethodClass,
71	createInterfaceClassUnionTypeMethod,
72	SubsetByRefClass,
73	subsetByRefInterface,
74	callSubsetByRefInterfaceFromEts,
75	SubsetByValueClass,
76	createSubsetByValueClassFromEts,
77	TupleTypeMethodClass,
78	createInterfaceClassTupleTypeMethod,
79};
80
81module.exports = Object.assign(exposedValues, FIXES_IMPLEMENTED ? getExtras() : {});
82