diff --git a/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_function_arg_type_optional_primitive_default.js b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_function_arg_type_optional_primitive_default.js new file mode 100644 index 0000000000000000000000000000000000000000..62a0fdc4c544e7a2be057ff87374f30114514ad2 --- /dev/null +++ b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_function_arg_type_optional_primitive_default.js @@ -0,0 +1,24 @@ +/** + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +const { etsVm, getTestModule } = require('scenarios.test.js'); + +const etsMod = getTestModule('scenarios_test'); +const GCJSRuntimeCleanup = etsMod.getFunction('GCJSRuntimeCleanup'); +const functionArgTypeOptionalPrimitiveEts = etsMod.getFunction('function_arg_type_optional_primitive'); + +{ + let ret = functionArgTypeOptionalPrimitiveEts(); + ASSERT_EQ(ret, undefined); +} diff --git a/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_function_arg_type_optional_primitive_explicit.js b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_function_arg_type_optional_primitive_explicit.js new file mode 100644 index 0000000000000000000000000000000000000000..2b1f850236fa6615f1ce1545049e16300f4fe987 --- /dev/null +++ b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_function_arg_type_optional_primitive_explicit.js @@ -0,0 +1,24 @@ +/** + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +const { etsVm, getTestModule } = require('scenarios.test.js'); + +const etsMod = getTestModule('scenarios_test'); +const GCJSRuntimeCleanup = etsMod.getFunction('GCJSRuntimeCleanup'); +const functionArgTypeOptionalPrimitiveEts = etsMod.getFunction('function_arg_type_optional_primitive'); + +{ + let ret = functionArgTypeOptionalPrimitiveEts(1); + ASSERT_EQ(ret, 1); +} diff --git a/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_function_arg_type_primitive.js b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_function_arg_type_primitive.js new file mode 100644 index 0000000000000000000000000000000000000000..a5977e862a4cb4f0579955485f08cbb22911ced5 --- /dev/null +++ b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_function_arg_type_primitive.js @@ -0,0 +1,24 @@ +/** + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +const { etsVm, getTestModule } = require('scenarios.test.js'); + +const etsMod = getTestModule('scenarios_test'); +const GCJSRuntimeCleanup = etsMod.getFunction('GCJSRuntimeCleanup'); +const functionArgTypePrimitiveEts = etsMod.getFunction('function_arg_type_primitive'); + +{ + let ret = functionArgTypePrimitiveEts(1); + ASSERT_EQ(ret, 1); +} diff --git a/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_function_return_type_primitive.js b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_function_return_type_primitive.js new file mode 100644 index 0000000000000000000000000000000000000000..5d93640718d7e141e7e2104f0aa612f609f3fede --- /dev/null +++ b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_function_return_type_primitive.js @@ -0,0 +1,24 @@ +/** + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +const { etsVm, getTestModule } = require('scenarios.test.js'); + +const etsMod = getTestModule('scenarios_test'); +const GCJSRuntimeCleanup = etsMod.getFunction('GCJSRuntimeCleanup'); +const functionReturnTypePrimitiveEts = etsMod.getFunction('function_return_type_primitive'); + +{ + let ret = functionReturnTypePrimitiveEts(); + ASSERT_EQ(typeof ret, 'number'); +} diff --git a/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/scenarios.cpp b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/scenarios.cpp index 49b9098ba3aa2dd5a0a5aebe8ff87141893faa26..7b54d1e7ff0d8c8d086a1cbb0468415845856f47 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/scenarios.cpp +++ b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/scenarios.cpp @@ -115,4 +115,25 @@ TEST_F(EtsInteropScenariosEtsToJs, DISABLED_test_default_value_define_for_parame ASSERT_EQ(true, RunJsTestSuite("js_suites/test_default_value_define_for_parameter_undefine.js")); } +// NOTE (splatov) #15925 enable this after interop is implemented in this direction +TEST_F(EtsInteropScenariosEtsToJs, DISABLED_test_function_arg_type_optional_primitive_explicit) +{ + ASSERT_EQ(true, RunJsTestSuite("js_suites/test_function_arg_type_optional_primitive_explicit.js")); +} + +TEST_F(EtsInteropScenariosEtsToJs, test_function_arg_type_optional_primitive_default) +{ + ASSERT_EQ(true, RunJsTestSuite("js_suites/test_function_arg_type_optional_primitive_default.js")); +} + +TEST_F(EtsInteropScenariosEtsToJs, test_function_arg_type_primitive) +{ + ASSERT_EQ(true, RunJsTestSuite("js_suites/test_function_arg_type_primitive.js")); +} + +TEST_F(EtsInteropScenariosEtsToJs, test_function_return_type_primitive) +{ + ASSERT_EQ(true, RunJsTestSuite("js_suites/test_function_return_type_primitive.js")); +} + } // namespace ark::ets::interop::js::testing diff --git a/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/scenarios.ets b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/scenarios.ets index 31a7bce9fb36c9c914ae514086a5a3b96ea6107e..536195d18bee169851a7bb58fda6e044acf47fc2 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/scenarios.ets +++ b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/scenarios.ets @@ -114,6 +114,18 @@ function default_undefined_parameter_function(arg: JSValue|undefined = undefined return arg; } +function function_arg_type_optional_primitive(arg?: Number): Number | undefined { + return arg; +} + +function function_arg_type_primitive(arg: number): number { + return arg; +} + +function function_return_type_primitive(): number { + return 1; +} + function GCJSRuntimeCleanup(): void { try { // trigger FinalizationRegistry cleanup diff --git a/static_core/plugins/ets/tests/interop_js/tests/scenarios/js_to_ets/scenarios.cpp b/static_core/plugins/ets/tests/interop_js/tests/scenarios/js_to_ets/scenarios.cpp index 36cc0ef5dee30c07dbb19abc41d0f3a7eeafb4ce..42f640eea8b763cd96d02b10d15efea820b39f46 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/scenarios/js_to_ets/scenarios.cpp +++ b/static_core/plugins/ets/tests/interop_js/tests/scenarios/js_to_ets/scenarios.cpp @@ -138,4 +138,28 @@ TEST_F(EtsInteropScenariosJsToEts, Test_generic_type_as_return_value) ASSERT_EQ(ret, true); } +TEST_F(EtsInteropScenariosJsToEts, Test_function_arg_type_optional_primitive_explicit) +{ + auto ret = CallEtsMethod("Test_function_arg_type_optional_primitive_explicit"); + ASSERT_EQ(ret, true); +} + +TEST_F(EtsInteropScenariosJsToEts, Test_function_arg_type_optional_primitive_default) +{ + auto ret = CallEtsMethod("Test_function_arg_type_optional_primitive_default"); + ASSERT_EQ(ret, true); +} + +TEST_F(EtsInteropScenariosJsToEts, Test_function_arg_type_primitive) +{ + auto ret = CallEtsMethod("Test_function_arg_type_primitive"); + ASSERT_EQ(ret, true); +} + +TEST_F(EtsInteropScenariosJsToEts, Test_function_return_type_primitive) +{ + auto ret = CallEtsMethod("Test_function_return_type_primitive"); + ASSERT_EQ(ret, true); +} + } // namespace ark::ets::interop::js::testing diff --git a/static_core/plugins/ets/tests/interop_js/tests/scenarios/js_to_ets/scenarios.ets b/static_core/plugins/ets/tests/interop_js/tests/scenarios/js_to_ets/scenarios.ets index 03613c6b8a2ceb325bdadaa5e16b402f2b5c0a2f..570c202fd5b0b16d3091596e8165ebc3fffc0e95 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/scenarios/js_to_ets/scenarios.ets +++ b/static_core/plugins/ets/tests/interop_js/tests/scenarios/js_to_ets/scenarios.ets @@ -18,7 +18,8 @@ import { standaloneFunctionJs, ClassWithMethodJs, newInterfaceWithMethod, ClassW functionArgTypeTuple, functionReturnTypeAny, functionReturnTypeUnknown, functionReturnTypeUndefined, functionArgTypeCallable, functionDefaultParameterFunction, functionDefaultIntParameterFunction, functionDefaultStringParameterFunction, functionDefaultFloatParameterFunction, genericTypeParameter, - genericTypeReturnValue } from "/plugins/ets/tests/interop_js/tests/scenarios/js_to_ets/scenarios.js" + genericTypeReturnValue, functionArgTypeOptionalPrimitive, functionArgTypePrimitive, + functionReturnTypePrimitive } from "/plugins/ets/tests/interop_js/tests/scenarios/js_to_ets/scenarios.js" function Test_standalone_function_call(): boolean { return standaloneFunctionJs() as int == 1; @@ -123,3 +124,21 @@ function Test_generic_type_as_parameter(): boolean { function Test_generic_type_as_return_value(): boolean { return genericTypeReturnValue(1) as int == 1; } + +function Test_function_arg_type_optional_primitive_explicit(): boolean { + return functionArgTypeOptionalPrimitive(1) as int == 1; +} + +function Test_function_arg_type_optional_primitive_default(): boolean { + return functionArgTypeOptionalPrimitive() as int == 1; +} + +function Test_function_arg_type_primitive(): boolean { + let arg: int = 1; + return functionArgTypePrimitive(arg) as int == 1; +} + +function Test_function_return_type_primitive(): boolean { + let res: boolean = functionReturnTypePrimitive() as boolean; + return typeof res === "boolean"; +} diff --git a/static_core/plugins/ets/tests/interop_js/tests/scenarios/js_to_ets/scenarios.js b/static_core/plugins/ets/tests/interop_js/tests/scenarios/js_to_ets/scenarios.js index 2a1e1ccd45774d51e4c53a8e13b6d8d82f223248..70df5829b4dac79c4dc70b13a82eced07f3cc45c 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/scenarios/js_to_ets/scenarios.js +++ b/static_core/plugins/ets/tests/interop_js/tests/scenarios/js_to_ets/scenarios.js @@ -152,6 +152,21 @@ function functionDefaultFloatParameterFunction(arg = FLOAT_VALUE) { // transpiled from Typescript code: function default_float_parameter_function(arg: JSValue = FLOAT_VALUE): JSValue{ } +function functionArgTypeOptionalPrimitive(arg) { + if (typeof arg !== 'undefined') { + return arg; + } + return INT_VALUE; +} + +function functionArgTypePrimitive(arg) { + return arg; +} + +function functionReturnTypePrimitive() { + return true; +} + exports.standaloneFunctionJs = standaloneFunctionJs; exports.ClassWithMethodJs = ClassWithMethodJs; exports.newInterfaceWithMethod = newInterfaceWithMethod; @@ -172,4 +187,7 @@ exports.functionArgTypeCallable = functionArgTypeCallable; exports.functionDefaultParameterFunction = functionDefaultParameterFunction; exports.functionDefaultIntParameterFunction = functionDefaultIntParameterFunction; exports.functionDefaultStringParameterFunction = functionDefaultStringParameterFunction; -exports.functionDefaultFloatParameterFunction = functionDefaultFloatParameterFunction; \ No newline at end of file +exports.functionDefaultFloatParameterFunction = functionDefaultFloatParameterFunction; +exports.functionArgTypeOptionalPrimitive = functionArgTypeOptionalPrimitive; +exports.functionArgTypePrimitive = functionArgTypePrimitive; +exports.functionReturnTypePrimitive = functionReturnTypePrimitive;