diff --git a/packages/react-native-codegen/e2e/deep_imports/__tests__/modules/GenerateModuleCpp-test.js b/packages/react-native-codegen/e2e/deep_imports/__tests__/modules/GenerateModuleCpp-test.js deleted file mode 100644 index 4e04f1fa3de556..00000000000000 --- a/packages/react-native-codegen/e2e/deep_imports/__tests__/modules/GenerateModuleCpp-test.js +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow strict-local - * @format - */ - -'use strict'; - -import type {SchemaType} from '../../../../src/CodegenSchema'; - -const generator = require('../../../../src/generators/modules/GenerateModuleCpp'); -const {FlowParser} = require('../../../../src/parsers/flow/parser'); -const fs = require('fs'); - -const FIXTURE_DIR = `${__dirname}/../../__test_fixtures__/modules`; - -const parser = new FlowParser(); - -function getModules(): SchemaType { - const filenames: Array = fs.readdirSync(FIXTURE_DIR); - return filenames.reduce( - (accumulator, file) => { - const schema = parser.parseFile(`${FIXTURE_DIR}/${file}`); - return { - modules: { - ...accumulator.modules, - ...schema.modules, - }, - }; - }, - {modules: {}}, - ); -} - -describe('GenerateModuleCpp', () => { - it('can generate an implementation file NativeModule specs', () => { - const libName = 'RNCodegenModuleFixtures'; - const output = generator.generate(libName, getModules(), undefined, false); - expect(output.get(libName + 'JSI-generated.cpp')).toMatchSnapshot(); - }); - - it('can generate a header file NativeModule specs with assume nonnull enabled', () => { - const libName = 'RNCodegenModuleFixtures'; - const output = generator.generate(libName, getModules(), undefined, true); - expect(output.get(libName + 'JSI-generated.cpp')).toMatchSnapshot(); - }); -}); diff --git a/packages/react-native-codegen/e2e/deep_imports/__tests__/modules/__snapshots__/GenerateModuleCpp-test.js.snap b/packages/react-native-codegen/e2e/deep_imports/__tests__/modules/__snapshots__/GenerateModuleCpp-test.js.snap deleted file mode 100644 index 0b9629545621fd..00000000000000 --- a/packages/react-native-codegen/e2e/deep_imports/__tests__/modules/__snapshots__/GenerateModuleCpp-test.js.snap +++ /dev/null @@ -1,1643 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`GenerateModuleCpp can generate a header file NativeModule specs with assume nonnull enabled 1`] = ` -"/** - * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). - * - * Do not edit this file as changes may cause incorrect behavior and will be lost - * once the code is regenerated. - * - * @generated by codegen project: GenerateModuleCpp.js - */ - -#include \\"RNCodegenModuleFixturesJSI.h\\" - -namespace facebook::react { - -static jsi::Value __hostFunction_NativeArrayTurboModuleCxxSpecJSI_getArray(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getArray( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeArrayTurboModuleCxxSpecJSI_getReadOnlyArray(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getReadOnlyArray( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeArrayTurboModuleCxxSpecJSI_getArrayWithAlias(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getArrayWithAlias( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt), - count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asObject(rt).asArray(rt) - ); -} - -NativeArrayTurboModuleCxxSpecJSI::NativeArrayTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - methodMap_[\\"getArray\\"] = MethodMetadata {1, __hostFunction_NativeArrayTurboModuleCxxSpecJSI_getArray}; - methodMap_[\\"getReadOnlyArray\\"] = MethodMetadata {1, __hostFunction_NativeArrayTurboModuleCxxSpecJSI_getReadOnlyArray}; - methodMap_[\\"getArrayWithAlias\\"] = MethodMetadata {2, __hostFunction_NativeArrayTurboModuleCxxSpecJSI_getArrayWithAlias}; -} -static jsi::Value __hostFunction_NativeBooleanTurboModuleCxxSpecJSI_getBoolean(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getBoolean( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool() - ); -} -static jsi::Value __hostFunction_NativeBooleanTurboModuleCxxSpecJSI_getBooleanWithAlias(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getBooleanWithAlias( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool() - ); -} - -NativeBooleanTurboModuleCxxSpecJSI::NativeBooleanTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - methodMap_[\\"getBoolean\\"] = MethodMetadata {1, __hostFunction_NativeBooleanTurboModuleCxxSpecJSI_getBoolean}; - methodMap_[\\"getBooleanWithAlias\\"] = MethodMetadata {1, __hostFunction_NativeBooleanTurboModuleCxxSpecJSI_getBooleanWithAlias}; -} -static jsi::Value __hostFunction_NativeCallbackTurboModuleCxxSpecJSI_getValueWithCallback(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->getValueWithCallback( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asFunction(rt) - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeCallbackTurboModuleCxxSpecJSI_getValueWithCallbackWithAlias(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->getValueWithCallbackWithAlias( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asFunction(rt) - ); - return jsi::Value::undefined(); -} - -NativeCallbackTurboModuleCxxSpecJSI::NativeCallbackTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {1, __hostFunction_NativeCallbackTurboModuleCxxSpecJSI_getValueWithCallback}; - methodMap_[\\"getValueWithCallbackWithAlias\\"] = MethodMetadata {1, __hostFunction_NativeCallbackTurboModuleCxxSpecJSI_getValueWithCallbackWithAlias}; -} -static jsi::Value __hostFunction_NativeEnumTurboModuleCxxSpecJSI_getStatusRegular(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getStatusRegular( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeEnumTurboModuleCxxSpecJSI_getStatusStr(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getStatusStr( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeEnumTurboModuleCxxSpecJSI_getStatusNum(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getStatusNum( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeEnumTurboModuleCxxSpecJSI_getStatusLowerCase(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getStatusLowerCase( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeEnumTurboModuleCxxSpecJSI_getStateType(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getStateType( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt), - count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asString(rt), - count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asNumber(), - count <= 3 ? throw jsi::JSError(rt, \\"Expected argument in position 3 to be passed\\") : args[3].asString(rt) - ); -} -static jsi::Value __hostFunction_NativeEnumTurboModuleCxxSpecJSI_getStateTypeWithEnums(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getStateTypeWithEnums( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} - -NativeEnumTurboModuleCxxSpecJSI::NativeEnumTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"NativeEnumTurboModule\\", jsInvoker) { - methodMap_[\\"getStatusRegular\\"] = MethodMetadata {1, __hostFunction_NativeEnumTurboModuleCxxSpecJSI_getStatusRegular}; - methodMap_[\\"getStatusStr\\"] = MethodMetadata {1, __hostFunction_NativeEnumTurboModuleCxxSpecJSI_getStatusStr}; - methodMap_[\\"getStatusNum\\"] = MethodMetadata {1, __hostFunction_NativeEnumTurboModuleCxxSpecJSI_getStatusNum}; - methodMap_[\\"getStatusLowerCase\\"] = MethodMetadata {1, __hostFunction_NativeEnumTurboModuleCxxSpecJSI_getStatusLowerCase}; - methodMap_[\\"getStateType\\"] = MethodMetadata {4, __hostFunction_NativeEnumTurboModuleCxxSpecJSI_getStateType}; - methodMap_[\\"getStateTypeWithEnums\\"] = MethodMetadata {1, __hostFunction_NativeEnumTurboModuleCxxSpecJSI_getStateTypeWithEnums}; -} -static jsi::Value __hostFunction_NativeNullableTurboModuleCxxSpecJSI_getBool(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getBool( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool()) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeNullableTurboModuleCxxSpecJSI_getNumber(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getNumber( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeNullableTurboModuleCxxSpecJSI_getString(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getString( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeNullableTurboModuleCxxSpecJSI_getArray(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getArray( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt).asArray(rt)) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeNullableTurboModuleCxxSpecJSI_getObject(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getObject( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeNullableTurboModuleCxxSpecJSI_getValueWithPromise(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getValueWithPromise( - rt - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} - -NativeNullableTurboModuleCxxSpecJSI::NativeNullableTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - methodMap_[\\"getBool\\"] = MethodMetadata {1, __hostFunction_NativeNullableTurboModuleCxxSpecJSI_getBool}; - methodMap_[\\"getNumber\\"] = MethodMetadata {1, __hostFunction_NativeNullableTurboModuleCxxSpecJSI_getNumber}; - methodMap_[\\"getString\\"] = MethodMetadata {1, __hostFunction_NativeNullableTurboModuleCxxSpecJSI_getString}; - methodMap_[\\"getArray\\"] = MethodMetadata {1, __hostFunction_NativeNullableTurboModuleCxxSpecJSI_getArray}; - methodMap_[\\"getObject\\"] = MethodMetadata {1, __hostFunction_NativeNullableTurboModuleCxxSpecJSI_getObject}; - methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {0, __hostFunction_NativeNullableTurboModuleCxxSpecJSI_getValueWithPromise}; -} -static jsi::Value __hostFunction_NativeNumberTurboModuleCxxSpecJSI_getNumber(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getNumber( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber() - ); -} -static jsi::Value __hostFunction_NativeNumberTurboModuleCxxSpecJSI_getNumberWithAlias(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getNumberWithAlias( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber() - ); -} - -NativeNumberTurboModuleCxxSpecJSI::NativeNumberTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - methodMap_[\\"getNumber\\"] = MethodMetadata {1, __hostFunction_NativeNumberTurboModuleCxxSpecJSI_getNumber}; - methodMap_[\\"getNumberWithAlias\\"] = MethodMetadata {1, __hostFunction_NativeNumberTurboModuleCxxSpecJSI_getNumberWithAlias}; -} -static jsi::Value __hostFunction_NativeObjectTurboModuleCxxSpecJSI_getGenericObject(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getGenericObject( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeObjectTurboModuleCxxSpecJSI_getGenericObjectReadOnly(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getGenericObjectReadOnly( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeObjectTurboModuleCxxSpecJSI_getGenericObjectWithAlias(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getGenericObjectWithAlias( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeObjectTurboModuleCxxSpecJSI_difficultObject(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->difficultObject( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeObjectTurboModuleCxxSpecJSI_getConstants(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getConstants( - rt - ); -} - -NativeObjectTurboModuleCxxSpecJSI::NativeObjectTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - methodMap_[\\"getGenericObject\\"] = MethodMetadata {1, __hostFunction_NativeObjectTurboModuleCxxSpecJSI_getGenericObject}; - methodMap_[\\"getGenericObjectReadOnly\\"] = MethodMetadata {1, __hostFunction_NativeObjectTurboModuleCxxSpecJSI_getGenericObjectReadOnly}; - methodMap_[\\"getGenericObjectWithAlias\\"] = MethodMetadata {1, __hostFunction_NativeObjectTurboModuleCxxSpecJSI_getGenericObjectWithAlias}; - methodMap_[\\"difficultObject\\"] = MethodMetadata {1, __hostFunction_NativeObjectTurboModuleCxxSpecJSI_difficultObject}; - methodMap_[\\"getConstants\\"] = MethodMetadata {0, __hostFunction_NativeObjectTurboModuleCxxSpecJSI_getConstants}; -} -static jsi::Value __hostFunction_NativeOptionalObjectTurboModuleCxxSpecJSI_getConstants(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getConstants( - rt - ); -} - -NativeOptionalObjectTurboModuleCxxSpecJSI::NativeOptionalObjectTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - methodMap_[\\"getConstants\\"] = MethodMetadata {0, __hostFunction_NativeOptionalObjectTurboModuleCxxSpecJSI_getConstants}; -} -static jsi::Value __hostFunction_NativePartialAnnotationTurboModuleCxxSpecJSI_getSomeObj(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getSomeObj( - rt - ); -} -static jsi::Value __hostFunction_NativePartialAnnotationTurboModuleCxxSpecJSI_getPartialSomeObj(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getPartialSomeObj( - rt - ); -} -static jsi::Value __hostFunction_NativePartialAnnotationTurboModuleCxxSpecJSI_getSomeObjFromPartialSomeObj(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getSomeObjFromPartialSomeObj( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativePartialAnnotationTurboModuleCxxSpecJSI_getPartialPartial(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getPartialPartial( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt), - count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asObject(rt) - ); -} - -NativePartialAnnotationTurboModuleCxxSpecJSI::NativePartialAnnotationTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"NativePartialAnnotationTurboModule\\", jsInvoker) { - methodMap_[\\"getSomeObj\\"] = MethodMetadata {0, __hostFunction_NativePartialAnnotationTurboModuleCxxSpecJSI_getSomeObj}; - methodMap_[\\"getPartialSomeObj\\"] = MethodMetadata {0, __hostFunction_NativePartialAnnotationTurboModuleCxxSpecJSI_getPartialSomeObj}; - methodMap_[\\"getSomeObjFromPartialSomeObj\\"] = MethodMetadata {1, __hostFunction_NativePartialAnnotationTurboModuleCxxSpecJSI_getSomeObjFromPartialSomeObj}; - methodMap_[\\"getPartialPartial\\"] = MethodMetadata {2, __hostFunction_NativePartialAnnotationTurboModuleCxxSpecJSI_getPartialPartial}; -} -static jsi::Value __hostFunction_NativePromiseTurboModuleCxxSpecJSI_getValueWithPromise(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getValueWithPromise( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool() - ); -} -static jsi::Value __hostFunction_NativePromiseTurboModuleCxxSpecJSI_getValueWithPromiseWithAlias(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getValueWithPromiseWithAlias( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt) - ); -} - -NativePromiseTurboModuleCxxSpecJSI::NativePromiseTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {1, __hostFunction_NativePromiseTurboModuleCxxSpecJSI_getValueWithPromise}; - methodMap_[\\"getValueWithPromiseWithAlias\\"] = MethodMetadata {1, __hostFunction_NativePromiseTurboModuleCxxSpecJSI_getValueWithPromiseWithAlias}; -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getConstants(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getConstants( - rt - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_voidFunc(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->voidFunc( - rt - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getBool(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getBool( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool() - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getNumber(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getNumber( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber() - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getString(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getString( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getArray(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getArray( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getObject(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getObject( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getObjectShape(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getObjectShape( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getAlias(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getAlias( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getRootTag(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getRootTag( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber() - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getValue(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getValue( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber(), - count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asString(rt), - count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getValueWithCallback(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->getValueWithCallback( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asFunction(rt) - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getValueWithPromise(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getValueWithPromise( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool() - ); -} - -NativeSampleTurboModuleCxxSpecJSI::NativeSampleTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - methodMap_[\\"getConstants\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getConstants}; - methodMap_[\\"voidFunc\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_voidFunc}; - methodMap_[\\"getBool\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getBool}; - methodMap_[\\"getNumber\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getNumber}; - methodMap_[\\"getString\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getString}; - methodMap_[\\"getArray\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getArray}; - methodMap_[\\"getObject\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getObject}; - methodMap_[\\"getObjectShape\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getObjectShape}; - methodMap_[\\"getAlias\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getAlias}; - methodMap_[\\"getRootTag\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getRootTag}; - methodMap_[\\"getValue\\"] = MethodMetadata {3, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getValue}; - methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getValueWithCallback}; - methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getValueWithPromise}; -} -static jsi::Value __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getConstants(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getConstants( - rt - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_voidFunc(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->voidFunc( - rt - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getBool(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getBool( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getNumber(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getNumber( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getString(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getString( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getArray(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getArray( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getObject(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getObject( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getObjectShape(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getObjectShape( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getAlias(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getAlias( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getRootTag(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getRootTag( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getValue(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getValue( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt), - count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asObject(rt).asArray(rt), - count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getValueWithCallback(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->getValueWithCallback( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asFunction(rt) - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getValueWithPromise(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getValueWithPromise( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} - -NativeSampleTurboModuleArraysCxxSpecJSI::NativeSampleTurboModuleArraysCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModuleArrays\\", jsInvoker) { - methodMap_[\\"getConstants\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getConstants}; - methodMap_[\\"voidFunc\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_voidFunc}; - methodMap_[\\"getBool\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getBool}; - methodMap_[\\"getNumber\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getNumber}; - methodMap_[\\"getString\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getString}; - methodMap_[\\"getArray\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getArray}; - methodMap_[\\"getObject\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getObject}; - methodMap_[\\"getObjectShape\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getObjectShape}; - methodMap_[\\"getAlias\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getAlias}; - methodMap_[\\"getRootTag\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getRootTag}; - methodMap_[\\"getValue\\"] = MethodMetadata {3, __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getValue}; - methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getValueWithCallback}; - methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getValueWithPromise}; -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getConstants(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getConstants( - rt - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_voidFunc(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->voidFunc( - rt - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getBool(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getBool( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool()) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getNumber(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getNumber( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getString(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getString( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asString(rt)) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getArray(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getArray( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt).asArray(rt)) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getObject(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getObject( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getObjectShape(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getObjectShape( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getAlias(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getAlias( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getRootTag(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getRootTag( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getValue(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getValue( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()), - count <= 1 || args[1].isNull() || args[1].isUndefined() ? std::nullopt : std::make_optional(args[1].asString(rt)), - count <= 2 || args[2].isNull() || args[2].isUndefined() ? std::nullopt : std::make_optional(args[2].asObject(rt)) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getValueWithCallback(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->getValueWithCallback( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asFunction(rt) - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getValueWithPromise(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getValueWithPromise( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool()) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} - -NativeSampleTurboModuleNullableCxxSpecJSI::NativeSampleTurboModuleNullableCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModuleNullable\\", jsInvoker) { - methodMap_[\\"getConstants\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getConstants}; - methodMap_[\\"voidFunc\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_voidFunc}; - methodMap_[\\"getBool\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getBool}; - methodMap_[\\"getNumber\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getNumber}; - methodMap_[\\"getString\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getString}; - methodMap_[\\"getArray\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getArray}; - methodMap_[\\"getObject\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getObject}; - methodMap_[\\"getObjectShape\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getObjectShape}; - methodMap_[\\"getAlias\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getAlias}; - methodMap_[\\"getRootTag\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getRootTag}; - methodMap_[\\"getValue\\"] = MethodMetadata {3, __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getValue}; - methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getValueWithCallback}; - methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getValueWithPromise}; -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getConstants(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getConstants( - rt - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_voidFunc(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->voidFunc( - rt - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getBool(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getBool( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool()) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getNumber(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getNumber( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getString(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getString( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asString(rt)) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getArray(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getArray( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt).asArray(rt)) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getObject(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getObject( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getObjectShape(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getObjectShape( - rt, - count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getAlias(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getAlias( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getRootTag(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getRootTag( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getValue(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getValue( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()), - count <= 1 || args[1].isNull() || args[1].isUndefined() ? std::nullopt : std::make_optional(args[1].asString(rt)), - count <= 2 || args[2].isNull() || args[2].isUndefined() ? std::nullopt : std::make_optional(args[2].asObject(rt)) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getValueWithCallback(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->getValueWithCallback( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt).asFunction(rt)) - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getValueWithPromise(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getValueWithPromise( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool()) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} - -NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI::NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModuleNullableAndOptional\\", jsInvoker) { - methodMap_[\\"getConstants\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getConstants}; - methodMap_[\\"voidFunc\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_voidFunc}; - methodMap_[\\"getBool\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getBool}; - methodMap_[\\"getNumber\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getNumber}; - methodMap_[\\"getString\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getString}; - methodMap_[\\"getArray\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getArray}; - methodMap_[\\"getObject\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getObject}; - methodMap_[\\"getObjectShape\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getObjectShape}; - methodMap_[\\"getAlias\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getAlias}; - methodMap_[\\"getRootTag\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getRootTag}; - methodMap_[\\"getValue\\"] = MethodMetadata {3, __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getValue}; - methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getValueWithCallback}; - methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getValueWithPromise}; -} -static jsi::Value __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getConstants(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getConstants( - rt - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_voidFunc(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->voidFunc( - rt - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getBool(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getBool( - rt, - count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool()) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getNumber(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getNumber( - rt, - count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getString(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getString( - rt, - count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asString(rt)) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getArray(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getArray( - rt, - count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt).asArray(rt)) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getObject(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getObject( - rt, - count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getObjectShape(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getObjectShape( - rt, - count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getAlias(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getAlias( - rt, - count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getRootTag(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getRootTag( - rt, - count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getValue(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getValue( - rt, - count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()), - count <= 1 || args[1].isUndefined() ? std::nullopt : std::make_optional(args[1].asString(rt)), - count <= 2 || args[2].isUndefined() ? std::nullopt : std::make_optional(args[2].asObject(rt)) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getValueWithCallback(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->getValueWithCallback( - rt, - count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt).asFunction(rt)) - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getValueWithPromise(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getValueWithPromise( - rt, - count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool()) - ); -} - -NativeSampleTurboModuleOptionalCxxSpecJSI::NativeSampleTurboModuleOptionalCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModuleOptional\\", jsInvoker) { - methodMap_[\\"getConstants\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getConstants}; - methodMap_[\\"voidFunc\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_voidFunc}; - methodMap_[\\"getBool\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getBool}; - methodMap_[\\"getNumber\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getNumber}; - methodMap_[\\"getString\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getString}; - methodMap_[\\"getArray\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getArray}; - methodMap_[\\"getObject\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getObject}; - methodMap_[\\"getObjectShape\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getObjectShape}; - methodMap_[\\"getAlias\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getAlias}; - methodMap_[\\"getRootTag\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getRootTag}; - methodMap_[\\"getValue\\"] = MethodMetadata {3, __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getValue}; - methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getValueWithCallback}; - methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getValueWithPromise}; -} -static jsi::Value __hostFunction_NativeStringTurboModuleCxxSpecJSI_getString(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getString( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt) - ); -} -static jsi::Value __hostFunction_NativeStringTurboModuleCxxSpecJSI_getStringWithAlias(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getStringWithAlias( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt) - ); -} - -NativeStringTurboModuleCxxSpecJSI::NativeStringTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - methodMap_[\\"getString\\"] = MethodMetadata {1, __hostFunction_NativeStringTurboModuleCxxSpecJSI_getString}; - methodMap_[\\"getStringWithAlias\\"] = MethodMetadata {1, __hostFunction_NativeStringTurboModuleCxxSpecJSI_getStringWithAlias}; -} - - -} // namespace facebook::react -" -`; - -exports[`GenerateModuleCpp can generate an implementation file NativeModule specs 1`] = ` -"/** - * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). - * - * Do not edit this file as changes may cause incorrect behavior and will be lost - * once the code is regenerated. - * - * @generated by codegen project: GenerateModuleCpp.js - */ - -#include \\"RNCodegenModuleFixturesJSI.h\\" - -namespace facebook::react { - -static jsi::Value __hostFunction_NativeArrayTurboModuleCxxSpecJSI_getArray(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getArray( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeArrayTurboModuleCxxSpecJSI_getReadOnlyArray(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getReadOnlyArray( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeArrayTurboModuleCxxSpecJSI_getArrayWithAlias(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getArrayWithAlias( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt), - count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asObject(rt).asArray(rt) - ); -} - -NativeArrayTurboModuleCxxSpecJSI::NativeArrayTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - methodMap_[\\"getArray\\"] = MethodMetadata {1, __hostFunction_NativeArrayTurboModuleCxxSpecJSI_getArray}; - methodMap_[\\"getReadOnlyArray\\"] = MethodMetadata {1, __hostFunction_NativeArrayTurboModuleCxxSpecJSI_getReadOnlyArray}; - methodMap_[\\"getArrayWithAlias\\"] = MethodMetadata {2, __hostFunction_NativeArrayTurboModuleCxxSpecJSI_getArrayWithAlias}; -} -static jsi::Value __hostFunction_NativeBooleanTurboModuleCxxSpecJSI_getBoolean(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getBoolean( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool() - ); -} -static jsi::Value __hostFunction_NativeBooleanTurboModuleCxxSpecJSI_getBooleanWithAlias(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getBooleanWithAlias( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool() - ); -} - -NativeBooleanTurboModuleCxxSpecJSI::NativeBooleanTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - methodMap_[\\"getBoolean\\"] = MethodMetadata {1, __hostFunction_NativeBooleanTurboModuleCxxSpecJSI_getBoolean}; - methodMap_[\\"getBooleanWithAlias\\"] = MethodMetadata {1, __hostFunction_NativeBooleanTurboModuleCxxSpecJSI_getBooleanWithAlias}; -} -static jsi::Value __hostFunction_NativeCallbackTurboModuleCxxSpecJSI_getValueWithCallback(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->getValueWithCallback( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asFunction(rt) - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeCallbackTurboModuleCxxSpecJSI_getValueWithCallbackWithAlias(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->getValueWithCallbackWithAlias( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asFunction(rt) - ); - return jsi::Value::undefined(); -} - -NativeCallbackTurboModuleCxxSpecJSI::NativeCallbackTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {1, __hostFunction_NativeCallbackTurboModuleCxxSpecJSI_getValueWithCallback}; - methodMap_[\\"getValueWithCallbackWithAlias\\"] = MethodMetadata {1, __hostFunction_NativeCallbackTurboModuleCxxSpecJSI_getValueWithCallbackWithAlias}; -} -static jsi::Value __hostFunction_NativeEnumTurboModuleCxxSpecJSI_getStatusRegular(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getStatusRegular( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeEnumTurboModuleCxxSpecJSI_getStatusStr(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getStatusStr( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeEnumTurboModuleCxxSpecJSI_getStatusNum(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getStatusNum( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeEnumTurboModuleCxxSpecJSI_getStatusLowerCase(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getStatusLowerCase( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeEnumTurboModuleCxxSpecJSI_getStateType(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getStateType( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt), - count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asString(rt), - count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asNumber(), - count <= 3 ? throw jsi::JSError(rt, \\"Expected argument in position 3 to be passed\\") : args[3].asString(rt) - ); -} -static jsi::Value __hostFunction_NativeEnumTurboModuleCxxSpecJSI_getStateTypeWithEnums(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getStateTypeWithEnums( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} - -NativeEnumTurboModuleCxxSpecJSI::NativeEnumTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"NativeEnumTurboModule\\", jsInvoker) { - methodMap_[\\"getStatusRegular\\"] = MethodMetadata {1, __hostFunction_NativeEnumTurboModuleCxxSpecJSI_getStatusRegular}; - methodMap_[\\"getStatusStr\\"] = MethodMetadata {1, __hostFunction_NativeEnumTurboModuleCxxSpecJSI_getStatusStr}; - methodMap_[\\"getStatusNum\\"] = MethodMetadata {1, __hostFunction_NativeEnumTurboModuleCxxSpecJSI_getStatusNum}; - methodMap_[\\"getStatusLowerCase\\"] = MethodMetadata {1, __hostFunction_NativeEnumTurboModuleCxxSpecJSI_getStatusLowerCase}; - methodMap_[\\"getStateType\\"] = MethodMetadata {4, __hostFunction_NativeEnumTurboModuleCxxSpecJSI_getStateType}; - methodMap_[\\"getStateTypeWithEnums\\"] = MethodMetadata {1, __hostFunction_NativeEnumTurboModuleCxxSpecJSI_getStateTypeWithEnums}; -} -static jsi::Value __hostFunction_NativeNullableTurboModuleCxxSpecJSI_getBool(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getBool( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool()) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeNullableTurboModuleCxxSpecJSI_getNumber(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getNumber( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeNullableTurboModuleCxxSpecJSI_getString(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getString( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeNullableTurboModuleCxxSpecJSI_getArray(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getArray( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt).asArray(rt)) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeNullableTurboModuleCxxSpecJSI_getObject(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getObject( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeNullableTurboModuleCxxSpecJSI_getValueWithPromise(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getValueWithPromise( - rt - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} - -NativeNullableTurboModuleCxxSpecJSI::NativeNullableTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - methodMap_[\\"getBool\\"] = MethodMetadata {1, __hostFunction_NativeNullableTurboModuleCxxSpecJSI_getBool}; - methodMap_[\\"getNumber\\"] = MethodMetadata {1, __hostFunction_NativeNullableTurboModuleCxxSpecJSI_getNumber}; - methodMap_[\\"getString\\"] = MethodMetadata {1, __hostFunction_NativeNullableTurboModuleCxxSpecJSI_getString}; - methodMap_[\\"getArray\\"] = MethodMetadata {1, __hostFunction_NativeNullableTurboModuleCxxSpecJSI_getArray}; - methodMap_[\\"getObject\\"] = MethodMetadata {1, __hostFunction_NativeNullableTurboModuleCxxSpecJSI_getObject}; - methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {0, __hostFunction_NativeNullableTurboModuleCxxSpecJSI_getValueWithPromise}; -} -static jsi::Value __hostFunction_NativeNumberTurboModuleCxxSpecJSI_getNumber(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getNumber( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber() - ); -} -static jsi::Value __hostFunction_NativeNumberTurboModuleCxxSpecJSI_getNumberWithAlias(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getNumberWithAlias( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber() - ); -} - -NativeNumberTurboModuleCxxSpecJSI::NativeNumberTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - methodMap_[\\"getNumber\\"] = MethodMetadata {1, __hostFunction_NativeNumberTurboModuleCxxSpecJSI_getNumber}; - methodMap_[\\"getNumberWithAlias\\"] = MethodMetadata {1, __hostFunction_NativeNumberTurboModuleCxxSpecJSI_getNumberWithAlias}; -} -static jsi::Value __hostFunction_NativeObjectTurboModuleCxxSpecJSI_getGenericObject(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getGenericObject( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeObjectTurboModuleCxxSpecJSI_getGenericObjectReadOnly(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getGenericObjectReadOnly( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeObjectTurboModuleCxxSpecJSI_getGenericObjectWithAlias(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getGenericObjectWithAlias( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeObjectTurboModuleCxxSpecJSI_difficultObject(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->difficultObject( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeObjectTurboModuleCxxSpecJSI_getConstants(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getConstants( - rt - ); -} - -NativeObjectTurboModuleCxxSpecJSI::NativeObjectTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - methodMap_[\\"getGenericObject\\"] = MethodMetadata {1, __hostFunction_NativeObjectTurboModuleCxxSpecJSI_getGenericObject}; - methodMap_[\\"getGenericObjectReadOnly\\"] = MethodMetadata {1, __hostFunction_NativeObjectTurboModuleCxxSpecJSI_getGenericObjectReadOnly}; - methodMap_[\\"getGenericObjectWithAlias\\"] = MethodMetadata {1, __hostFunction_NativeObjectTurboModuleCxxSpecJSI_getGenericObjectWithAlias}; - methodMap_[\\"difficultObject\\"] = MethodMetadata {1, __hostFunction_NativeObjectTurboModuleCxxSpecJSI_difficultObject}; - methodMap_[\\"getConstants\\"] = MethodMetadata {0, __hostFunction_NativeObjectTurboModuleCxxSpecJSI_getConstants}; -} -static jsi::Value __hostFunction_NativeOptionalObjectTurboModuleCxxSpecJSI_getConstants(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getConstants( - rt - ); -} - -NativeOptionalObjectTurboModuleCxxSpecJSI::NativeOptionalObjectTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - methodMap_[\\"getConstants\\"] = MethodMetadata {0, __hostFunction_NativeOptionalObjectTurboModuleCxxSpecJSI_getConstants}; -} -static jsi::Value __hostFunction_NativePartialAnnotationTurboModuleCxxSpecJSI_getSomeObj(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getSomeObj( - rt - ); -} -static jsi::Value __hostFunction_NativePartialAnnotationTurboModuleCxxSpecJSI_getPartialSomeObj(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getPartialSomeObj( - rt - ); -} -static jsi::Value __hostFunction_NativePartialAnnotationTurboModuleCxxSpecJSI_getSomeObjFromPartialSomeObj(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getSomeObjFromPartialSomeObj( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativePartialAnnotationTurboModuleCxxSpecJSI_getPartialPartial(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getPartialPartial( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt), - count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asObject(rt) - ); -} - -NativePartialAnnotationTurboModuleCxxSpecJSI::NativePartialAnnotationTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"NativePartialAnnotationTurboModule\\", jsInvoker) { - methodMap_[\\"getSomeObj\\"] = MethodMetadata {0, __hostFunction_NativePartialAnnotationTurboModuleCxxSpecJSI_getSomeObj}; - methodMap_[\\"getPartialSomeObj\\"] = MethodMetadata {0, __hostFunction_NativePartialAnnotationTurboModuleCxxSpecJSI_getPartialSomeObj}; - methodMap_[\\"getSomeObjFromPartialSomeObj\\"] = MethodMetadata {1, __hostFunction_NativePartialAnnotationTurboModuleCxxSpecJSI_getSomeObjFromPartialSomeObj}; - methodMap_[\\"getPartialPartial\\"] = MethodMetadata {2, __hostFunction_NativePartialAnnotationTurboModuleCxxSpecJSI_getPartialPartial}; -} -static jsi::Value __hostFunction_NativePromiseTurboModuleCxxSpecJSI_getValueWithPromise(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getValueWithPromise( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool() - ); -} -static jsi::Value __hostFunction_NativePromiseTurboModuleCxxSpecJSI_getValueWithPromiseWithAlias(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getValueWithPromiseWithAlias( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt) - ); -} - -NativePromiseTurboModuleCxxSpecJSI::NativePromiseTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {1, __hostFunction_NativePromiseTurboModuleCxxSpecJSI_getValueWithPromise}; - methodMap_[\\"getValueWithPromiseWithAlias\\"] = MethodMetadata {1, __hostFunction_NativePromiseTurboModuleCxxSpecJSI_getValueWithPromiseWithAlias}; -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getConstants(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getConstants( - rt - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_voidFunc(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->voidFunc( - rt - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getBool(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getBool( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool() - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getNumber(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getNumber( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber() - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getString(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getString( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getArray(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getArray( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getObject(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getObject( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getObjectShape(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getObjectShape( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getAlias(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getAlias( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getRootTag(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getRootTag( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber() - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getValue(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getValue( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber(), - count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asString(rt), - count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getValueWithCallback(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->getValueWithCallback( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asFunction(rt) - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getValueWithPromise(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getValueWithPromise( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool() - ); -} - -NativeSampleTurboModuleCxxSpecJSI::NativeSampleTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - methodMap_[\\"getConstants\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getConstants}; - methodMap_[\\"voidFunc\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_voidFunc}; - methodMap_[\\"getBool\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getBool}; - methodMap_[\\"getNumber\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getNumber}; - methodMap_[\\"getString\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getString}; - methodMap_[\\"getArray\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getArray}; - methodMap_[\\"getObject\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getObject}; - methodMap_[\\"getObjectShape\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getObjectShape}; - methodMap_[\\"getAlias\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getAlias}; - methodMap_[\\"getRootTag\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getRootTag}; - methodMap_[\\"getValue\\"] = MethodMetadata {3, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getValue}; - methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getValueWithCallback}; - methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getValueWithPromise}; -} -static jsi::Value __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getConstants(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getConstants( - rt - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_voidFunc(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->voidFunc( - rt - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getBool(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getBool( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getNumber(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getNumber( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getString(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getString( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getArray(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getArray( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getObject(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getObject( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getObjectShape(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getObjectShape( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getAlias(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getAlias( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getRootTag(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getRootTag( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getValue(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getValue( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt), - count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asObject(rt).asArray(rt), - count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getValueWithCallback(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->getValueWithCallback( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asFunction(rt) - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getValueWithPromise(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getValueWithPromise( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} - -NativeSampleTurboModuleArraysCxxSpecJSI::NativeSampleTurboModuleArraysCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModuleArrays\\", jsInvoker) { - methodMap_[\\"getConstants\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getConstants}; - methodMap_[\\"voidFunc\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_voidFunc}; - methodMap_[\\"getBool\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getBool}; - methodMap_[\\"getNumber\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getNumber}; - methodMap_[\\"getString\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getString}; - methodMap_[\\"getArray\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getArray}; - methodMap_[\\"getObject\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getObject}; - methodMap_[\\"getObjectShape\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getObjectShape}; - methodMap_[\\"getAlias\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getAlias}; - methodMap_[\\"getRootTag\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getRootTag}; - methodMap_[\\"getValue\\"] = MethodMetadata {3, __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getValue}; - methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getValueWithCallback}; - methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleArraysCxxSpecJSI_getValueWithPromise}; -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getConstants(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getConstants( - rt - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_voidFunc(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->voidFunc( - rt - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getBool(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getBool( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool()) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getNumber(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getNumber( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getString(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getString( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asString(rt)) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getArray(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getArray( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt).asArray(rt)) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getObject(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getObject( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getObjectShape(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getObjectShape( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getAlias(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getAlias( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getRootTag(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getRootTag( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getValue(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getValue( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()), - count <= 1 || args[1].isNull() || args[1].isUndefined() ? std::nullopt : std::make_optional(args[1].asString(rt)), - count <= 2 || args[2].isNull() || args[2].isUndefined() ? std::nullopt : std::make_optional(args[2].asObject(rt)) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getValueWithCallback(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->getValueWithCallback( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asFunction(rt) - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getValueWithPromise(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getValueWithPromise( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool()) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} - -NativeSampleTurboModuleNullableCxxSpecJSI::NativeSampleTurboModuleNullableCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModuleNullable\\", jsInvoker) { - methodMap_[\\"getConstants\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getConstants}; - methodMap_[\\"voidFunc\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_voidFunc}; - methodMap_[\\"getBool\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getBool}; - methodMap_[\\"getNumber\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getNumber}; - methodMap_[\\"getString\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getString}; - methodMap_[\\"getArray\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getArray}; - methodMap_[\\"getObject\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getObject}; - methodMap_[\\"getObjectShape\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getObjectShape}; - methodMap_[\\"getAlias\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getAlias}; - methodMap_[\\"getRootTag\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getRootTag}; - methodMap_[\\"getValue\\"] = MethodMetadata {3, __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getValue}; - methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getValueWithCallback}; - methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableCxxSpecJSI_getValueWithPromise}; -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getConstants(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getConstants( - rt - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_voidFunc(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->voidFunc( - rt - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getBool(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getBool( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool()) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getNumber(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getNumber( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getString(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getString( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asString(rt)) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getArray(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getArray( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt).asArray(rt)) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getObject(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getObject( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getObjectShape(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getObjectShape( - rt, - count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getAlias(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getAlias( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getRootTag(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getRootTag( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getValue(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getValue( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()), - count <= 1 || args[1].isNull() || args[1].isUndefined() ? std::nullopt : std::make_optional(args[1].asString(rt)), - count <= 2 || args[2].isNull() || args[2].isUndefined() ? std::nullopt : std::make_optional(args[2].asObject(rt)) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getValueWithCallback(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->getValueWithCallback( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt).asFunction(rt)) - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getValueWithPromise(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getValueWithPromise( - rt, - count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool()) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} - -NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI::NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModuleNullableAndOptional\\", jsInvoker) { - methodMap_[\\"getConstants\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getConstants}; - methodMap_[\\"voidFunc\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_voidFunc}; - methodMap_[\\"getBool\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getBool}; - methodMap_[\\"getNumber\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getNumber}; - methodMap_[\\"getString\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getString}; - methodMap_[\\"getArray\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getArray}; - methodMap_[\\"getObject\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getObject}; - methodMap_[\\"getObjectShape\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getObjectShape}; - methodMap_[\\"getAlias\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getAlias}; - methodMap_[\\"getRootTag\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getRootTag}; - methodMap_[\\"getValue\\"] = MethodMetadata {3, __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getValue}; - methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getValueWithCallback}; - methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI_getValueWithPromise}; -} -static jsi::Value __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getConstants(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getConstants( - rt - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_voidFunc(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->voidFunc( - rt - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getBool(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getBool( - rt, - count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool()) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getNumber(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getNumber( - rt, - count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getString(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getString( - rt, - count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asString(rt)) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getArray(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getArray( - rt, - count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt).asArray(rt)) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getObject(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getObject( - rt, - count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getObjectShape(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getObjectShape( - rt, - count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getAlias(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getAlias( - rt, - count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getRootTag(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getRootTag( - rt, - count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getValue(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getValue( - rt, - count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()), - count <= 1 || args[1].isUndefined() ? std::nullopt : std::make_optional(args[1].asString(rt)), - count <= 2 || args[2].isUndefined() ? std::nullopt : std::make_optional(args[2].asObject(rt)) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getValueWithCallback(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->getValueWithCallback( - rt, - count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt).asFunction(rt)) - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getValueWithPromise(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getValueWithPromise( - rt, - count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool()) - ); -} - -NativeSampleTurboModuleOptionalCxxSpecJSI::NativeSampleTurboModuleOptionalCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModuleOptional\\", jsInvoker) { - methodMap_[\\"getConstants\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getConstants}; - methodMap_[\\"voidFunc\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_voidFunc}; - methodMap_[\\"getBool\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getBool}; - methodMap_[\\"getNumber\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getNumber}; - methodMap_[\\"getString\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getString}; - methodMap_[\\"getArray\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getArray}; - methodMap_[\\"getObject\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getObject}; - methodMap_[\\"getObjectShape\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getObjectShape}; - methodMap_[\\"getAlias\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getAlias}; - methodMap_[\\"getRootTag\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getRootTag}; - methodMap_[\\"getValue\\"] = MethodMetadata {3, __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getValue}; - methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getValueWithCallback}; - methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleOptionalCxxSpecJSI_getValueWithPromise}; -} -static jsi::Value __hostFunction_NativeStringTurboModuleCxxSpecJSI_getString(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getString( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt) - ); -} -static jsi::Value __hostFunction_NativeStringTurboModuleCxxSpecJSI_getStringWithAlias(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getStringWithAlias( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt) - ); -} - -NativeStringTurboModuleCxxSpecJSI::NativeStringTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - methodMap_[\\"getString\\"] = MethodMetadata {1, __hostFunction_NativeStringTurboModuleCxxSpecJSI_getString}; - methodMap_[\\"getStringWithAlias\\"] = MethodMetadata {1, __hostFunction_NativeStringTurboModuleCxxSpecJSI_getStringWithAlias}; -} - - -} // namespace facebook::react -" -`; diff --git a/packages/react-native-codegen/e2e/deep_imports/__tests__/modules/__snapshots__/GenerateModuleH-test.js.snap b/packages/react-native-codegen/e2e/deep_imports/__tests__/modules/__snapshots__/GenerateModuleH-test.js.snap index f47510a4540f1a..0e519db7e50944 100644 --- a/packages/react-native-codegen/e2e/deep_imports/__tests__/modules/__snapshots__/GenerateModuleH-test.js.snap +++ b/packages/react-native-codegen/e2e/deep_imports/__tests__/modules/__snapshots__/GenerateModuleH-test.js.snap @@ -18,201 +18,110 @@ exports[`GenerateModuleH can generate a header file NativeModule specs 1`] = ` namespace facebook::react { - class JSI_EXPORT NativeArrayTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeArrayTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Array getArray(jsi::Runtime &rt, jsi::Array a) = 0; - virtual jsi::Array getReadOnlyArray(jsi::Runtime &rt, jsi::Array a) = 0; - virtual jsi::Array getArrayWithAlias(jsi::Runtime &rt, jsi::Array a, jsi::Array b) = 0; - -}; - template class JSI_EXPORT NativeArrayTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; protected: - NativeArrayTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeArrayTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeArrayTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeArrayTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getArray\\"] = MethodMetadata {.argCount = 1, .invoker = __getArrayJSI}; + methodMap_[\\"getReadOnlyArray\\"] = MethodMetadata {.argCount = 1, .invoker = __getReadOnlyArrayJSI}; + methodMap_[\\"getArrayWithAlias\\"] = MethodMetadata {.argCount = 2, .invoker = __getArrayWithAliasJSI}; + } + private: - class Delegate : public NativeArrayTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeArrayTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::Array getArray(jsi::Runtime &rt, jsi::Array a) override { - static_assert( - bridging::getParameterCount(&T::getArray) == 2, - \\"Expected getArray(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getArray, jsInvoker_, instance_, std::move(a)); - } - jsi::Array getReadOnlyArray(jsi::Runtime &rt, jsi::Array a) override { - static_assert( - bridging::getParameterCount(&T::getReadOnlyArray) == 2, - \\"Expected getReadOnlyArray(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getReadOnlyArray, jsInvoker_, instance_, std::move(a)); - } - jsi::Array getArrayWithAlias(jsi::Runtime &rt, jsi::Array a, jsi::Array b) override { - static_assert( - bridging::getParameterCount(&T::getArrayWithAlias) == 3, - \\"Expected getArrayWithAlias(...) to have 3 parameters\\"); - - return bridging::callFromJs( - rt, &T::getArrayWithAlias, jsInvoker_, instance_, std::move(a), std::move(b)); - } + static jsi::Value __getArrayJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getArray) == 2, + \\"Expected getArray(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getArray, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); + } - private: - friend class NativeArrayTurboModuleCxxSpec; - T *instance_; - }; + static jsi::Value __getReadOnlyArrayJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getReadOnlyArray) == 2, + \\"Expected getReadOnlyArray(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getReadOnlyArray, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); + } - Delegate delegate_; + static jsi::Value __getArrayWithAliasJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getArrayWithAlias) == 3, + \\"Expected getArrayWithAlias(...) to have 3 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getArrayWithAlias, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt), + count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asObject(rt).asArray(rt)); + } }; - class JSI_EXPORT NativeBooleanTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeBooleanTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual bool getBoolean(jsi::Runtime &rt, bool arg) = 0; - virtual bool getBooleanWithAlias(jsi::Runtime &rt, bool arg) = 0; - -}; - template class JSI_EXPORT NativeBooleanTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; protected: - NativeBooleanTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeBooleanTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeBooleanTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeBooleanTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getBoolean\\"] = MethodMetadata {.argCount = 1, .invoker = __getBooleanJSI}; + methodMap_[\\"getBooleanWithAlias\\"] = MethodMetadata {.argCount = 1, .invoker = __getBooleanWithAliasJSI}; + } + private: - class Delegate : public NativeBooleanTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeBooleanTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - bool getBoolean(jsi::Runtime &rt, bool arg) override { - static_assert( - bridging::getParameterCount(&T::getBoolean) == 2, - \\"Expected getBoolean(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getBoolean, jsInvoker_, instance_, std::move(arg)); - } - bool getBooleanWithAlias(jsi::Runtime &rt, bool arg) override { - static_assert( - bridging::getParameterCount(&T::getBooleanWithAlias) == 2, - \\"Expected getBooleanWithAlias(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getBooleanWithAlias, jsInvoker_, instance_, std::move(arg)); - } - - private: - friend class NativeBooleanTurboModuleCxxSpec; - T *instance_; - }; + static jsi::Value __getBooleanJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getBoolean) == 2, + \\"Expected getBoolean(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getBoolean, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool()); + } - Delegate delegate_; + static jsi::Value __getBooleanWithAliasJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getBooleanWithAlias) == 2, + \\"Expected getBooleanWithAlias(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getBooleanWithAlias, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool()); + } }; - class JSI_EXPORT NativeCallbackTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeCallbackTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual void getValueWithCallback(jsi::Runtime &rt, jsi::Function callback) = 0; - virtual void getValueWithCallbackWithAlias(jsi::Runtime &rt, jsi::Function c) = 0; - -}; - template class JSI_EXPORT NativeCallbackTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; protected: - NativeCallbackTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeCallbackTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeCallbackTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeCallbackTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithCallbackJSI}; + methodMap_[\\"getValueWithCallbackWithAlias\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithCallbackWithAliasJSI}; + } + private: - class Delegate : public NativeCallbackTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeCallbackTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - void getValueWithCallback(jsi::Runtime &rt, jsi::Function callback) override { - static_assert( - bridging::getParameterCount(&T::getValueWithCallback) == 2, - \\"Expected getValueWithCallback(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithCallback, jsInvoker_, instance_, std::move(callback)); - } - void getValueWithCallbackWithAlias(jsi::Runtime &rt, jsi::Function c) override { - static_assert( - bridging::getParameterCount(&T::getValueWithCallbackWithAlias) == 2, - \\"Expected getValueWithCallbackWithAlias(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithCallbackWithAlias, jsInvoker_, instance_, std::move(c)); - } - - private: - friend class NativeCallbackTurboModuleCxxSpec; - T *instance_; - }; + static jsi::Value __getValueWithCallbackJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithCallback) == 2, + \\"Expected getValueWithCallback(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::getValueWithCallback, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asFunction(rt));return jsi::Value::undefined(); + } - Delegate delegate_; + static jsi::Value __getValueWithCallbackWithAliasJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithCallbackWithAlias) == 2, + \\"Expected getValueWithCallbackWithAlias(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::getValueWithCallbackWithAlias, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asFunction(rt));return jsi::Value::undefined(); + } }; @@ -343,7 +252,6 @@ struct Bridging { } } }; - #pragma mark - NativeEnumTurboModuleStateType template @@ -420,19 +328,15 @@ struct NativeEnumTurboModuleStateTypeWithEnumsBridging { static jsi::String stateToJs(jsi::Runtime &rt, decltype(types.state) value) { return bridging::toJs(rt, value); } - static jsi::String regularToJs(jsi::Runtime &rt, decltype(types.regular) value) { return bridging::toJs(rt, value); } - static jsi::String strToJs(jsi::Runtime &rt, decltype(types.str) value) { return bridging::toJs(rt, value); } - static jsi::Value numToJs(jsi::Runtime &rt, decltype(types.num) value) { return bridging::toJs(rt, value); } - static jsi::String lowerCaseToJs(jsi::Runtime &rt, decltype(types.lowerCase) value) { return bridging::toJs(rt, value); } @@ -452,412 +356,267 @@ struct NativeEnumTurboModuleStateTypeWithEnumsBridging { } }; -class JSI_EXPORT NativeEnumTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeEnumTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::String getStatusRegular(jsi::Runtime &rt, jsi::Object statusProp) = 0; - virtual jsi::String getStatusStr(jsi::Runtime &rt, jsi::Object statusProp) = 0; - virtual jsi::Value getStatusNum(jsi::Runtime &rt, jsi::Object statusProp) = 0; - virtual jsi::String getStatusLowerCase(jsi::Runtime &rt, jsi::Object statusProp) = 0; - virtual jsi::Object getStateType(jsi::Runtime &rt, jsi::String a, jsi::String b, jsi::Value c, jsi::String d) = 0; - virtual jsi::Object getStateTypeWithEnums(jsi::Runtime &rt, jsi::Object paramOfTypeWithEnums) = 0; - -}; template class JSI_EXPORT NativeEnumTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"NativeEnumTurboModule\\"; protected: - NativeEnumTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeEnumTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeEnumTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeEnumTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getStatusRegular\\"] = MethodMetadata {.argCount = 1, .invoker = __getStatusRegularJSI}; + methodMap_[\\"getStatusStr\\"] = MethodMetadata {.argCount = 1, .invoker = __getStatusStrJSI}; + methodMap_[\\"getStatusNum\\"] = MethodMetadata {.argCount = 1, .invoker = __getStatusNumJSI}; + methodMap_[\\"getStatusLowerCase\\"] = MethodMetadata {.argCount = 1, .invoker = __getStatusLowerCaseJSI}; + methodMap_[\\"getStateType\\"] = MethodMetadata {.argCount = 4, .invoker = __getStateTypeJSI}; + methodMap_[\\"getStateTypeWithEnums\\"] = MethodMetadata {.argCount = 1, .invoker = __getStateTypeWithEnumsJSI}; + } + private: - class Delegate : public NativeEnumTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeEnumTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::String getStatusRegular(jsi::Runtime &rt, jsi::Object statusProp) override { - static_assert( - bridging::getParameterCount(&T::getStatusRegular) == 2, - \\"Expected getStatusRegular(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getStatusRegular, jsInvoker_, instance_, std::move(statusProp)); - } - jsi::String getStatusStr(jsi::Runtime &rt, jsi::Object statusProp) override { - static_assert( - bridging::getParameterCount(&T::getStatusStr) == 2, - \\"Expected getStatusStr(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getStatusStr, jsInvoker_, instance_, std::move(statusProp)); - } - jsi::Value getStatusNum(jsi::Runtime &rt, jsi::Object statusProp) override { - static_assert( - bridging::getParameterCount(&T::getStatusNum) == 2, - \\"Expected getStatusNum(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getStatusNum, jsInvoker_, instance_, std::move(statusProp)); - } - jsi::String getStatusLowerCase(jsi::Runtime &rt, jsi::Object statusProp) override { - static_assert( - bridging::getParameterCount(&T::getStatusLowerCase) == 2, - \\"Expected getStatusLowerCase(...) to have 2 parameters\\"); + static jsi::Value __getStatusRegularJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getStatusRegular) == 2, + \\"Expected getStatusRegular(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getStatusRegular, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } - return bridging::callFromJs( - rt, &T::getStatusLowerCase, jsInvoker_, instance_, std::move(statusProp)); - } - jsi::Object getStateType(jsi::Runtime &rt, jsi::String a, jsi::String b, jsi::Value c, jsi::String d) override { - static_assert( - bridging::getParameterCount(&T::getStateType) == 5, - \\"Expected getStateType(...) to have 5 parameters\\"); + static jsi::Value __getStatusStrJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getStatusStr) == 2, + \\"Expected getStatusStr(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getStatusStr, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } - return bridging::callFromJs( - rt, &T::getStateType, jsInvoker_, instance_, std::move(a), std::move(b), std::move(c), std::move(d)); - } - jsi::Object getStateTypeWithEnums(jsi::Runtime &rt, jsi::Object paramOfTypeWithEnums) override { - static_assert( - bridging::getParameterCount(&T::getStateTypeWithEnums) == 2, - \\"Expected getStateTypeWithEnums(...) to have 2 parameters\\"); + static jsi::Value __getStatusNumJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getStatusNum) == 2, + \\"Expected getStatusNum(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getStatusNum, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } - return bridging::callFromJs( - rt, &T::getStateTypeWithEnums, jsInvoker_, instance_, std::move(paramOfTypeWithEnums)); - } + static jsi::Value __getStatusLowerCaseJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getStatusLowerCase) == 2, + \\"Expected getStatusLowerCase(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getStatusLowerCase, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } - private: - friend class NativeEnumTurboModuleCxxSpec; - T *instance_; - }; + static jsi::Value __getStateTypeJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getStateType) == 5, + \\"Expected getStateType(...) to have 5 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getStateType, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt), + count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asString(rt), + count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asNumber(), + count <= 3 ? throw jsi::JSError(rt, \\"Expected argument in position 3 to be passed\\") : args[3].asString(rt)); + } - Delegate delegate_; + static jsi::Value __getStateTypeWithEnumsJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getStateTypeWithEnums) == 2, + \\"Expected getStateTypeWithEnums(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getStateTypeWithEnums, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } }; - class JSI_EXPORT NativeNullableTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeNullableTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual std::optional getBool(jsi::Runtime &rt, std::optional a) = 0; - virtual std::optional getNumber(jsi::Runtime &rt, std::optional a) = 0; - virtual std::optional getString(jsi::Runtime &rt, std::optional a) = 0; - virtual std::optional getArray(jsi::Runtime &rt, std::optional a) = 0; - virtual std::optional getObject(jsi::Runtime &rt, std::optional a) = 0; - virtual std::optional getValueWithPromise(jsi::Runtime &rt) = 0; - -}; - template class JSI_EXPORT NativeNullableTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; protected: - NativeNullableTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeNullableTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeNullableTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeNullableTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getBool\\"] = MethodMetadata {.argCount = 1, .invoker = __getBoolJSI}; + methodMap_[\\"getNumber\\"] = MethodMetadata {.argCount = 1, .invoker = __getNumberJSI}; + methodMap_[\\"getString\\"] = MethodMetadata {.argCount = 1, .invoker = __getStringJSI}; + methodMap_[\\"getArray\\"] = MethodMetadata {.argCount = 1, .invoker = __getArrayJSI}; + methodMap_[\\"getObject\\"] = MethodMetadata {.argCount = 1, .invoker = __getObjectJSI}; + methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {.argCount = 0, .invoker = __getValueWithPromiseJSI}; + } + private: - class Delegate : public NativeNullableTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeNullableTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - std::optional getBool(jsi::Runtime &rt, std::optional a) override { - static_assert( - bridging::getParameterCount(&T::getBool) == 2, - \\"Expected getBool(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getBool, jsInvoker_, instance_, std::move(a)); - } - std::optional getNumber(jsi::Runtime &rt, std::optional a) override { - static_assert( - bridging::getParameterCount(&T::getNumber) == 2, - \\"Expected getNumber(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getNumber, jsInvoker_, instance_, std::move(a)); - } - std::optional getString(jsi::Runtime &rt, std::optional a) override { - static_assert( - bridging::getParameterCount(&T::getString) == 2, - \\"Expected getString(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getString, jsInvoker_, instance_, std::move(a)); - } - std::optional getArray(jsi::Runtime &rt, std::optional a) override { - static_assert( - bridging::getParameterCount(&T::getArray) == 2, - \\"Expected getArray(...) to have 2 parameters\\"); + static jsi::Value __getBoolJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getBool) == 2, + \\"Expected getBool(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getBool, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool()));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } - return bridging::callFromJs>( - rt, &T::getArray, jsInvoker_, instance_, std::move(a)); - } - std::optional getObject(jsi::Runtime &rt, std::optional a) override { - static_assert( - bridging::getParameterCount(&T::getObject) == 2, - \\"Expected getObject(...) to have 2 parameters\\"); + static jsi::Value __getNumberJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getNumber) == 2, + \\"Expected getNumber(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getNumber, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } - return bridging::callFromJs>( - rt, &T::getObject, jsInvoker_, instance_, std::move(a)); - } - std::optional getValueWithPromise(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getValueWithPromise) == 1, - \\"Expected getValueWithPromise(...) to have 1 parameters\\"); + static jsi::Value __getStringJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getString) == 2, + \\"Expected getString(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getString, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } - return bridging::callFromJs>( - rt, &T::getValueWithPromise, jsInvoker_, instance_); - } + static jsi::Value __getArrayJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getArray) == 2, + \\"Expected getArray(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getArray, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt).asArray(rt)));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } - private: - friend class NativeNullableTurboModuleCxxSpec; - T *instance_; - }; + static jsi::Value __getObjectJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getObject) == 2, + \\"Expected getObject(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getObject, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } - Delegate delegate_; + static jsi::Value __getValueWithPromiseJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getValueWithPromise) == 1, + \\"Expected getValueWithPromise(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getValueWithPromise, self->jsInvoker_, self);return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } }; - class JSI_EXPORT NativeNumberTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeNumberTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual double getNumber(jsi::Runtime &rt, double arg) = 0; - virtual double getNumberWithAlias(jsi::Runtime &rt, double arg) = 0; - -}; - template class JSI_EXPORT NativeNumberTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; protected: - NativeNumberTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeNumberTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeNumberTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeNumberTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getNumber\\"] = MethodMetadata {.argCount = 1, .invoker = __getNumberJSI}; + methodMap_[\\"getNumberWithAlias\\"] = MethodMetadata {.argCount = 1, .invoker = __getNumberWithAliasJSI}; + } + private: - class Delegate : public NativeNumberTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeNumberTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - double getNumber(jsi::Runtime &rt, double arg) override { - static_assert( - bridging::getParameterCount(&T::getNumber) == 2, - \\"Expected getNumber(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getNumber, jsInvoker_, instance_, std::move(arg)); - } - double getNumberWithAlias(jsi::Runtime &rt, double arg) override { - static_assert( - bridging::getParameterCount(&T::getNumberWithAlias) == 2, - \\"Expected getNumberWithAlias(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getNumberWithAlias, jsInvoker_, instance_, std::move(arg)); - } - - private: - friend class NativeNumberTurboModuleCxxSpec; - T *instance_; - }; + static jsi::Value __getNumberJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getNumber) == 2, + \\"Expected getNumber(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getNumber, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber()); + } - Delegate delegate_; + static jsi::Value __getNumberWithAliasJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getNumberWithAlias) == 2, + \\"Expected getNumberWithAlias(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getNumberWithAlias, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber()); + } }; - class JSI_EXPORT NativeObjectTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeObjectTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Object getGenericObject(jsi::Runtime &rt, jsi::Object arg) = 0; - virtual jsi::Object getGenericObjectReadOnly(jsi::Runtime &rt, jsi::Object arg) = 0; - virtual jsi::Object getGenericObjectWithAlias(jsi::Runtime &rt, jsi::Object arg) = 0; - virtual jsi::Object difficultObject(jsi::Runtime &rt, jsi::Object A) = 0; - virtual jsi::Object getConstants(jsi::Runtime &rt) = 0; - -}; - template class JSI_EXPORT NativeObjectTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; protected: - NativeObjectTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeObjectTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeObjectTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeObjectTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getGenericObject\\"] = MethodMetadata {.argCount = 1, .invoker = __getGenericObjectJSI}; + methodMap_[\\"getGenericObjectReadOnly\\"] = MethodMetadata {.argCount = 1, .invoker = __getGenericObjectReadOnlyJSI}; + methodMap_[\\"getGenericObjectWithAlias\\"] = MethodMetadata {.argCount = 1, .invoker = __getGenericObjectWithAliasJSI}; + methodMap_[\\"difficultObject\\"] = MethodMetadata {.argCount = 1, .invoker = __difficultObjectJSI}; + methodMap_[\\"getConstants\\"] = MethodMetadata {.argCount = 0, .invoker = __getConstantsJSI}; + } + private: - class Delegate : public NativeObjectTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeObjectTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::Object getGenericObject(jsi::Runtime &rt, jsi::Object arg) override { - static_assert( - bridging::getParameterCount(&T::getGenericObject) == 2, - \\"Expected getGenericObject(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getGenericObject, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getGenericObjectReadOnly(jsi::Runtime &rt, jsi::Object arg) override { - static_assert( - bridging::getParameterCount(&T::getGenericObjectReadOnly) == 2, - \\"Expected getGenericObjectReadOnly(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getGenericObjectReadOnly, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getGenericObjectWithAlias(jsi::Runtime &rt, jsi::Object arg) override { - static_assert( - bridging::getParameterCount(&T::getGenericObjectWithAlias) == 2, - \\"Expected getGenericObjectWithAlias(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getGenericObjectWithAlias, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object difficultObject(jsi::Runtime &rt, jsi::Object A) override { - static_assert( - bridging::getParameterCount(&T::difficultObject) == 2, - \\"Expected difficultObject(...) to have 2 parameters\\"); + static jsi::Value __getGenericObjectJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getGenericObject) == 2, + \\"Expected getGenericObject(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getGenericObject, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } - return bridging::callFromJs( - rt, &T::difficultObject, jsInvoker_, instance_, std::move(A)); - } - jsi::Object getConstants(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getConstants) == 1, - \\"Expected getConstants(...) to have 1 parameters\\"); + static jsi::Value __getGenericObjectReadOnlyJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getGenericObjectReadOnly) == 2, + \\"Expected getGenericObjectReadOnly(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getGenericObjectReadOnly, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } - return bridging::callFromJs( - rt, &T::getConstants, jsInvoker_, instance_); - } + static jsi::Value __getGenericObjectWithAliasJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getGenericObjectWithAlias) == 2, + \\"Expected getGenericObjectWithAlias(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getGenericObjectWithAlias, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } - private: - friend class NativeObjectTurboModuleCxxSpec; - T *instance_; - }; + static jsi::Value __difficultObjectJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::difficultObject) == 2, + \\"Expected difficultObject(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::difficultObject, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } - Delegate delegate_; + static jsi::Value __getConstantsJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getConstants) == 1, + \\"Expected getConstants(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getConstants, self->jsInvoker_, self); + } }; - class JSI_EXPORT NativeOptionalObjectTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeOptionalObjectTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Object getConstants(jsi::Runtime &rt) = 0; - -}; - template class JSI_EXPORT NativeOptionalObjectTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; protected: - NativeOptionalObjectTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeOptionalObjectTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeOptionalObjectTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeOptionalObjectTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getConstants\\"] = MethodMetadata {.argCount = 0, .invoker = __getConstantsJSI}; + } + private: - class Delegate : public NativeOptionalObjectTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeOptionalObjectTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::Object getConstants(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getConstants) == 1, - \\"Expected getConstants(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::getConstants, jsInvoker_, instance_); - } - - private: - friend class NativeOptionalObjectTurboModuleCxxSpec; - T *instance_; - }; - - Delegate delegate_; + static jsi::Value __getConstantsJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getConstants) == 1, + \\"Expected getConstants(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getConstants, self->jsInvoker_, self); + } }; - #pragma mark - NativePartialAnnotationTurboModuleSomeObj template @@ -887,7 +646,6 @@ struct NativePartialAnnotationTurboModuleSomeObjBridging { static jsi::String aToJs(jsi::Runtime &rt, decltype(types.a) value) { return bridging::toJs(rt, value); } - static bool bToJs(jsi::Runtime &rt, decltype(types.b) value) { return bridging::toJs(rt, value); } @@ -906,151 +664,90 @@ struct NativePartialAnnotationTurboModuleSomeObjBridging { } }; -class JSI_EXPORT NativePartialAnnotationTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativePartialAnnotationTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Object getSomeObj(jsi::Runtime &rt) = 0; - virtual jsi::Object getPartialSomeObj(jsi::Runtime &rt) = 0; - virtual jsi::Object getSomeObjFromPartialSomeObj(jsi::Runtime &rt, jsi::Object value) = 0; - virtual jsi::Object getPartialPartial(jsi::Runtime &rt, jsi::Object value1, jsi::Object value2) = 0; - -}; template class JSI_EXPORT NativePartialAnnotationTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"NativePartialAnnotationTurboModule\\"; protected: - NativePartialAnnotationTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativePartialAnnotationTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativePartialAnnotationTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativePartialAnnotationTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getSomeObj\\"] = MethodMetadata {.argCount = 0, .invoker = __getSomeObjJSI}; + methodMap_[\\"getPartialSomeObj\\"] = MethodMetadata {.argCount = 0, .invoker = __getPartialSomeObjJSI}; + methodMap_[\\"getSomeObjFromPartialSomeObj\\"] = MethodMetadata {.argCount = 1, .invoker = __getSomeObjFromPartialSomeObjJSI}; + methodMap_[\\"getPartialPartial\\"] = MethodMetadata {.argCount = 2, .invoker = __getPartialPartialJSI}; + } + private: - class Delegate : public NativePartialAnnotationTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativePartialAnnotationTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::Object getSomeObj(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getSomeObj) == 1, - \\"Expected getSomeObj(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::getSomeObj, jsInvoker_, instance_); - } - jsi::Object getPartialSomeObj(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getPartialSomeObj) == 1, - \\"Expected getPartialSomeObj(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::getPartialSomeObj, jsInvoker_, instance_); - } - jsi::Object getSomeObjFromPartialSomeObj(jsi::Runtime &rt, jsi::Object value) override { - static_assert( - bridging::getParameterCount(&T::getSomeObjFromPartialSomeObj) == 2, - \\"Expected getSomeObjFromPartialSomeObj(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getSomeObjFromPartialSomeObj, jsInvoker_, instance_, std::move(value)); - } - jsi::Object getPartialPartial(jsi::Runtime &rt, jsi::Object value1, jsi::Object value2) override { - static_assert( - bridging::getParameterCount(&T::getPartialPartial) == 3, - \\"Expected getPartialPartial(...) to have 3 parameters\\"); + static jsi::Value __getSomeObjJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getSomeObj) == 1, + \\"Expected getSomeObj(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getSomeObj, self->jsInvoker_, self); + } - return bridging::callFromJs( - rt, &T::getPartialPartial, jsInvoker_, instance_, std::move(value1), std::move(value2)); - } + static jsi::Value __getPartialSomeObjJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getPartialSomeObj) == 1, + \\"Expected getPartialSomeObj(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getPartialSomeObj, self->jsInvoker_, self); + } - private: - friend class NativePartialAnnotationTurboModuleCxxSpec; - T *instance_; - }; + static jsi::Value __getSomeObjFromPartialSomeObjJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getSomeObjFromPartialSomeObj) == 2, + \\"Expected getSomeObjFromPartialSomeObj(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getSomeObjFromPartialSomeObj, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } - Delegate delegate_; + static jsi::Value __getPartialPartialJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getPartialPartial) == 3, + \\"Expected getPartialPartial(...) to have 3 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getPartialPartial, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt), + count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asObject(rt)); + } }; - class JSI_EXPORT NativePromiseTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativePromiseTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Value getValueWithPromise(jsi::Runtime &rt, bool error) = 0; - virtual jsi::Value getValueWithPromiseWithAlias(jsi::Runtime &rt, jsi::String arg) = 0; - -}; - template class JSI_EXPORT NativePromiseTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } + static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); +protected: + NativePromiseTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativePromiseTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithPromiseJSI}; + methodMap_[\\"getValueWithPromiseWithAlias\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithPromiseWithAliasJSI}; } - - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; - -protected: - NativePromiseTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativePromiseTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + private: - class Delegate : public NativePromiseTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativePromiseTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::Value getValueWithPromise(jsi::Runtime &rt, bool error) override { - static_assert( - bridging::getParameterCount(&T::getValueWithPromise) == 2, - \\"Expected getValueWithPromise(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithPromise, jsInvoker_, instance_, std::move(error)); - } - jsi::Value getValueWithPromiseWithAlias(jsi::Runtime &rt, jsi::String arg) override { - static_assert( - bridging::getParameterCount(&T::getValueWithPromiseWithAlias) == 2, - \\"Expected getValueWithPromiseWithAlias(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithPromiseWithAlias, jsInvoker_, instance_, std::move(arg)); - } - - private: - friend class NativePromiseTurboModuleCxxSpec; - T *instance_; - }; + static jsi::Value __getValueWithPromiseJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithPromise) == 2, + \\"Expected getValueWithPromise(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getValueWithPromise, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool()); + } - Delegate delegate_; + static jsi::Value __getValueWithPromiseWithAliasJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithPromiseWithAlias) == 2, + \\"Expected getValueWithPromiseWithAlias(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getValueWithPromiseWithAlias, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt)); + } }; - #pragma mark - NativeSampleTurboModuleAnimal template @@ -1090,169 +787,149 @@ struct NativeSampleTurboModuleAnimalBridging { } }; -class JSI_EXPORT NativeSampleTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeSampleTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Object getConstants(jsi::Runtime &rt) = 0; - virtual void voidFunc(jsi::Runtime &rt) = 0; - virtual bool getBool(jsi::Runtime &rt, bool arg) = 0; - virtual double getNumber(jsi::Runtime &rt, double arg) = 0; - virtual jsi::String getString(jsi::Runtime &rt, jsi::String arg) = 0; - virtual jsi::Array getArray(jsi::Runtime &rt, jsi::Array arg) = 0; - virtual jsi::Object getObject(jsi::Runtime &rt, jsi::Object arg) = 0; - virtual jsi::Object getObjectShape(jsi::Runtime &rt, jsi::Object arg) = 0; - virtual jsi::Object getAlias(jsi::Runtime &rt, jsi::Object arg) = 0; - virtual double getRootTag(jsi::Runtime &rt, double arg) = 0; - virtual jsi::Object getValue(jsi::Runtime &rt, double x, jsi::String getValuegetValuegetValuegetValuegetValuey, jsi::Object z) = 0; - virtual void getValueWithCallback(jsi::Runtime &rt, jsi::Function callback) = 0; - virtual jsi::Value getValueWithPromise(jsi::Runtime &rt, bool error) = 0; - -}; template class JSI_EXPORT NativeSampleTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; protected: - NativeSampleTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeSampleTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeSampleTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeSampleTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getConstants\\"] = MethodMetadata {.argCount = 0, .invoker = __getConstantsJSI}; + methodMap_[\\"voidFunc\\"] = MethodMetadata {.argCount = 0, .invoker = __voidFuncJSI}; + methodMap_[\\"getBool\\"] = MethodMetadata {.argCount = 1, .invoker = __getBoolJSI}; + methodMap_[\\"getNumber\\"] = MethodMetadata {.argCount = 1, .invoker = __getNumberJSI}; + methodMap_[\\"getString\\"] = MethodMetadata {.argCount = 1, .invoker = __getStringJSI}; + methodMap_[\\"getArray\\"] = MethodMetadata {.argCount = 1, .invoker = __getArrayJSI}; + methodMap_[\\"getObject\\"] = MethodMetadata {.argCount = 1, .invoker = __getObjectJSI}; + methodMap_[\\"getObjectShape\\"] = MethodMetadata {.argCount = 1, .invoker = __getObjectShapeJSI}; + methodMap_[\\"getAlias\\"] = MethodMetadata {.argCount = 1, .invoker = __getAliasJSI}; + methodMap_[\\"getRootTag\\"] = MethodMetadata {.argCount = 1, .invoker = __getRootTagJSI}; + methodMap_[\\"getValue\\"] = MethodMetadata {.argCount = 3, .invoker = __getValueJSI}; + methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithCallbackJSI}; + methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithPromiseJSI}; + } + private: - class Delegate : public NativeSampleTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeSampleTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::Object getConstants(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getConstants) == 1, - \\"Expected getConstants(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::getConstants, jsInvoker_, instance_); - } - void voidFunc(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::voidFunc) == 1, - \\"Expected voidFunc(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::voidFunc, jsInvoker_, instance_); - } - bool getBool(jsi::Runtime &rt, bool arg) override { - static_assert( - bridging::getParameterCount(&T::getBool) == 2, - \\"Expected getBool(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getBool, jsInvoker_, instance_, std::move(arg)); - } - double getNumber(jsi::Runtime &rt, double arg) override { - static_assert( - bridging::getParameterCount(&T::getNumber) == 2, - \\"Expected getNumber(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getNumber, jsInvoker_, instance_, std::move(arg)); - } - jsi::String getString(jsi::Runtime &rt, jsi::String arg) override { - static_assert( - bridging::getParameterCount(&T::getString) == 2, - \\"Expected getString(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getString, jsInvoker_, instance_, std::move(arg)); - } - jsi::Array getArray(jsi::Runtime &rt, jsi::Array arg) override { - static_assert( - bridging::getParameterCount(&T::getArray) == 2, - \\"Expected getArray(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getArray, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getObject(jsi::Runtime &rt, jsi::Object arg) override { - static_assert( - bridging::getParameterCount(&T::getObject) == 2, - \\"Expected getObject(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getObject, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getObjectShape(jsi::Runtime &rt, jsi::Object arg) override { - static_assert( - bridging::getParameterCount(&T::getObjectShape) == 2, - \\"Expected getObjectShape(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getObjectShape, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getAlias(jsi::Runtime &rt, jsi::Object arg) override { - static_assert( - bridging::getParameterCount(&T::getAlias) == 2, - \\"Expected getAlias(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getAlias, jsInvoker_, instance_, std::move(arg)); - } - double getRootTag(jsi::Runtime &rt, double arg) override { - static_assert( - bridging::getParameterCount(&T::getRootTag) == 2, - \\"Expected getRootTag(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getRootTag, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getValue(jsi::Runtime &rt, double x, jsi::String getValuegetValuegetValuegetValuegetValuey, jsi::Object z) override { - static_assert( - bridging::getParameterCount(&T::getValue) == 4, - \\"Expected getValue(...) to have 4 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValue, jsInvoker_, instance_, std::move(x), std::move(getValuegetValuegetValuegetValuegetValuey), std::move(z)); - } - void getValueWithCallback(jsi::Runtime &rt, jsi::Function callback) override { - static_assert( - bridging::getParameterCount(&T::getValueWithCallback) == 2, - \\"Expected getValueWithCallback(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithCallback, jsInvoker_, instance_, std::move(callback)); - } - jsi::Value getValueWithPromise(jsi::Runtime &rt, bool error) override { - static_assert( - bridging::getParameterCount(&T::getValueWithPromise) == 2, - \\"Expected getValueWithPromise(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithPromise, jsInvoker_, instance_, std::move(error)); - } - - private: - friend class NativeSampleTurboModuleCxxSpec; - T *instance_; - }; - - Delegate delegate_; + static jsi::Value __getConstantsJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getConstants) == 1, + \\"Expected getConstants(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getConstants, self->jsInvoker_, self); + } + + static jsi::Value __voidFuncJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::voidFunc) == 1, + \\"Expected voidFunc(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::voidFunc, self->jsInvoker_, self);return jsi::Value::undefined(); + } + + static jsi::Value __getBoolJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getBool) == 2, + \\"Expected getBool(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getBool, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool()); + } + + static jsi::Value __getNumberJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getNumber) == 2, + \\"Expected getNumber(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getNumber, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber()); + } + + static jsi::Value __getStringJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getString) == 2, + \\"Expected getString(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getString, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt)); + } + + static jsi::Value __getArrayJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getArray) == 2, + \\"Expected getArray(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getArray, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); + } + + static jsi::Value __getObjectJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getObject) == 2, + \\"Expected getObject(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getObject, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } + + static jsi::Value __getObjectShapeJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getObjectShape) == 2, + \\"Expected getObjectShape(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getObjectShape, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } + + static jsi::Value __getAliasJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getAlias) == 2, + \\"Expected getAlias(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getAlias, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } + + static jsi::Value __getRootTagJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getRootTag) == 2, + \\"Expected getRootTag(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getRootTag, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber()); + } + + static jsi::Value __getValueJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValue) == 4, + \\"Expected getValue(...) to have 4 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getValue, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber(), + count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asString(rt), + count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asObject(rt)); + } + + static jsi::Value __getValueWithCallbackJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithCallback) == 2, + \\"Expected getValueWithCallback(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::getValueWithCallback, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asFunction(rt));return jsi::Value::undefined(); + } + + static jsi::Value __getValueWithPromiseJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithPromise) == 2, + \\"Expected getValueWithPromise(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getValueWithPromise, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool()); + } }; - #pragma mark - NativeSampleTurboModuleArraysAnimal template @@ -1292,169 +969,149 @@ struct NativeSampleTurboModuleArraysAnimalBridging { } }; -class JSI_EXPORT NativeSampleTurboModuleArraysCxxSpecJSI : public TurboModule { -protected: - NativeSampleTurboModuleArraysCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Object getConstants(jsi::Runtime &rt) = 0; - virtual void voidFunc(jsi::Runtime &rt) = 0; - virtual jsi::Array getBool(jsi::Runtime &rt, jsi::Array id) = 0; - virtual jsi::Array getNumber(jsi::Runtime &rt, jsi::Array arg) = 0; - virtual jsi::Array getString(jsi::Runtime &rt, jsi::Array arg) = 0; - virtual jsi::Array getArray(jsi::Runtime &rt, jsi::Array arg) = 0; - virtual jsi::Array getObject(jsi::Runtime &rt, jsi::Array arg) = 0; - virtual jsi::Array getObjectShape(jsi::Runtime &rt, jsi::Array arg) = 0; - virtual jsi::Array getAlias(jsi::Runtime &rt, jsi::Array arg) = 0; - virtual jsi::Array getRootTag(jsi::Runtime &rt, jsi::Array arg) = 0; - virtual jsi::Array getValue(jsi::Runtime &rt, jsi::Array x, jsi::Array y, jsi::Array z) = 0; - virtual void getValueWithCallback(jsi::Runtime &rt, jsi::Function callback) = 0; - virtual jsi::Value getValueWithPromise(jsi::Runtime &rt, jsi::Array error) = 0; - -}; template class JSI_EXPORT NativeSampleTurboModuleArraysCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModuleArrays\\"; protected: - NativeSampleTurboModuleArraysCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeSampleTurboModuleArraysCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeSampleTurboModuleArraysCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeSampleTurboModuleArraysCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getConstants\\"] = MethodMetadata {.argCount = 0, .invoker = __getConstantsJSI}; + methodMap_[\\"voidFunc\\"] = MethodMetadata {.argCount = 0, .invoker = __voidFuncJSI}; + methodMap_[\\"getBool\\"] = MethodMetadata {.argCount = 1, .invoker = __getBoolJSI}; + methodMap_[\\"getNumber\\"] = MethodMetadata {.argCount = 1, .invoker = __getNumberJSI}; + methodMap_[\\"getString\\"] = MethodMetadata {.argCount = 1, .invoker = __getStringJSI}; + methodMap_[\\"getArray\\"] = MethodMetadata {.argCount = 1, .invoker = __getArrayJSI}; + methodMap_[\\"getObject\\"] = MethodMetadata {.argCount = 1, .invoker = __getObjectJSI}; + methodMap_[\\"getObjectShape\\"] = MethodMetadata {.argCount = 1, .invoker = __getObjectShapeJSI}; + methodMap_[\\"getAlias\\"] = MethodMetadata {.argCount = 1, .invoker = __getAliasJSI}; + methodMap_[\\"getRootTag\\"] = MethodMetadata {.argCount = 1, .invoker = __getRootTagJSI}; + methodMap_[\\"getValue\\"] = MethodMetadata {.argCount = 3, .invoker = __getValueJSI}; + methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithCallbackJSI}; + methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithPromiseJSI}; + } + private: - class Delegate : public NativeSampleTurboModuleArraysCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeSampleTurboModuleArraysCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::Object getConstants(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getConstants) == 1, - \\"Expected getConstants(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::getConstants, jsInvoker_, instance_); - } - void voidFunc(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::voidFunc) == 1, - \\"Expected voidFunc(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::voidFunc, jsInvoker_, instance_); - } - jsi::Array getBool(jsi::Runtime &rt, jsi::Array id) override { - static_assert( - bridging::getParameterCount(&T::getBool) == 2, - \\"Expected getBool(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getBool, jsInvoker_, instance_, std::move(id)); - } - jsi::Array getNumber(jsi::Runtime &rt, jsi::Array arg) override { - static_assert( - bridging::getParameterCount(&T::getNumber) == 2, - \\"Expected getNumber(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getNumber, jsInvoker_, instance_, std::move(arg)); - } - jsi::Array getString(jsi::Runtime &rt, jsi::Array arg) override { - static_assert( - bridging::getParameterCount(&T::getString) == 2, - \\"Expected getString(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getString, jsInvoker_, instance_, std::move(arg)); - } - jsi::Array getArray(jsi::Runtime &rt, jsi::Array arg) override { - static_assert( - bridging::getParameterCount(&T::getArray) == 2, - \\"Expected getArray(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getArray, jsInvoker_, instance_, std::move(arg)); - } - jsi::Array getObject(jsi::Runtime &rt, jsi::Array arg) override { - static_assert( - bridging::getParameterCount(&T::getObject) == 2, - \\"Expected getObject(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getObject, jsInvoker_, instance_, std::move(arg)); - } - jsi::Array getObjectShape(jsi::Runtime &rt, jsi::Array arg) override { - static_assert( - bridging::getParameterCount(&T::getObjectShape) == 2, - \\"Expected getObjectShape(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getObjectShape, jsInvoker_, instance_, std::move(arg)); - } - jsi::Array getAlias(jsi::Runtime &rt, jsi::Array arg) override { - static_assert( - bridging::getParameterCount(&T::getAlias) == 2, - \\"Expected getAlias(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getAlias, jsInvoker_, instance_, std::move(arg)); - } - jsi::Array getRootTag(jsi::Runtime &rt, jsi::Array arg) override { - static_assert( - bridging::getParameterCount(&T::getRootTag) == 2, - \\"Expected getRootTag(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getRootTag, jsInvoker_, instance_, std::move(arg)); - } - jsi::Array getValue(jsi::Runtime &rt, jsi::Array x, jsi::Array y, jsi::Array z) override { - static_assert( - bridging::getParameterCount(&T::getValue) == 4, - \\"Expected getValue(...) to have 4 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValue, jsInvoker_, instance_, std::move(x), std::move(y), std::move(z)); - } - void getValueWithCallback(jsi::Runtime &rt, jsi::Function callback) override { - static_assert( - bridging::getParameterCount(&T::getValueWithCallback) == 2, - \\"Expected getValueWithCallback(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithCallback, jsInvoker_, instance_, std::move(callback)); - } - jsi::Value getValueWithPromise(jsi::Runtime &rt, jsi::Array error) override { - static_assert( - bridging::getParameterCount(&T::getValueWithPromise) == 2, - \\"Expected getValueWithPromise(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithPromise, jsInvoker_, instance_, std::move(error)); - } - - private: - friend class NativeSampleTurboModuleArraysCxxSpec; - T *instance_; - }; - - Delegate delegate_; + static jsi::Value __getConstantsJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getConstants) == 1, + \\"Expected getConstants(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getConstants, self->jsInvoker_, self); + } + + static jsi::Value __voidFuncJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::voidFunc) == 1, + \\"Expected voidFunc(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::voidFunc, self->jsInvoker_, self);return jsi::Value::undefined(); + } + + static jsi::Value __getBoolJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getBool) == 2, + \\"Expected getBool(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getBool, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); + } + + static jsi::Value __getNumberJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getNumber) == 2, + \\"Expected getNumber(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getNumber, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); + } + + static jsi::Value __getStringJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getString) == 2, + \\"Expected getString(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getString, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); + } + + static jsi::Value __getArrayJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getArray) == 2, + \\"Expected getArray(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getArray, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); + } + + static jsi::Value __getObjectJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getObject) == 2, + \\"Expected getObject(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getObject, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); + } + + static jsi::Value __getObjectShapeJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getObjectShape) == 2, + \\"Expected getObjectShape(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getObjectShape, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); + } + + static jsi::Value __getAliasJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getAlias) == 2, + \\"Expected getAlias(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getAlias, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); + } + + static jsi::Value __getRootTagJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getRootTag) == 2, + \\"Expected getRootTag(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getRootTag, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); + } + + static jsi::Value __getValueJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValue) == 4, + \\"Expected getValue(...) to have 4 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getValue, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt), + count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asObject(rt).asArray(rt), + count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asObject(rt).asArray(rt)); + } + + static jsi::Value __getValueWithCallbackJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithCallback) == 2, + \\"Expected getValueWithCallback(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::getValueWithCallback, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asFunction(rt));return jsi::Value::undefined(); + } + + static jsi::Value __getValueWithPromiseJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithPromise) == 2, + \\"Expected getValueWithPromise(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getValueWithPromise, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); + } }; - #pragma mark - NativeSampleTurboModuleNullableAnimal template @@ -1494,169 +1151,149 @@ struct NativeSampleTurboModuleNullableAnimalBridging { } }; -class JSI_EXPORT NativeSampleTurboModuleNullableCxxSpecJSI : public TurboModule { -protected: - NativeSampleTurboModuleNullableCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Object getConstants(jsi::Runtime &rt) = 0; - virtual void voidFunc(jsi::Runtime &rt) = 0; - virtual std::optional getBool(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getNumber(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getString(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getArray(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getObject(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getObjectShape(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getAlias(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getRootTag(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getValue(jsi::Runtime &rt, std::optional x, std::optional y, std::optional z) = 0; - virtual void getValueWithCallback(jsi::Runtime &rt, jsi::Function callback) = 0; - virtual std::optional getValueWithPromise(jsi::Runtime &rt, std::optional error) = 0; - -}; template class JSI_EXPORT NativeSampleTurboModuleNullableCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModuleNullable\\"; protected: - NativeSampleTurboModuleNullableCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeSampleTurboModuleNullableCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeSampleTurboModuleNullableCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeSampleTurboModuleNullableCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getConstants\\"] = MethodMetadata {.argCount = 0, .invoker = __getConstantsJSI}; + methodMap_[\\"voidFunc\\"] = MethodMetadata {.argCount = 0, .invoker = __voidFuncJSI}; + methodMap_[\\"getBool\\"] = MethodMetadata {.argCount = 1, .invoker = __getBoolJSI}; + methodMap_[\\"getNumber\\"] = MethodMetadata {.argCount = 1, .invoker = __getNumberJSI}; + methodMap_[\\"getString\\"] = MethodMetadata {.argCount = 1, .invoker = __getStringJSI}; + methodMap_[\\"getArray\\"] = MethodMetadata {.argCount = 1, .invoker = __getArrayJSI}; + methodMap_[\\"getObject\\"] = MethodMetadata {.argCount = 1, .invoker = __getObjectJSI}; + methodMap_[\\"getObjectShape\\"] = MethodMetadata {.argCount = 1, .invoker = __getObjectShapeJSI}; + methodMap_[\\"getAlias\\"] = MethodMetadata {.argCount = 1, .invoker = __getAliasJSI}; + methodMap_[\\"getRootTag\\"] = MethodMetadata {.argCount = 1, .invoker = __getRootTagJSI}; + methodMap_[\\"getValue\\"] = MethodMetadata {.argCount = 3, .invoker = __getValueJSI}; + methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithCallbackJSI}; + methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithPromiseJSI}; + } + private: - class Delegate : public NativeSampleTurboModuleNullableCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeSampleTurboModuleNullableCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::Object getConstants(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getConstants) == 1, - \\"Expected getConstants(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::getConstants, jsInvoker_, instance_); - } - void voidFunc(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::voidFunc) == 1, - \\"Expected voidFunc(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::voidFunc, jsInvoker_, instance_); - } - std::optional getBool(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getBool) == 2, - \\"Expected getBool(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getBool, jsInvoker_, instance_, std::move(arg)); - } - std::optional getNumber(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getNumber) == 2, - \\"Expected getNumber(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getNumber, jsInvoker_, instance_, std::move(arg)); - } - std::optional getString(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getString) == 2, - \\"Expected getString(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getString, jsInvoker_, instance_, std::move(arg)); - } - std::optional getArray(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getArray) == 2, - \\"Expected getArray(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getArray, jsInvoker_, instance_, std::move(arg)); - } - std::optional getObject(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getObject) == 2, - \\"Expected getObject(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getObject, jsInvoker_, instance_, std::move(arg)); - } - std::optional getObjectShape(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getObjectShape) == 2, - \\"Expected getObjectShape(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getObjectShape, jsInvoker_, instance_, std::move(arg)); - } - std::optional getAlias(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getAlias) == 2, - \\"Expected getAlias(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getAlias, jsInvoker_, instance_, std::move(arg)); - } - std::optional getRootTag(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getRootTag) == 2, - \\"Expected getRootTag(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getRootTag, jsInvoker_, instance_, std::move(arg)); - } - std::optional getValue(jsi::Runtime &rt, std::optional x, std::optional y, std::optional z) override { - static_assert( - bridging::getParameterCount(&T::getValue) == 4, - \\"Expected getValue(...) to have 4 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getValue, jsInvoker_, instance_, std::move(x), std::move(y), std::move(z)); - } - void getValueWithCallback(jsi::Runtime &rt, jsi::Function callback) override { - static_assert( - bridging::getParameterCount(&T::getValueWithCallback) == 2, - \\"Expected getValueWithCallback(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithCallback, jsInvoker_, instance_, std::move(callback)); - } - std::optional getValueWithPromise(jsi::Runtime &rt, std::optional error) override { - static_assert( - bridging::getParameterCount(&T::getValueWithPromise) == 2, - \\"Expected getValueWithPromise(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getValueWithPromise, jsInvoker_, instance_, std::move(error)); - } - - private: - friend class NativeSampleTurboModuleNullableCxxSpec; - T *instance_; - }; - - Delegate delegate_; + static jsi::Value __getConstantsJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getConstants) == 1, + \\"Expected getConstants(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getConstants, self->jsInvoker_, self); + } + + static jsi::Value __voidFuncJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::voidFunc) == 1, + \\"Expected voidFunc(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::voidFunc, self->jsInvoker_, self);return jsi::Value::undefined(); + } + + static jsi::Value __getBoolJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getBool) == 2, + \\"Expected getBool(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getBool, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool()));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getNumberJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getNumber) == 2, + \\"Expected getNumber(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getNumber, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getStringJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getString) == 2, + \\"Expected getString(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getString, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asString(rt)));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getArrayJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getArray) == 2, + \\"Expected getArray(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getArray, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt).asArray(rt)));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getObjectJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getObject) == 2, + \\"Expected getObject(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getObject, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getObjectShapeJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getObjectShape) == 2, + \\"Expected getObjectShape(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getObjectShape, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getAliasJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getAlias) == 2, + \\"Expected getAlias(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getAlias, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getRootTagJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getRootTag) == 2, + \\"Expected getRootTag(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getRootTag, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getValueJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValue) == 4, + \\"Expected getValue(...) to have 4 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getValue, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()), + count <= 1 || args[1].isNull() || args[1].isUndefined() ? std::nullopt : std::make_optional(args[1].asString(rt)), + count <= 2 || args[2].isNull() || args[2].isUndefined() ? std::nullopt : std::make_optional(args[2].asObject(rt)));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getValueWithCallbackJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithCallback) == 2, + \\"Expected getValueWithCallback(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::getValueWithCallback, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asFunction(rt));return jsi::Value::undefined(); + } + + static jsi::Value __getValueWithPromiseJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithPromise) == 2, + \\"Expected getValueWithPromise(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getValueWithPromise, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool()));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } }; - #pragma mark - NativeSampleTurboModuleNullableAndOptionalAnimal template @@ -1698,169 +1335,149 @@ struct NativeSampleTurboModuleNullableAndOptionalAnimalBridging { } }; -class JSI_EXPORT NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI : public TurboModule { -protected: - NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Object getConstants(jsi::Runtime &rt) = 0; - virtual void voidFunc(jsi::Runtime &rt) = 0; - virtual std::optional getBool(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getNumber(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getString(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getArray(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getObject(jsi::Runtime &rt, std::optional arg) = 0; - virtual jsi::Object getObjectShape(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getAlias(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getRootTag(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getValue(jsi::Runtime &rt, std::optional x, std::optional y, std::optional z) = 0; - virtual void getValueWithCallback(jsi::Runtime &rt, std::optional callback) = 0; - virtual std::optional getValueWithPromise(jsi::Runtime &rt, std::optional error) = 0; - -}; template class JSI_EXPORT NativeSampleTurboModuleNullableAndOptionalCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModuleNullableAndOptional\\"; protected: - NativeSampleTurboModuleNullableAndOptionalCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeSampleTurboModuleNullableAndOptionalCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeSampleTurboModuleNullableAndOptionalCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeSampleTurboModuleNullableAndOptionalCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getConstants\\"] = MethodMetadata {.argCount = 0, .invoker = __getConstantsJSI}; + methodMap_[\\"voidFunc\\"] = MethodMetadata {.argCount = 0, .invoker = __voidFuncJSI}; + methodMap_[\\"getBool\\"] = MethodMetadata {.argCount = 1, .invoker = __getBoolJSI}; + methodMap_[\\"getNumber\\"] = MethodMetadata {.argCount = 1, .invoker = __getNumberJSI}; + methodMap_[\\"getString\\"] = MethodMetadata {.argCount = 1, .invoker = __getStringJSI}; + methodMap_[\\"getArray\\"] = MethodMetadata {.argCount = 1, .invoker = __getArrayJSI}; + methodMap_[\\"getObject\\"] = MethodMetadata {.argCount = 1, .invoker = __getObjectJSI}; + methodMap_[\\"getObjectShape\\"] = MethodMetadata {.argCount = 1, .invoker = __getObjectShapeJSI}; + methodMap_[\\"getAlias\\"] = MethodMetadata {.argCount = 1, .invoker = __getAliasJSI}; + methodMap_[\\"getRootTag\\"] = MethodMetadata {.argCount = 1, .invoker = __getRootTagJSI}; + methodMap_[\\"getValue\\"] = MethodMetadata {.argCount = 3, .invoker = __getValueJSI}; + methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithCallbackJSI}; + methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithPromiseJSI}; + } + private: - class Delegate : public NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::Object getConstants(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getConstants) == 1, - \\"Expected getConstants(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::getConstants, jsInvoker_, instance_); - } - void voidFunc(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::voidFunc) == 1, - \\"Expected voidFunc(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::voidFunc, jsInvoker_, instance_); - } - std::optional getBool(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getBool) == 2, - \\"Expected getBool(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getBool, jsInvoker_, instance_, std::move(arg)); - } - std::optional getNumber(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getNumber) == 2, - \\"Expected getNumber(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getNumber, jsInvoker_, instance_, std::move(arg)); - } - std::optional getString(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getString) == 2, - \\"Expected getString(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getString, jsInvoker_, instance_, std::move(arg)); - } - std::optional getArray(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getArray) == 2, - \\"Expected getArray(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getArray, jsInvoker_, instance_, std::move(arg)); - } - std::optional getObject(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getObject) == 2, - \\"Expected getObject(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getObject, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getObjectShape(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getObjectShape) == 2, - \\"Expected getObjectShape(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getObjectShape, jsInvoker_, instance_, std::move(arg)); - } - std::optional getAlias(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getAlias) == 2, - \\"Expected getAlias(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getAlias, jsInvoker_, instance_, std::move(arg)); - } - std::optional getRootTag(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getRootTag) == 2, - \\"Expected getRootTag(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getRootTag, jsInvoker_, instance_, std::move(arg)); - } - std::optional getValue(jsi::Runtime &rt, std::optional x, std::optional y, std::optional z) override { - static_assert( - bridging::getParameterCount(&T::getValue) == 4, - \\"Expected getValue(...) to have 4 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getValue, jsInvoker_, instance_, std::move(x), std::move(y), std::move(z)); - } - void getValueWithCallback(jsi::Runtime &rt, std::optional callback) override { - static_assert( - bridging::getParameterCount(&T::getValueWithCallback) == 2, - \\"Expected getValueWithCallback(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithCallback, jsInvoker_, instance_, std::move(callback)); - } - std::optional getValueWithPromise(jsi::Runtime &rt, std::optional error) override { - static_assert( - bridging::getParameterCount(&T::getValueWithPromise) == 2, - \\"Expected getValueWithPromise(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getValueWithPromise, jsInvoker_, instance_, std::move(error)); - } - - private: - friend class NativeSampleTurboModuleNullableAndOptionalCxxSpec; - T *instance_; - }; - - Delegate delegate_; + static jsi::Value __getConstantsJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getConstants) == 1, + \\"Expected getConstants(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getConstants, self->jsInvoker_, self); + } + + static jsi::Value __voidFuncJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::voidFunc) == 1, + \\"Expected voidFunc(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::voidFunc, self->jsInvoker_, self);return jsi::Value::undefined(); + } + + static jsi::Value __getBoolJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getBool) == 2, + \\"Expected getBool(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getBool, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool()));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getNumberJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getNumber) == 2, + \\"Expected getNumber(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getNumber, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getStringJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getString) == 2, + \\"Expected getString(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getString, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asString(rt)));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getArrayJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getArray) == 2, + \\"Expected getArray(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getArray, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt).asArray(rt)));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getObjectJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getObject) == 2, + \\"Expected getObject(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getObject, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getObjectShapeJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getObjectShape) == 2, + \\"Expected getObjectShape(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getObjectShape, self->jsInvoker_, self, + count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt))); + } + + static jsi::Value __getAliasJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getAlias) == 2, + \\"Expected getAlias(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getAlias, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getRootTagJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getRootTag) == 2, + \\"Expected getRootTag(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getRootTag, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getValueJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValue) == 4, + \\"Expected getValue(...) to have 4 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getValue, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()), + count <= 1 || args[1].isNull() || args[1].isUndefined() ? std::nullopt : std::make_optional(args[1].asString(rt)), + count <= 2 || args[2].isNull() || args[2].isUndefined() ? std::nullopt : std::make_optional(args[2].asObject(rt)));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getValueWithCallbackJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithCallback) == 2, + \\"Expected getValueWithCallback(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::getValueWithCallback, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt).asFunction(rt)));return jsi::Value::undefined(); + } + + static jsi::Value __getValueWithPromiseJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithPromise) == 2, + \\"Expected getValueWithPromise(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getValueWithPromise, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool()));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } }; - #pragma mark - NativeSampleTurboModuleOptionalAnimal template @@ -1902,447 +1519,306 @@ struct NativeSampleTurboModuleOptionalAnimalBridging { } }; -class JSI_EXPORT NativeSampleTurboModuleOptionalCxxSpecJSI : public TurboModule { -protected: - NativeSampleTurboModuleOptionalCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Object getConstants(jsi::Runtime &rt) = 0; - virtual void voidFunc(jsi::Runtime &rt) = 0; - virtual bool getBool(jsi::Runtime &rt, std::optional arg) = 0; - virtual double getNumber(jsi::Runtime &rt, std::optional arg) = 0; - virtual jsi::String getString(jsi::Runtime &rt, std::optional arg) = 0; - virtual jsi::Array getArray(jsi::Runtime &rt, std::optional arg) = 0; - virtual jsi::Object getObject(jsi::Runtime &rt, std::optional arg) = 0; - virtual jsi::Object getObjectShape(jsi::Runtime &rt, std::optional arg) = 0; - virtual jsi::Object getAlias(jsi::Runtime &rt, std::optional arg) = 0; - virtual double getRootTag(jsi::Runtime &rt, std::optional arg) = 0; - virtual jsi::Object getValue(jsi::Runtime &rt, std::optional x, std::optional y, std::optional z) = 0; - virtual void getValueWithCallback(jsi::Runtime &rt, std::optional callback) = 0; - virtual jsi::Value getValueWithPromise(jsi::Runtime &rt, std::optional error) = 0; - -}; template class JSI_EXPORT NativeSampleTurboModuleOptionalCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModuleOptional\\"; protected: - NativeSampleTurboModuleOptionalCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeSampleTurboModuleOptionalCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} + NativeSampleTurboModuleOptionalCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeSampleTurboModuleOptionalCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getConstants\\"] = MethodMetadata {.argCount = 0, .invoker = __getConstantsJSI}; + methodMap_[\\"voidFunc\\"] = MethodMetadata {.argCount = 0, .invoker = __voidFuncJSI}; + methodMap_[\\"getBool\\"] = MethodMetadata {.argCount = 1, .invoker = __getBoolJSI}; + methodMap_[\\"getNumber\\"] = MethodMetadata {.argCount = 1, .invoker = __getNumberJSI}; + methodMap_[\\"getString\\"] = MethodMetadata {.argCount = 1, .invoker = __getStringJSI}; + methodMap_[\\"getArray\\"] = MethodMetadata {.argCount = 1, .invoker = __getArrayJSI}; + methodMap_[\\"getObject\\"] = MethodMetadata {.argCount = 1, .invoker = __getObjectJSI}; + methodMap_[\\"getObjectShape\\"] = MethodMetadata {.argCount = 1, .invoker = __getObjectShapeJSI}; + methodMap_[\\"getAlias\\"] = MethodMetadata {.argCount = 1, .invoker = __getAliasJSI}; + methodMap_[\\"getRootTag\\"] = MethodMetadata {.argCount = 1, .invoker = __getRootTagJSI}; + methodMap_[\\"getValue\\"] = MethodMetadata {.argCount = 3, .invoker = __getValueJSI}; + methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithCallbackJSI}; + methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithPromiseJSI}; + } + +private: + static jsi::Value __getConstantsJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getConstants) == 1, + \\"Expected getConstants(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getConstants, self->jsInvoker_, self); + } + + static jsi::Value __voidFuncJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::voidFunc) == 1, + \\"Expected voidFunc(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::voidFunc, self->jsInvoker_, self);return jsi::Value::undefined(); + } + + static jsi::Value __getBoolJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getBool) == 2, + \\"Expected getBool(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getBool, self->jsInvoker_, self, + count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool())); + } + + static jsi::Value __getNumberJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getNumber) == 2, + \\"Expected getNumber(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getNumber, self->jsInvoker_, self, + count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber())); + } + + static jsi::Value __getStringJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getString) == 2, + \\"Expected getString(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getString, self->jsInvoker_, self, + count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asString(rt))); + } + + static jsi::Value __getArrayJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getArray) == 2, + \\"Expected getArray(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getArray, self->jsInvoker_, self, + count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt).asArray(rt))); + } + + static jsi::Value __getObjectJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getObject) == 2, + \\"Expected getObject(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getObject, self->jsInvoker_, self, + count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt))); + } + + static jsi::Value __getObjectShapeJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getObjectShape) == 2, + \\"Expected getObjectShape(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getObjectShape, self->jsInvoker_, self, + count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt))); + } + + static jsi::Value __getAliasJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getAlias) == 2, + \\"Expected getAlias(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getAlias, self->jsInvoker_, self, + count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt))); + } + + static jsi::Value __getRootTagJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getRootTag) == 2, + \\"Expected getRootTag(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getRootTag, self->jsInvoker_, self, + count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber())); + } + + static jsi::Value __getValueJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValue) == 4, + \\"Expected getValue(...) to have 4 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getValue, self->jsInvoker_, self, + count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()), + count <= 1 || args[1].isUndefined() ? std::nullopt : std::make_optional(args[1].asString(rt)), + count <= 2 || args[2].isUndefined() ? std::nullopt : std::make_optional(args[2].asObject(rt))); + } + + static jsi::Value __getValueWithCallbackJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithCallback) == 2, + \\"Expected getValueWithCallback(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::getValueWithCallback, self->jsInvoker_, self, + count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt).asFunction(rt)));return jsi::Value::undefined(); + } + + static jsi::Value __getValueWithPromiseJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithPromise) == 2, + \\"Expected getValueWithPromise(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getValueWithPromise, self->jsInvoker_, self, + count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool())); + } +}; -private: - class Delegate : public NativeSampleTurboModuleOptionalCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeSampleTurboModuleOptionalCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { +template +class JSI_EXPORT NativeStringTurboModuleCxxSpec : public TurboModule { +public: + static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; - } +protected: + NativeStringTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeStringTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getString\\"] = MethodMetadata {.argCount = 1, .invoker = __getStringJSI}; + methodMap_[\\"getStringWithAlias\\"] = MethodMetadata {.argCount = 1, .invoker = __getStringWithAliasJSI}; + } + +private: + static jsi::Value __getStringJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getString) == 2, + \\"Expected getString(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getString, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt)); + } - jsi::Object getConstants(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getConstants) == 1, - \\"Expected getConstants(...) to have 1 parameters\\"); + static jsi::Value __getStringWithAliasJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getStringWithAlias) == 2, + \\"Expected getStringWithAlias(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getStringWithAlias, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt)); + } +}; - return bridging::callFromJs( - rt, &T::getConstants, jsInvoker_, instance_); - } - void voidFunc(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::voidFunc) == 1, - \\"Expected voidFunc(...) to have 1 parameters\\"); +} // namespace facebook::react +" +`; - return bridging::callFromJs( - rt, &T::voidFunc, jsInvoker_, instance_); - } - bool getBool(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getBool) == 2, - \\"Expected getBool(...) to have 2 parameters\\"); +exports[`GenerateModuleH can generate a header file NativeModule specs with assume nonnull enabled 1`] = ` +"/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateModuleH.js + */ - return bridging::callFromJs( - rt, &T::getBool, jsInvoker_, instance_, std::move(arg)); - } - double getNumber(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getNumber) == 2, - \\"Expected getNumber(...) to have 2 parameters\\"); +#pragma once - return bridging::callFromJs( - rt, &T::getNumber, jsInvoker_, instance_, std::move(arg)); - } - jsi::String getString(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getString) == 2, - \\"Expected getString(...) to have 2 parameters\\"); +#include +#include - return bridging::callFromJs( - rt, &T::getString, jsInvoker_, instance_, std::move(arg)); - } - jsi::Array getArray(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getArray) == 2, - \\"Expected getArray(...) to have 2 parameters\\"); +namespace facebook::react { - return bridging::callFromJs( - rt, &T::getArray, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getObject(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getObject) == 2, - \\"Expected getObject(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getObject, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getObjectShape(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getObjectShape) == 2, - \\"Expected getObjectShape(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getObjectShape, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getAlias(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getAlias) == 2, - \\"Expected getAlias(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getAlias, jsInvoker_, instance_, std::move(arg)); - } - double getRootTag(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getRootTag) == 2, - \\"Expected getRootTag(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getRootTag, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getValue(jsi::Runtime &rt, std::optional x, std::optional y, std::optional z) override { - static_assert( - bridging::getParameterCount(&T::getValue) == 4, - \\"Expected getValue(...) to have 4 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValue, jsInvoker_, instance_, std::move(x), std::move(y), std::move(z)); - } - void getValueWithCallback(jsi::Runtime &rt, std::optional callback) override { - static_assert( - bridging::getParameterCount(&T::getValueWithCallback) == 2, - \\"Expected getValueWithCallback(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithCallback, jsInvoker_, instance_, std::move(callback)); - } - jsi::Value getValueWithPromise(jsi::Runtime &rt, std::optional error) override { - static_assert( - bridging::getParameterCount(&T::getValueWithPromise) == 2, - \\"Expected getValueWithPromise(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithPromise, jsInvoker_, instance_, std::move(error)); - } - - private: - friend class NativeSampleTurboModuleOptionalCxxSpec; - T *instance_; - }; - - Delegate delegate_; -}; - - - class JSI_EXPORT NativeStringTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeStringTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::String getString(jsi::Runtime &rt, jsi::String arg) = 0; - virtual jsi::String getStringWithAlias(jsi::Runtime &rt, jsi::String arg) = 0; - -}; template -class JSI_EXPORT NativeStringTurboModuleCxxSpec : public TurboModule { +class JSI_EXPORT NativeArrayTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; protected: - NativeStringTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeStringTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeArrayTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeArrayTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getArray\\"] = MethodMetadata {.argCount = 1, .invoker = __getArrayJSI}; + methodMap_[\\"getReadOnlyArray\\"] = MethodMetadata {.argCount = 1, .invoker = __getReadOnlyArrayJSI}; + methodMap_[\\"getArrayWithAlias\\"] = MethodMetadata {.argCount = 2, .invoker = __getArrayWithAliasJSI}; + } + private: - class Delegate : public NativeStringTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeStringTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::String getString(jsi::Runtime &rt, jsi::String arg) override { - static_assert( - bridging::getParameterCount(&T::getString) == 2, - \\"Expected getString(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getString, jsInvoker_, instance_, std::move(arg)); - } - jsi::String getStringWithAlias(jsi::Runtime &rt, jsi::String arg) override { - static_assert( - bridging::getParameterCount(&T::getStringWithAlias) == 2, - \\"Expected getStringWithAlias(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getStringWithAlias, jsInvoker_, instance_, std::move(arg)); - } - - private: - friend class NativeStringTurboModuleCxxSpec; - T *instance_; - }; - - Delegate delegate_; -}; - -} // namespace facebook::react -" -`; - -exports[`GenerateModuleH can generate a header file NativeModule specs with assume nonnull enabled 1`] = ` -"/** - * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). - * - * Do not edit this file as changes may cause incorrect behavior and will be lost - * once the code is regenerated. - * - * @generated by codegen project: GenerateModuleH.js - */ - -#pragma once - -#include -#include - -namespace facebook::react { - - - class JSI_EXPORT NativeArrayTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeArrayTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Array getArray(jsi::Runtime &rt, jsi::Array a) = 0; - virtual jsi::Array getReadOnlyArray(jsi::Runtime &rt, jsi::Array a) = 0; - virtual jsi::Array getArrayWithAlias(jsi::Runtime &rt, jsi::Array a, jsi::Array b) = 0; - -}; - -template -class JSI_EXPORT NativeArrayTurboModuleCxxSpec : public TurboModule { -public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); + static jsi::Value __getArrayJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getArray) == 2, + \\"Expected getArray(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getArray, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); } - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); + static jsi::Value __getReadOnlyArrayJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getReadOnlyArray) == 2, + \\"Expected getReadOnlyArray(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getReadOnlyArray, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; - -protected: - NativeArrayTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeArrayTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - -private: - class Delegate : public NativeArrayTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeArrayTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::Array getArray(jsi::Runtime &rt, jsi::Array a) override { - static_assert( - bridging::getParameterCount(&T::getArray) == 2, - \\"Expected getArray(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getArray, jsInvoker_, instance_, std::move(a)); - } - jsi::Array getReadOnlyArray(jsi::Runtime &rt, jsi::Array a) override { - static_assert( - bridging::getParameterCount(&T::getReadOnlyArray) == 2, - \\"Expected getReadOnlyArray(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getReadOnlyArray, jsInvoker_, instance_, std::move(a)); - } - jsi::Array getArrayWithAlias(jsi::Runtime &rt, jsi::Array a, jsi::Array b) override { - static_assert( - bridging::getParameterCount(&T::getArrayWithAlias) == 3, - \\"Expected getArrayWithAlias(...) to have 3 parameters\\"); - - return bridging::callFromJs( - rt, &T::getArrayWithAlias, jsInvoker_, instance_, std::move(a), std::move(b)); - } - - private: - friend class NativeArrayTurboModuleCxxSpec; - T *instance_; - }; - - Delegate delegate_; + static jsi::Value __getArrayWithAliasJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getArrayWithAlias) == 3, + \\"Expected getArrayWithAlias(...) to have 3 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getArrayWithAlias, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt), + count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asObject(rt).asArray(rt)); + } }; - class JSI_EXPORT NativeBooleanTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeBooleanTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual bool getBoolean(jsi::Runtime &rt, bool arg) = 0; - virtual bool getBooleanWithAlias(jsi::Runtime &rt, bool arg) = 0; - -}; - template class JSI_EXPORT NativeBooleanTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; protected: - NativeBooleanTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeBooleanTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeBooleanTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeBooleanTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getBoolean\\"] = MethodMetadata {.argCount = 1, .invoker = __getBooleanJSI}; + methodMap_[\\"getBooleanWithAlias\\"] = MethodMetadata {.argCount = 1, .invoker = __getBooleanWithAliasJSI}; + } + private: - class Delegate : public NativeBooleanTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeBooleanTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - bool getBoolean(jsi::Runtime &rt, bool arg) override { - static_assert( - bridging::getParameterCount(&T::getBoolean) == 2, - \\"Expected getBoolean(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getBoolean, jsInvoker_, instance_, std::move(arg)); - } - bool getBooleanWithAlias(jsi::Runtime &rt, bool arg) override { - static_assert( - bridging::getParameterCount(&T::getBooleanWithAlias) == 2, - \\"Expected getBooleanWithAlias(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getBooleanWithAlias, jsInvoker_, instance_, std::move(arg)); - } - - private: - friend class NativeBooleanTurboModuleCxxSpec; - T *instance_; - }; + static jsi::Value __getBooleanJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getBoolean) == 2, + \\"Expected getBoolean(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getBoolean, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool()); + } - Delegate delegate_; + static jsi::Value __getBooleanWithAliasJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getBooleanWithAlias) == 2, + \\"Expected getBooleanWithAlias(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getBooleanWithAlias, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool()); + } }; - class JSI_EXPORT NativeCallbackTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeCallbackTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual void getValueWithCallback(jsi::Runtime &rt, jsi::Function callback) = 0; - virtual void getValueWithCallbackWithAlias(jsi::Runtime &rt, jsi::Function c) = 0; - -}; - template class JSI_EXPORT NativeCallbackTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; protected: - NativeCallbackTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeCallbackTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeCallbackTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeCallbackTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithCallbackJSI}; + methodMap_[\\"getValueWithCallbackWithAlias\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithCallbackWithAliasJSI}; + } + private: - class Delegate : public NativeCallbackTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeCallbackTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - void getValueWithCallback(jsi::Runtime &rt, jsi::Function callback) override { - static_assert( - bridging::getParameterCount(&T::getValueWithCallback) == 2, - \\"Expected getValueWithCallback(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithCallback, jsInvoker_, instance_, std::move(callback)); - } - void getValueWithCallbackWithAlias(jsi::Runtime &rt, jsi::Function c) override { - static_assert( - bridging::getParameterCount(&T::getValueWithCallbackWithAlias) == 2, - \\"Expected getValueWithCallbackWithAlias(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithCallbackWithAlias, jsInvoker_, instance_, std::move(c)); - } - - private: - friend class NativeCallbackTurboModuleCxxSpec; - T *instance_; - }; + static jsi::Value __getValueWithCallbackJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithCallback) == 2, + \\"Expected getValueWithCallback(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::getValueWithCallback, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asFunction(rt));return jsi::Value::undefined(); + } - Delegate delegate_; + static jsi::Value __getValueWithCallbackWithAliasJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithCallbackWithAlias) == 2, + \\"Expected getValueWithCallbackWithAlias(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::getValueWithCallbackWithAlias, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asFunction(rt));return jsi::Value::undefined(); + } }; @@ -2473,7 +1949,6 @@ struct Bridging { } } }; - #pragma mark - NativeEnumTurboModuleStateType template @@ -2550,19 +2025,15 @@ struct NativeEnumTurboModuleStateTypeWithEnumsBridging { static jsi::String stateToJs(jsi::Runtime &rt, decltype(types.state) value) { return bridging::toJs(rt, value); } - static jsi::String regularToJs(jsi::Runtime &rt, decltype(types.regular) value) { return bridging::toJs(rt, value); } - static jsi::String strToJs(jsi::Runtime &rt, decltype(types.str) value) { return bridging::toJs(rt, value); } - static jsi::Value numToJs(jsi::Runtime &rt, decltype(types.num) value) { return bridging::toJs(rt, value); } - static jsi::String lowerCaseToJs(jsi::Runtime &rt, decltype(types.lowerCase) value) { return bridging::toJs(rt, value); } @@ -2582,412 +2053,267 @@ struct NativeEnumTurboModuleStateTypeWithEnumsBridging { } }; -class JSI_EXPORT NativeEnumTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeEnumTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::String getStatusRegular(jsi::Runtime &rt, jsi::Object statusProp) = 0; - virtual jsi::String getStatusStr(jsi::Runtime &rt, jsi::Object statusProp) = 0; - virtual jsi::Value getStatusNum(jsi::Runtime &rt, jsi::Object statusProp) = 0; - virtual jsi::String getStatusLowerCase(jsi::Runtime &rt, jsi::Object statusProp) = 0; - virtual jsi::Object getStateType(jsi::Runtime &rt, jsi::String a, jsi::String b, jsi::Value c, jsi::String d) = 0; - virtual jsi::Object getStateTypeWithEnums(jsi::Runtime &rt, jsi::Object paramOfTypeWithEnums) = 0; - -}; template class JSI_EXPORT NativeEnumTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"NativeEnumTurboModule\\"; protected: - NativeEnumTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeEnumTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeEnumTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeEnumTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getStatusRegular\\"] = MethodMetadata {.argCount = 1, .invoker = __getStatusRegularJSI}; + methodMap_[\\"getStatusStr\\"] = MethodMetadata {.argCount = 1, .invoker = __getStatusStrJSI}; + methodMap_[\\"getStatusNum\\"] = MethodMetadata {.argCount = 1, .invoker = __getStatusNumJSI}; + methodMap_[\\"getStatusLowerCase\\"] = MethodMetadata {.argCount = 1, .invoker = __getStatusLowerCaseJSI}; + methodMap_[\\"getStateType\\"] = MethodMetadata {.argCount = 4, .invoker = __getStateTypeJSI}; + methodMap_[\\"getStateTypeWithEnums\\"] = MethodMetadata {.argCount = 1, .invoker = __getStateTypeWithEnumsJSI}; + } + private: - class Delegate : public NativeEnumTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeEnumTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::String getStatusRegular(jsi::Runtime &rt, jsi::Object statusProp) override { - static_assert( - bridging::getParameterCount(&T::getStatusRegular) == 2, - \\"Expected getStatusRegular(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getStatusRegular, jsInvoker_, instance_, std::move(statusProp)); - } - jsi::String getStatusStr(jsi::Runtime &rt, jsi::Object statusProp) override { - static_assert( - bridging::getParameterCount(&T::getStatusStr) == 2, - \\"Expected getStatusStr(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getStatusStr, jsInvoker_, instance_, std::move(statusProp)); - } - jsi::Value getStatusNum(jsi::Runtime &rt, jsi::Object statusProp) override { - static_assert( - bridging::getParameterCount(&T::getStatusNum) == 2, - \\"Expected getStatusNum(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getStatusNum, jsInvoker_, instance_, std::move(statusProp)); - } - jsi::String getStatusLowerCase(jsi::Runtime &rt, jsi::Object statusProp) override { - static_assert( - bridging::getParameterCount(&T::getStatusLowerCase) == 2, - \\"Expected getStatusLowerCase(...) to have 2 parameters\\"); + static jsi::Value __getStatusRegularJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getStatusRegular) == 2, + \\"Expected getStatusRegular(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getStatusRegular, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } - return bridging::callFromJs( - rt, &T::getStatusLowerCase, jsInvoker_, instance_, std::move(statusProp)); - } - jsi::Object getStateType(jsi::Runtime &rt, jsi::String a, jsi::String b, jsi::Value c, jsi::String d) override { - static_assert( - bridging::getParameterCount(&T::getStateType) == 5, - \\"Expected getStateType(...) to have 5 parameters\\"); + static jsi::Value __getStatusStrJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getStatusStr) == 2, + \\"Expected getStatusStr(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getStatusStr, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } - return bridging::callFromJs( - rt, &T::getStateType, jsInvoker_, instance_, std::move(a), std::move(b), std::move(c), std::move(d)); - } - jsi::Object getStateTypeWithEnums(jsi::Runtime &rt, jsi::Object paramOfTypeWithEnums) override { - static_assert( - bridging::getParameterCount(&T::getStateTypeWithEnums) == 2, - \\"Expected getStateTypeWithEnums(...) to have 2 parameters\\"); + static jsi::Value __getStatusNumJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getStatusNum) == 2, + \\"Expected getStatusNum(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getStatusNum, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } - return bridging::callFromJs( - rt, &T::getStateTypeWithEnums, jsInvoker_, instance_, std::move(paramOfTypeWithEnums)); - } + static jsi::Value __getStatusLowerCaseJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getStatusLowerCase) == 2, + \\"Expected getStatusLowerCase(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getStatusLowerCase, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } - private: - friend class NativeEnumTurboModuleCxxSpec; - T *instance_; - }; + static jsi::Value __getStateTypeJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getStateType) == 5, + \\"Expected getStateType(...) to have 5 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getStateType, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt), + count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asString(rt), + count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asNumber(), + count <= 3 ? throw jsi::JSError(rt, \\"Expected argument in position 3 to be passed\\") : args[3].asString(rt)); + } - Delegate delegate_; + static jsi::Value __getStateTypeWithEnumsJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getStateTypeWithEnums) == 2, + \\"Expected getStateTypeWithEnums(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getStateTypeWithEnums, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } }; - class JSI_EXPORT NativeNullableTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeNullableTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual std::optional getBool(jsi::Runtime &rt, std::optional a) = 0; - virtual std::optional getNumber(jsi::Runtime &rt, std::optional a) = 0; - virtual std::optional getString(jsi::Runtime &rt, std::optional a) = 0; - virtual std::optional getArray(jsi::Runtime &rt, std::optional a) = 0; - virtual std::optional getObject(jsi::Runtime &rt, std::optional a) = 0; - virtual std::optional getValueWithPromise(jsi::Runtime &rt) = 0; - -}; - template class JSI_EXPORT NativeNullableTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; protected: - NativeNullableTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeNullableTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeNullableTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeNullableTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getBool\\"] = MethodMetadata {.argCount = 1, .invoker = __getBoolJSI}; + methodMap_[\\"getNumber\\"] = MethodMetadata {.argCount = 1, .invoker = __getNumberJSI}; + methodMap_[\\"getString\\"] = MethodMetadata {.argCount = 1, .invoker = __getStringJSI}; + methodMap_[\\"getArray\\"] = MethodMetadata {.argCount = 1, .invoker = __getArrayJSI}; + methodMap_[\\"getObject\\"] = MethodMetadata {.argCount = 1, .invoker = __getObjectJSI}; + methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {.argCount = 0, .invoker = __getValueWithPromiseJSI}; + } + private: - class Delegate : public NativeNullableTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeNullableTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - std::optional getBool(jsi::Runtime &rt, std::optional a) override { - static_assert( - bridging::getParameterCount(&T::getBool) == 2, - \\"Expected getBool(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getBool, jsInvoker_, instance_, std::move(a)); - } - std::optional getNumber(jsi::Runtime &rt, std::optional a) override { - static_assert( - bridging::getParameterCount(&T::getNumber) == 2, - \\"Expected getNumber(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getNumber, jsInvoker_, instance_, std::move(a)); - } - std::optional getString(jsi::Runtime &rt, std::optional a) override { - static_assert( - bridging::getParameterCount(&T::getString) == 2, - \\"Expected getString(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getString, jsInvoker_, instance_, std::move(a)); - } - std::optional getArray(jsi::Runtime &rt, std::optional a) override { - static_assert( - bridging::getParameterCount(&T::getArray) == 2, - \\"Expected getArray(...) to have 2 parameters\\"); + static jsi::Value __getBoolJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getBool) == 2, + \\"Expected getBool(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getBool, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool()));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } - return bridging::callFromJs>( - rt, &T::getArray, jsInvoker_, instance_, std::move(a)); - } - std::optional getObject(jsi::Runtime &rt, std::optional a) override { - static_assert( - bridging::getParameterCount(&T::getObject) == 2, - \\"Expected getObject(...) to have 2 parameters\\"); + static jsi::Value __getNumberJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getNumber) == 2, + \\"Expected getNumber(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getNumber, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } - return bridging::callFromJs>( - rt, &T::getObject, jsInvoker_, instance_, std::move(a)); - } - std::optional getValueWithPromise(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getValueWithPromise) == 1, - \\"Expected getValueWithPromise(...) to have 1 parameters\\"); + static jsi::Value __getStringJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getString) == 2, + \\"Expected getString(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getString, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } - return bridging::callFromJs>( - rt, &T::getValueWithPromise, jsInvoker_, instance_); - } + static jsi::Value __getArrayJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getArray) == 2, + \\"Expected getArray(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getArray, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt).asArray(rt)));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } - private: - friend class NativeNullableTurboModuleCxxSpec; - T *instance_; - }; + static jsi::Value __getObjectJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getObject) == 2, + \\"Expected getObject(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getObject, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } - Delegate delegate_; + static jsi::Value __getValueWithPromiseJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getValueWithPromise) == 1, + \\"Expected getValueWithPromise(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getValueWithPromise, self->jsInvoker_, self);return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } }; - class JSI_EXPORT NativeNumberTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeNumberTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual double getNumber(jsi::Runtime &rt, double arg) = 0; - virtual double getNumberWithAlias(jsi::Runtime &rt, double arg) = 0; - -}; - template class JSI_EXPORT NativeNumberTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; protected: - NativeNumberTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeNumberTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeNumberTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeNumberTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getNumber\\"] = MethodMetadata {.argCount = 1, .invoker = __getNumberJSI}; + methodMap_[\\"getNumberWithAlias\\"] = MethodMetadata {.argCount = 1, .invoker = __getNumberWithAliasJSI}; + } + private: - class Delegate : public NativeNumberTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeNumberTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - double getNumber(jsi::Runtime &rt, double arg) override { - static_assert( - bridging::getParameterCount(&T::getNumber) == 2, - \\"Expected getNumber(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getNumber, jsInvoker_, instance_, std::move(arg)); - } - double getNumberWithAlias(jsi::Runtime &rt, double arg) override { - static_assert( - bridging::getParameterCount(&T::getNumberWithAlias) == 2, - \\"Expected getNumberWithAlias(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getNumberWithAlias, jsInvoker_, instance_, std::move(arg)); - } - - private: - friend class NativeNumberTurboModuleCxxSpec; - T *instance_; - }; + static jsi::Value __getNumberJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getNumber) == 2, + \\"Expected getNumber(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getNumber, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber()); + } - Delegate delegate_; + static jsi::Value __getNumberWithAliasJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getNumberWithAlias) == 2, + \\"Expected getNumberWithAlias(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getNumberWithAlias, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber()); + } }; - class JSI_EXPORT NativeObjectTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeObjectTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Object getGenericObject(jsi::Runtime &rt, jsi::Object arg) = 0; - virtual jsi::Object getGenericObjectReadOnly(jsi::Runtime &rt, jsi::Object arg) = 0; - virtual jsi::Object getGenericObjectWithAlias(jsi::Runtime &rt, jsi::Object arg) = 0; - virtual jsi::Object difficultObject(jsi::Runtime &rt, jsi::Object A) = 0; - virtual jsi::Object getConstants(jsi::Runtime &rt) = 0; - -}; - template class JSI_EXPORT NativeObjectTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; protected: - NativeObjectTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeObjectTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} + NativeObjectTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeObjectTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getGenericObject\\"] = MethodMetadata {.argCount = 1, .invoker = __getGenericObjectJSI}; + methodMap_[\\"getGenericObjectReadOnly\\"] = MethodMetadata {.argCount = 1, .invoker = __getGenericObjectReadOnlyJSI}; + methodMap_[\\"getGenericObjectWithAlias\\"] = MethodMetadata {.argCount = 1, .invoker = __getGenericObjectWithAliasJSI}; + methodMap_[\\"difficultObject\\"] = MethodMetadata {.argCount = 1, .invoker = __difficultObjectJSI}; + methodMap_[\\"getConstants\\"] = MethodMetadata {.argCount = 0, .invoker = __getConstantsJSI}; + } + +private: + static jsi::Value __getGenericObjectJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getGenericObject) == 2, + \\"Expected getGenericObject(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getGenericObject, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } + static jsi::Value __getGenericObjectReadOnlyJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getGenericObjectReadOnly) == 2, + \\"Expected getGenericObjectReadOnly(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getGenericObjectReadOnly, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } -private: - class Delegate : public NativeObjectTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeObjectTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { + static jsi::Value __getGenericObjectWithAliasJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getGenericObjectWithAlias) == 2, + \\"Expected getGenericObjectWithAlias(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getGenericObjectWithAlias, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } - } + static jsi::Value __difficultObjectJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::difficultObject) == 2, + \\"Expected difficultObject(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::difficultObject, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } - jsi::Object getGenericObject(jsi::Runtime &rt, jsi::Object arg) override { - static_assert( - bridging::getParameterCount(&T::getGenericObject) == 2, - \\"Expected getGenericObject(...) to have 2 parameters\\"); + static jsi::Value __getConstantsJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getConstants) == 1, + \\"Expected getConstants(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getConstants, self->jsInvoker_, self); + } +}; - return bridging::callFromJs( - rt, &T::getGenericObject, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getGenericObjectReadOnly(jsi::Runtime &rt, jsi::Object arg) override { - static_assert( - bridging::getParameterCount(&T::getGenericObjectReadOnly) == 2, - \\"Expected getGenericObjectReadOnly(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getGenericObjectReadOnly, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getGenericObjectWithAlias(jsi::Runtime &rt, jsi::Object arg) override { - static_assert( - bridging::getParameterCount(&T::getGenericObjectWithAlias) == 2, - \\"Expected getGenericObjectWithAlias(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getGenericObjectWithAlias, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object difficultObject(jsi::Runtime &rt, jsi::Object A) override { - static_assert( - bridging::getParameterCount(&T::difficultObject) == 2, - \\"Expected difficultObject(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::difficultObject, jsInvoker_, instance_, std::move(A)); - } - jsi::Object getConstants(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getConstants) == 1, - \\"Expected getConstants(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::getConstants, jsInvoker_, instance_); - } - - private: - friend class NativeObjectTurboModuleCxxSpec; - T *instance_; - }; - - Delegate delegate_; -}; - - - class JSI_EXPORT NativeOptionalObjectTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeOptionalObjectTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Object getConstants(jsi::Runtime &rt) = 0; - -}; template class JSI_EXPORT NativeOptionalObjectTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; protected: - NativeOptionalObjectTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeOptionalObjectTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeOptionalObjectTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeOptionalObjectTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getConstants\\"] = MethodMetadata {.argCount = 0, .invoker = __getConstantsJSI}; + } + private: - class Delegate : public NativeOptionalObjectTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeOptionalObjectTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::Object getConstants(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getConstants) == 1, - \\"Expected getConstants(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::getConstants, jsInvoker_, instance_); - } - - private: - friend class NativeOptionalObjectTurboModuleCxxSpec; - T *instance_; - }; - - Delegate delegate_; + static jsi::Value __getConstantsJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getConstants) == 1, + \\"Expected getConstants(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getConstants, self->jsInvoker_, self); + } }; - #pragma mark - NativePartialAnnotationTurboModuleSomeObj template @@ -3017,7 +2343,6 @@ struct NativePartialAnnotationTurboModuleSomeObjBridging { static jsi::String aToJs(jsi::Runtime &rt, decltype(types.a) value) { return bridging::toJs(rt, value); } - static bool bToJs(jsi::Runtime &rt, decltype(types.b) value) { return bridging::toJs(rt, value); } @@ -3036,151 +2361,90 @@ struct NativePartialAnnotationTurboModuleSomeObjBridging { } }; -class JSI_EXPORT NativePartialAnnotationTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativePartialAnnotationTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Object getSomeObj(jsi::Runtime &rt) = 0; - virtual jsi::Object getPartialSomeObj(jsi::Runtime &rt) = 0; - virtual jsi::Object getSomeObjFromPartialSomeObj(jsi::Runtime &rt, jsi::Object value) = 0; - virtual jsi::Object getPartialPartial(jsi::Runtime &rt, jsi::Object value1, jsi::Object value2) = 0; - -}; template class JSI_EXPORT NativePartialAnnotationTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"NativePartialAnnotationTurboModule\\"; protected: - NativePartialAnnotationTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativePartialAnnotationTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativePartialAnnotationTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativePartialAnnotationTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getSomeObj\\"] = MethodMetadata {.argCount = 0, .invoker = __getSomeObjJSI}; + methodMap_[\\"getPartialSomeObj\\"] = MethodMetadata {.argCount = 0, .invoker = __getPartialSomeObjJSI}; + methodMap_[\\"getSomeObjFromPartialSomeObj\\"] = MethodMetadata {.argCount = 1, .invoker = __getSomeObjFromPartialSomeObjJSI}; + methodMap_[\\"getPartialPartial\\"] = MethodMetadata {.argCount = 2, .invoker = __getPartialPartialJSI}; + } + private: - class Delegate : public NativePartialAnnotationTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativePartialAnnotationTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::Object getSomeObj(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getSomeObj) == 1, - \\"Expected getSomeObj(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::getSomeObj, jsInvoker_, instance_); - } - jsi::Object getPartialSomeObj(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getPartialSomeObj) == 1, - \\"Expected getPartialSomeObj(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::getPartialSomeObj, jsInvoker_, instance_); - } - jsi::Object getSomeObjFromPartialSomeObj(jsi::Runtime &rt, jsi::Object value) override { - static_assert( - bridging::getParameterCount(&T::getSomeObjFromPartialSomeObj) == 2, - \\"Expected getSomeObjFromPartialSomeObj(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getSomeObjFromPartialSomeObj, jsInvoker_, instance_, std::move(value)); - } - jsi::Object getPartialPartial(jsi::Runtime &rt, jsi::Object value1, jsi::Object value2) override { - static_assert( - bridging::getParameterCount(&T::getPartialPartial) == 3, - \\"Expected getPartialPartial(...) to have 3 parameters\\"); + static jsi::Value __getSomeObjJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getSomeObj) == 1, + \\"Expected getSomeObj(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getSomeObj, self->jsInvoker_, self); + } - return bridging::callFromJs( - rt, &T::getPartialPartial, jsInvoker_, instance_, std::move(value1), std::move(value2)); - } + static jsi::Value __getPartialSomeObjJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getPartialSomeObj) == 1, + \\"Expected getPartialSomeObj(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getPartialSomeObj, self->jsInvoker_, self); + } - private: - friend class NativePartialAnnotationTurboModuleCxxSpec; - T *instance_; - }; + static jsi::Value __getSomeObjFromPartialSomeObjJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getSomeObjFromPartialSomeObj) == 2, + \\"Expected getSomeObjFromPartialSomeObj(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getSomeObjFromPartialSomeObj, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } - Delegate delegate_; + static jsi::Value __getPartialPartialJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getPartialPartial) == 3, + \\"Expected getPartialPartial(...) to have 3 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getPartialPartial, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt), + count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asObject(rt)); + } }; - class JSI_EXPORT NativePromiseTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativePromiseTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Value getValueWithPromise(jsi::Runtime &rt, bool error) = 0; - virtual jsi::Value getValueWithPromiseWithAlias(jsi::Runtime &rt, jsi::String arg) = 0; - -}; - template class JSI_EXPORT NativePromiseTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; protected: - NativePromiseTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativePromiseTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativePromiseTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativePromiseTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithPromiseJSI}; + methodMap_[\\"getValueWithPromiseWithAlias\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithPromiseWithAliasJSI}; + } + private: - class Delegate : public NativePromiseTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativePromiseTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::Value getValueWithPromise(jsi::Runtime &rt, bool error) override { - static_assert( - bridging::getParameterCount(&T::getValueWithPromise) == 2, - \\"Expected getValueWithPromise(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithPromise, jsInvoker_, instance_, std::move(error)); - } - jsi::Value getValueWithPromiseWithAlias(jsi::Runtime &rt, jsi::String arg) override { - static_assert( - bridging::getParameterCount(&T::getValueWithPromiseWithAlias) == 2, - \\"Expected getValueWithPromiseWithAlias(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithPromiseWithAlias, jsInvoker_, instance_, std::move(arg)); - } - - private: - friend class NativePromiseTurboModuleCxxSpec; - T *instance_; - }; + static jsi::Value __getValueWithPromiseJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithPromise) == 2, + \\"Expected getValueWithPromise(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getValueWithPromise, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool()); + } - Delegate delegate_; + static jsi::Value __getValueWithPromiseWithAliasJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithPromiseWithAlias) == 2, + \\"Expected getValueWithPromiseWithAlias(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getValueWithPromiseWithAlias, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt)); + } }; - #pragma mark - NativeSampleTurboModuleAnimal template @@ -3220,169 +2484,149 @@ struct NativeSampleTurboModuleAnimalBridging { } }; -class JSI_EXPORT NativeSampleTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeSampleTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Object getConstants(jsi::Runtime &rt) = 0; - virtual void voidFunc(jsi::Runtime &rt) = 0; - virtual bool getBool(jsi::Runtime &rt, bool arg) = 0; - virtual double getNumber(jsi::Runtime &rt, double arg) = 0; - virtual jsi::String getString(jsi::Runtime &rt, jsi::String arg) = 0; - virtual jsi::Array getArray(jsi::Runtime &rt, jsi::Array arg) = 0; - virtual jsi::Object getObject(jsi::Runtime &rt, jsi::Object arg) = 0; - virtual jsi::Object getObjectShape(jsi::Runtime &rt, jsi::Object arg) = 0; - virtual jsi::Object getAlias(jsi::Runtime &rt, jsi::Object arg) = 0; - virtual double getRootTag(jsi::Runtime &rt, double arg) = 0; - virtual jsi::Object getValue(jsi::Runtime &rt, double x, jsi::String getValuegetValuegetValuegetValuegetValuey, jsi::Object z) = 0; - virtual void getValueWithCallback(jsi::Runtime &rt, jsi::Function callback) = 0; - virtual jsi::Value getValueWithPromise(jsi::Runtime &rt, bool error) = 0; - -}; template class JSI_EXPORT NativeSampleTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; protected: - NativeSampleTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeSampleTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeSampleTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeSampleTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getConstants\\"] = MethodMetadata {.argCount = 0, .invoker = __getConstantsJSI}; + methodMap_[\\"voidFunc\\"] = MethodMetadata {.argCount = 0, .invoker = __voidFuncJSI}; + methodMap_[\\"getBool\\"] = MethodMetadata {.argCount = 1, .invoker = __getBoolJSI}; + methodMap_[\\"getNumber\\"] = MethodMetadata {.argCount = 1, .invoker = __getNumberJSI}; + methodMap_[\\"getString\\"] = MethodMetadata {.argCount = 1, .invoker = __getStringJSI}; + methodMap_[\\"getArray\\"] = MethodMetadata {.argCount = 1, .invoker = __getArrayJSI}; + methodMap_[\\"getObject\\"] = MethodMetadata {.argCount = 1, .invoker = __getObjectJSI}; + methodMap_[\\"getObjectShape\\"] = MethodMetadata {.argCount = 1, .invoker = __getObjectShapeJSI}; + methodMap_[\\"getAlias\\"] = MethodMetadata {.argCount = 1, .invoker = __getAliasJSI}; + methodMap_[\\"getRootTag\\"] = MethodMetadata {.argCount = 1, .invoker = __getRootTagJSI}; + methodMap_[\\"getValue\\"] = MethodMetadata {.argCount = 3, .invoker = __getValueJSI}; + methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithCallbackJSI}; + methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithPromiseJSI}; + } + private: - class Delegate : public NativeSampleTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeSampleTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::Object getConstants(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getConstants) == 1, - \\"Expected getConstants(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::getConstants, jsInvoker_, instance_); - } - void voidFunc(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::voidFunc) == 1, - \\"Expected voidFunc(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::voidFunc, jsInvoker_, instance_); - } - bool getBool(jsi::Runtime &rt, bool arg) override { - static_assert( - bridging::getParameterCount(&T::getBool) == 2, - \\"Expected getBool(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getBool, jsInvoker_, instance_, std::move(arg)); - } - double getNumber(jsi::Runtime &rt, double arg) override { - static_assert( - bridging::getParameterCount(&T::getNumber) == 2, - \\"Expected getNumber(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getNumber, jsInvoker_, instance_, std::move(arg)); - } - jsi::String getString(jsi::Runtime &rt, jsi::String arg) override { - static_assert( - bridging::getParameterCount(&T::getString) == 2, - \\"Expected getString(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getString, jsInvoker_, instance_, std::move(arg)); - } - jsi::Array getArray(jsi::Runtime &rt, jsi::Array arg) override { - static_assert( - bridging::getParameterCount(&T::getArray) == 2, - \\"Expected getArray(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getArray, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getObject(jsi::Runtime &rt, jsi::Object arg) override { - static_assert( - bridging::getParameterCount(&T::getObject) == 2, - \\"Expected getObject(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getObject, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getObjectShape(jsi::Runtime &rt, jsi::Object arg) override { - static_assert( - bridging::getParameterCount(&T::getObjectShape) == 2, - \\"Expected getObjectShape(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getObjectShape, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getAlias(jsi::Runtime &rt, jsi::Object arg) override { - static_assert( - bridging::getParameterCount(&T::getAlias) == 2, - \\"Expected getAlias(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getAlias, jsInvoker_, instance_, std::move(arg)); - } - double getRootTag(jsi::Runtime &rt, double arg) override { - static_assert( - bridging::getParameterCount(&T::getRootTag) == 2, - \\"Expected getRootTag(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getRootTag, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getValue(jsi::Runtime &rt, double x, jsi::String getValuegetValuegetValuegetValuegetValuey, jsi::Object z) override { - static_assert( - bridging::getParameterCount(&T::getValue) == 4, - \\"Expected getValue(...) to have 4 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValue, jsInvoker_, instance_, std::move(x), std::move(getValuegetValuegetValuegetValuegetValuey), std::move(z)); - } - void getValueWithCallback(jsi::Runtime &rt, jsi::Function callback) override { - static_assert( - bridging::getParameterCount(&T::getValueWithCallback) == 2, - \\"Expected getValueWithCallback(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithCallback, jsInvoker_, instance_, std::move(callback)); - } - jsi::Value getValueWithPromise(jsi::Runtime &rt, bool error) override { - static_assert( - bridging::getParameterCount(&T::getValueWithPromise) == 2, - \\"Expected getValueWithPromise(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithPromise, jsInvoker_, instance_, std::move(error)); - } - - private: - friend class NativeSampleTurboModuleCxxSpec; - T *instance_; - }; - - Delegate delegate_; + static jsi::Value __getConstantsJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getConstants) == 1, + \\"Expected getConstants(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getConstants, self->jsInvoker_, self); + } + + static jsi::Value __voidFuncJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::voidFunc) == 1, + \\"Expected voidFunc(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::voidFunc, self->jsInvoker_, self);return jsi::Value::undefined(); + } + + static jsi::Value __getBoolJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getBool) == 2, + \\"Expected getBool(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getBool, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool()); + } + + static jsi::Value __getNumberJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getNumber) == 2, + \\"Expected getNumber(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getNumber, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber()); + } + + static jsi::Value __getStringJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getString) == 2, + \\"Expected getString(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getString, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt)); + } + + static jsi::Value __getArrayJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getArray) == 2, + \\"Expected getArray(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getArray, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); + } + + static jsi::Value __getObjectJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getObject) == 2, + \\"Expected getObject(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getObject, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } + + static jsi::Value __getObjectShapeJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getObjectShape) == 2, + \\"Expected getObjectShape(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getObjectShape, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } + + static jsi::Value __getAliasJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getAlias) == 2, + \\"Expected getAlias(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getAlias, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } + + static jsi::Value __getRootTagJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getRootTag) == 2, + \\"Expected getRootTag(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getRootTag, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber()); + } + + static jsi::Value __getValueJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValue) == 4, + \\"Expected getValue(...) to have 4 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getValue, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber(), + count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asString(rt), + count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asObject(rt)); + } + + static jsi::Value __getValueWithCallbackJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithCallback) == 2, + \\"Expected getValueWithCallback(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::getValueWithCallback, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asFunction(rt));return jsi::Value::undefined(); + } + + static jsi::Value __getValueWithPromiseJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithPromise) == 2, + \\"Expected getValueWithPromise(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getValueWithPromise, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool()); + } }; - #pragma mark - NativeSampleTurboModuleArraysAnimal template @@ -3422,169 +2666,149 @@ struct NativeSampleTurboModuleArraysAnimalBridging { } }; -class JSI_EXPORT NativeSampleTurboModuleArraysCxxSpecJSI : public TurboModule { -protected: - NativeSampleTurboModuleArraysCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Object getConstants(jsi::Runtime &rt) = 0; - virtual void voidFunc(jsi::Runtime &rt) = 0; - virtual jsi::Array getBool(jsi::Runtime &rt, jsi::Array id) = 0; - virtual jsi::Array getNumber(jsi::Runtime &rt, jsi::Array arg) = 0; - virtual jsi::Array getString(jsi::Runtime &rt, jsi::Array arg) = 0; - virtual jsi::Array getArray(jsi::Runtime &rt, jsi::Array arg) = 0; - virtual jsi::Array getObject(jsi::Runtime &rt, jsi::Array arg) = 0; - virtual jsi::Array getObjectShape(jsi::Runtime &rt, jsi::Array arg) = 0; - virtual jsi::Array getAlias(jsi::Runtime &rt, jsi::Array arg) = 0; - virtual jsi::Array getRootTag(jsi::Runtime &rt, jsi::Array arg) = 0; - virtual jsi::Array getValue(jsi::Runtime &rt, jsi::Array x, jsi::Array y, jsi::Array z) = 0; - virtual void getValueWithCallback(jsi::Runtime &rt, jsi::Function callback) = 0; - virtual jsi::Value getValueWithPromise(jsi::Runtime &rt, jsi::Array error) = 0; - -}; template class JSI_EXPORT NativeSampleTurboModuleArraysCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModuleArrays\\"; protected: - NativeSampleTurboModuleArraysCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeSampleTurboModuleArraysCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeSampleTurboModuleArraysCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeSampleTurboModuleArraysCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getConstants\\"] = MethodMetadata {.argCount = 0, .invoker = __getConstantsJSI}; + methodMap_[\\"voidFunc\\"] = MethodMetadata {.argCount = 0, .invoker = __voidFuncJSI}; + methodMap_[\\"getBool\\"] = MethodMetadata {.argCount = 1, .invoker = __getBoolJSI}; + methodMap_[\\"getNumber\\"] = MethodMetadata {.argCount = 1, .invoker = __getNumberJSI}; + methodMap_[\\"getString\\"] = MethodMetadata {.argCount = 1, .invoker = __getStringJSI}; + methodMap_[\\"getArray\\"] = MethodMetadata {.argCount = 1, .invoker = __getArrayJSI}; + methodMap_[\\"getObject\\"] = MethodMetadata {.argCount = 1, .invoker = __getObjectJSI}; + methodMap_[\\"getObjectShape\\"] = MethodMetadata {.argCount = 1, .invoker = __getObjectShapeJSI}; + methodMap_[\\"getAlias\\"] = MethodMetadata {.argCount = 1, .invoker = __getAliasJSI}; + methodMap_[\\"getRootTag\\"] = MethodMetadata {.argCount = 1, .invoker = __getRootTagJSI}; + methodMap_[\\"getValue\\"] = MethodMetadata {.argCount = 3, .invoker = __getValueJSI}; + methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithCallbackJSI}; + methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithPromiseJSI}; + } + private: - class Delegate : public NativeSampleTurboModuleArraysCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeSampleTurboModuleArraysCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::Object getConstants(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getConstants) == 1, - \\"Expected getConstants(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::getConstants, jsInvoker_, instance_); - } - void voidFunc(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::voidFunc) == 1, - \\"Expected voidFunc(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::voidFunc, jsInvoker_, instance_); - } - jsi::Array getBool(jsi::Runtime &rt, jsi::Array id) override { - static_assert( - bridging::getParameterCount(&T::getBool) == 2, - \\"Expected getBool(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getBool, jsInvoker_, instance_, std::move(id)); - } - jsi::Array getNumber(jsi::Runtime &rt, jsi::Array arg) override { - static_assert( - bridging::getParameterCount(&T::getNumber) == 2, - \\"Expected getNumber(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getNumber, jsInvoker_, instance_, std::move(arg)); - } - jsi::Array getString(jsi::Runtime &rt, jsi::Array arg) override { - static_assert( - bridging::getParameterCount(&T::getString) == 2, - \\"Expected getString(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getString, jsInvoker_, instance_, std::move(arg)); - } - jsi::Array getArray(jsi::Runtime &rt, jsi::Array arg) override { - static_assert( - bridging::getParameterCount(&T::getArray) == 2, - \\"Expected getArray(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getArray, jsInvoker_, instance_, std::move(arg)); - } - jsi::Array getObject(jsi::Runtime &rt, jsi::Array arg) override { - static_assert( - bridging::getParameterCount(&T::getObject) == 2, - \\"Expected getObject(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getObject, jsInvoker_, instance_, std::move(arg)); - } - jsi::Array getObjectShape(jsi::Runtime &rt, jsi::Array arg) override { - static_assert( - bridging::getParameterCount(&T::getObjectShape) == 2, - \\"Expected getObjectShape(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getObjectShape, jsInvoker_, instance_, std::move(arg)); - } - jsi::Array getAlias(jsi::Runtime &rt, jsi::Array arg) override { - static_assert( - bridging::getParameterCount(&T::getAlias) == 2, - \\"Expected getAlias(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getAlias, jsInvoker_, instance_, std::move(arg)); - } - jsi::Array getRootTag(jsi::Runtime &rt, jsi::Array arg) override { - static_assert( - bridging::getParameterCount(&T::getRootTag) == 2, - \\"Expected getRootTag(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getRootTag, jsInvoker_, instance_, std::move(arg)); - } - jsi::Array getValue(jsi::Runtime &rt, jsi::Array x, jsi::Array y, jsi::Array z) override { - static_assert( - bridging::getParameterCount(&T::getValue) == 4, - \\"Expected getValue(...) to have 4 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValue, jsInvoker_, instance_, std::move(x), std::move(y), std::move(z)); - } - void getValueWithCallback(jsi::Runtime &rt, jsi::Function callback) override { - static_assert( - bridging::getParameterCount(&T::getValueWithCallback) == 2, - \\"Expected getValueWithCallback(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithCallback, jsInvoker_, instance_, std::move(callback)); - } - jsi::Value getValueWithPromise(jsi::Runtime &rt, jsi::Array error) override { - static_assert( - bridging::getParameterCount(&T::getValueWithPromise) == 2, - \\"Expected getValueWithPromise(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithPromise, jsInvoker_, instance_, std::move(error)); - } - - private: - friend class NativeSampleTurboModuleArraysCxxSpec; - T *instance_; - }; - - Delegate delegate_; + static jsi::Value __getConstantsJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getConstants) == 1, + \\"Expected getConstants(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getConstants, self->jsInvoker_, self); + } + + static jsi::Value __voidFuncJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::voidFunc) == 1, + \\"Expected voidFunc(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::voidFunc, self->jsInvoker_, self);return jsi::Value::undefined(); + } + + static jsi::Value __getBoolJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getBool) == 2, + \\"Expected getBool(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getBool, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); + } + + static jsi::Value __getNumberJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getNumber) == 2, + \\"Expected getNumber(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getNumber, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); + } + + static jsi::Value __getStringJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getString) == 2, + \\"Expected getString(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getString, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); + } + + static jsi::Value __getArrayJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getArray) == 2, + \\"Expected getArray(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getArray, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); + } + + static jsi::Value __getObjectJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getObject) == 2, + \\"Expected getObject(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getObject, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); + } + + static jsi::Value __getObjectShapeJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getObjectShape) == 2, + \\"Expected getObjectShape(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getObjectShape, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); + } + + static jsi::Value __getAliasJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getAlias) == 2, + \\"Expected getAlias(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getAlias, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); + } + + static jsi::Value __getRootTagJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getRootTag) == 2, + \\"Expected getRootTag(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getRootTag, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); + } + + static jsi::Value __getValueJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValue) == 4, + \\"Expected getValue(...) to have 4 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getValue, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt), + count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asObject(rt).asArray(rt), + count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asObject(rt).asArray(rt)); + } + + static jsi::Value __getValueWithCallbackJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithCallback) == 2, + \\"Expected getValueWithCallback(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::getValueWithCallback, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asFunction(rt));return jsi::Value::undefined(); + } + + static jsi::Value __getValueWithPromiseJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithPromise) == 2, + \\"Expected getValueWithPromise(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getValueWithPromise, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); + } }; - #pragma mark - NativeSampleTurboModuleNullableAnimal template @@ -3624,169 +2848,149 @@ struct NativeSampleTurboModuleNullableAnimalBridging { } }; -class JSI_EXPORT NativeSampleTurboModuleNullableCxxSpecJSI : public TurboModule { -protected: - NativeSampleTurboModuleNullableCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Object getConstants(jsi::Runtime &rt) = 0; - virtual void voidFunc(jsi::Runtime &rt) = 0; - virtual std::optional getBool(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getNumber(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getString(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getArray(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getObject(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getObjectShape(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getAlias(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getRootTag(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getValue(jsi::Runtime &rt, std::optional x, std::optional y, std::optional z) = 0; - virtual void getValueWithCallback(jsi::Runtime &rt, jsi::Function callback) = 0; - virtual std::optional getValueWithPromise(jsi::Runtime &rt, std::optional error) = 0; - -}; template class JSI_EXPORT NativeSampleTurboModuleNullableCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModuleNullable\\"; protected: - NativeSampleTurboModuleNullableCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeSampleTurboModuleNullableCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeSampleTurboModuleNullableCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeSampleTurboModuleNullableCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getConstants\\"] = MethodMetadata {.argCount = 0, .invoker = __getConstantsJSI}; + methodMap_[\\"voidFunc\\"] = MethodMetadata {.argCount = 0, .invoker = __voidFuncJSI}; + methodMap_[\\"getBool\\"] = MethodMetadata {.argCount = 1, .invoker = __getBoolJSI}; + methodMap_[\\"getNumber\\"] = MethodMetadata {.argCount = 1, .invoker = __getNumberJSI}; + methodMap_[\\"getString\\"] = MethodMetadata {.argCount = 1, .invoker = __getStringJSI}; + methodMap_[\\"getArray\\"] = MethodMetadata {.argCount = 1, .invoker = __getArrayJSI}; + methodMap_[\\"getObject\\"] = MethodMetadata {.argCount = 1, .invoker = __getObjectJSI}; + methodMap_[\\"getObjectShape\\"] = MethodMetadata {.argCount = 1, .invoker = __getObjectShapeJSI}; + methodMap_[\\"getAlias\\"] = MethodMetadata {.argCount = 1, .invoker = __getAliasJSI}; + methodMap_[\\"getRootTag\\"] = MethodMetadata {.argCount = 1, .invoker = __getRootTagJSI}; + methodMap_[\\"getValue\\"] = MethodMetadata {.argCount = 3, .invoker = __getValueJSI}; + methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithCallbackJSI}; + methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithPromiseJSI}; + } + private: - class Delegate : public NativeSampleTurboModuleNullableCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeSampleTurboModuleNullableCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::Object getConstants(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getConstants) == 1, - \\"Expected getConstants(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::getConstants, jsInvoker_, instance_); - } - void voidFunc(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::voidFunc) == 1, - \\"Expected voidFunc(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::voidFunc, jsInvoker_, instance_); - } - std::optional getBool(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getBool) == 2, - \\"Expected getBool(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getBool, jsInvoker_, instance_, std::move(arg)); - } - std::optional getNumber(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getNumber) == 2, - \\"Expected getNumber(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getNumber, jsInvoker_, instance_, std::move(arg)); - } - std::optional getString(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getString) == 2, - \\"Expected getString(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getString, jsInvoker_, instance_, std::move(arg)); - } - std::optional getArray(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getArray) == 2, - \\"Expected getArray(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getArray, jsInvoker_, instance_, std::move(arg)); - } - std::optional getObject(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getObject) == 2, - \\"Expected getObject(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getObject, jsInvoker_, instance_, std::move(arg)); - } - std::optional getObjectShape(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getObjectShape) == 2, - \\"Expected getObjectShape(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getObjectShape, jsInvoker_, instance_, std::move(arg)); - } - std::optional getAlias(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getAlias) == 2, - \\"Expected getAlias(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getAlias, jsInvoker_, instance_, std::move(arg)); - } - std::optional getRootTag(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getRootTag) == 2, - \\"Expected getRootTag(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getRootTag, jsInvoker_, instance_, std::move(arg)); - } - std::optional getValue(jsi::Runtime &rt, std::optional x, std::optional y, std::optional z) override { - static_assert( - bridging::getParameterCount(&T::getValue) == 4, - \\"Expected getValue(...) to have 4 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getValue, jsInvoker_, instance_, std::move(x), std::move(y), std::move(z)); - } - void getValueWithCallback(jsi::Runtime &rt, jsi::Function callback) override { - static_assert( - bridging::getParameterCount(&T::getValueWithCallback) == 2, - \\"Expected getValueWithCallback(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithCallback, jsInvoker_, instance_, std::move(callback)); - } - std::optional getValueWithPromise(jsi::Runtime &rt, std::optional error) override { - static_assert( - bridging::getParameterCount(&T::getValueWithPromise) == 2, - \\"Expected getValueWithPromise(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getValueWithPromise, jsInvoker_, instance_, std::move(error)); - } - - private: - friend class NativeSampleTurboModuleNullableCxxSpec; - T *instance_; - }; - - Delegate delegate_; + static jsi::Value __getConstantsJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getConstants) == 1, + \\"Expected getConstants(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getConstants, self->jsInvoker_, self); + } + + static jsi::Value __voidFuncJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::voidFunc) == 1, + \\"Expected voidFunc(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::voidFunc, self->jsInvoker_, self);return jsi::Value::undefined(); + } + + static jsi::Value __getBoolJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getBool) == 2, + \\"Expected getBool(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getBool, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool()));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getNumberJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getNumber) == 2, + \\"Expected getNumber(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getNumber, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getStringJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getString) == 2, + \\"Expected getString(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getString, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asString(rt)));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getArrayJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getArray) == 2, + \\"Expected getArray(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getArray, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt).asArray(rt)));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getObjectJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getObject) == 2, + \\"Expected getObject(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getObject, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getObjectShapeJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getObjectShape) == 2, + \\"Expected getObjectShape(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getObjectShape, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getAliasJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getAlias) == 2, + \\"Expected getAlias(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getAlias, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getRootTagJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getRootTag) == 2, + \\"Expected getRootTag(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getRootTag, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getValueJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValue) == 4, + \\"Expected getValue(...) to have 4 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getValue, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()), + count <= 1 || args[1].isNull() || args[1].isUndefined() ? std::nullopt : std::make_optional(args[1].asString(rt)), + count <= 2 || args[2].isNull() || args[2].isUndefined() ? std::nullopt : std::make_optional(args[2].asObject(rt)));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getValueWithCallbackJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithCallback) == 2, + \\"Expected getValueWithCallback(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::getValueWithCallback, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asFunction(rt));return jsi::Value::undefined(); + } + + static jsi::Value __getValueWithPromiseJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithPromise) == 2, + \\"Expected getValueWithPromise(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getValueWithPromise, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool()));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } }; - #pragma mark - NativeSampleTurboModuleNullableAndOptionalAnimal template @@ -3828,169 +3032,149 @@ struct NativeSampleTurboModuleNullableAndOptionalAnimalBridging { } }; -class JSI_EXPORT NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI : public TurboModule { -protected: - NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Object getConstants(jsi::Runtime &rt) = 0; - virtual void voidFunc(jsi::Runtime &rt) = 0; - virtual std::optional getBool(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getNumber(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getString(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getArray(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getObject(jsi::Runtime &rt, std::optional arg) = 0; - virtual jsi::Object getObjectShape(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getAlias(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getRootTag(jsi::Runtime &rt, std::optional arg) = 0; - virtual std::optional getValue(jsi::Runtime &rt, std::optional x, std::optional y, std::optional z) = 0; - virtual void getValueWithCallback(jsi::Runtime &rt, std::optional callback) = 0; - virtual std::optional getValueWithPromise(jsi::Runtime &rt, std::optional error) = 0; - -}; template class JSI_EXPORT NativeSampleTurboModuleNullableAndOptionalCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModuleNullableAndOptional\\"; protected: - NativeSampleTurboModuleNullableAndOptionalCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeSampleTurboModuleNullableAndOptionalCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeSampleTurboModuleNullableAndOptionalCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeSampleTurboModuleNullableAndOptionalCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getConstants\\"] = MethodMetadata {.argCount = 0, .invoker = __getConstantsJSI}; + methodMap_[\\"voidFunc\\"] = MethodMetadata {.argCount = 0, .invoker = __voidFuncJSI}; + methodMap_[\\"getBool\\"] = MethodMetadata {.argCount = 1, .invoker = __getBoolJSI}; + methodMap_[\\"getNumber\\"] = MethodMetadata {.argCount = 1, .invoker = __getNumberJSI}; + methodMap_[\\"getString\\"] = MethodMetadata {.argCount = 1, .invoker = __getStringJSI}; + methodMap_[\\"getArray\\"] = MethodMetadata {.argCount = 1, .invoker = __getArrayJSI}; + methodMap_[\\"getObject\\"] = MethodMetadata {.argCount = 1, .invoker = __getObjectJSI}; + methodMap_[\\"getObjectShape\\"] = MethodMetadata {.argCount = 1, .invoker = __getObjectShapeJSI}; + methodMap_[\\"getAlias\\"] = MethodMetadata {.argCount = 1, .invoker = __getAliasJSI}; + methodMap_[\\"getRootTag\\"] = MethodMetadata {.argCount = 1, .invoker = __getRootTagJSI}; + methodMap_[\\"getValue\\"] = MethodMetadata {.argCount = 3, .invoker = __getValueJSI}; + methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithCallbackJSI}; + methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithPromiseJSI}; + } + private: - class Delegate : public NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeSampleTurboModuleNullableAndOptionalCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::Object getConstants(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getConstants) == 1, - \\"Expected getConstants(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::getConstants, jsInvoker_, instance_); - } - void voidFunc(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::voidFunc) == 1, - \\"Expected voidFunc(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::voidFunc, jsInvoker_, instance_); - } - std::optional getBool(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getBool) == 2, - \\"Expected getBool(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getBool, jsInvoker_, instance_, std::move(arg)); - } - std::optional getNumber(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getNumber) == 2, - \\"Expected getNumber(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getNumber, jsInvoker_, instance_, std::move(arg)); - } - std::optional getString(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getString) == 2, - \\"Expected getString(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getString, jsInvoker_, instance_, std::move(arg)); - } - std::optional getArray(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getArray) == 2, - \\"Expected getArray(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getArray, jsInvoker_, instance_, std::move(arg)); - } - std::optional getObject(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getObject) == 2, - \\"Expected getObject(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getObject, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getObjectShape(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getObjectShape) == 2, - \\"Expected getObjectShape(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getObjectShape, jsInvoker_, instance_, std::move(arg)); - } - std::optional getAlias(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getAlias) == 2, - \\"Expected getAlias(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getAlias, jsInvoker_, instance_, std::move(arg)); - } - std::optional getRootTag(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getRootTag) == 2, - \\"Expected getRootTag(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getRootTag, jsInvoker_, instance_, std::move(arg)); - } - std::optional getValue(jsi::Runtime &rt, std::optional x, std::optional y, std::optional z) override { - static_assert( - bridging::getParameterCount(&T::getValue) == 4, - \\"Expected getValue(...) to have 4 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getValue, jsInvoker_, instance_, std::move(x), std::move(y), std::move(z)); - } - void getValueWithCallback(jsi::Runtime &rt, std::optional callback) override { - static_assert( - bridging::getParameterCount(&T::getValueWithCallback) == 2, - \\"Expected getValueWithCallback(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithCallback, jsInvoker_, instance_, std::move(callback)); - } - std::optional getValueWithPromise(jsi::Runtime &rt, std::optional error) override { - static_assert( - bridging::getParameterCount(&T::getValueWithPromise) == 2, - \\"Expected getValueWithPromise(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getValueWithPromise, jsInvoker_, instance_, std::move(error)); - } - - private: - friend class NativeSampleTurboModuleNullableAndOptionalCxxSpec; - T *instance_; - }; - - Delegate delegate_; + static jsi::Value __getConstantsJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getConstants) == 1, + \\"Expected getConstants(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getConstants, self->jsInvoker_, self); + } + + static jsi::Value __voidFuncJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::voidFunc) == 1, + \\"Expected voidFunc(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::voidFunc, self->jsInvoker_, self);return jsi::Value::undefined(); + } + + static jsi::Value __getBoolJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getBool) == 2, + \\"Expected getBool(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getBool, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool()));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getNumberJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getNumber) == 2, + \\"Expected getNumber(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getNumber, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getStringJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getString) == 2, + \\"Expected getString(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getString, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asString(rt)));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getArrayJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getArray) == 2, + \\"Expected getArray(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getArray, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt).asArray(rt)));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getObjectJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getObject) == 2, + \\"Expected getObject(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getObject, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getObjectShapeJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getObjectShape) == 2, + \\"Expected getObjectShape(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getObjectShape, self->jsInvoker_, self, + count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt))); + } + + static jsi::Value __getAliasJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getAlias) == 2, + \\"Expected getAlias(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getAlias, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getRootTagJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getRootTag) == 2, + \\"Expected getRootTag(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getRootTag, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getValueJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValue) == 4, + \\"Expected getValue(...) to have 4 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getValue, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()), + count <= 1 || args[1].isNull() || args[1].isUndefined() ? std::nullopt : std::make_optional(args[1].asString(rt)), + count <= 2 || args[2].isNull() || args[2].isUndefined() ? std::nullopt : std::make_optional(args[2].asObject(rt)));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getValueWithCallbackJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithCallback) == 2, + \\"Expected getValueWithCallback(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::getValueWithCallback, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt).asFunction(rt)));return jsi::Value::undefined(); + } + + static jsi::Value __getValueWithPromiseJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithPromise) == 2, + \\"Expected getValueWithPromise(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getValueWithPromise, self->jsInvoker_, self, + count <= 0 || args[0].isNull() || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool()));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } }; - #pragma mark - NativeSampleTurboModuleOptionalAnimal template @@ -4032,228 +3216,178 @@ struct NativeSampleTurboModuleOptionalAnimalBridging { } }; -class JSI_EXPORT NativeSampleTurboModuleOptionalCxxSpecJSI : public TurboModule { -protected: - NativeSampleTurboModuleOptionalCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Object getConstants(jsi::Runtime &rt) = 0; - virtual void voidFunc(jsi::Runtime &rt) = 0; - virtual bool getBool(jsi::Runtime &rt, std::optional arg) = 0; - virtual double getNumber(jsi::Runtime &rt, std::optional arg) = 0; - virtual jsi::String getString(jsi::Runtime &rt, std::optional arg) = 0; - virtual jsi::Array getArray(jsi::Runtime &rt, std::optional arg) = 0; - virtual jsi::Object getObject(jsi::Runtime &rt, std::optional arg) = 0; - virtual jsi::Object getObjectShape(jsi::Runtime &rt, std::optional arg) = 0; - virtual jsi::Object getAlias(jsi::Runtime &rt, std::optional arg) = 0; - virtual double getRootTag(jsi::Runtime &rt, std::optional arg) = 0; - virtual jsi::Object getValue(jsi::Runtime &rt, std::optional x, std::optional y, std::optional z) = 0; - virtual void getValueWithCallback(jsi::Runtime &rt, std::optional callback) = 0; - virtual jsi::Value getValueWithPromise(jsi::Runtime &rt, std::optional error) = 0; - -}; template class JSI_EXPORT NativeSampleTurboModuleOptionalCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModuleOptional\\"; protected: - NativeSampleTurboModuleOptionalCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeSampleTurboModuleOptionalCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeSampleTurboModuleOptionalCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeSampleTurboModuleOptionalCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getConstants\\"] = MethodMetadata {.argCount = 0, .invoker = __getConstantsJSI}; + methodMap_[\\"voidFunc\\"] = MethodMetadata {.argCount = 0, .invoker = __voidFuncJSI}; + methodMap_[\\"getBool\\"] = MethodMetadata {.argCount = 1, .invoker = __getBoolJSI}; + methodMap_[\\"getNumber\\"] = MethodMetadata {.argCount = 1, .invoker = __getNumberJSI}; + methodMap_[\\"getString\\"] = MethodMetadata {.argCount = 1, .invoker = __getStringJSI}; + methodMap_[\\"getArray\\"] = MethodMetadata {.argCount = 1, .invoker = __getArrayJSI}; + methodMap_[\\"getObject\\"] = MethodMetadata {.argCount = 1, .invoker = __getObjectJSI}; + methodMap_[\\"getObjectShape\\"] = MethodMetadata {.argCount = 1, .invoker = __getObjectShapeJSI}; + methodMap_[\\"getAlias\\"] = MethodMetadata {.argCount = 1, .invoker = __getAliasJSI}; + methodMap_[\\"getRootTag\\"] = MethodMetadata {.argCount = 1, .invoker = __getRootTagJSI}; + methodMap_[\\"getValue\\"] = MethodMetadata {.argCount = 3, .invoker = __getValueJSI}; + methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithCallbackJSI}; + methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithPromiseJSI}; + } + private: - class Delegate : public NativeSampleTurboModuleOptionalCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeSampleTurboModuleOptionalCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::Object getConstants(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getConstants) == 1, - \\"Expected getConstants(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::getConstants, jsInvoker_, instance_); - } - void voidFunc(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::voidFunc) == 1, - \\"Expected voidFunc(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::voidFunc, jsInvoker_, instance_); - } - bool getBool(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getBool) == 2, - \\"Expected getBool(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getBool, jsInvoker_, instance_, std::move(arg)); - } - double getNumber(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getNumber) == 2, - \\"Expected getNumber(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getNumber, jsInvoker_, instance_, std::move(arg)); - } - jsi::String getString(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getString) == 2, - \\"Expected getString(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getString, jsInvoker_, instance_, std::move(arg)); - } - jsi::Array getArray(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getArray) == 2, - \\"Expected getArray(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getArray, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getObject(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getObject) == 2, - \\"Expected getObject(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getObject, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getObjectShape(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getObjectShape) == 2, - \\"Expected getObjectShape(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getObjectShape, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getAlias(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getAlias) == 2, - \\"Expected getAlias(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getAlias, jsInvoker_, instance_, std::move(arg)); - } - double getRootTag(jsi::Runtime &rt, std::optional arg) override { - static_assert( - bridging::getParameterCount(&T::getRootTag) == 2, - \\"Expected getRootTag(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getRootTag, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getValue(jsi::Runtime &rt, std::optional x, std::optional y, std::optional z) override { - static_assert( - bridging::getParameterCount(&T::getValue) == 4, - \\"Expected getValue(...) to have 4 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValue, jsInvoker_, instance_, std::move(x), std::move(y), std::move(z)); - } - void getValueWithCallback(jsi::Runtime &rt, std::optional callback) override { - static_assert( - bridging::getParameterCount(&T::getValueWithCallback) == 2, - \\"Expected getValueWithCallback(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithCallback, jsInvoker_, instance_, std::move(callback)); - } - jsi::Value getValueWithPromise(jsi::Runtime &rt, std::optional error) override { - static_assert( - bridging::getParameterCount(&T::getValueWithPromise) == 2, - \\"Expected getValueWithPromise(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithPromise, jsInvoker_, instance_, std::move(error)); - } - - private: - friend class NativeSampleTurboModuleOptionalCxxSpec; - T *instance_; - }; - - Delegate delegate_; + static jsi::Value __getConstantsJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getConstants) == 1, + \\"Expected getConstants(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getConstants, self->jsInvoker_, self); + } + + static jsi::Value __voidFuncJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::voidFunc) == 1, + \\"Expected voidFunc(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::voidFunc, self->jsInvoker_, self);return jsi::Value::undefined(); + } + + static jsi::Value __getBoolJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getBool) == 2, + \\"Expected getBool(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getBool, self->jsInvoker_, self, + count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool())); + } + + static jsi::Value __getNumberJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getNumber) == 2, + \\"Expected getNumber(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getNumber, self->jsInvoker_, self, + count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber())); + } + + static jsi::Value __getStringJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getString) == 2, + \\"Expected getString(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getString, self->jsInvoker_, self, + count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asString(rt))); + } + + static jsi::Value __getArrayJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getArray) == 2, + \\"Expected getArray(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getArray, self->jsInvoker_, self, + count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt).asArray(rt))); + } + + static jsi::Value __getObjectJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getObject) == 2, + \\"Expected getObject(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getObject, self->jsInvoker_, self, + count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt))); + } + + static jsi::Value __getObjectShapeJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getObjectShape) == 2, + \\"Expected getObjectShape(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getObjectShape, self->jsInvoker_, self, + count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt))); + } + + static jsi::Value __getAliasJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getAlias) == 2, + \\"Expected getAlias(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getAlias, self->jsInvoker_, self, + count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt))); + } + + static jsi::Value __getRootTagJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getRootTag) == 2, + \\"Expected getRootTag(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getRootTag, self->jsInvoker_, self, + count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber())); + } + + static jsi::Value __getValueJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValue) == 4, + \\"Expected getValue(...) to have 4 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getValue, self->jsInvoker_, self, + count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asNumber()), + count <= 1 || args[1].isUndefined() ? std::nullopt : std::make_optional(args[1].asString(rt)), + count <= 2 || args[2].isUndefined() ? std::nullopt : std::make_optional(args[2].asObject(rt))); + } + + static jsi::Value __getValueWithCallbackJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithCallback) == 2, + \\"Expected getValueWithCallback(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::getValueWithCallback, self->jsInvoker_, self, + count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt).asFunction(rt)));return jsi::Value::undefined(); + } + + static jsi::Value __getValueWithPromiseJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithPromise) == 2, + \\"Expected getValueWithPromise(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getValueWithPromise, self->jsInvoker_, self, + count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool())); + } }; - class JSI_EXPORT NativeStringTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeStringTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::String getString(jsi::Runtime &rt, jsi::String arg) = 0; - virtual jsi::String getStringWithAlias(jsi::Runtime &rt, jsi::String arg) = 0; - -}; - template class JSI_EXPORT NativeStringTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; protected: - NativeStringTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeStringTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeStringTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeStringTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getString\\"] = MethodMetadata {.argCount = 1, .invoker = __getStringJSI}; + methodMap_[\\"getStringWithAlias\\"] = MethodMetadata {.argCount = 1, .invoker = __getStringWithAliasJSI}; + } + private: - class Delegate : public NativeStringTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeStringTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::String getString(jsi::Runtime &rt, jsi::String arg) override { - static_assert( - bridging::getParameterCount(&T::getString) == 2, - \\"Expected getString(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getString, jsInvoker_, instance_, std::move(arg)); - } - jsi::String getStringWithAlias(jsi::Runtime &rt, jsi::String arg) override { - static_assert( - bridging::getParameterCount(&T::getStringWithAlias) == 2, - \\"Expected getStringWithAlias(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getStringWithAlias, jsInvoker_, instance_, std::move(arg)); - } - - private: - friend class NativeStringTurboModuleCxxSpec; - T *instance_; - }; - - Delegate delegate_; + static jsi::Value __getStringJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getString) == 2, + \\"Expected getString(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getString, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt)); + } + + static jsi::Value __getStringWithAliasJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getStringWithAlias) == 2, + \\"Expected getStringWithAlias(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getStringWithAlias, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt)); + } }; } // namespace facebook::react diff --git a/packages/react-native-codegen/src/generators/RNCodegen.js b/packages/react-native-codegen/src/generators/RNCodegen.js index 70322cfb9b3a65..33f86c7f80eb1d 100644 --- a/packages/react-native-codegen/src/generators/RNCodegen.js +++ b/packages/react-native-codegen/src/generators/RNCodegen.js @@ -36,7 +36,6 @@ const generateTests = require('./components/GenerateTests.js'); const generateThirdPartyFabricComponentsProviderH = require('./components/GenerateThirdPartyFabricComponentsProviderH.js'); const generateThirdPartyFabricComponentsProviderObjCpp = require('./components/GenerateThirdPartyFabricComponentsProviderObjCpp.js'); const generateViewConfigJs = require('./components/GenerateViewConfigJs.js'); -const generateModuleCpp = require('./modules/GenerateModuleCpp.js'); const generateModuleH = require('./modules/GenerateModuleH.js'); const generateModuleJavaSpec = require('./modules/GenerateModuleJavaSpec.js'); const generateModuleJniCpp = require('./modules/GenerateModuleJniCpp.js'); @@ -56,7 +55,6 @@ const ALL_GENERATORS = { generateStateCpp: generateStateCpp.generate, generateStateH: generateStateH.generate, generateModuleH: generateModuleH.generate, - generateModuleCpp: generateModuleCpp.generate, generateModuleObjCpp: generateModuleObjCpp.generate, generateModuleJavaSpec: generateModuleJavaSpec.generate, generateModuleJniCpp: generateModuleJniCpp.generate, @@ -179,7 +177,7 @@ const LIBRARY_GENERATORS: LibraryGeneratorsFunctions = { generateModuleJniH.generate, generateModuleJavaSpec.generate, ], - modulesCxx: [generateModuleCpp.generate, generateModuleH.generate], + modulesCxx: [generateModuleH.generate], modulesIOS: [generateModuleObjCpp.generate], tests: [generateTests.generate], 'shadow-nodes': [ diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleCpp.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleCpp.js deleted file mode 100644 index e26b789740bcb9..00000000000000 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleCpp.js +++ /dev/null @@ -1,296 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow strict - * @format - */ - -'use strict'; - -import type { - NamedShape, - NativeModuleEnumMap, - NativeModuleFunctionTypeAnnotation, - NativeModuleParamTypeAnnotation, - NativeModulePropertyShape, - NativeModuleTypeAnnotation, - Nullable, - SchemaType, -} from '../../CodegenSchema'; -import type {AliasResolver} from './Utils'; - -const {unwrapNullable} = require('../../parsers/parsers-commons'); -const {createAliasResolver, getModules} = require('./Utils'); - -type FilesOutput = Map; - -const HostFunctionTemplate = ({ - hasteModuleName, - methodName, - returnTypeAnnotation, - args, -}: $ReadOnly<{ - hasteModuleName: string, - methodName: string, - returnTypeAnnotation: Nullable, - args: Array, -}>) => { - const isNullable = returnTypeAnnotation.type === 'NullableTypeAnnotation'; - const isVoid = returnTypeAnnotation.type === 'VoidTypeAnnotation'; - const methodCallArgs = [' rt', ...args].join(',\n '); - const methodCall = `static_cast<${hasteModuleName}CxxSpecJSI *>(&turboModule)->${methodName}(\n${methodCallArgs}\n )`; - - return `static jsi::Value __hostFunction_${hasteModuleName}CxxSpecJSI_${methodName}(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {${ - isVoid - ? `\n ${methodCall};` - : isNullable - ? `\n auto result = ${methodCall};` - : '' - } - return ${ - isVoid - ? 'jsi::Value::undefined()' - : isNullable - ? 'result ? jsi::Value(std::move(*result)) : jsi::Value::null()' - : methodCall - }; -}`; -}; - -const ModuleTemplate = ({ - hasteModuleName, - hostFunctions, - moduleName, - methods, -}: $ReadOnly<{ - hasteModuleName: string, - hostFunctions: $ReadOnlyArray, - moduleName: string, - methods: $ReadOnlyArray<$ReadOnly<{methodName: string, paramCount: number}>>, -}>) => { - return `${hostFunctions.join('\n')} - -${hasteModuleName}CxxSpecJSI::${hasteModuleName}CxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule("${moduleName}", jsInvoker) { -${methods - .map(({methodName, paramCount}) => { - return ` methodMap_["${methodName}"] = MethodMetadata {${paramCount}, __hostFunction_${hasteModuleName}CxxSpecJSI_${methodName}};`; - }) - .join('\n')} -}`; -}; - -const FileTemplate = ({ - libraryName, - modules, -}: $ReadOnly<{ - libraryName: string, - modules: string, -}>) => { - return `/** - * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). - * - * Do not edit this file as changes may cause incorrect behavior and will be lost - * once the code is regenerated. - * - * ${'@'}generated by codegen project: GenerateModuleCpp.js - */ - -#include "${libraryName}JSI.h" - -namespace facebook::react { - -${modules} - - -} // namespace facebook::react -`; -}; - -type Param = NamedShape>; - -function serializeArg( - moduleName: string, - arg: Param, - index: number, - resolveAlias: AliasResolver, - enumMap: NativeModuleEnumMap, -): string { - const {typeAnnotation: nullableTypeAnnotation, optional} = arg; - const [typeAnnotation, nullable] = - unwrapNullable(nullableTypeAnnotation); - - let realTypeAnnotation = typeAnnotation; - if (realTypeAnnotation.type === 'TypeAliasTypeAnnotation') { - realTypeAnnotation = resolveAlias(realTypeAnnotation.name); - } - - function wrap(callback: (val: string) => string) { - const val = `args[${index}]`; - const expression = callback(val); - - // param?: T - if (optional && !nullable) { - // throw new Error('are we hitting this case? ' + moduleName); - return `count <= ${index} || ${val}.isUndefined() ? std::nullopt : std::make_optional(${expression})`; - } - - // param: ?T - // param?: ?T - if (nullable || optional) { - return `count <= ${index} || ${val}.isNull() || ${val}.isUndefined() ? std::nullopt : std::make_optional(${expression})`; - } - - // param: T - return `count <= ${index} ? throw jsi::JSError(rt, "Expected argument in position ${index} to be passed") : ${expression}`; - } - - switch (realTypeAnnotation.type) { - case 'ReservedTypeAnnotation': - switch (realTypeAnnotation.name) { - case 'RootTag': - return wrap(val => `${val}.asNumber()`); - default: - (realTypeAnnotation.name: empty); - throw new Error( - `Unknown prop type for "${arg.name}, found: ${realTypeAnnotation.name}"`, - ); - } - case 'StringTypeAnnotation': - return wrap(val => `${val}.asString(rt)`); - case 'StringLiteralTypeAnnotation': - return wrap(val => `${val}.asString(rt)`); - case 'StringLiteralUnionTypeAnnotation': - return wrap(val => `${val}.asString(rt)`); - case 'BooleanTypeAnnotation': - return wrap(val => `${val}.asBool()`); - case 'EnumDeclaration': - switch (realTypeAnnotation.memberType) { - case 'NumberTypeAnnotation': - return wrap(val => `${val}.asNumber()`); - case 'StringTypeAnnotation': - return wrap(val => `${val}.asString(rt)`); - default: - throw new Error( - `Unknown enum type for "${arg.name}, found: ${realTypeAnnotation.type}"`, - ); - } - case 'NumberTypeAnnotation': - return wrap(val => `${val}.asNumber()`); - case 'FloatTypeAnnotation': - return wrap(val => `${val}.asNumber()`); - case 'DoubleTypeAnnotation': - return wrap(val => `${val}.asNumber()`); - case 'Int32TypeAnnotation': - return wrap(val => `${val}.asNumber()`); - case 'NumberLiteralTypeAnnotation': - return wrap(val => `${val}.asNumber()`); - case 'ArrayTypeAnnotation': - return wrap(val => `${val}.asObject(rt).asArray(rt)`); - case 'FunctionTypeAnnotation': - return wrap(val => `${val}.asObject(rt).asFunction(rt)`); - case 'GenericObjectTypeAnnotation': - return wrap(val => `${val}.asObject(rt)`); - case 'UnionTypeAnnotation': - switch (typeAnnotation.memberType) { - case 'NumberTypeAnnotation': - return wrap(val => `${val}.asNumber()`); - case 'ObjectTypeAnnotation': - return wrap(val => `${val}.asObject(rt)`); - case 'StringTypeAnnotation': - return wrap(val => `${val}.asString(rt)`); - default: - throw new Error( - `Unsupported union member type for param "${arg.name}, found: ${realTypeAnnotation.memberType}"`, - ); - } - case 'ObjectTypeAnnotation': - return wrap(val => `${val}.asObject(rt)`); - case 'MixedTypeAnnotation': - return wrap(val => `jsi::Value(rt, ${val})`); - default: - (realTypeAnnotation.type: empty); - throw new Error( - `Unknown prop type for "${arg.name}, found: ${realTypeAnnotation.type}"`, - ); - } -} - -function serializePropertyIntoHostFunction( - moduleName: string, - hasteModuleName: string, - property: NativeModulePropertyShape, - resolveAlias: AliasResolver, - enumMap: NativeModuleEnumMap, -): string { - const [propertyTypeAnnotation] = - unwrapNullable(property.typeAnnotation); - - return HostFunctionTemplate({ - hasteModuleName, - methodName: property.name, - returnTypeAnnotation: propertyTypeAnnotation.returnTypeAnnotation, - args: propertyTypeAnnotation.params.map((p, i) => - serializeArg(moduleName, p, i, resolveAlias, enumMap), - ), - }); -} - -module.exports = { - generate( - libraryName: string, - schema: SchemaType, - packageName?: string, - assumeNonnull: boolean = false, - headerPrefix?: string, - ): FilesOutput { - const nativeModules = getModules(schema); - - const modules = Object.keys(nativeModules) - .map((hasteModuleName: string) => { - const nativeModule = nativeModules[hasteModuleName]; - const { - aliasMap, - enumMap, - spec: {methods}, - moduleName, - } = nativeModule; - const resolveAlias = createAliasResolver(aliasMap); - const hostFunctions = methods.map(property => - serializePropertyIntoHostFunction( - moduleName, - hasteModuleName, - property, - resolveAlias, - enumMap, - ), - ); - - return ModuleTemplate({ - hasteModuleName, - hostFunctions, - moduleName, - methods: methods.map( - ({name: propertyName, typeAnnotation: nullableTypeAnnotation}) => { - const [{params}] = unwrapNullable(nullableTypeAnnotation); - return { - methodName: propertyName, - paramCount: params.length, - }; - }, - ), - }); - }) - .join('\n'); - - const fileName = `${libraryName}JSI-generated.cpp`; - const replacedTemplate = FileTemplate({ - modules, - libraryName, - }); - return new Map([[fileName, replacedTemplate]]); - }, -}; diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js index 2e666347e51446..f85d8494dd2938 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js @@ -9,17 +9,17 @@ */ 'use strict'; + import type { NamedShape, - NativeModuleBaseTypeAnnotation, -} from '../../CodegenSchema'; -import type { NativeModuleAliasMap, + NativeModuleBaseTypeAnnotation, NativeModuleEnumMap, NativeModuleEnumMember, NativeModuleEnumMemberType, NativeModuleEventEmitterShape, NativeModuleFunctionTypeAnnotation, + NativeModuleParamTypeAnnotation, NativeModulePropertyShape, NativeModuleTypeAnnotation, Nullable, @@ -30,7 +30,6 @@ import type {AliasResolver} from './Utils'; const {unwrapNullable} = require('../../parsers/parsers-commons'); const {wrapOptional} = require('../TypeUtils/Cxx'); const {getEnumName, toPascalCase, toSafeCppString} = require('../Utils'); -const {indent} = require('../Utils'); const { createAliasResolver, getModules, @@ -40,74 +39,151 @@ const { type FilesOutput = Map; -const ModuleClassDeclarationTemplate = ({ - hasteModuleName, - moduleProperties, - structs, - enums, -}: $ReadOnly<{ - hasteModuleName: string, - moduleProperties: string[], - structs: string, - enums: string, -}>) => { - return `${enums} - ${structs}class JSI_EXPORT ${hasteModuleName}CxxSpecJSI : public TurboModule { -protected: - ${hasteModuleName}CxxSpecJSI(std::shared_ptr jsInvoker); +type Param = NamedShape>; -public: - ${indent(moduleProperties.join('\n'), 2)} +function serializeArg( + moduleName: string, + arg: Param, + index: number, + resolveAlias: AliasResolver, + enumMap: NativeModuleEnumMap, +): string { + const {typeAnnotation: nullableTypeAnnotation, optional} = arg; + const [typeAnnotation, nullable] = + unwrapNullable(nullableTypeAnnotation); -};`; -}; + let realTypeAnnotation = typeAnnotation; + if (realTypeAnnotation.type === 'TypeAliasTypeAnnotation') { + realTypeAnnotation = resolveAlias(realTypeAnnotation.name); + } + + function wrap(callback: (val: string) => string) { + const val = `args[${index}]`; + const expression = callback(val); + + // param?: T + if (optional && !nullable) { + // throw new Error('are we hitting this case? ' + moduleName); + return `count <= ${index} || ${val}.isUndefined() ? std::nullopt : std::make_optional(${expression})`; + } + + // param: ?T + // param?: ?T + if (nullable || optional) { + return `count <= ${index} || ${val}.isNull() || ${val}.isUndefined() ? std::nullopt : std::make_optional(${expression})`; + } + + // param: T + return `count <= ${index} ? throw jsi::JSError(rt, "Expected argument in position ${index} to be passed") : ${expression}`; + } + + switch (realTypeAnnotation.type) { + case 'ReservedTypeAnnotation': + switch (realTypeAnnotation.name) { + case 'RootTag': + return wrap(val => `${val}.asNumber()`); + default: + (realTypeAnnotation.name: empty); + throw new Error( + `Unknown prop type for "${arg.name}, found: ${realTypeAnnotation.name}"`, + ); + } + case 'StringTypeAnnotation': + return wrap(val => `${val}.asString(rt)`); + case 'StringLiteralTypeAnnotation': + return wrap(val => `${val}.asString(rt)`); + case 'StringLiteralUnionTypeAnnotation': + return wrap(val => `${val}.asString(rt)`); + case 'BooleanTypeAnnotation': + return wrap(val => `${val}.asBool()`); + case 'EnumDeclaration': + switch (realTypeAnnotation.memberType) { + case 'NumberTypeAnnotation': + return wrap(val => `${val}.asNumber()`); + case 'StringTypeAnnotation': + return wrap(val => `${val}.asString(rt)`); + default: + throw new Error( + `Unknown enum type for "${arg.name}, found: ${realTypeAnnotation.type}"`, + ); + } + case 'NumberTypeAnnotation': + return wrap(val => `${val}.asNumber()`); + case 'FloatTypeAnnotation': + return wrap(val => `${val}.asNumber()`); + case 'DoubleTypeAnnotation': + return wrap(val => `${val}.asNumber()`); + case 'Int32TypeAnnotation': + return wrap(val => `${val}.asNumber()`); + case 'NumberLiteralTypeAnnotation': + return wrap(val => `${val}.asNumber()`); + case 'ArrayTypeAnnotation': + return wrap(val => `${val}.asObject(rt).asArray(rt)`); + case 'FunctionTypeAnnotation': + return wrap(val => `${val}.asObject(rt).asFunction(rt)`); + case 'GenericObjectTypeAnnotation': + return wrap(val => `${val}.asObject(rt)`); + case 'UnionTypeAnnotation': + switch (typeAnnotation.memberType) { + case 'NumberTypeAnnotation': + return wrap(val => `${val}.asNumber()`); + case 'ObjectTypeAnnotation': + return wrap(val => `${val}.asObject(rt)`); + case 'StringTypeAnnotation': + return wrap(val => `${val}.asString(rt)`); + default: + throw new Error( + `Unsupported union member type for param "${arg.name}, found: ${realTypeAnnotation.memberType}"`, + ); + } + case 'ObjectTypeAnnotation': + return wrap(val => `${val}.asObject(rt)`); + case 'MixedTypeAnnotation': + return wrap(val => `jsi::Value(rt, ${val})`); + default: + (realTypeAnnotation.type: empty); + throw new Error( + `Unknown prop type for "${arg.name}, found: ${realTypeAnnotation.type}"`, + ); + } +} const ModuleSpecClassDeclarationTemplate = ({ hasteModuleName, moduleName, + structs, + enums, moduleEventEmitters, - moduleProperties, + moduleFunctions, + methods, }: $ReadOnly<{ hasteModuleName: string, moduleName: string, + structs: string, + enums: string, moduleEventEmitters: EventEmitterCpp[], - moduleProperties: string[], + moduleFunctions: string[], + methods: $ReadOnlyArray<$ReadOnly<{methodName: string, paramCount: number}>>, }>) => { - return `template + return `${enums}${structs} +template class JSI_EXPORT ${hasteModuleName}CxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = "${moduleName}"; protected: - ${hasteModuleName}CxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{${hasteModuleName}CxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} -${moduleEventEmitters.map(e => e.emitFunction).join('\n')} - + ${hasteModuleName}CxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{${hasteModuleName}CxxSpec::kModuleName}, jsInvoker) { +${methods + .map(({methodName, paramCount}) => { + return ` methodMap_["${methodName}"] = MethodMetadata {.argCount = ${paramCount}, .invoker = __${methodName}JSI};`; + }) + .join( + '\n', + )}${moduleEventEmitters.length > 0 ? '\n' : ''}${moduleEventEmitters.map(e => e.registerEventEmitter).join('\n')} + } + ${moduleEventEmitters.map(e => e.emitFunction).join('\n')} private: - class Delegate : public ${hasteModuleName}CxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - ${hasteModuleName}CxxSpecJSI(std::move(jsInvoker)), instance_(instance) { -${moduleEventEmitters.map(e => e.registerEventEmitter).join('\n')} - } - - ${indent(moduleProperties.join('\n'), 4)} - - private: - friend class ${hasteModuleName}CxxSpec; - T *instance_; - }; - - Delegate delegate_; +${moduleFunctions.join('\n\n')} };`; }; @@ -292,7 +368,7 @@ function createStructsString( return bridging::toJs(rt, value); }`, ) - .join('\n\n'); + .join('\n'); return ` #pragma mark - ${structName} @@ -476,19 +552,19 @@ function createEnums( .join('\n'); } -function translatePropertyToCpp( +function translateFunctionToCpp( hasteModuleName: string, prop: NativeModulePropertyShape, resolveAlias: AliasResolver, enumMap: NativeModuleEnumMap, - abstract: boolean = false, + args: Array, + returnTypeAnnotation: Nullable, ): string { const [propTypeAnnotation] = unwrapNullable(prop.typeAnnotation); - const params = propTypeAnnotation.params.map( - param => `std::move(${param.name})`, - ); + const isNullable = returnTypeAnnotation.type === 'NullableTypeAnnotation'; + const isVoid = returnTypeAnnotation.type === 'VoidTypeAnnotation'; const paramTypes = propTypeAnnotation.params.map(param => { const translatedParam = translatePrimitiveJSTypeToCpp( @@ -503,6 +579,7 @@ function translatePropertyToCpp( ); return `${translatedParam} ${param.name}`; }); + paramTypes.unshift('jsi::Runtime &rt'); const returnType = translatePrimitiveJSTypeToCpp( hasteModuleName, @@ -514,23 +591,17 @@ function translatePropertyToCpp( enumMap, ); - // The first param will always be the runtime reference. - paramTypes.unshift('jsi::Runtime &rt'); - - const method = `${returnType} ${prop.name}(${paramTypes.join(', ')})`; - - if (abstract) { - return `virtual ${method} = 0;`; + let methodCallArgs = [...args].join(',\n '); + if (methodCallArgs.length > 0) { + methodCallArgs = `,\n ${methodCallArgs}`; } - return `${method} override { - static_assert( + return ` static jsi::Value __${prop.name}JSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* ${args.length > 0 ? 'args' : '/*args*/'}, size_t ${args.length > 0 ? 'count' : '/*count*/'}) { + static_assert( bridging::getParameterCount(&T::${prop.name}) == ${paramTypes.length}, "Expected ${prop.name}(...) to have ${paramTypes.length} parameters"); - - return bridging::callFromJs<${returnType}>( - rt, &T::${prop.name}, jsInvoker_, ${['instance_', ...params].join(', ')}); -}`; + auto* self = static_cast(&turboModule); + ${!isVoid ? (!isNullable ? 'return ' : 'auto result = ') : ''}bridging::callFromJs<${returnType}>(rt, &T::${prop.name}, self->jsInvoker_, self${methodCallArgs});${!isVoid ? (!isNullable ? '' : 'return result ? jsi::Value(std::move(*result)) : jsi::Value::null();') : 'return jsi::Value::undefined();'}\n }`; } type EventEmitterCpp = { @@ -563,7 +634,7 @@ function translateEventEmitterToCpp( return { isVoidTypeAnnotation: isVoidTypeAnnotation, templateName: isVoidTypeAnnotation ? `/*${templateName}*/` : templateName, - registerEventEmitter: ` eventEmitterMap_["${ + registerEventEmitter: ` eventEmitterMap_["${ eventEmitter.name }"] = std::make_shared&>(*delegate_.eventEmitterMap_["${eventEmitter.name}"]).emit(${ + }>&>(*eventEmitterMap_["${eventEmitter.name}"]).emit(${ isVoidTypeAnnotation ? '' : `[jsInvoker = jsInvoker_, eventValue = value](jsi::Runtime& rt) -> jsi::Value { @@ -607,8 +678,14 @@ module.exports = { const nativeModules = getModules(schema); const modules = Object.keys(nativeModules).flatMap(hasteModuleName => { - const {aliasMap, enumMap, spec, moduleName} = - nativeModules[hasteModuleName]; + const nativeModule = nativeModules[hasteModuleName]; + const { + aliasMap, + enumMap, + spec: {methods}, + spec, + moduleName, + } = nativeModule; const resolveAlias = createAliasResolver(aliasMap); const structs = createStructsString( hasteModuleName, @@ -617,25 +694,12 @@ module.exports = { enumMap, ); const enums = createEnums(hasteModuleName, enumMap, resolveAlias); - return [ - ModuleClassDeclarationTemplate({ - hasteModuleName, - moduleProperties: spec.methods.map(prop => - translatePropertyToCpp( - hasteModuleName, - prop, - resolveAlias, - enumMap, - true, - ), - ), - structs, - enums, - }), ModuleSpecClassDeclarationTemplate({ hasteModuleName, moduleName, + structs, + enums, moduleEventEmitters: spec.eventEmitters.map(eventEmitter => translateEventEmitterToCpp( moduleName, @@ -644,13 +708,30 @@ module.exports = { enumMap, ), ), - moduleProperties: spec.methods.map(prop => - translatePropertyToCpp( + moduleFunctions: spec.methods.map(property => { + const [propertyTypeAnnotation] = + unwrapNullable( + property.typeAnnotation, + ); + return translateFunctionToCpp( hasteModuleName, - prop, + property, resolveAlias, enumMap, - ), + propertyTypeAnnotation.params.map((p, i) => + serializeArg(moduleName, p, i, resolveAlias, enumMap), + ), + propertyTypeAnnotation.returnTypeAnnotation, + ); + }), + methods: methods.map( + ({name: propertyName, typeAnnotation: nullableTypeAnnotation}) => { + const [{params}] = unwrapNullable(nullableTypeAnnotation); + return { + methodName: propertyName, + paramCount: params.length, + }; + }, ), }), ]; diff --git a/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleCpp-test.js b/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleCpp-test.js deleted file mode 100644 index a0ec9d477d6244..00000000000000 --- a/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleCpp-test.js +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow strict-local - * @format - */ - -'use strict'; - -const fixtures = require('../__test_fixtures__/fixtures.js'); -const generator = require('../GenerateModuleCpp.js'); - -describe('GenerateModuleCpp', () => { - Object.keys(fixtures) - .sort() - .forEach(fixtureName => { - const fixture = fixtures[fixtureName]; - - it(`can generate fixture ${fixtureName}`, () => { - expect( - generator.generate( - fixtureName, - fixture, - 'com.facebook.fbreact.specs', - ), - ).toMatchSnapshot(); - }); - }); -}); diff --git a/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleCpp-test.js.snap b/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleCpp-test.js.snap deleted file mode 100644 index ebdad85f6edfb4..00000000000000 --- a/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleCpp-test.js.snap +++ /dev/null @@ -1,782 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`GenerateModuleCpp can generate fixture SampleWithUppercaseName 1`] = ` -Map { - "SampleWithUppercaseNameJSI-generated.cpp" => "/** - * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). - * - * Do not edit this file as changes may cause incorrect behavior and will be lost - * once the code is regenerated. - * - * @generated by codegen project: GenerateModuleCpp.js - */ - -#include \\"SampleWithUppercaseNameJSI.h\\" - -namespace facebook::react { - - - -NativeSampleTurboModuleCxxSpecJSI::NativeSampleTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - -} - - -} // namespace facebook::react -", -} -`; - -exports[`GenerateModuleCpp can generate fixture complex_objects 1`] = ` -Map { - "complex_objectsJSI-generated.cpp" => "/** - * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). - * - * Do not edit this file as changes may cause incorrect behavior and will be lost - * once the code is regenerated. - * - * @generated by codegen project: GenerateModuleCpp.js - */ - -#include \\"complex_objectsJSI.h\\" - -namespace facebook::react { - -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_difficult(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->difficult( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_optionals(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->optionals( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_optionalMethod(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->optionalMethod( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt), - count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asObject(rt).asFunction(rt), - count <= 2 || args[2].isUndefined() ? std::nullopt : std::make_optional(args[2].asObject(rt).asArray(rt)) - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getArrays(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->getArrays( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getNullableObject(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getNullableObject( - rt - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getNullableGenericObject(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getNullableGenericObject( - rt - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getNullableArray(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getNullableArray( - rt - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} - -NativeSampleTurboModuleCxxSpecJSI::NativeSampleTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - methodMap_[\\"difficult\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_difficult}; - methodMap_[\\"optionals\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_optionals}; - methodMap_[\\"optionalMethod\\"] = MethodMetadata {3, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_optionalMethod}; - methodMap_[\\"getArrays\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getArrays}; - methodMap_[\\"getNullableObject\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getNullableObject}; - methodMap_[\\"getNullableGenericObject\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getNullableGenericObject}; - methodMap_[\\"getNullableArray\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getNullableArray}; -} - - -} // namespace facebook::react -", -} -`; - -exports[`GenerateModuleCpp can generate fixture cxx_only_native_modules 1`] = ` -Map { - "cxx_only_native_modulesJSI-generated.cpp" => "/** - * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). - * - * Do not edit this file as changes may cause incorrect behavior and will be lost - * once the code is regenerated. - * - * @generated by codegen project: GenerateModuleCpp.js - */ - -#include \\"cxx_only_native_modulesJSI.h\\" - -namespace facebook::react { - -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getArray(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getArray( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getBool(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getBool( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool() - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getConstants(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getConstants( - rt - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getCustomEnum(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getCustomEnum( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber() - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getCustomHostObject(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getCustomHostObject( - rt - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_consumeCustomHostObject(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->consumeCustomHostObject( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getBinaryTreeNode(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getBinaryTreeNode( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getGraphNode(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getGraphNode( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getNumEnum(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getNumEnum( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber() - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getStrEnum(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getStrEnum( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getMap(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getMap( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getNumber(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getNumber( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber() - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getObject(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getObject( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getSet(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getSet( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getString(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getString( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getUnion(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getUnion( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber(), - count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asString(rt), - count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asString(rt), - count <= 3 ? throw jsi::JSError(rt, \\"Expected argument in position 3 to be passed\\") : args[3].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getValue(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getValue( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber(), - count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asString(rt), - count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getValueWithCallback(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->getValueWithCallback( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asFunction(rt) - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getValueWithPromise(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getValueWithPromise( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool() - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getWithWithOptionalArgs(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - auto result = static_cast(&turboModule)->getWithWithOptionalArgs( - rt, - count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool()) - ); - return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_voidFunc(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->voidFunc( - rt - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_setMenu(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->setMenu( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_emitCustomDeviceEvent(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->emitCustomDeviceEvent( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt) - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_voidFuncThrows(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->voidFuncThrows( - rt - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getObjectThrows(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getObjectThrows( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_voidFuncAssert(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->voidFuncAssert( - rt - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getObjectAssert(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getObjectAssert( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} - -NativeSampleTurboModuleCxxSpecJSI::NativeSampleTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModuleCxx\\", jsInvoker) { - methodMap_[\\"getArray\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getArray}; - methodMap_[\\"getBool\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getBool}; - methodMap_[\\"getConstants\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getConstants}; - methodMap_[\\"getCustomEnum\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getCustomEnum}; - methodMap_[\\"getCustomHostObject\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getCustomHostObject}; - methodMap_[\\"consumeCustomHostObject\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_consumeCustomHostObject}; - methodMap_[\\"getBinaryTreeNode\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getBinaryTreeNode}; - methodMap_[\\"getGraphNode\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getGraphNode}; - methodMap_[\\"getNumEnum\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getNumEnum}; - methodMap_[\\"getStrEnum\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getStrEnum}; - methodMap_[\\"getMap\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getMap}; - methodMap_[\\"getNumber\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getNumber}; - methodMap_[\\"getObject\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getObject}; - methodMap_[\\"getSet\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getSet}; - methodMap_[\\"getString\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getString}; - methodMap_[\\"getUnion\\"] = MethodMetadata {4, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getUnion}; - methodMap_[\\"getValue\\"] = MethodMetadata {3, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getValue}; - methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getValueWithCallback}; - methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getValueWithPromise}; - methodMap_[\\"getWithWithOptionalArgs\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getWithWithOptionalArgs}; - methodMap_[\\"voidFunc\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_voidFunc}; - methodMap_[\\"setMenu\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_setMenu}; - methodMap_[\\"emitCustomDeviceEvent\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_emitCustomDeviceEvent}; - methodMap_[\\"voidFuncThrows\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_voidFuncThrows}; - methodMap_[\\"getObjectThrows\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getObjectThrows}; - methodMap_[\\"voidFuncAssert\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_voidFuncAssert}; - methodMap_[\\"getObjectAssert\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getObjectAssert}; -} - - -} // namespace facebook::react -", -} -`; - -exports[`GenerateModuleCpp can generate fixture empty_native_modules 1`] = ` -Map { - "empty_native_modulesJSI-generated.cpp" => "/** - * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). - * - * Do not edit this file as changes may cause incorrect behavior and will be lost - * once the code is regenerated. - * - * @generated by codegen project: GenerateModuleCpp.js - */ - -#include \\"empty_native_modulesJSI.h\\" - -namespace facebook::react { - - - -NativeSampleTurboModuleCxxSpecJSI::NativeSampleTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - -} - - -} // namespace facebook::react -", -} -`; - -exports[`GenerateModuleCpp can generate fixture event_emitter_module 1`] = ` -Map { - "event_emitter_moduleJSI-generated.cpp" => "/** - * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). - * - * Do not edit this file as changes may cause incorrect behavior and will be lost - * once the code is regenerated. - * - * @generated by codegen project: GenerateModuleCpp.js - */ - -#include \\"event_emitter_moduleJSI.h\\" - -namespace facebook::react { - -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_voidFunc(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->voidFunc( - rt - ); - return jsi::Value::undefined(); -} - -NativeSampleTurboModuleCxxSpecJSI::NativeSampleTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - methodMap_[\\"voidFunc\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_voidFunc}; -} - - -} // namespace facebook::react -", -} -`; - -exports[`GenerateModuleCpp can generate fixture native_modules_with_type_aliases 1`] = ` -Map { - "native_modules_with_type_aliasesJSI-generated.cpp" => "/** - * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). - * - * Do not edit this file as changes may cause incorrect behavior and will be lost - * once the code is regenerated. - * - * @generated by codegen project: GenerateModuleCpp.js - */ - -#include \\"native_modules_with_type_aliasesJSI.h\\" - -namespace facebook::react { - -static jsi::Value __hostFunction_AliasTurboModuleCxxSpecJSI_getConstants(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getConstants( - rt - ); -} -static jsi::Value __hostFunction_AliasTurboModuleCxxSpecJSI_cropImage(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->cropImage( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); - return jsi::Value::undefined(); -} - -AliasTurboModuleCxxSpecJSI::AliasTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"AliasTurboModule\\", jsInvoker) { - methodMap_[\\"getConstants\\"] = MethodMetadata {0, __hostFunction_AliasTurboModuleCxxSpecJSI_getConstants}; - methodMap_[\\"cropImage\\"] = MethodMetadata {1, __hostFunction_AliasTurboModuleCxxSpecJSI_cropImage}; -} - - -} // namespace facebook::react -", -} -`; - -exports[`GenerateModuleCpp can generate fixture real_module_example 1`] = ` -Map { - "real_module_exampleJSI-generated.cpp" => "/** - * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). - * - * Do not edit this file as changes may cause incorrect behavior and will be lost - * once the code is regenerated. - * - * @generated by codegen project: GenerateModuleCpp.js - */ - -#include \\"real_module_exampleJSI.h\\" - -namespace facebook::react { - -static jsi::Value __hostFunction_NativeCameraRollManagerCxxSpecJSI_getConstants(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getConstants( - rt - ); -} -static jsi::Value __hostFunction_NativeCameraRollManagerCxxSpecJSI_getPhotos(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getPhotos( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeCameraRollManagerCxxSpecJSI_saveToCameraRoll(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->saveToCameraRoll( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt), - count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asString(rt) - ); -} -static jsi::Value __hostFunction_NativeCameraRollManagerCxxSpecJSI_deletePhotos(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->deletePhotos( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} - -NativeCameraRollManagerCxxSpecJSI::NativeCameraRollManagerCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"CameraRollManager\\", jsInvoker) { - methodMap_[\\"getConstants\\"] = MethodMetadata {0, __hostFunction_NativeCameraRollManagerCxxSpecJSI_getConstants}; - methodMap_[\\"getPhotos\\"] = MethodMetadata {1, __hostFunction_NativeCameraRollManagerCxxSpecJSI_getPhotos}; - methodMap_[\\"saveToCameraRoll\\"] = MethodMetadata {2, __hostFunction_NativeCameraRollManagerCxxSpecJSI_saveToCameraRoll}; - methodMap_[\\"deletePhotos\\"] = MethodMetadata {1, __hostFunction_NativeCameraRollManagerCxxSpecJSI_deletePhotos}; -} -static jsi::Value __hostFunction_NativeExceptionsManagerCxxSpecJSI_reportFatalException(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->reportFatalException( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt), - count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asObject(rt).asArray(rt), - count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asNumber() - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeExceptionsManagerCxxSpecJSI_reportSoftException(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->reportSoftException( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt), - count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asObject(rt).asArray(rt), - count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asNumber() - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeExceptionsManagerCxxSpecJSI_reportException(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->reportException( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeExceptionsManagerCxxSpecJSI_updateExceptionMessage(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->updateExceptionMessage( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt), - count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asObject(rt).asArray(rt), - count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asNumber() - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeExceptionsManagerCxxSpecJSI_dismissRedbox(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->dismissRedbox( - rt - ); - return jsi::Value::undefined(); -} - -NativeExceptionsManagerCxxSpecJSI::NativeExceptionsManagerCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"ExceptionsManager\\", jsInvoker) { - methodMap_[\\"reportFatalException\\"] = MethodMetadata {3, __hostFunction_NativeExceptionsManagerCxxSpecJSI_reportFatalException}; - methodMap_[\\"reportSoftException\\"] = MethodMetadata {3, __hostFunction_NativeExceptionsManagerCxxSpecJSI_reportSoftException}; - methodMap_[\\"reportException\\"] = MethodMetadata {1, __hostFunction_NativeExceptionsManagerCxxSpecJSI_reportException}; - methodMap_[\\"updateExceptionMessage\\"] = MethodMetadata {3, __hostFunction_NativeExceptionsManagerCxxSpecJSI_updateExceptionMessage}; - methodMap_[\\"dismissRedbox\\"] = MethodMetadata {0, __hostFunction_NativeExceptionsManagerCxxSpecJSI_dismissRedbox}; -} - - -} // namespace facebook::react -", -} -`; - -exports[`GenerateModuleCpp can generate fixture simple_native_modules 1`] = ` -Map { - "simple_native_modulesJSI-generated.cpp" => "/** - * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). - * - * Do not edit this file as changes may cause incorrect behavior and will be lost - * once the code is regenerated. - * - * @generated by codegen project: GenerateModuleCpp.js - */ - -#include \\"simple_native_modulesJSI.h\\" - -namespace facebook::react { - -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getConstants(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getConstants( - rt - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_voidFunc(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->voidFunc( - rt - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getBool(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getBool( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool() - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getNumber(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getNumber( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber() - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getString(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getString( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getArray(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getArray( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getObject(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getObject( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getRootTag(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getRootTag( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber() - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getValue(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getValue( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber(), - count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asString(rt), - count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asObject(rt) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getEnumReturn(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getEnumReturn( - rt - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getValueWithCallback(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->getValueWithCallback( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asFunction(rt) - ); - return jsi::Value::undefined(); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getValueWithPromise(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getValueWithPromise( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool() - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getValueWithOptionalArg(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getValueWithOptionalArg( - rt, - count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt)) - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getEnums(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getEnums( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber(), - count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asNumber(), - count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asString(rt) - ); -} - -NativeSampleTurboModuleCxxSpecJSI::NativeSampleTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - methodMap_[\\"getConstants\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getConstants}; - methodMap_[\\"voidFunc\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_voidFunc}; - methodMap_[\\"getBool\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getBool}; - methodMap_[\\"getNumber\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getNumber}; - methodMap_[\\"getString\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getString}; - methodMap_[\\"getArray\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getArray}; - methodMap_[\\"getObject\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getObject}; - methodMap_[\\"getRootTag\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getRootTag}; - methodMap_[\\"getValue\\"] = MethodMetadata {3, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getValue}; - methodMap_[\\"getEnumReturn\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getEnumReturn}; - methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getValueWithCallback}; - methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getValueWithPromise}; - methodMap_[\\"getValueWithOptionalArg\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getValueWithOptionalArg}; - methodMap_[\\"getEnums\\"] = MethodMetadata {3, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getEnums}; -} - - -} // namespace facebook::react -", -} -`; - -exports[`GenerateModuleCpp can generate fixture string_literals 1`] = ` -Map { - "string_literalsJSI-generated.cpp" => "/** - * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). - * - * Do not edit this file as changes may cause incorrect behavior and will be lost - * once the code is regenerated. - * - * @generated by codegen project: GenerateModuleCpp.js - */ - -#include \\"string_literalsJSI.h\\" - -namespace facebook::react { - -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getStringLiteral(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getStringLiteral( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt) - ); -} - -NativeSampleTurboModuleCxxSpecJSI::NativeSampleTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - methodMap_[\\"getStringLiteral\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getStringLiteral}; -} - - -} // namespace facebook::react -", -} -`; - -exports[`GenerateModuleCpp can generate fixture two_modules_different_files 1`] = ` -Map { - "two_modules_different_filesJSI-generated.cpp" => "/** - * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). - * - * Do not edit this file as changes may cause incorrect behavior and will be lost - * once the code is regenerated. - * - * @generated by codegen project: GenerateModuleCpp.js - */ - -#include \\"two_modules_different_filesJSI.h\\" - -namespace facebook::react { - -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_voidFunc(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->voidFunc( - rt - ); - return jsi::Value::undefined(); -} - -NativeSampleTurboModuleCxxSpecJSI::NativeSampleTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - methodMap_[\\"voidFunc\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_voidFunc}; -} -static jsi::Value __hostFunction_NativeSampleTurboModule2CxxSpecJSI_getConstants(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getConstants( - rt - ); -} -static jsi::Value __hostFunction_NativeSampleTurboModule2CxxSpecJSI_voidFunc(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - static_cast(&turboModule)->voidFunc( - rt - ); - return jsi::Value::undefined(); -} - -NativeSampleTurboModule2CxxSpecJSI::NativeSampleTurboModule2CxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule2\\", jsInvoker) { - methodMap_[\\"getConstants\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModule2CxxSpecJSI_getConstants}; - methodMap_[\\"voidFunc\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModule2CxxSpecJSI_voidFunc}; -} - - -} // namespace facebook::react -", -} -`; - -exports[`GenerateModuleCpp can generate fixture union_module 1`] = ` -Map { - "union_moduleJSI-generated.cpp" => "/** - * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). - * - * Do not edit this file as changes may cause incorrect behavior and will be lost - * once the code is regenerated. - * - * @generated by codegen project: GenerateModuleCpp.js - */ - -#include \\"union_moduleJSI.h\\" - -namespace facebook::react { - -static jsi::Value __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getUnion(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getUnion( - rt, - count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber(), - count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asNumber(), - count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asObject(rt), - count <= 3 ? throw jsi::JSError(rt, \\"Expected argument in position 3 to be passed\\") : args[3].asString(rt), - count <= 4 ? throw jsi::JSError(rt, \\"Expected argument in position 4 to be passed\\") : args[4].asString(rt) - ); -} - -NativeSampleTurboModuleCxxSpecJSI::NativeSampleTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker) - : TurboModule(\\"SampleTurboModule\\", jsInvoker) { - methodMap_[\\"getUnion\\"] = MethodMetadata {5, __hostFunction_NativeSampleTurboModuleCxxSpecJSI_getUnion}; -} - - -} // namespace facebook::react -", -} -`; diff --git a/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleH-test.js.snap b/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleH-test.js.snap index 9807a21f5633b0..29afcd371a8cf2 100644 --- a/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleH-test.js.snap +++ b/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleH-test.js.snap @@ -19,50 +19,18 @@ Map { namespace facebook::react { - class JSI_EXPORT NativeSampleTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeSampleTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - - -}; - template class JSI_EXPORT NativeSampleTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; protected: - NativeSampleTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeSampleTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - + NativeSampleTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeSampleTurboModuleCxxSpec::kModuleName}, jsInvoker) { + } + private: - class Delegate : public NativeSampleTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeSampleTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - } - - - - private: - friend class NativeSampleTurboModuleCxxSpec; - T *instance_; - }; - - Delegate delegate_; }; } // namespace facebook::react @@ -89,111 +57,84 @@ Map { namespace facebook::react { - class JSI_EXPORT NativeSampleTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeSampleTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Object difficult(jsi::Runtime &rt, jsi::Object A) = 0; - virtual void optionals(jsi::Runtime &rt, jsi::Object A) = 0; - virtual void optionalMethod(jsi::Runtime &rt, jsi::Object options, jsi::Function callback, std::optional extras) = 0; - virtual void getArrays(jsi::Runtime &rt, jsi::Object options) = 0; - virtual std::optional getNullableObject(jsi::Runtime &rt) = 0; - virtual std::optional getNullableGenericObject(jsi::Runtime &rt) = 0; - virtual std::optional getNullableArray(jsi::Runtime &rt) = 0; - -}; - template class JSI_EXPORT NativeSampleTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; protected: - NativeSampleTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeSampleTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeSampleTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeSampleTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"difficult\\"] = MethodMetadata {.argCount = 1, .invoker = __difficultJSI}; + methodMap_[\\"optionals\\"] = MethodMetadata {.argCount = 1, .invoker = __optionalsJSI}; + methodMap_[\\"optionalMethod\\"] = MethodMetadata {.argCount = 3, .invoker = __optionalMethodJSI}; + methodMap_[\\"getArrays\\"] = MethodMetadata {.argCount = 1, .invoker = __getArraysJSI}; + methodMap_[\\"getNullableObject\\"] = MethodMetadata {.argCount = 0, .invoker = __getNullableObjectJSI}; + methodMap_[\\"getNullableGenericObject\\"] = MethodMetadata {.argCount = 0, .invoker = __getNullableGenericObjectJSI}; + methodMap_[\\"getNullableArray\\"] = MethodMetadata {.argCount = 0, .invoker = __getNullableArrayJSI}; + } + private: - class Delegate : public NativeSampleTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeSampleTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::Object difficult(jsi::Runtime &rt, jsi::Object A) override { - static_assert( - bridging::getParameterCount(&T::difficult) == 2, - \\"Expected difficult(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::difficult, jsInvoker_, instance_, std::move(A)); - } - void optionals(jsi::Runtime &rt, jsi::Object A) override { - static_assert( - bridging::getParameterCount(&T::optionals) == 2, - \\"Expected optionals(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::optionals, jsInvoker_, instance_, std::move(A)); - } - void optionalMethod(jsi::Runtime &rt, jsi::Object options, jsi::Function callback, std::optional extras) override { - static_assert( - bridging::getParameterCount(&T::optionalMethod) == 4, - \\"Expected optionalMethod(...) to have 4 parameters\\"); - - return bridging::callFromJs( - rt, &T::optionalMethod, jsInvoker_, instance_, std::move(options), std::move(callback), std::move(extras)); - } - void getArrays(jsi::Runtime &rt, jsi::Object options) override { - static_assert( - bridging::getParameterCount(&T::getArrays) == 2, - \\"Expected getArrays(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getArrays, jsInvoker_, instance_, std::move(options)); - } - std::optional getNullableObject(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getNullableObject) == 1, - \\"Expected getNullableObject(...) to have 1 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getNullableObject, jsInvoker_, instance_); - } - std::optional getNullableGenericObject(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getNullableGenericObject) == 1, - \\"Expected getNullableGenericObject(...) to have 1 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getNullableGenericObject, jsInvoker_, instance_); - } - std::optional getNullableArray(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getNullableArray) == 1, - \\"Expected getNullableArray(...) to have 1 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getNullableArray, jsInvoker_, instance_); - } - - private: - friend class NativeSampleTurboModuleCxxSpec; - T *instance_; - }; - - Delegate delegate_; + static jsi::Value __difficultJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::difficult) == 2, + \\"Expected difficult(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::difficult, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } + + static jsi::Value __optionalsJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::optionals) == 2, + \\"Expected optionals(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::optionals, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt));return jsi::Value::undefined(); + } + + static jsi::Value __optionalMethodJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::optionalMethod) == 4, + \\"Expected optionalMethod(...) to have 4 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::optionalMethod, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt), + count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asObject(rt).asFunction(rt), + count <= 2 || args[2].isUndefined() ? std::nullopt : std::make_optional(args[2].asObject(rt).asArray(rt)));return jsi::Value::undefined(); + } + + static jsi::Value __getArraysJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getArrays) == 2, + \\"Expected getArrays(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::getArrays, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt));return jsi::Value::undefined(); + } + + static jsi::Value __getNullableObjectJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getNullableObject) == 1, + \\"Expected getNullableObject(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getNullableObject, self->jsInvoker_, self);return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getNullableGenericObjectJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getNullableGenericObject) == 1, + \\"Expected getNullableGenericObject(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getNullableGenericObject, self->jsInvoker_, self);return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __getNullableArrayJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getNullableArray) == 1, + \\"Expected getNullableArray(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getNullableArray, self->jsInvoker_, self);return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } }; } // namespace facebook::react @@ -331,7 +272,6 @@ struct Bridging { } } }; - #pragma mark - NativeSampleTurboModuleConstantsStruct template @@ -363,11 +303,9 @@ struct NativeSampleTurboModuleConstantsStructBridging { static bool const1ToJs(jsi::Runtime &rt, decltype(types.const1) value) { return bridging::toJs(rt, value); } - static double const2ToJs(jsi::Runtime &rt, decltype(types.const2) value) { return bridging::toJs(rt, value); } - static jsi::String const3ToJs(jsi::Runtime &rt, decltype(types.const3) value) { return bridging::toJs(rt, value); } @@ -419,11 +357,9 @@ struct NativeSampleTurboModuleBinaryTreeNodeBridging { static jsi::Object leftToJs(jsi::Runtime &rt, decltype(types.left) value) { return bridging::toJs(rt, value); } - static double valueToJs(jsi::Runtime &rt, decltype(types.value) value) { return bridging::toJs(rt, value); } - static jsi::Object rightToJs(jsi::Runtime &rt, decltype(types.right) value) { return bridging::toJs(rt, value); } @@ -476,7 +412,6 @@ struct NativeSampleTurboModuleGraphNodeBridging { static jsi::String labelToJs(jsi::Runtime &rt, decltype(types.label) value) { return bridging::toJs(rt, value); } - static jsi::Array neighborsToJs(jsi::Runtime &rt, decltype(types.neighbors) value) { return bridging::toJs(rt, value); } @@ -528,11 +463,9 @@ struct NativeSampleTurboModuleObjectStructBridging { static double aToJs(jsi::Runtime &rt, decltype(types.a) value) { return bridging::toJs(rt, value); } - static jsi::String bToJs(jsi::Runtime &rt, decltype(types.b) value) { return bridging::toJs(rt, value); } - static std::optional cToJs(jsi::Runtime &rt, decltype(types.c) value) { return bridging::toJs(rt, value); } @@ -585,11 +518,9 @@ struct NativeSampleTurboModuleValueStructBridging { static double xToJs(jsi::Runtime &rt, decltype(types.x) value) { return bridging::toJs(rt, value); } - static jsi::String yToJs(jsi::Runtime &rt, decltype(types.y) value) { return bridging::toJs(rt, value); } - static jsi::Object zToJs(jsi::Runtime &rt, decltype(types.z) value) { return bridging::toJs(rt, value); } @@ -642,15 +573,12 @@ struct NativeSampleTurboModuleMenuItemBridging { static jsi::String labelToJs(jsi::Runtime &rt, decltype(types.label) value) { return bridging::toJs(rt, value); } - static jsi::Function onPressToJs(jsi::Runtime &rt, decltype(types.onPress) value) { return bridging::toJs(rt, value); } - static std::optional shortcutToJs(jsi::Runtime &rt, decltype(types.shortcut) value) { return bridging::toJs(rt, value); } - static jsi::Array itemsToJs(jsi::Runtime &rt, decltype(types.items) value) { return bridging::toJs(rt, value); } @@ -673,291 +601,286 @@ struct NativeSampleTurboModuleMenuItemBridging { } }; -class JSI_EXPORT NativeSampleTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeSampleTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Array getArray(jsi::Runtime &rt, jsi::Array arg) = 0; - virtual bool getBool(jsi::Runtime &rt, bool arg) = 0; - virtual jsi::Object getConstants(jsi::Runtime &rt) = 0; - virtual jsi::Value getCustomEnum(jsi::Runtime &rt, jsi::Value arg) = 0; - virtual jsi::Object getCustomHostObject(jsi::Runtime &rt) = 0; - virtual jsi::String consumeCustomHostObject(jsi::Runtime &rt, jsi::Object customHostObject) = 0; - virtual jsi::Object getBinaryTreeNode(jsi::Runtime &rt, jsi::Object arg) = 0; - virtual jsi::Object getGraphNode(jsi::Runtime &rt, jsi::Object arg) = 0; - virtual jsi::Value getNumEnum(jsi::Runtime &rt, jsi::Value arg) = 0; - virtual jsi::String getStrEnum(jsi::Runtime &rt, jsi::String arg) = 0; - virtual jsi::Object getMap(jsi::Runtime &rt, jsi::Object arg) = 0; - virtual double getNumber(jsi::Runtime &rt, double arg) = 0; - virtual jsi::Object getObject(jsi::Runtime &rt, jsi::Object arg) = 0; - virtual jsi::Array getSet(jsi::Runtime &rt, jsi::Array arg) = 0; - virtual jsi::String getString(jsi::Runtime &rt, jsi::String arg) = 0; - virtual jsi::String getUnion(jsi::Runtime &rt, double x, jsi::String y, jsi::String y-literal, jsi::Object z) = 0; - virtual jsi::Object getValue(jsi::Runtime &rt, double x, jsi::String y, jsi::Object z) = 0; - virtual void getValueWithCallback(jsi::Runtime &rt, jsi::Function callback) = 0; - virtual jsi::Value getValueWithPromise(jsi::Runtime &rt, bool error) = 0; - virtual std::optional getWithWithOptionalArgs(jsi::Runtime &rt, std::optional optionalArg) = 0; - virtual void voidFunc(jsi::Runtime &rt) = 0; - virtual void setMenu(jsi::Runtime &rt, jsi::Object menuItem) = 0; - virtual void emitCustomDeviceEvent(jsi::Runtime &rt, jsi::String eventName) = 0; - virtual void voidFuncThrows(jsi::Runtime &rt) = 0; - virtual jsi::Object getObjectThrows(jsi::Runtime &rt, jsi::Object arg) = 0; - virtual void voidFuncAssert(jsi::Runtime &rt) = 0; - virtual jsi::Object getObjectAssert(jsi::Runtime &rt, jsi::Object arg) = 0; - -}; template class JSI_EXPORT NativeSampleTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModuleCxx\\"; protected: - NativeSampleTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeSampleTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeSampleTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeSampleTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getArray\\"] = MethodMetadata {.argCount = 1, .invoker = __getArrayJSI}; + methodMap_[\\"getBool\\"] = MethodMetadata {.argCount = 1, .invoker = __getBoolJSI}; + methodMap_[\\"getConstants\\"] = MethodMetadata {.argCount = 0, .invoker = __getConstantsJSI}; + methodMap_[\\"getCustomEnum\\"] = MethodMetadata {.argCount = 1, .invoker = __getCustomEnumJSI}; + methodMap_[\\"getCustomHostObject\\"] = MethodMetadata {.argCount = 0, .invoker = __getCustomHostObjectJSI}; + methodMap_[\\"consumeCustomHostObject\\"] = MethodMetadata {.argCount = 1, .invoker = __consumeCustomHostObjectJSI}; + methodMap_[\\"getBinaryTreeNode\\"] = MethodMetadata {.argCount = 1, .invoker = __getBinaryTreeNodeJSI}; + methodMap_[\\"getGraphNode\\"] = MethodMetadata {.argCount = 1, .invoker = __getGraphNodeJSI}; + methodMap_[\\"getNumEnum\\"] = MethodMetadata {.argCount = 1, .invoker = __getNumEnumJSI}; + methodMap_[\\"getStrEnum\\"] = MethodMetadata {.argCount = 1, .invoker = __getStrEnumJSI}; + methodMap_[\\"getMap\\"] = MethodMetadata {.argCount = 1, .invoker = __getMapJSI}; + methodMap_[\\"getNumber\\"] = MethodMetadata {.argCount = 1, .invoker = __getNumberJSI}; + methodMap_[\\"getObject\\"] = MethodMetadata {.argCount = 1, .invoker = __getObjectJSI}; + methodMap_[\\"getSet\\"] = MethodMetadata {.argCount = 1, .invoker = __getSetJSI}; + methodMap_[\\"getString\\"] = MethodMetadata {.argCount = 1, .invoker = __getStringJSI}; + methodMap_[\\"getUnion\\"] = MethodMetadata {.argCount = 4, .invoker = __getUnionJSI}; + methodMap_[\\"getValue\\"] = MethodMetadata {.argCount = 3, .invoker = __getValueJSI}; + methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithCallbackJSI}; + methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithPromiseJSI}; + methodMap_[\\"getWithWithOptionalArgs\\"] = MethodMetadata {.argCount = 1, .invoker = __getWithWithOptionalArgsJSI}; + methodMap_[\\"voidFunc\\"] = MethodMetadata {.argCount = 0, .invoker = __voidFuncJSI}; + methodMap_[\\"setMenu\\"] = MethodMetadata {.argCount = 1, .invoker = __setMenuJSI}; + methodMap_[\\"emitCustomDeviceEvent\\"] = MethodMetadata {.argCount = 1, .invoker = __emitCustomDeviceEventJSI}; + methodMap_[\\"voidFuncThrows\\"] = MethodMetadata {.argCount = 0, .invoker = __voidFuncThrowsJSI}; + methodMap_[\\"getObjectThrows\\"] = MethodMetadata {.argCount = 1, .invoker = __getObjectThrowsJSI}; + methodMap_[\\"voidFuncAssert\\"] = MethodMetadata {.argCount = 0, .invoker = __voidFuncAssertJSI}; + methodMap_[\\"getObjectAssert\\"] = MethodMetadata {.argCount = 1, .invoker = __getObjectAssertJSI}; + } + private: - class Delegate : public NativeSampleTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeSampleTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::Array getArray(jsi::Runtime &rt, jsi::Array arg) override { - static_assert( - bridging::getParameterCount(&T::getArray) == 2, - \\"Expected getArray(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getArray, jsInvoker_, instance_, std::move(arg)); - } - bool getBool(jsi::Runtime &rt, bool arg) override { - static_assert( - bridging::getParameterCount(&T::getBool) == 2, - \\"Expected getBool(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getBool, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getConstants(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getConstants) == 1, - \\"Expected getConstants(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::getConstants, jsInvoker_, instance_); - } - jsi::Value getCustomEnum(jsi::Runtime &rt, jsi::Value arg) override { - static_assert( - bridging::getParameterCount(&T::getCustomEnum) == 2, - \\"Expected getCustomEnum(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getCustomEnum, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getCustomHostObject(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getCustomHostObject) == 1, - \\"Expected getCustomHostObject(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::getCustomHostObject, jsInvoker_, instance_); - } - jsi::String consumeCustomHostObject(jsi::Runtime &rt, jsi::Object customHostObject) override { - static_assert( - bridging::getParameterCount(&T::consumeCustomHostObject) == 2, - \\"Expected consumeCustomHostObject(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::consumeCustomHostObject, jsInvoker_, instance_, std::move(customHostObject)); - } - jsi::Object getBinaryTreeNode(jsi::Runtime &rt, jsi::Object arg) override { - static_assert( - bridging::getParameterCount(&T::getBinaryTreeNode) == 2, - \\"Expected getBinaryTreeNode(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getBinaryTreeNode, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getGraphNode(jsi::Runtime &rt, jsi::Object arg) override { - static_assert( - bridging::getParameterCount(&T::getGraphNode) == 2, - \\"Expected getGraphNode(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getGraphNode, jsInvoker_, instance_, std::move(arg)); - } - jsi::Value getNumEnum(jsi::Runtime &rt, jsi::Value arg) override { - static_assert( - bridging::getParameterCount(&T::getNumEnum) == 2, - \\"Expected getNumEnum(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getNumEnum, jsInvoker_, instance_, std::move(arg)); - } - jsi::String getStrEnum(jsi::Runtime &rt, jsi::String arg) override { - static_assert( - bridging::getParameterCount(&T::getStrEnum) == 2, - \\"Expected getStrEnum(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getStrEnum, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getMap(jsi::Runtime &rt, jsi::Object arg) override { - static_assert( - bridging::getParameterCount(&T::getMap) == 2, - \\"Expected getMap(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getMap, jsInvoker_, instance_, std::move(arg)); - } - double getNumber(jsi::Runtime &rt, double arg) override { - static_assert( - bridging::getParameterCount(&T::getNumber) == 2, - \\"Expected getNumber(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getNumber, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getObject(jsi::Runtime &rt, jsi::Object arg) override { - static_assert( - bridging::getParameterCount(&T::getObject) == 2, - \\"Expected getObject(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getObject, jsInvoker_, instance_, std::move(arg)); - } - jsi::Array getSet(jsi::Runtime &rt, jsi::Array arg) override { - static_assert( - bridging::getParameterCount(&T::getSet) == 2, - \\"Expected getSet(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getSet, jsInvoker_, instance_, std::move(arg)); - } - jsi::String getString(jsi::Runtime &rt, jsi::String arg) override { - static_assert( - bridging::getParameterCount(&T::getString) == 2, - \\"Expected getString(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getString, jsInvoker_, instance_, std::move(arg)); - } - jsi::String getUnion(jsi::Runtime &rt, double x, jsi::String y, jsi::String y-literal, jsi::Object z) override { - static_assert( - bridging::getParameterCount(&T::getUnion) == 5, - \\"Expected getUnion(...) to have 5 parameters\\"); - - return bridging::callFromJs( - rt, &T::getUnion, jsInvoker_, instance_, std::move(x), std::move(y), std::move(y-literal), std::move(z)); - } - jsi::Object getValue(jsi::Runtime &rt, double x, jsi::String y, jsi::Object z) override { - static_assert( - bridging::getParameterCount(&T::getValue) == 4, - \\"Expected getValue(...) to have 4 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValue, jsInvoker_, instance_, std::move(x), std::move(y), std::move(z)); - } - void getValueWithCallback(jsi::Runtime &rt, jsi::Function callback) override { - static_assert( - bridging::getParameterCount(&T::getValueWithCallback) == 2, - \\"Expected getValueWithCallback(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithCallback, jsInvoker_, instance_, std::move(callback)); - } - jsi::Value getValueWithPromise(jsi::Runtime &rt, bool error) override { - static_assert( - bridging::getParameterCount(&T::getValueWithPromise) == 2, - \\"Expected getValueWithPromise(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithPromise, jsInvoker_, instance_, std::move(error)); - } - std::optional getWithWithOptionalArgs(jsi::Runtime &rt, std::optional optionalArg) override { - static_assert( - bridging::getParameterCount(&T::getWithWithOptionalArgs) == 2, - \\"Expected getWithWithOptionalArgs(...) to have 2 parameters\\"); - - return bridging::callFromJs>( - rt, &T::getWithWithOptionalArgs, jsInvoker_, instance_, std::move(optionalArg)); - } - void voidFunc(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::voidFunc) == 1, - \\"Expected voidFunc(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::voidFunc, jsInvoker_, instance_); - } - void setMenu(jsi::Runtime &rt, jsi::Object menuItem) override { - static_assert( - bridging::getParameterCount(&T::setMenu) == 2, - \\"Expected setMenu(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::setMenu, jsInvoker_, instance_, std::move(menuItem)); - } - void emitCustomDeviceEvent(jsi::Runtime &rt, jsi::String eventName) override { - static_assert( - bridging::getParameterCount(&T::emitCustomDeviceEvent) == 2, - \\"Expected emitCustomDeviceEvent(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::emitCustomDeviceEvent, jsInvoker_, instance_, std::move(eventName)); - } - void voidFuncThrows(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::voidFuncThrows) == 1, - \\"Expected voidFuncThrows(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::voidFuncThrows, jsInvoker_, instance_); - } - jsi::Object getObjectThrows(jsi::Runtime &rt, jsi::Object arg) override { - static_assert( - bridging::getParameterCount(&T::getObjectThrows) == 2, - \\"Expected getObjectThrows(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getObjectThrows, jsInvoker_, instance_, std::move(arg)); - } - void voidFuncAssert(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::voidFuncAssert) == 1, - \\"Expected voidFuncAssert(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::voidFuncAssert, jsInvoker_, instance_); - } - jsi::Object getObjectAssert(jsi::Runtime &rt, jsi::Object arg) override { - static_assert( - bridging::getParameterCount(&T::getObjectAssert) == 2, - \\"Expected getObjectAssert(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getObjectAssert, jsInvoker_, instance_, std::move(arg)); - } - - private: - friend class NativeSampleTurboModuleCxxSpec; - T *instance_; - }; - - Delegate delegate_; + static jsi::Value __getArrayJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getArray) == 2, + \\"Expected getArray(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getArray, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); + } + + static jsi::Value __getBoolJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getBool) == 2, + \\"Expected getBool(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getBool, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool()); + } + + static jsi::Value __getConstantsJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getConstants) == 1, + \\"Expected getConstants(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getConstants, self->jsInvoker_, self); + } + + static jsi::Value __getCustomEnumJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getCustomEnum) == 2, + \\"Expected getCustomEnum(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getCustomEnum, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber()); + } + + static jsi::Value __getCustomHostObjectJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getCustomHostObject) == 1, + \\"Expected getCustomHostObject(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getCustomHostObject, self->jsInvoker_, self); + } + + static jsi::Value __consumeCustomHostObjectJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::consumeCustomHostObject) == 2, + \\"Expected consumeCustomHostObject(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::consumeCustomHostObject, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } + + static jsi::Value __getBinaryTreeNodeJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getBinaryTreeNode) == 2, + \\"Expected getBinaryTreeNode(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getBinaryTreeNode, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } + + static jsi::Value __getGraphNodeJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getGraphNode) == 2, + \\"Expected getGraphNode(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getGraphNode, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } + + static jsi::Value __getNumEnumJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getNumEnum) == 2, + \\"Expected getNumEnum(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getNumEnum, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber()); + } + + static jsi::Value __getStrEnumJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getStrEnum) == 2, + \\"Expected getStrEnum(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getStrEnum, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt)); + } + + static jsi::Value __getMapJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getMap) == 2, + \\"Expected getMap(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getMap, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } + + static jsi::Value __getNumberJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getNumber) == 2, + \\"Expected getNumber(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getNumber, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber()); + } + + static jsi::Value __getObjectJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getObject) == 2, + \\"Expected getObject(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getObject, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } + + static jsi::Value __getSetJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getSet) == 2, + \\"Expected getSet(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getSet, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); + } + + static jsi::Value __getStringJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getString) == 2, + \\"Expected getString(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getString, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt)); + } + + static jsi::Value __getUnionJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getUnion) == 5, + \\"Expected getUnion(...) to have 5 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getUnion, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber(), + count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asString(rt), + count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asString(rt), + count <= 3 ? throw jsi::JSError(rt, \\"Expected argument in position 3 to be passed\\") : args[3].asObject(rt)); + } + + static jsi::Value __getValueJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValue) == 4, + \\"Expected getValue(...) to have 4 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getValue, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber(), + count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asString(rt), + count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asObject(rt)); + } + + static jsi::Value __getValueWithCallbackJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithCallback) == 2, + \\"Expected getValueWithCallback(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::getValueWithCallback, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asFunction(rt));return jsi::Value::undefined(); + } + + static jsi::Value __getValueWithPromiseJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithPromise) == 2, + \\"Expected getValueWithPromise(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getValueWithPromise, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool()); + } + + static jsi::Value __getWithWithOptionalArgsJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getWithWithOptionalArgs) == 2, + \\"Expected getWithWithOptionalArgs(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + auto result = bridging::callFromJs>(rt, &T::getWithWithOptionalArgs, self->jsInvoker_, self, + count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asBool()));return result ? jsi::Value(std::move(*result)) : jsi::Value::null(); + } + + static jsi::Value __voidFuncJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::voidFunc) == 1, + \\"Expected voidFunc(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::voidFunc, self->jsInvoker_, self);return jsi::Value::undefined(); + } + + static jsi::Value __setMenuJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::setMenu) == 2, + \\"Expected setMenu(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::setMenu, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt));return jsi::Value::undefined(); + } + + static jsi::Value __emitCustomDeviceEventJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::emitCustomDeviceEvent) == 2, + \\"Expected emitCustomDeviceEvent(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::emitCustomDeviceEvent, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt));return jsi::Value::undefined(); + } + + static jsi::Value __voidFuncThrowsJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::voidFuncThrows) == 1, + \\"Expected voidFuncThrows(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::voidFuncThrows, self->jsInvoker_, self);return jsi::Value::undefined(); + } + + static jsi::Value __getObjectThrowsJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getObjectThrows) == 2, + \\"Expected getObjectThrows(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getObjectThrows, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } + + static jsi::Value __voidFuncAssertJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::voidFuncAssert) == 1, + \\"Expected voidFuncAssert(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::voidFuncAssert, self->jsInvoker_, self);return jsi::Value::undefined(); + } + + static jsi::Value __getObjectAssertJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getObjectAssert) == 2, + \\"Expected getObjectAssert(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getObjectAssert, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } }; } // namespace facebook::react @@ -984,50 +907,18 @@ Map { namespace facebook::react { - class JSI_EXPORT NativeSampleTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeSampleTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - - -}; - template class JSI_EXPORT NativeSampleTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; protected: - NativeSampleTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeSampleTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - + NativeSampleTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeSampleTurboModuleCxxSpec::kModuleName}, jsInvoker) { + } + private: - class Delegate : public NativeSampleTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeSampleTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - - private: - friend class NativeSampleTurboModuleCxxSpec; - T *instance_; - }; - - Delegate delegate_; }; } // namespace facebook::react @@ -1054,7 +945,6 @@ Map { namespace facebook::react { - #pragma mark - NativeSampleTurboModuleObjectStruct template @@ -1086,11 +976,9 @@ struct NativeSampleTurboModuleObjectStructBridging { static double aToJs(jsi::Runtime &rt, decltype(types.a) value) { return bridging::toJs(rt, value); } - static jsi::String bToJs(jsi::Runtime &rt, decltype(types.b) value) { return bridging::toJs(rt, value); } - static std::optional cToJs(jsi::Runtime &rt, decltype(types.c) value) { return bridging::toJs(rt, value); } @@ -1110,100 +998,69 @@ struct NativeSampleTurboModuleObjectStructBridging { } }; -class JSI_EXPORT NativeSampleTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeSampleTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual void voidFunc(jsi::Runtime &rt) = 0; - -}; template class JSI_EXPORT NativeSampleTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; protected: - NativeSampleTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeSampleTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - + NativeSampleTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeSampleTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"voidFunc\\"] = MethodMetadata {.argCount = 0, .invoker = __voidFuncJSI}; + eventEmitterMap_[\\"onEvent1\\"] = std::make_shared>(); + eventEmitterMap_[\\"onEvent2\\"] = std::make_shared>(); + eventEmitterMap_[\\"onEvent3\\"] = std::make_shared>(); + eventEmitterMap_[\\"onEvent4\\"] = std::make_shared>(); + eventEmitterMap_[\\"onEvent5\\"] = std::make_shared>(); + eventEmitterMap_[\\"onEvent6\\"] = std::make_shared>(); + } + void emitOnEvent1() { - static_cast&>(*delegate_.eventEmitterMap_[\\"onEvent1\\"]).emit(); + static_cast&>(*eventEmitterMap_[\\"onEvent1\\"]).emit(); } template void emitOnEvent2(OnEvent2Type value) { static_assert(bridging::supportsFromJs, \\"value cannnot be converted to jsi::String\\"); - static_cast&>(*delegate_.eventEmitterMap_[\\"onEvent2\\"]).emit([jsInvoker = jsInvoker_, eventValue = value](jsi::Runtime& rt) -> jsi::Value { + static_cast&>(*eventEmitterMap_[\\"onEvent2\\"]).emit([jsInvoker = jsInvoker_, eventValue = value](jsi::Runtime& rt) -> jsi::Value { return bridging::toJs(rt, eventValue, jsInvoker); }); } template void emitOnEvent3(OnEvent3Type value) { static_assert(bridging::supportsFromJs, \\"value cannnot be converted to double\\"); - static_cast&>(*delegate_.eventEmitterMap_[\\"onEvent3\\"]).emit([jsInvoker = jsInvoker_, eventValue = value](jsi::Runtime& rt) -> jsi::Value { + static_cast&>(*eventEmitterMap_[\\"onEvent3\\"]).emit([jsInvoker = jsInvoker_, eventValue = value](jsi::Runtime& rt) -> jsi::Value { return bridging::toJs(rt, eventValue, jsInvoker); }); } template void emitOnEvent4(OnEvent4Type value) { static_assert(bridging::supportsFromJs, \\"value cannnot be converted to bool\\"); - static_cast&>(*delegate_.eventEmitterMap_[\\"onEvent4\\"]).emit([jsInvoker = jsInvoker_, eventValue = value](jsi::Runtime& rt) -> jsi::Value { + static_cast&>(*eventEmitterMap_[\\"onEvent4\\"]).emit([jsInvoker = jsInvoker_, eventValue = value](jsi::Runtime& rt) -> jsi::Value { return bridging::toJs(rt, eventValue, jsInvoker); }); } template void emitOnEvent5(OnEvent5Type value) { static_assert(bridging::supportsFromJs, \\"value cannnot be converted to jsi::Object\\"); - static_cast&>(*delegate_.eventEmitterMap_[\\"onEvent5\\"]).emit([jsInvoker = jsInvoker_, eventValue = value](jsi::Runtime& rt) -> jsi::Value { + static_cast&>(*eventEmitterMap_[\\"onEvent5\\"]).emit([jsInvoker = jsInvoker_, eventValue = value](jsi::Runtime& rt) -> jsi::Value { return bridging::toJs(rt, eventValue, jsInvoker); }); } template void emitOnEvent6(std::vector value) { static_assert(bridging::supportsFromJs, jsi::Array>, \\"value cannnot be converted to jsi::Array\\"); - static_cast&>(*delegate_.eventEmitterMap_[\\"onEvent6\\"]).emit([jsInvoker = jsInvoker_, eventValue = value](jsi::Runtime& rt) -> jsi::Value { + static_cast&>(*eventEmitterMap_[\\"onEvent6\\"]).emit([jsInvoker = jsInvoker_, eventValue = value](jsi::Runtime& rt) -> jsi::Value { return bridging::toJs(rt, eventValue, jsInvoker); }); } - private: - class Delegate : public NativeSampleTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeSampleTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - eventEmitterMap_[\\"onEvent1\\"] = std::make_shared>(); - eventEmitterMap_[\\"onEvent2\\"] = std::make_shared>(); - eventEmitterMap_[\\"onEvent3\\"] = std::make_shared>(); - eventEmitterMap_[\\"onEvent4\\"] = std::make_shared>(); - eventEmitterMap_[\\"onEvent5\\"] = std::make_shared>(); - eventEmitterMap_[\\"onEvent6\\"] = std::make_shared>(); - } - - void voidFunc(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::voidFunc) == 1, - \\"Expected voidFunc(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::voidFunc, jsInvoker_, instance_); - } - - private: - friend class NativeSampleTurboModuleCxxSpec; - T *instance_; - }; - - Delegate delegate_; + static jsi::Value __voidFuncJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::voidFunc) == 1, + \\"Expected voidFunc(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::voidFunc, self->jsInvoker_, self);return jsi::Value::undefined(); + } }; } // namespace facebook::react @@ -1230,7 +1087,6 @@ Map { namespace facebook::react { - #pragma mark - AliasTurboModuleOptions template @@ -1266,19 +1122,15 @@ struct AliasTurboModuleOptionsBridging { static jsi::Object offsetToJs(jsi::Runtime &rt, decltype(types.offset) value) { return bridging::toJs(rt, value); } - static jsi::Object sizeToJs(jsi::Runtime &rt, decltype(types.size) value) { return bridging::toJs(rt, value); } - static jsi::Object displaySizeToJs(jsi::Runtime &rt, decltype(types.displaySize) value) { return bridging::toJs(rt, value); } - static jsi::String resizeModeToJs(jsi::Runtime &rt, decltype(types.resizeMode) value) { return bridging::toJs(rt, value); } - static bool allowExternalStorageToJs(jsi::Runtime &rt, decltype(types.allowExternalStorage) value) { return bridging::toJs(rt, value); } @@ -1304,66 +1156,35 @@ struct AliasTurboModuleOptionsBridging { } }; -class JSI_EXPORT AliasTurboModuleCxxSpecJSI : public TurboModule { -protected: - AliasTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Object getConstants(jsi::Runtime &rt) = 0; - virtual void cropImage(jsi::Runtime &rt, jsi::Object cropData) = 0; - -}; template class JSI_EXPORT AliasTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"AliasTurboModule\\"; protected: - AliasTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{AliasTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + AliasTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{AliasTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getConstants\\"] = MethodMetadata {.argCount = 0, .invoker = __getConstantsJSI}; + methodMap_[\\"cropImage\\"] = MethodMetadata {.argCount = 1, .invoker = __cropImageJSI}; + } + private: - class Delegate : public AliasTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - AliasTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::Object getConstants(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getConstants) == 1, - \\"Expected getConstants(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::getConstants, jsInvoker_, instance_); - } - void cropImage(jsi::Runtime &rt, jsi::Object cropData) override { - static_assert( - bridging::getParameterCount(&T::cropImage) == 2, - \\"Expected cropImage(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::cropImage, jsInvoker_, instance_, std::move(cropData)); - } - - private: - friend class AliasTurboModuleCxxSpec; - T *instance_; - }; - - Delegate delegate_; + static jsi::Value __getConstantsJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getConstants) == 1, + \\"Expected getConstants(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getConstants, self->jsInvoker_, self); + } + + static jsi::Value __cropImageJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::cropImage) == 2, + \\"Expected cropImage(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::cropImage, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt));return jsi::Value::undefined(); + } }; } // namespace facebook::react @@ -1390,7 +1211,6 @@ Map { namespace facebook::react { - #pragma mark - NativeCameraRollManagerPhotoIdentifierImage template @@ -1428,23 +1248,18 @@ struct NativeCameraRollManagerPhotoIdentifierImageBridging { static jsi::String uriToJs(jsi::Runtime &rt, decltype(types.uri) value) { return bridging::toJs(rt, value); } - static double playableDurationToJs(jsi::Runtime &rt, decltype(types.playableDuration) value) { return bridging::toJs(rt, value); } - static double widthToJs(jsi::Runtime &rt, decltype(types.width) value) { return bridging::toJs(rt, value); } - static double heightToJs(jsi::Runtime &rt, decltype(types.height) value) { return bridging::toJs(rt, value); } - static bool isStoredToJs(jsi::Runtime &rt, decltype(types.isStored) value) { return bridging::toJs(rt, value); } - static jsi::String filenameToJs(jsi::Runtime &rt, decltype(types.filename) value) { return bridging::toJs(rt, value); } @@ -1539,7 +1354,6 @@ struct NativeCameraRollManagerPhotoIdentifiersPageBridging { static jsi::Array edgesToJs(jsi::Runtime &rt, decltype(types.edges) value) { return bridging::toJs(rt, value); } - static jsi::Object page_infoToJs(jsi::Runtime &rt, decltype(types.page_info) value) { return bridging::toJs(rt, value); } @@ -1597,27 +1411,21 @@ struct NativeCameraRollManagerGetPhotosParamsBridging { static double firstToJs(jsi::Runtime &rt, decltype(types.first) value) { return bridging::toJs(rt, value); } - static jsi::String afterToJs(jsi::Runtime &rt, decltype(types.after) value) { return bridging::toJs(rt, value); } - static jsi::String groupNameToJs(jsi::Runtime &rt, decltype(types.groupName) value) { return bridging::toJs(rt, value); } - static jsi::String groupTypesToJs(jsi::Runtime &rt, decltype(types.groupTypes) value) { return bridging::toJs(rt, value); } - static jsi::String assetTypeToJs(jsi::Runtime &rt, decltype(types.assetType) value) { return bridging::toJs(rt, value); } - static double maxSizeToJs(jsi::Runtime &rt, decltype(types.maxSize) value) { return bridging::toJs(rt, value); } - static jsi::Array mimeTypesToJs(jsi::Runtime &rt, decltype(types.mimeTypes) value) { return bridging::toJs(rt, value); } @@ -1651,88 +1459,59 @@ struct NativeCameraRollManagerGetPhotosParamsBridging { } }; -class JSI_EXPORT NativeCameraRollManagerCxxSpecJSI : public TurboModule { -protected: - NativeCameraRollManagerCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Object getConstants(jsi::Runtime &rt) = 0; - virtual jsi::Value getPhotos(jsi::Runtime &rt, jsi::Object params) = 0; - virtual jsi::Value saveToCameraRoll(jsi::Runtime &rt, jsi::String uri, jsi::String type) = 0; - virtual jsi::Value deletePhotos(jsi::Runtime &rt, jsi::Array assets) = 0; - -}; template class JSI_EXPORT NativeCameraRollManagerCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"CameraRollManager\\"; protected: - NativeCameraRollManagerCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeCameraRollManagerCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeCameraRollManagerCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeCameraRollManagerCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getConstants\\"] = MethodMetadata {.argCount = 0, .invoker = __getConstantsJSI}; + methodMap_[\\"getPhotos\\"] = MethodMetadata {.argCount = 1, .invoker = __getPhotosJSI}; + methodMap_[\\"saveToCameraRoll\\"] = MethodMetadata {.argCount = 2, .invoker = __saveToCameraRollJSI}; + methodMap_[\\"deletePhotos\\"] = MethodMetadata {.argCount = 1, .invoker = __deletePhotosJSI}; + } + private: - class Delegate : public NativeCameraRollManagerCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeCameraRollManagerCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::Object getConstants(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getConstants) == 1, - \\"Expected getConstants(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::getConstants, jsInvoker_, instance_); - } - jsi::Value getPhotos(jsi::Runtime &rt, jsi::Object params) override { - static_assert( - bridging::getParameterCount(&T::getPhotos) == 2, - \\"Expected getPhotos(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getPhotos, jsInvoker_, instance_, std::move(params)); - } - jsi::Value saveToCameraRoll(jsi::Runtime &rt, jsi::String uri, jsi::String type) override { - static_assert( - bridging::getParameterCount(&T::saveToCameraRoll) == 3, - \\"Expected saveToCameraRoll(...) to have 3 parameters\\"); - - return bridging::callFromJs( - rt, &T::saveToCameraRoll, jsInvoker_, instance_, std::move(uri), std::move(type)); - } - jsi::Value deletePhotos(jsi::Runtime &rt, jsi::Array assets) override { - static_assert( - bridging::getParameterCount(&T::deletePhotos) == 2, - \\"Expected deletePhotos(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::deletePhotos, jsInvoker_, instance_, std::move(assets)); - } - - private: - friend class NativeCameraRollManagerCxxSpec; - T *instance_; - }; - - Delegate delegate_; + static jsi::Value __getConstantsJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getConstants) == 1, + \\"Expected getConstants(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getConstants, self->jsInvoker_, self); + } + + static jsi::Value __getPhotosJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getPhotos) == 2, + \\"Expected getPhotos(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getPhotos, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } + + static jsi::Value __saveToCameraRollJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::saveToCameraRoll) == 3, + \\"Expected saveToCameraRoll(...) to have 3 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::saveToCameraRoll, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt), + count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asString(rt)); + } + + static jsi::Value __deletePhotosJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::deletePhotos) == 2, + \\"Expected deletePhotos(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::deletePhotos, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); + } }; - #pragma mark - NativeExceptionsManagerStackFrame template @@ -1768,19 +1547,15 @@ struct NativeExceptionsManagerStackFrameBridging { static double columnToJs(jsi::Runtime &rt, decltype(types.column) value) { return bridging::toJs(rt, value); } - static jsi::String fileToJs(jsi::Runtime &rt, decltype(types.file) value) { return bridging::toJs(rt, value); } - static double lineNumberToJs(jsi::Runtime &rt, decltype(types.lineNumber) value) { return bridging::toJs(rt, value); } - static jsi::String methodNameToJs(jsi::Runtime &rt, decltype(types.methodName) value) { return bridging::toJs(rt, value); } - static bool collapseToJs(jsi::Runtime &rt, decltype(types.collapse) value) { return bridging::toJs(rt, value); } @@ -1849,31 +1624,24 @@ struct NativeExceptionsManagerExceptionDataBridging { static jsi::String messageToJs(jsi::Runtime &rt, decltype(types.message) value) { return bridging::toJs(rt, value); } - static jsi::String originalMessageToJs(jsi::Runtime &rt, decltype(types.originalMessage) value) { return bridging::toJs(rt, value); } - static jsi::String nameToJs(jsi::Runtime &rt, decltype(types.name) value) { return bridging::toJs(rt, value); } - static jsi::String componentStackToJs(jsi::Runtime &rt, decltype(types.componentStack) value) { return bridging::toJs(rt, value); } - static jsi::Array stackToJs(jsi::Runtime &rt, decltype(types.stack) value) { return bridging::toJs(rt, value); } - static double idToJs(jsi::Runtime &rt, decltype(types.id) value) { return bridging::toJs(rt, value); } - static bool isFatalToJs(jsi::Runtime &rt, decltype(types.isFatal) value) { return bridging::toJs(rt, value); } - static jsi::Object extraDataToJs(jsi::Runtime &rt, decltype(types.extraData) value) { return bridging::toJs(rt, value); } @@ -1898,93 +1666,71 @@ struct NativeExceptionsManagerExceptionDataBridging { } }; -class JSI_EXPORT NativeExceptionsManagerCxxSpecJSI : public TurboModule { -protected: - NativeExceptionsManagerCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual void reportFatalException(jsi::Runtime &rt, jsi::String message, jsi::Array stack, double exceptionId) = 0; - virtual void reportSoftException(jsi::Runtime &rt, jsi::String message, jsi::Array stack, double exceptionId) = 0; - virtual void reportException(jsi::Runtime &rt, jsi::Object data) = 0; - virtual void updateExceptionMessage(jsi::Runtime &rt, jsi::String message, jsi::Array stack, double exceptionId) = 0; - virtual void dismissRedbox(jsi::Runtime &rt) = 0; - -}; template class JSI_EXPORT NativeExceptionsManagerCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"ExceptionsManager\\"; protected: - NativeExceptionsManagerCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeExceptionsManagerCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeExceptionsManagerCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeExceptionsManagerCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"reportFatalException\\"] = MethodMetadata {.argCount = 3, .invoker = __reportFatalExceptionJSI}; + methodMap_[\\"reportSoftException\\"] = MethodMetadata {.argCount = 3, .invoker = __reportSoftExceptionJSI}; + methodMap_[\\"reportException\\"] = MethodMetadata {.argCount = 1, .invoker = __reportExceptionJSI}; + methodMap_[\\"updateExceptionMessage\\"] = MethodMetadata {.argCount = 3, .invoker = __updateExceptionMessageJSI}; + methodMap_[\\"dismissRedbox\\"] = MethodMetadata {.argCount = 0, .invoker = __dismissRedboxJSI}; + } + private: - class Delegate : public NativeExceptionsManagerCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeExceptionsManagerCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - void reportFatalException(jsi::Runtime &rt, jsi::String message, jsi::Array stack, double exceptionId) override { - static_assert( - bridging::getParameterCount(&T::reportFatalException) == 4, - \\"Expected reportFatalException(...) to have 4 parameters\\"); - - return bridging::callFromJs( - rt, &T::reportFatalException, jsInvoker_, instance_, std::move(message), std::move(stack), std::move(exceptionId)); - } - void reportSoftException(jsi::Runtime &rt, jsi::String message, jsi::Array stack, double exceptionId) override { - static_assert( - bridging::getParameterCount(&T::reportSoftException) == 4, - \\"Expected reportSoftException(...) to have 4 parameters\\"); - - return bridging::callFromJs( - rt, &T::reportSoftException, jsInvoker_, instance_, std::move(message), std::move(stack), std::move(exceptionId)); - } - void reportException(jsi::Runtime &rt, jsi::Object data) override { - static_assert( - bridging::getParameterCount(&T::reportException) == 2, - \\"Expected reportException(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::reportException, jsInvoker_, instance_, std::move(data)); - } - void updateExceptionMessage(jsi::Runtime &rt, jsi::String message, jsi::Array stack, double exceptionId) override { - static_assert( - bridging::getParameterCount(&T::updateExceptionMessage) == 4, - \\"Expected updateExceptionMessage(...) to have 4 parameters\\"); - - return bridging::callFromJs( - rt, &T::updateExceptionMessage, jsInvoker_, instance_, std::move(message), std::move(stack), std::move(exceptionId)); - } - void dismissRedbox(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::dismissRedbox) == 1, - \\"Expected dismissRedbox(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::dismissRedbox, jsInvoker_, instance_); - } - - private: - friend class NativeExceptionsManagerCxxSpec; - T *instance_; - }; - - Delegate delegate_; + static jsi::Value __reportFatalExceptionJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::reportFatalException) == 4, + \\"Expected reportFatalException(...) to have 4 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::reportFatalException, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt), + count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asObject(rt).asArray(rt), + count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asNumber());return jsi::Value::undefined(); + } + + static jsi::Value __reportSoftExceptionJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::reportSoftException) == 4, + \\"Expected reportSoftException(...) to have 4 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::reportSoftException, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt), + count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asObject(rt).asArray(rt), + count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asNumber());return jsi::Value::undefined(); + } + + static jsi::Value __reportExceptionJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::reportException) == 2, + \\"Expected reportException(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::reportException, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt));return jsi::Value::undefined(); + } + + static jsi::Value __updateExceptionMessageJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::updateExceptionMessage) == 4, + \\"Expected updateExceptionMessage(...) to have 4 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::updateExceptionMessage, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt), + count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asObject(rt).asArray(rt), + count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asNumber());return jsi::Value::undefined(); + } + + static jsi::Value __dismissRedboxJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::dismissRedbox) == 1, + \\"Expected dismissRedbox(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::dismissRedbox, self->jsInvoker_, self);return jsi::Value::undefined(); + } }; } // namespace facebook::react @@ -2098,174 +1844,156 @@ struct Bridging { } } }; - class JSI_EXPORT NativeSampleTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeSampleTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Object getConstants(jsi::Runtime &rt) = 0; - virtual void voidFunc(jsi::Runtime &rt) = 0; - virtual bool getBool(jsi::Runtime &rt, bool arg) = 0; - virtual double getNumber(jsi::Runtime &rt, double arg) = 0; - virtual jsi::String getString(jsi::Runtime &rt, jsi::String arg) = 0; - virtual jsi::Array getArray(jsi::Runtime &rt, jsi::Array arg) = 0; - virtual jsi::Object getObject(jsi::Runtime &rt, jsi::Object arg) = 0; - virtual double getRootTag(jsi::Runtime &rt, double arg) = 0; - virtual jsi::Object getValue(jsi::Runtime &rt, double x, jsi::String y, jsi::Object z) = 0; - virtual jsi::Value getEnumReturn(jsi::Runtime &rt) = 0; - virtual void getValueWithCallback(jsi::Runtime &rt, jsi::Function callback) = 0; - virtual jsi::Value getValueWithPromise(jsi::Runtime &rt, bool error) = 0; - virtual jsi::Value getValueWithOptionalArg(jsi::Runtime &rt, std::optional parameter) = 0; - virtual jsi::String getEnums(jsi::Runtime &rt, jsi::Value enumInt, jsi::Value enumFloat, jsi::String enumString) = 0; - -}; - template class JSI_EXPORT NativeSampleTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; protected: - NativeSampleTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeSampleTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeSampleTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeSampleTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getConstants\\"] = MethodMetadata {.argCount = 0, .invoker = __getConstantsJSI}; + methodMap_[\\"voidFunc\\"] = MethodMetadata {.argCount = 0, .invoker = __voidFuncJSI}; + methodMap_[\\"getBool\\"] = MethodMetadata {.argCount = 1, .invoker = __getBoolJSI}; + methodMap_[\\"getNumber\\"] = MethodMetadata {.argCount = 1, .invoker = __getNumberJSI}; + methodMap_[\\"getString\\"] = MethodMetadata {.argCount = 1, .invoker = __getStringJSI}; + methodMap_[\\"getArray\\"] = MethodMetadata {.argCount = 1, .invoker = __getArrayJSI}; + methodMap_[\\"getObject\\"] = MethodMetadata {.argCount = 1, .invoker = __getObjectJSI}; + methodMap_[\\"getRootTag\\"] = MethodMetadata {.argCount = 1, .invoker = __getRootTagJSI}; + methodMap_[\\"getValue\\"] = MethodMetadata {.argCount = 3, .invoker = __getValueJSI}; + methodMap_[\\"getEnumReturn\\"] = MethodMetadata {.argCount = 0, .invoker = __getEnumReturnJSI}; + methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithCallbackJSI}; + methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithPromiseJSI}; + methodMap_[\\"getValueWithOptionalArg\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithOptionalArgJSI}; + methodMap_[\\"getEnums\\"] = MethodMetadata {.argCount = 3, .invoker = __getEnumsJSI}; + } + private: - class Delegate : public NativeSampleTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeSampleTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::Object getConstants(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getConstants) == 1, - \\"Expected getConstants(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::getConstants, jsInvoker_, instance_); - } - void voidFunc(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::voidFunc) == 1, - \\"Expected voidFunc(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::voidFunc, jsInvoker_, instance_); - } - bool getBool(jsi::Runtime &rt, bool arg) override { - static_assert( - bridging::getParameterCount(&T::getBool) == 2, - \\"Expected getBool(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getBool, jsInvoker_, instance_, std::move(arg)); - } - double getNumber(jsi::Runtime &rt, double arg) override { - static_assert( - bridging::getParameterCount(&T::getNumber) == 2, - \\"Expected getNumber(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getNumber, jsInvoker_, instance_, std::move(arg)); - } - jsi::String getString(jsi::Runtime &rt, jsi::String arg) override { - static_assert( - bridging::getParameterCount(&T::getString) == 2, - \\"Expected getString(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getString, jsInvoker_, instance_, std::move(arg)); - } - jsi::Array getArray(jsi::Runtime &rt, jsi::Array arg) override { - static_assert( - bridging::getParameterCount(&T::getArray) == 2, - \\"Expected getArray(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getArray, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getObject(jsi::Runtime &rt, jsi::Object arg) override { - static_assert( - bridging::getParameterCount(&T::getObject) == 2, - \\"Expected getObject(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getObject, jsInvoker_, instance_, std::move(arg)); - } - double getRootTag(jsi::Runtime &rt, double arg) override { - static_assert( - bridging::getParameterCount(&T::getRootTag) == 2, - \\"Expected getRootTag(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getRootTag, jsInvoker_, instance_, std::move(arg)); - } - jsi::Object getValue(jsi::Runtime &rt, double x, jsi::String y, jsi::Object z) override { - static_assert( - bridging::getParameterCount(&T::getValue) == 4, - \\"Expected getValue(...) to have 4 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValue, jsInvoker_, instance_, std::move(x), std::move(y), std::move(z)); - } - jsi::Value getEnumReturn(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getEnumReturn) == 1, - \\"Expected getEnumReturn(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::getEnumReturn, jsInvoker_, instance_); - } - void getValueWithCallback(jsi::Runtime &rt, jsi::Function callback) override { - static_assert( - bridging::getParameterCount(&T::getValueWithCallback) == 2, - \\"Expected getValueWithCallback(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithCallback, jsInvoker_, instance_, std::move(callback)); - } - jsi::Value getValueWithPromise(jsi::Runtime &rt, bool error) override { - static_assert( - bridging::getParameterCount(&T::getValueWithPromise) == 2, - \\"Expected getValueWithPromise(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithPromise, jsInvoker_, instance_, std::move(error)); - } - jsi::Value getValueWithOptionalArg(jsi::Runtime &rt, std::optional parameter) override { - static_assert( - bridging::getParameterCount(&T::getValueWithOptionalArg) == 2, - \\"Expected getValueWithOptionalArg(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getValueWithOptionalArg, jsInvoker_, instance_, std::move(parameter)); - } - jsi::String getEnums(jsi::Runtime &rt, jsi::Value enumInt, jsi::Value enumFloat, jsi::String enumString) override { - static_assert( - bridging::getParameterCount(&T::getEnums) == 4, - \\"Expected getEnums(...) to have 4 parameters\\"); - - return bridging::callFromJs( - rt, &T::getEnums, jsInvoker_, instance_, std::move(enumInt), std::move(enumFloat), std::move(enumString)); - } - - private: - friend class NativeSampleTurboModuleCxxSpec; - T *instance_; - }; - - Delegate delegate_; + static jsi::Value __getConstantsJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getConstants) == 1, + \\"Expected getConstants(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getConstants, self->jsInvoker_, self); + } + + static jsi::Value __voidFuncJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::voidFunc) == 1, + \\"Expected voidFunc(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::voidFunc, self->jsInvoker_, self);return jsi::Value::undefined(); + } + + static jsi::Value __getBoolJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getBool) == 2, + \\"Expected getBool(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getBool, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool()); + } + + static jsi::Value __getNumberJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getNumber) == 2, + \\"Expected getNumber(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getNumber, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber()); + } + + static jsi::Value __getStringJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getString) == 2, + \\"Expected getString(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getString, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt)); + } + + static jsi::Value __getArrayJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getArray) == 2, + \\"Expected getArray(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getArray, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asArray(rt)); + } + + static jsi::Value __getObjectJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getObject) == 2, + \\"Expected getObject(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getObject, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt)); + } + + static jsi::Value __getRootTagJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getRootTag) == 2, + \\"Expected getRootTag(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getRootTag, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber()); + } + + static jsi::Value __getValueJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValue) == 4, + \\"Expected getValue(...) to have 4 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getValue, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber(), + count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asString(rt), + count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asObject(rt)); + } + + static jsi::Value __getEnumReturnJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getEnumReturn) == 1, + \\"Expected getEnumReturn(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getEnumReturn, self->jsInvoker_, self); + } + + static jsi::Value __getValueWithCallbackJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithCallback) == 2, + \\"Expected getValueWithCallback(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::getValueWithCallback, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asObject(rt).asFunction(rt));return jsi::Value::undefined(); + } + + static jsi::Value __getValueWithPromiseJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithPromise) == 2, + \\"Expected getValueWithPromise(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getValueWithPromise, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asBool()); + } + + static jsi::Value __getValueWithOptionalArgJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getValueWithOptionalArg) == 2, + \\"Expected getValueWithOptionalArg(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getValueWithOptionalArg, self->jsInvoker_, self, + count <= 0 || args[0].isUndefined() ? std::nullopt : std::make_optional(args[0].asObject(rt))); + } + + static jsi::Value __getEnumsJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getEnums) == 4, + \\"Expected getEnums(...) to have 4 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getEnums, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber(), + count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asNumber(), + count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asString(rt)); + } }; } // namespace facebook::react @@ -2292,63 +2020,32 @@ Map { namespace facebook::react { - class JSI_EXPORT NativeSampleTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeSampleTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::String getStringLiteral(jsi::Runtime &rt, jsi::String literalParam) = 0; - -}; - template class JSI_EXPORT NativeSampleTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; protected: - NativeSampleTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeSampleTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - + NativeSampleTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeSampleTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getStringLiteral\\"] = MethodMetadata {.argCount = 1, .invoker = __getStringLiteralJSI}; + eventEmitterMap_[\\"literalEvent\\"] = std::make_shared>(); + } + template void emitLiteralEvent(LiteralEventType value) { static_assert(bridging::supportsFromJs, \\"value cannnot be converted to jsi::String\\"); - static_cast&>(*delegate_.eventEmitterMap_[\\"literalEvent\\"]).emit([jsInvoker = jsInvoker_, eventValue = value](jsi::Runtime& rt) -> jsi::Value { + static_cast&>(*eventEmitterMap_[\\"literalEvent\\"]).emit([jsInvoker = jsInvoker_, eventValue = value](jsi::Runtime& rt) -> jsi::Value { return bridging::toJs(rt, eventValue, jsInvoker); }); } - private: - class Delegate : public NativeSampleTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeSampleTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - eventEmitterMap_[\\"literalEvent\\"] = std::make_shared>(); - } - - jsi::String getStringLiteral(jsi::Runtime &rt, jsi::String literalParam) override { - static_assert( - bridging::getParameterCount(&T::getStringLiteral) == 2, - \\"Expected getStringLiteral(...) to have 2 parameters\\"); - - return bridging::callFromJs( - rt, &T::getStringLiteral, jsInvoker_, instance_, std::move(literalParam)); - } - - private: - friend class NativeSampleTurboModuleCxxSpec; - T *instance_; - }; - - Delegate delegate_; + static jsi::Value __getStringLiteralJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getStringLiteral) == 2, + \\"Expected getStringLiteral(...) to have 2 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getStringLiteral, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asString(rt)); + } }; } // namespace facebook::react @@ -2375,120 +2072,54 @@ Map { namespace facebook::react { - class JSI_EXPORT NativeSampleTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeSampleTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual void voidFunc(jsi::Runtime &rt) = 0; - -}; - template class JSI_EXPORT NativeSampleTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; protected: - NativeSampleTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeSampleTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeSampleTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeSampleTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"voidFunc\\"] = MethodMetadata {.argCount = 0, .invoker = __voidFuncJSI}; + } + private: - class Delegate : public NativeSampleTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeSampleTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - void voidFunc(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::voidFunc) == 1, - \\"Expected voidFunc(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::voidFunc, jsInvoker_, instance_); - } - - private: - friend class NativeSampleTurboModuleCxxSpec; - T *instance_; - }; - - Delegate delegate_; + static jsi::Value __voidFuncJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::voidFunc) == 1, + \\"Expected voidFunc(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::voidFunc, self->jsInvoker_, self);return jsi::Value::undefined(); + } }; - class JSI_EXPORT NativeSampleTurboModule2CxxSpecJSI : public TurboModule { -protected: - NativeSampleTurboModule2CxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Object getConstants(jsi::Runtime &rt) = 0; - virtual void voidFunc(jsi::Runtime &rt) = 0; - -}; - template class JSI_EXPORT NativeSampleTurboModule2CxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule2\\"; protected: - NativeSampleTurboModule2CxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeSampleTurboModule2CxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeSampleTurboModule2CxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeSampleTurboModule2CxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getConstants\\"] = MethodMetadata {.argCount = 0, .invoker = __getConstantsJSI}; + methodMap_[\\"voidFunc\\"] = MethodMetadata {.argCount = 0, .invoker = __voidFuncJSI}; + } + private: - class Delegate : public NativeSampleTurboModule2CxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeSampleTurboModule2CxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::Object getConstants(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::getConstants) == 1, - \\"Expected getConstants(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::getConstants, jsInvoker_, instance_); - } - void voidFunc(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::voidFunc) == 1, - \\"Expected voidFunc(...) to have 1 parameters\\"); - - return bridging::callFromJs( - rt, &T::voidFunc, jsInvoker_, instance_); - } - - private: - friend class NativeSampleTurboModule2CxxSpec; - T *instance_; - }; + static jsi::Value __getConstantsJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::getConstants) == 1, + \\"Expected getConstants(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getConstants, self->jsInvoker_, self); + } - Delegate delegate_; + static jsi::Value __voidFuncJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) { + static_assert( + bridging::getParameterCount(&T::voidFunc) == 1, + \\"Expected voidFunc(...) to have 1 parameters\\"); + auto* self = static_cast(&turboModule); + bridging::callFromJs(rt, &T::voidFunc, self->jsInvoker_, self);return jsi::Value::undefined(); + } }; } // namespace facebook::react @@ -2515,57 +2146,29 @@ Map { namespace facebook::react { - class JSI_EXPORT NativeSampleTurboModuleCxxSpecJSI : public TurboModule { -protected: - NativeSampleTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker); - -public: - virtual jsi::Object getUnion(jsi::Runtime &rt, double chooseInt, double chooseFloat, jsi::Object chooseObject, jsi::String chooseString, jsi::String chooseStringLiteral) = 0; - -}; - template class JSI_EXPORT NativeSampleTurboModuleCxxSpec : public TurboModule { public: - jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override { - return delegate_.create(rt, propName); - } - - std::vector getPropertyNames(jsi::Runtime& runtime) override { - return delegate_.getPropertyNames(runtime); - } - static constexpr std::string_view kModuleName = \\"SampleTurboModule\\"; protected: - NativeSampleTurboModuleCxxSpec(std::shared_ptr jsInvoker) - : TurboModule(std::string{NativeSampleTurboModuleCxxSpec::kModuleName}, jsInvoker), - delegate_(reinterpret_cast(this), jsInvoker) {} - - + NativeSampleTurboModuleCxxSpec(std::shared_ptr jsInvoker) : TurboModule(std::string{NativeSampleTurboModuleCxxSpec::kModuleName}, jsInvoker) { + methodMap_[\\"getUnion\\"] = MethodMetadata {.argCount = 5, .invoker = __getUnionJSI}; + } + private: - class Delegate : public NativeSampleTurboModuleCxxSpecJSI { - public: - Delegate(T *instance, std::shared_ptr jsInvoker) : - NativeSampleTurboModuleCxxSpecJSI(std::move(jsInvoker)), instance_(instance) { - - } - - jsi::Object getUnion(jsi::Runtime &rt, double chooseInt, double chooseFloat, jsi::Object chooseObject, jsi::String chooseString, jsi::String chooseStringLiteral) override { - static_assert( - bridging::getParameterCount(&T::getUnion) == 6, - \\"Expected getUnion(...) to have 6 parameters\\"); - - return bridging::callFromJs( - rt, &T::getUnion, jsInvoker_, instance_, std::move(chooseInt), std::move(chooseFloat), std::move(chooseObject), std::move(chooseString), std::move(chooseStringLiteral)); - } - - private: - friend class NativeSampleTurboModuleCxxSpec; - T *instance_; - }; - - Delegate delegate_; + static jsi::Value __getUnionJSI(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_assert( + bridging::getParameterCount(&T::getUnion) == 6, + \\"Expected getUnion(...) to have 6 parameters\\"); + auto* self = static_cast(&turboModule); + return bridging::callFromJs(rt, &T::getUnion, self->jsInvoker_, self, + count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber(), + count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asNumber(), + count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asObject(rt), + count <= 3 ? throw jsi::JSError(rt, \\"Expected argument in position 3 to be passed\\") : args[3].asString(rt), + count <= 4 ? throw jsi::JSError(rt, \\"Expected argument in position 4 to be passed\\") : args[4].asString(rt)); + } }; } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp index fa79d14c6459a3..c7b856aa8eeb61 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<> + * @generated SignedSource<<4d5d0795ed4cea8c1e185f6fe3fa0fad>> */ /** @@ -35,7 +35,7 @@ namespace facebook::react { NativeReactNativeFeatureFlags::NativeReactNativeFeatureFlags( std::shared_ptr jsInvoker) - : NativeReactNativeFeatureFlagsCxxSpecJSI(std::move(jsInvoker)) {} + : NativeReactNativeFeatureFlagsCxxSpec(std::move(jsInvoker)) {} bool NativeReactNativeFeatureFlags::commonTestFlag( jsi::Runtime& /*runtime*/) { diff --git a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h index 00ca1a309364e8..cf2875d1563dd5 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h +++ b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<990b6518e7b1d196deb0965e9ada6605>> + * @generated SignedSource<> */ /** @@ -28,7 +28,7 @@ namespace facebook::react { class NativeReactNativeFeatureFlags - : public NativeReactNativeFeatureFlagsCxxSpecJSI { + : public NativeReactNativeFeatureFlagsCxxSpec { public: NativeReactNativeFeatureFlags(std::shared_ptr jsInvoker); diff --git a/packages/react-native/scripts/featureflags/templates/js/NativeReactNativeFeatureFlags.cpp-template.js b/packages/react-native/scripts/featureflags/templates/js/NativeReactNativeFeatureFlags.cpp-template.js index 184e260f8d7bad..b925934ecd6dd0 100644 --- a/packages/react-native/scripts/featureflags/templates/js/NativeReactNativeFeatureFlags.cpp-template.js +++ b/packages/react-native/scripts/featureflags/templates/js/NativeReactNativeFeatureFlags.cpp-template.js @@ -47,7 +47,7 @@ namespace facebook::react { NativeReactNativeFeatureFlags::NativeReactNativeFeatureFlags( std::shared_ptr jsInvoker) - : NativeReactNativeFeatureFlagsCxxSpecJSI(std::move(jsInvoker)) {} + : NativeReactNativeFeatureFlagsCxxSpec(std::move(jsInvoker)) {} ${Object.entries(definitions.common) .map(([flagName, flagConfig]) => diff --git a/packages/react-native/scripts/featureflags/templates/js/NativeReactNativeFeatureFlags.h-template.js b/packages/react-native/scripts/featureflags/templates/js/NativeReactNativeFeatureFlags.h-template.js index 64f0f403b427db..96fd93bf9e3f61 100644 --- a/packages/react-native/scripts/featureflags/templates/js/NativeReactNativeFeatureFlags.h-template.js +++ b/packages/react-native/scripts/featureflags/templates/js/NativeReactNativeFeatureFlags.h-template.js @@ -36,7 +36,7 @@ ${DO_NOT_MODIFY_COMMENT} namespace facebook::react { class NativeReactNativeFeatureFlags - : public NativeReactNativeFeatureFlagsCxxSpecJSI { + : public NativeReactNativeFeatureFlagsCxxSpec { public: NativeReactNativeFeatureFlags(std::shared_ptr jsInvoker);