Skip to content

Commit c533369

Browse files
christophpurrermeta-codesync[bot]
authored andcommitted
Remove invalid float enum example from RN Codegen (#56489)
Summary: Pull Request resolved: #56489 C++ enums cannot have float values - they must be int or long. This removes the invalid FloatEnum example (with values 0.0, 0.1, 0.2) from the react-native-codegen test fixtures and the corresponding enumFloat parameter reference. All affected test snapshots have been regenerated. Changelog: [Internal] Reviewed By: shwanton Differential Revision: D101433764 fbshipit-source-id: eff21d3fa9c48ab11dfb8ef861ac0b8122ff5602
1 parent aa5a78c commit c533369

6 files changed

Lines changed: 9 additions & 80 deletions

File tree

packages/react-native-codegen/src/generators/modules/__test_fixtures__/fixtures.js

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -177,34 +177,6 @@ const SIMPLE_NATIVE_MODULES: SchemaType = {
177177
},
178178
],
179179
},
180-
FloatEnum: {
181-
type: 'EnumDeclarationWithMembers',
182-
name: 'FloatEnum',
183-
memberType: 'NumberTypeAnnotation',
184-
members: [
185-
{
186-
name: 'POINT_ZERO',
187-
value: {
188-
type: 'NumberLiteralTypeAnnotation',
189-
value: 0.0,
190-
},
191-
},
192-
{
193-
name: 'POINT_ONE',
194-
value: {
195-
type: 'NumberLiteralTypeAnnotation',
196-
value: 0.1,
197-
},
198-
},
199-
{
200-
name: 'POINT_TWO',
201-
value: {
202-
type: 'NumberLiteralTypeAnnotation',
203-
value: 0.2,
204-
},
205-
},
206-
],
207-
},
208180
StringEnum: {
209181
type: 'EnumDeclarationWithMembers',
210182
name: 'StringEnum',
@@ -531,15 +503,6 @@ const SIMPLE_NATIVE_MODULES: SchemaType = {
531503
memberType: 'NumberTypeAnnotation',
532504
},
533505
},
534-
{
535-
name: 'enumFloat',
536-
optional: false,
537-
typeAnnotation: {
538-
name: 'FloatEnum',
539-
type: 'EnumDeclaration',
540-
memberType: 'NumberTypeAnnotation',
541-
},
542-
},
543506
{
544507
name: 'enumString',
545508
optional: false,

packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleH-test.js.snap

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,38 +1739,6 @@ struct Bridging<NativeSampleTurboModuleNumEnum> {
17391739
}
17401740
};
17411741

1742-
#pragma mark - NativeSampleTurboModuleFloatEnum
1743-
1744-
enum class NativeSampleTurboModuleFloatEnum { POINT_ZERO = 0, POINT_ONE, POINT_TWO };
1745-
1746-
template <>
1747-
struct Bridging<NativeSampleTurboModuleFloatEnum> {
1748-
static NativeSampleTurboModuleFloatEnum fromJs(jsi::Runtime &rt, const jsi::Value &rawValue) {
1749-
double value = (double)rawValue.asNumber();
1750-
if (value == 0) {
1751-
return NativeSampleTurboModuleFloatEnum::POINT_ZERO;
1752-
} else if (value == 0.1) {
1753-
return NativeSampleTurboModuleFloatEnum::POINT_ONE;
1754-
} else if (value == 0.2) {
1755-
return NativeSampleTurboModuleFloatEnum::POINT_TWO;
1756-
} else {
1757-
throw jsi::JSError(rt, \\"No appropriate enum member found for value in NativeSampleTurboModuleFloatEnum\\");
1758-
}
1759-
}
1760-
1761-
static jsi::Value toJs(jsi::Runtime &rt, NativeSampleTurboModuleFloatEnum value) {
1762-
if (value == NativeSampleTurboModuleFloatEnum::POINT_ZERO) {
1763-
return bridging::toJs(rt, 0);
1764-
} else if (value == NativeSampleTurboModuleFloatEnum::POINT_ONE) {
1765-
return bridging::toJs(rt, 0.1);
1766-
} else if (value == NativeSampleTurboModuleFloatEnum::POINT_TWO) {
1767-
return bridging::toJs(rt, 0.2);
1768-
} else {
1769-
throw jsi::JSError(rt, \\"No appropriate enum member found for enum value in NativeSampleTurboModuleFloatEnum\\");
1770-
}
1771-
}
1772-
};
1773-
17741742
#pragma mark - NativeSampleTurboModuleStringEnum
17751743

