[Bridge] RCT_REMAP_METHOD(js_name, selector)

Summary:
cc @a2 @nicklockwood

This diff introduces a new macro called `RCT_EXPORT_NAMED_METHOD`, which is like `RCT_EXPORT_METHOD` but lets you choose the name of the method in JS. This diff is backwards compatible with the `RCT_EXPORT_METHOD` and legacy `RCT_EXPORT` macros.

The entries in the data segment now contain `__func__`, the Obj-C selector signature, and the JS name. If the JS name is `NULL`, we take the legacy `RCT_EXPORT` code path. If the JS name is an empty string, we use the Obj-C selector's name up to the first colon (that is, the behavior of `RCT_EXPORT_METHOD`).

Since there are three values in each data segment entry, the macros now specify 1-byte alignment. Without the byte alignment, the compiler defaults to 2-byte alignment meaning that each entry takes up 4 bytes instead of 3. The extra byte isn't a concern but being explicit about the alignment should reduce compiler surprises.
Closes https://github.com/facebook/react-native/pull/802
Github Author: James Ide <ide@jameside.com>

Test Plan: Imported from GitHub, without a `Test Plan:` line.
This commit is contained in:
James Ide
2015-04-14 13:03:16 -07:00
parent 5bbb351816
commit e193a13ef7
4 changed files with 121 additions and 101 deletions

View File

@@ -135,6 +135,11 @@ BOOL RCTSetProperty(id target, NSString *keyPath, SEL type, id json);
*/
BOOL RCTCopyProperty(id target, id source, NSString *keyPath);
/**
* Underlying implementation of RCT_ENUM_CONVERTER macro. Ignore this.
*/
NSNumber *RCTConverterEnumValue(const char *, NSDictionary *, NSNumber *, id);
#ifdef __cplusplus
}
#endif
@@ -169,13 +174,11 @@ RCT_CUSTOM_CONVERTER(type, name, [json getter])
/**
* This macro is similar to RCT_CONVERTER, but specifically geared towards
* numeric types. It will handle string input correctly, and provides more
* detailed error reporting if a wrong value is passed in.
* detailed error reporting if an invalid value is passed in.
*/
#define RCT_NUMBER_CONVERTER(type, getter) \
RCT_CUSTOM_CONVERTER(type, type, [[self NSNumber:json] getter])
NSNumber *RCTEnumConverterImpl(const char *typeName, NSDictionary *values, NSNumber *defaultValue, id json);
/**
* This macro is used for creating converters for enum types.
*/
@@ -187,7 +190,7 @@ NSNumber *RCTEnumConverterImpl(const char *typeName, NSDictionary *values, NSNum
dispatch_once(&onceToken, ^{ \
mapping = values; \
}); \
NSNumber *converted = RCTEnumConverterImpl(#type, mapping, @(default), json); \
NSNumber *converted = RCTConverterEnumValue(#type, mapping, @(default), json); \
return ((type(*)(id, SEL))objc_msgSend)(converted, @selector(getter)); \
}