react-native-macos/ReactCommon
Ramanpreet Nara 58cd20459f Force JS null to be translated to ObjC nil
Summary:
In D14571128, we made it so that when a JS object's property was `undefined`, we wouldn't insert that property into the corresponding NSDictionary. Here are two important observations about that diff:
1. ALL JS `null`s were now being converted to `NSNull`, and JS `undefined`s were now being converted to `nil`.
2. If a JS object's property was explicitly `null`, then we'd insert `NSNull` into the corresponding dictionary.

Considering that when a property doesn't exist in a `NSDictionary`, property access returns `nil`, I've made it so that if a JS object's property is either `null` or `undefined`, then we simply do not insert it in the corresponding `NSDictionary`. Also, I've reverted #1 and made it so that `undefined` and `null` always map to the ObjC `nil`.

This shouldn't unfix the problem that D14571128 was trying to fix.

Here's my understanding of the problem that D14571128 was trying to fix (to make sure I'm not breaking something by this diff).

This method was invoked from JS.
```
RCT_EXPORT_METHOD(logEvents:(NSDictionary *)events)
{
  RCTAssert(events, @"You should provide events for logger");
  [[NSNotificationCenter defaultCenter] postNotificationName:@"FBReactPerfLoggerDidReceiveEventsNotification"
                                                      object:nil
                                                    userInfo:@{@"FBReactPerfLoggerUserInfoPerfEventsKey" : [events copy]}];
}
```

The above dispatch calls into this method, which appends `events` into `_pendingJSPerfEvents`.

```
- (void)reactPerfLoggerDidReceiveEvents:(NSNotification *)notification
{
  NSDictionary *events = notification.userInfo[@"FBReactPerfLoggerUserInfoPerfEventsKey"];
  if (events) {
    dispatch_async(_eventQueue, ^{
      if (self->_sessionData.perfLoggerFlagId != nil) {
        if ([self processJSPerfEvents:events]) {
          [self reportMetricsIfFinished];
        }
      } else {
        [self->_pendingJSPerfEvents addObject:events];
      }
    });
  }
}
```

Then, in `_processJSPerfEvents`, we do the following (link: https://fburl.com/tr4wr2a7):
```
NSNumber *actionId = events[@"actionId"];
if (actionId) {
  self->_sessionData.actionId = actionId;
}
```

So, if `undefined` or `null` was passed in as the `actionId` property of the `events` JS object in `FBReactPerformanceLogger logEvents:`, then we'd default the `NSDictionary` to have `NSNull` in the corresponding property. This is bad because we had this line in FBReactWildePerfLogger (link: https://fburl.com/2nsywl2n):  `actionId ? [actionId shortValue] : PerfLoggerActions.SUCCESS`. Essentially, this is the same problem that my diff is trying to fix.

Reviewed By: fkgozali

Differential Revision: D14625287

fbshipit-source-id: c701d4b6172484cee62494256175e8b205b23c73
2019-03-26 14:28:23 -07:00
..
better Fabric: Disabling custom ("better") containers in DEBUG mode 2019-03-20 09:24:59 -07:00
config xplat// -> fbsource//xplat/ for xplat/js 2019-02-14 23:53:32 -08:00
cxxreact JSBigString to map via MAP_PRIVATE not MAP_SHARED 2019-03-21 14:27:23 -07:00
fabric Fabric: Removing ShadowNode::constructAncestorPath() 2019-03-25 20:32:21 -07:00
jsi JSI es6 Symbol impl for JSCRuntime 2019-03-21 13:33:32 -07:00
jsiexecutor Refactor JSIExecutor to use runtimeInstaller for injecting the logger instance 2019-03-25 09:12:11 -07:00
jsinspector Split React.podspec into separate podspecs for each Xcode project (#23559) 2019-02-21 18:35:44 -08:00
microprofiler Upgrade mobile BUCK and .bzl files to use C++14 2019-03-16 02:25:33 -07:00
turbomodule/core Force JS null to be translated to ObjC nil 2019-03-26 14:28:23 -07:00
utils Fabric: Introducing SimpleThreadSafeCache 2019-03-03 12:07:12 -08:00
yoga `CompactValue` overrides of `YGResolveValue`/`YGValueEqual` 2019-03-26 05:22:24 -07:00
React-Fabric.podspec Fabric: working podspecs & works in RNTester (#23803) 2019-03-15 23:59:22 -07:00