17761744
enum class NativeSampleTurboModuleStringEnum { HELLO, GoodBye };
@@ -1818,7 +1786,7 @@ protected:
18181786
methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithCallback};
18191787
methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithPromise};
18201788
methodMap_[\\"getValueWithOptionalArg\\"] = MethodMetadata {.argCount = 1, .invoker = __getValueWithOptionalArg};
1821-
methodMap_[\\"getEnums\\"] = MethodMetadata {.argCount = 3, .invoker = __getEnums};
1789+
methodMap_[\\"getEnums\\"] = MethodMetadata {.argCount = 2, .invoker = __getEnums};
18221790
}
18231791

18241792
private:
@@ -1927,12 +1895,11 @@ private:
19271895

19281896
static jsi::Value __getEnums(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
19291897
static_assert(
1930-
bridging::getParameterCount(&T::getEnums) == 4,
1931-
\\"Expected getEnums(...) to have 4 parameters\\");
1898+
bridging::getParameterCount(&T::getEnums) == 3,
1899+
\\"Expected getEnums(...) to have 3 parameters\\");
19321900
return bridging::callFromJs<jsi::String>(rt, &T::getEnums, static_cast<NativeSampleTurboModuleCxxSpec*>(&turboModule)->jsInvoker_, static_cast<T*>(&turboModule),
19331901
count <= 0 ? throw jsi::JSError(rt, \\"Expected argument in position 0 to be passed\\") : args[0].asNumber(),
1934-
count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asNumber(),
1935-
count <= 2 ? throw jsi::JSError(rt, \\"Expected argument in position 2 to be passed\\") : args[2].asString(rt));
1902+
count <= 1 ? throw jsi::JSError(rt, \\"Expected argument in position 1 to be passed\\") : args[1].asString(rt));
19361903
}
19371904
};
19381905

packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleHObjCpp-test.js.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,6 @@ namespace JS {
10561056
resolve:(RCTPromiseResolveBlock)resolve
10571057
reject:(RCTPromiseRejectBlock)reject;
10581058
- (NSString *)getEnums:(double)enumInt
1059-
enumFloat:(double)enumFloat
10601059
enumString:(NSString *)enumString;
10611060
- (facebook::react::ModuleConstants<JS::NativeSampleTurboModule::Constants>)constantsToExport;
10621061
- (facebook::react::ModuleConstants<JS::NativeSampleTurboModule::Constants>)getConstants;

packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleJavaSpec-test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ public abstract class NativeSampleTurboModuleSpec extends ReactContextBaseJavaMo
505505
506506
@ReactMethod(isBlockingSynchronousMethod = true)
507507
@DoNotStrip
508-
public abstract String getEnums(double enumInt, double enumFloat, String enumString);
508+
public abstract String getEnums(double enumInt, String enumString);
509509
}
510510
",
511511
}

packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleJniCpp-test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getVal
428428
429429
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getEnums(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
430430
static jmethodID cachedMethodId = nullptr;
431-
return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, StringKind, \\"getEnums\\", \\"(DDLjava/lang/String;)Ljava/lang/String;\\", args, count, cachedMethodId);
431+
return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, StringKind, \\"getEnums\\", \\"(DLjava/lang/String;)Ljava/lang/String;\\", args, count, cachedMethodId);
432432
}
433433
434434
NativeSampleTurboModuleSpecJSI::NativeSampleTurboModuleSpecJSI(const JavaTurboModule::InitParams &params)
@@ -446,7 +446,7 @@ NativeSampleTurboModuleSpecJSI::NativeSampleTurboModuleSpecJSI(const JavaTurboMo
446446
methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithCallback};
447447
methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithPromise};
448448
methodMap_[\\"getValueWithOptionalArg\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithOptionalArg};
449-
methodMap_[\\"getEnums\\"] = MethodMetadata {3, __hostFunction_NativeSampleTurboModuleSpecJSI_getEnums};
449+
methodMap_[\\"getEnums\\"] = MethodMetadata {2, __hostFunction_NativeSampleTurboModuleSpecJSI_getEnums};
450450
}
451451
452452
std::shared_ptr<TurboModule> simple_native_modules_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params) {

packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleMm-test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ namespace facebook::react {
575575
}
576576
577577
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getEnums(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
578-
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, StringKind, \\"getEnums\\", @selector(getEnums:enumFloat:enumString:), args, count);
578+
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, StringKind, \\"getEnums\\", @selector(getEnums:enumString:), args, count);
579579
}
580580
581581
static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getConstants(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
@@ -621,7 +621,7 @@ namespace facebook::react {
621621
methodMap_[\\"getValueWithOptionalArg\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithOptionalArg};
622622
623623
624-
methodMap_[\\"getEnums\\"] = MethodMetadata {3, __hostFunction_NativeSampleTurboModuleSpecJSI_getEnums};
624+
methodMap_[\\"getEnums\\"] = MethodMetadata {2, __hostFunction_NativeSampleTurboModuleSpecJSI_getEnums};
625625
626626
627627
methodMap_[\\"getConstants\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleSpecJSI_getConstants};

0 commit comments

Comments
 (0)