RCTModuleMethod.mm 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #import "RCTModuleMethod.h"
  8. #import <objc/message.h>
  9. #import "RCTAssert.h"
  10. #import "RCTBridge+Private.h"
  11. #import "RCTBridge.h"
  12. #import "RCTConvert.h"
  13. #import "RCTCxxConvert.h"
  14. #import "RCTLog.h"
  15. #import "RCTManagedPointer.h"
  16. #import "RCTParserUtils.h"
  17. #import "RCTProfile.h"
  18. #import "RCTUtils.h"
  19. typedef BOOL (^RCTArgumentBlock)(RCTBridge *, NSUInteger, id);
  20. /**
  21. * Get the converter function for the specified type
  22. */
  23. static SEL selectorForType(NSString *type)
  24. {
  25. const char *input = type.UTF8String;
  26. return NSSelectorFromString([RCTParseType(&input) stringByAppendingString:@":"]);
  27. }
  28. @implementation RCTMethodArgument
  29. - (instancetype)initWithType:(NSString *)type
  30. nullability:(RCTNullability)nullability
  31. unused:(BOOL)unused
  32. {
  33. if (self = [super init]) {
  34. _type = [type copy];
  35. _nullability = nullability;
  36. _unused = unused;
  37. }
  38. return self;
  39. }
  40. @end
  41. @implementation RCTModuleMethod
  42. {
  43. Class _moduleClass;
  44. const RCTMethodInfo *_methodInfo;
  45. NSString *_JSMethodName;
  46. SEL _selector;
  47. NSInvocation *_invocation;
  48. NSArray<RCTArgumentBlock> *_argumentBlocks;
  49. NSMutableArray *_retainedObjects;
  50. }
  51. static void RCTLogArgumentError(RCTModuleMethod *method, NSUInteger index,
  52. id valueOrType, const char *issue)
  53. {
  54. RCTLogError(@"Argument %tu (%@) of %@.%s %s", index, valueOrType,
  55. RCTBridgeModuleNameForClass(method->_moduleClass),
  56. method.JSMethodName, issue);
  57. }
  58. RCT_NOT_IMPLEMENTED(- (instancetype)init)
  59. RCT_EXTERN_C_BEGIN
  60. // returns YES if the selector ends in a colon (indicating that there is at
  61. // least one argument, and maybe more selector parts) or NO if it doesn't.
  62. static BOOL RCTParseSelectorPart(const char **input, NSMutableString *selector)
  63. {
  64. NSString *selectorPart;
  65. if (RCTParseSelectorIdentifier(input, &selectorPart)) {
  66. [selector appendString:selectorPart];
  67. }
  68. RCTSkipWhitespace(input);
  69. if (RCTReadChar(input, ':')) {
  70. [selector appendString:@":"];
  71. RCTSkipWhitespace(input);
  72. return YES;
  73. }
  74. return NO;
  75. }
  76. static BOOL RCTParseUnused(const char **input)
  77. {
  78. return RCTReadString(input, "__attribute__((unused))") ||
  79. RCTReadString(input, "__attribute__((__unused__))") ||
  80. RCTReadString(input, "__unused");
  81. }
  82. static RCTNullability RCTParseNullability(const char **input)
  83. {
  84. if (RCTReadString(input, "nullable")) {
  85. return RCTNullable;
  86. } else if (RCTReadString(input, "nonnull")) {
  87. return RCTNonnullable;
  88. }
  89. return RCTNullabilityUnspecified;
  90. }
  91. static RCTNullability RCTParseNullabilityPostfix(const char **input)
  92. {
  93. if (RCTReadString(input, "_Nullable")) {
  94. return RCTNullable;
  95. } else if (RCTReadString(input, "_Nonnull")) {
  96. return RCTNonnullable;
  97. }
  98. return RCTNullabilityUnspecified;
  99. }
  100. // returns YES if execution is safe to proceed (enqueue callback invocation), NO if callback has already been invoked
  101. #if RCT_DEBUG
  102. static BOOL checkCallbackMultipleInvocations(BOOL *didInvoke) {
  103. if (*didInvoke) {
  104. RCTFatal(RCTErrorWithMessage(@"Illegal callback invocation from native module. This callback type only permits a single invocation from native code."));
  105. return NO;
  106. } else {
  107. *didInvoke = YES;
  108. return YES;
  109. }
  110. }
  111. #endif
  112. extern NSString *RCTParseMethodSignature(const char *input, NSArray<RCTMethodArgument *> **arguments);
  113. NSString *RCTParseMethodSignature(const char *input, NSArray<RCTMethodArgument *> **arguments)
  114. {
  115. RCTSkipWhitespace(&input);
  116. NSMutableArray *args;
  117. NSMutableString *selector = [NSMutableString new];
  118. while (RCTParseSelectorPart(&input, selector)) {
  119. if (!args) {
  120. args = [NSMutableArray new];
  121. }
  122. // Parse type
  123. if (RCTReadChar(&input, '(')) {
  124. RCTSkipWhitespace(&input);
  125. BOOL unused = RCTParseUnused(&input);
  126. RCTSkipWhitespace(&input);
  127. RCTNullability nullability = RCTParseNullability(&input);
  128. RCTSkipWhitespace(&input);
  129. NSString *type = RCTParseType(&input);
  130. RCTSkipWhitespace(&input);
  131. if (nullability == RCTNullabilityUnspecified) {
  132. nullability = RCTParseNullabilityPostfix(&input);
  133. }
  134. [args addObject:[[RCTMethodArgument alloc] initWithType:type
  135. nullability:nullability
  136. unused:unused]];
  137. RCTSkipWhitespace(&input);
  138. RCTReadChar(&input, ')');
  139. RCTSkipWhitespace(&input);
  140. } else {
  141. // Type defaults to id if unspecified
  142. [args addObject:[[RCTMethodArgument alloc] initWithType:@"id"
  143. nullability:RCTNullable
  144. unused:NO]];
  145. }
  146. // Argument name
  147. RCTParseArgumentIdentifier(&input, NULL);
  148. RCTSkipWhitespace(&input);
  149. }
  150. *arguments = [args copy];
  151. return selector;
  152. }
  153. RCT_EXTERN_C_END
  154. - (instancetype)initWithExportedMethod:(const RCTMethodInfo *)exportedMethod
  155. moduleClass:(Class)moduleClass
  156. {
  157. if (self = [super init]) {
  158. _moduleClass = moduleClass;
  159. _methodInfo = exportedMethod;
  160. }
  161. return self;
  162. }
  163. - (void)processMethodSignature
  164. {
  165. NSArray<RCTMethodArgument *> *arguments;
  166. _selector = NSSelectorFromString(RCTParseMethodSignature(_methodInfo->objcName, &arguments));
  167. RCTAssert(_selector, @"%s is not a valid selector", _methodInfo->objcName);
  168. // Create method invocation
  169. NSMethodSignature *methodSignature = [_moduleClass instanceMethodSignatureForSelector:_selector];
  170. RCTAssert(methodSignature, @"%s is not a recognized Objective-C method.", sel_getName(_selector));
  171. NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
  172. invocation.selector = _selector;
  173. _invocation = invocation;
  174. NSMutableArray *retainedObjects = [NSMutableArray array];
  175. _retainedObjects = retainedObjects;
  176. // Process arguments
  177. NSUInteger numberOfArguments = methodSignature.numberOfArguments;
  178. NSMutableArray<RCTArgumentBlock> *argumentBlocks =
  179. [[NSMutableArray alloc] initWithCapacity:numberOfArguments - 2];
  180. #if RCT_DEBUG
  181. __weak RCTModuleMethod *weakSelf = self;
  182. #endif
  183. #define RCT_RETAINED_ARG_BLOCK(_logic) \
  184. [argumentBlocks addObject:^(__unused __weak RCTBridge *bridge, NSUInteger index, id json) { \
  185. _logic \
  186. [invocation setArgument:&value atIndex:(index) + 2]; \
  187. if (value) { \
  188. [retainedObjects addObject:value]; \
  189. } \
  190. return YES; \
  191. }]
  192. #define __PRIMITIVE_CASE(_type, _nullable) { \
  193. isNullableType = _nullable; \
  194. _type (*convert)(id, SEL, id) = (__typeof__(convert))objc_msgSend; \
  195. [argumentBlocks addObject:^(__unused RCTBridge *bridge, NSUInteger index, id json) { \
  196. _type value = convert([RCTConvert class], selector, json); \
  197. [invocation setArgument:&value atIndex:(index) + 2]; \
  198. return YES; \
  199. }]; \
  200. break; \
  201. }
  202. #define PRIMITIVE_CASE(_type) __PRIMITIVE_CASE(_type, NO)
  203. #define NULLABLE_PRIMITIVE_CASE(_type) __PRIMITIVE_CASE(_type, YES)
  204. // Explicitly copy the block
  205. #define __COPY_BLOCK(block...) \
  206. id value = [block copy]; \
  207. if (value) { \
  208. [retainedObjects addObject:value]; \
  209. } \
  210. #if RCT_DEBUG
  211. #define BLOCK_CASE(_block_args, _block) RCT_RETAINED_ARG_BLOCK( \
  212. if (json && ![json isKindOfClass:[NSNumber class]]) { \
  213. RCTLogArgumentError(weakSelf, index, json, "should be a function"); \
  214. return NO; \
  215. } \
  216. __block BOOL didInvoke = NO; \
  217. __COPY_BLOCK(^_block_args { \
  218. if (checkCallbackMultipleInvocations(&didInvoke)) _block \
  219. }); \
  220. )
  221. #else
  222. #define BLOCK_CASE(_block_args, _block) \
  223. RCT_RETAINED_ARG_BLOCK( __COPY_BLOCK(^_block_args { _block }); )
  224. #endif
  225. for (NSUInteger i = 2; i < numberOfArguments; i++) {
  226. const char *objcType = [methodSignature getArgumentTypeAtIndex:i];
  227. BOOL isNullableType = NO;
  228. RCTMethodArgument *argument = arguments[i - 2];
  229. NSString *typeName = argument.type;
  230. SEL selector = selectorForType(typeName);
  231. if ([RCTConvert respondsToSelector:selector]) {
  232. switch (objcType[0]) {
  233. // Primitives
  234. case _C_CHR: PRIMITIVE_CASE(char)
  235. case _C_UCHR: PRIMITIVE_CASE(unsigned char)
  236. case _C_SHT: PRIMITIVE_CASE(short)
  237. case _C_USHT: PRIMITIVE_CASE(unsigned short)
  238. case _C_INT: PRIMITIVE_CASE(int)
  239. case _C_UINT: PRIMITIVE_CASE(unsigned int)
  240. case _C_LNG: PRIMITIVE_CASE(long)
  241. case _C_ULNG: PRIMITIVE_CASE(unsigned long)
  242. case _C_LNG_LNG: PRIMITIVE_CASE(long long)
  243. case _C_ULNG_LNG: PRIMITIVE_CASE(unsigned long long)
  244. case _C_FLT: PRIMITIVE_CASE(float)
  245. case _C_DBL: PRIMITIVE_CASE(double)
  246. case _C_BOOL: PRIMITIVE_CASE(BOOL)
  247. case _C_SEL: NULLABLE_PRIMITIVE_CASE(SEL)
  248. case _C_CHARPTR: NULLABLE_PRIMITIVE_CASE(const char *)
  249. case _C_PTR: NULLABLE_PRIMITIVE_CASE(void *)
  250. case _C_ID: {
  251. isNullableType = YES;
  252. id (*convert)(id, SEL, id) = (__typeof__(convert))objc_msgSend;
  253. RCT_RETAINED_ARG_BLOCK(
  254. id value = convert([RCTConvert class], selector, json);
  255. );
  256. break;
  257. }
  258. case _C_STRUCT_B: {
  259. NSMethodSignature *typeSignature = [RCTConvert methodSignatureForSelector:selector];
  260. NSInvocation *typeInvocation = [NSInvocation invocationWithMethodSignature:typeSignature];
  261. typeInvocation.selector = selector;
  262. typeInvocation.target = [RCTConvert class];
  263. [argumentBlocks addObject:^(__unused RCTBridge *bridge, NSUInteger index, id json) {
  264. void *returnValue = malloc(typeSignature.methodReturnLength);
  265. if (!returnValue) {
  266. // CWE - 391 : Unchecked error condition
  267. // https://www.cvedetails.com/cwe-details/391/Unchecked-Error-Condition.html
  268. // https://eli.thegreenplace.net/2009/10/30/handling-out-of-memory-conditions-in-c
  269. abort();
  270. }
  271. [typeInvocation setArgument:&json atIndex:2];
  272. [typeInvocation invoke];
  273. [typeInvocation getReturnValue:returnValue];
  274. [invocation setArgument:returnValue atIndex:index + 2];
  275. free(returnValue);
  276. return YES;
  277. }];
  278. break;
  279. }
  280. default: {
  281. static const char *blockType = @encode(__typeof__(^{}));
  282. if (!strcmp(objcType, blockType)) {
  283. BLOCK_CASE((NSArray *args), {
  284. [bridge enqueueCallback:json args:args];
  285. });
  286. } else {
  287. RCTLogError(@"Unsupported argument type '%@' in method %@.",
  288. typeName, [self methodName]);
  289. }
  290. }
  291. }
  292. } else if ([typeName isEqualToString:@"RCTResponseSenderBlock"]) {
  293. BLOCK_CASE((NSArray *args), {
  294. [bridge enqueueCallback:json args:args];
  295. });
  296. } else if ([typeName isEqualToString:@"RCTResponseErrorBlock"]) {
  297. BLOCK_CASE((NSError *error), {
  298. [bridge enqueueCallback:json args:@[RCTJSErrorFromNSError(error)]];
  299. });
  300. } else if ([typeName isEqualToString:@"RCTPromiseResolveBlock"]) {
  301. RCTAssert(i == numberOfArguments - 2,
  302. @"The RCTPromiseResolveBlock must be the second to last parameter in %@",
  303. [self methodName]);
  304. BLOCK_CASE((id result), {
  305. [bridge enqueueCallback:json args:result ? @[result] : @[]];
  306. });
  307. } else if ([typeName isEqualToString:@"RCTPromiseRejectBlock"]) {
  308. RCTAssert(i == numberOfArguments - 1,
  309. @"The RCTPromiseRejectBlock must be the last parameter in %@",
  310. [self methodName]);
  311. BLOCK_CASE((NSString *code, NSString *message, NSError *error), {
  312. NSDictionary *errorJSON = RCTJSErrorFromCodeMessageAndNSError(code, message, error);
  313. [bridge enqueueCallback:json args:@[errorJSON]];
  314. });
  315. } else if ([typeName hasPrefix:@"JS::"]) {
  316. NSString *selectorNameForCxxType =
  317. [[typeName stringByReplacingOccurrencesOfString:@"::" withString:@"_"]
  318. stringByAppendingString:@":"];
  319. selector = NSSelectorFromString(selectorNameForCxxType);
  320. [argumentBlocks addObject:^(__unused RCTBridge *bridge, NSUInteger index, id json) {
  321. RCTManagedPointer *(*convert)(id, SEL, id) = (__typeof__(convert))objc_msgSend;
  322. RCTManagedPointer *box = convert([RCTCxxConvert class], selector, json);
  323. void *pointer = box.voidPointer;
  324. [invocation setArgument:&pointer atIndex:index + 2];
  325. [retainedObjects addObject:box];
  326. return YES;
  327. }];
  328. } else {
  329. // Unknown argument type
  330. RCTLogError(@"Unknown argument type '%@' in method %@. Extend RCTConvert to support this type.",
  331. typeName, [self methodName]);
  332. }
  333. #if RCT_DEBUG
  334. RCTNullability nullability = argument.nullability;
  335. if (!isNullableType) {
  336. if (nullability == RCTNullable) {
  337. RCTLogArgumentError(weakSelf, i - 2, typeName, "is marked as "
  338. "nullable, but is not a nullable type.");
  339. }
  340. nullability = RCTNonnullable;
  341. }
  342. /**
  343. * Special case - Numbers are not nullable in Android, so we
  344. * don't support this for now. In future we may allow it.
  345. */
  346. if ([typeName isEqualToString:@"NSNumber"]) {
  347. BOOL unspecified = (nullability == RCTNullabilityUnspecified);
  348. if (!argument.unused && (nullability == RCTNullable || unspecified)) {
  349. RCTLogArgumentError(weakSelf, i - 2, typeName,
  350. [unspecified ? @"has unspecified nullability" : @"is marked as nullable"
  351. stringByAppendingString: @" but React requires that all NSNumber "
  352. "arguments are explicitly marked as `nonnull` to ensure "
  353. "compatibility with Android."].UTF8String);
  354. }
  355. nullability = RCTNonnullable;
  356. }
  357. if (nullability == RCTNonnullable) {
  358. RCTArgumentBlock oldBlock = argumentBlocks[i - 2];
  359. argumentBlocks[i - 2] = ^(RCTBridge *bridge, NSUInteger index, id json) {
  360. if (json != nil) {
  361. if (!oldBlock(bridge, index, json)) {
  362. return NO;
  363. }
  364. if (isNullableType) {
  365. // Check converted value wasn't null either, as method probably
  366. // won't gracefully handle a nil vallue for a nonull argument
  367. void *value;
  368. [invocation getArgument:&value atIndex:index + 2];
  369. if (value == NULL) {
  370. return NO;
  371. }
  372. }
  373. return YES;
  374. }
  375. RCTLogArgumentError(weakSelf, index, typeName, "must not be null");
  376. return NO;
  377. };
  378. }
  379. #endif
  380. }
  381. #if RCT_DEBUG
  382. const char *objcType = _invocation.methodSignature.methodReturnType;
  383. if (_methodInfo->isSync && objcType[0] != _C_ID) {
  384. RCTLogError(@"Return type of %@.%s should be (id) as the method is \"sync\"",
  385. RCTBridgeModuleNameForClass(_moduleClass), self.JSMethodName);
  386. }
  387. #endif
  388. _argumentBlocks = argumentBlocks;
  389. }
  390. - (SEL)selector
  391. {
  392. if (_selector == NULL) {
  393. RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"", (@{ @"module": NSStringFromClass(_moduleClass),
  394. @"method": @(_methodInfo->objcName) }));
  395. [self processMethodSignature];
  396. RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"");
  397. }
  398. return _selector;
  399. }
  400. - (const char *)JSMethodName
  401. {
  402. NSString *methodName = _JSMethodName;
  403. if (!methodName) {
  404. const char *jsName = _methodInfo->jsName;
  405. if (jsName && strlen(jsName) > 0) {
  406. methodName = @(jsName);
  407. } else {
  408. methodName = @(_methodInfo->objcName);
  409. NSRange colonRange = [methodName rangeOfString:@":"];
  410. if (colonRange.location != NSNotFound) {
  411. methodName = [methodName substringToIndex:colonRange.location];
  412. }
  413. methodName = [methodName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  414. RCTAssert(methodName.length, @"%s is not a valid JS function name, please"
  415. " supply an alternative using RCT_REMAP_METHOD()", _methodInfo->objcName);
  416. }
  417. _JSMethodName = methodName;
  418. }
  419. return methodName.UTF8String;
  420. }
  421. - (RCTFunctionType)functionType
  422. {
  423. if (strstr(_methodInfo->objcName, "RCTPromise") != NULL) {
  424. RCTAssert(!_methodInfo->isSync, @"Promises cannot be used in sync functions");
  425. return RCTFunctionTypePromise;
  426. } else if (_methodInfo->isSync) {
  427. return RCTFunctionTypeSync;
  428. } else {
  429. return RCTFunctionTypeNormal;
  430. }
  431. }
  432. - (id)invokeWithBridge:(RCTBridge *)bridge
  433. module:(id)module
  434. arguments:(NSArray *)arguments
  435. {
  436. if (_argumentBlocks == nil) {
  437. [self processMethodSignature];
  438. }
  439. #if RCT_DEBUG
  440. // Sanity check
  441. RCTAssert([module class] == _moduleClass, @"Attempted to invoke method \
  442. %@ on a module of class %@", [self methodName], [module class]);
  443. // Safety check
  444. if (arguments.count != _argumentBlocks.count) {
  445. NSInteger actualCount = arguments.count;
  446. NSInteger expectedCount = _argumentBlocks.count;
  447. // Subtract the implicit Promise resolver and rejecter functions for implementations of async functions
  448. if (self.functionType == RCTFunctionTypePromise) {
  449. actualCount -= 2;
  450. expectedCount -= 2;
  451. }
  452. RCTLogError(@"%@.%s was called with %lld arguments but expects %lld arguments. "
  453. @"If you haven\'t changed this method yourself, this usually means that "
  454. @"your versions of the native code and JavaScript code are out of sync. "
  455. @"Updating both should make this error go away.",
  456. RCTBridgeModuleNameForClass(_moduleClass), self.JSMethodName,
  457. (long long)actualCount, (long long)expectedCount);
  458. return nil;
  459. }
  460. #endif
  461. // Set arguments
  462. NSUInteger index = 0;
  463. for (id json in arguments) {
  464. RCTArgumentBlock block = _argumentBlocks[index];
  465. if (!block(bridge, index, RCTNilIfNull(json))) {
  466. // Invalid argument, abort
  467. RCTLogArgumentError(self, index, json, "could not be processed. Aborting method call.");
  468. return nil;
  469. }
  470. index++;
  471. }
  472. // Invoke method
  473. #ifdef RCT_MAIN_THREAD_WATCH_DOG_THRESHOLD
  474. if (RCTIsMainQueue()) {
  475. CFTimeInterval start = CACurrentMediaTime();
  476. [_invocation invokeWithTarget:module];
  477. CFTimeInterval duration = CACurrentMediaTime() - start;
  478. if (duration > RCT_MAIN_THREAD_WATCH_DOG_THRESHOLD) {
  479. RCTLogWarn(
  480. @"Main Thread Watchdog: Invocation of %@ blocked the main thread for %dms. "
  481. "Consider using background-threaded modules and asynchronous calls "
  482. "to spend less time on the main thread and keep the app's UI responsive.",
  483. [self methodName],
  484. (int)(duration * 1000)
  485. );
  486. }
  487. } else {
  488. [_invocation invokeWithTarget:module];
  489. }
  490. #else
  491. [_invocation invokeWithTarget:module];
  492. #endif
  493. index = 2;
  494. [_retainedObjects removeAllObjects];
  495. if (_methodInfo->isSync) {
  496. void *returnValue;
  497. [_invocation getReturnValue:&returnValue];
  498. return (__bridge id)returnValue;
  499. }
  500. return nil;
  501. }
  502. - (NSString *)methodName
  503. {
  504. if (!_selector) {
  505. [self processMethodSignature];
  506. }
  507. return [NSString stringWithFormat:@"-[%@ %s]", _moduleClass, sel_getName(_selector)];
  508. }
  509. - (NSString *)description
  510. {
  511. return [NSString stringWithFormat:@"<%@: %p; exports %@ as %s(); type: %s>",
  512. [self class], self, [self methodName], self.JSMethodName, RCTFunctionDescriptorFromType(self.functionType)];
  513. }
  514. @end