From 80e236baca6e7ddfeffdc0e717b5b4fc6078f5f2 Mon Sep 17 00:00:00 2001 From: wojteg1337 Date: Thu, 16 May 2019 15:56:22 +0200 Subject: [PATCH 1/3] [TM] Add spec for HeapCapture --- Libraries/Core/setUpBatchedBridge.js | 2 +- .../{Utilities => HeapCapture}/HeapCapture.js | 7 ++--- Libraries/HeapCapture/NativeHeapCapture.js | 28 +++++++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) rename Libraries/{Utilities => HeapCapture}/HeapCapture.js (84%) create mode 100644 Libraries/HeapCapture/NativeHeapCapture.js diff --git a/Libraries/Core/setUpBatchedBridge.js b/Libraries/Core/setUpBatchedBridge.js index 680c1398e45b84..e9d33fe6ae3a25 100644 --- a/Libraries/Core/setUpBatchedBridge.js +++ b/Libraries/Core/setUpBatchedBridge.js @@ -22,7 +22,7 @@ BatchedBridge.registerLazyCallableModule('JSTimers', () => require('./Timers/JSTimers'), ); BatchedBridge.registerLazyCallableModule('HeapCapture', () => - require('../Utilities/HeapCapture'), + require('../HeapCapture/HeapCapture'), ); BatchedBridge.registerLazyCallableModule('SamplingProfiler', () => require('../Performance/SamplingProfiler'), diff --git a/Libraries/Utilities/HeapCapture.js b/Libraries/HeapCapture/HeapCapture.js similarity index 84% rename from Libraries/Utilities/HeapCapture.js rename to Libraries/HeapCapture/HeapCapture.js index 94ae18f1157606..90d6f3e44abedb 100644 --- a/Libraries/Utilities/HeapCapture.js +++ b/Libraries/HeapCapture/HeapCapture.js @@ -10,6 +10,8 @@ 'use strict'; +import NativeHeapCapture from './NativeHeapCapture'; + const HeapCapture = { captureHeap: function(path: string) { let error = null; @@ -20,10 +22,7 @@ const HeapCapture = { console.log('HeapCapture.captureHeap error: ' + e.toString()); error = e.toString(); } - require('../BatchedBridge/NativeModules').JSCHeapCapture.captureComplete( - path, - error, - ); + NativeHeapCapture.captureComplete(path, error); }, }; diff --git a/Libraries/HeapCapture/NativeHeapCapture.js b/Libraries/HeapCapture/NativeHeapCapture.js new file mode 100644 index 00000000000000..46607ea78413f6 --- /dev/null +++ b/Libraries/HeapCapture/NativeHeapCapture.js @@ -0,0 +1,28 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + * @format + */ + +'use strict'; + +import type {TurboModule} from 'RCTExport'; +import * as TurboModuleRegistry from 'TurboModuleRegistry'; + +export interface Spec extends TurboModule { + // Common interface + +captureHeap: (path: string) => void; + + // Android only + +captureComplete: (path: string, error: ?string) => void; + + // Events + +addListener: (eventName: string, handler: Function) => Object; + +removeListeners: (eventName: string, handler: Function) => void; +} + +export default TurboModuleRegistry.getEnforcing('HeapCapture'); From 704bb8b950154843a60e76abd4eb813b272ed823 Mon Sep 17 00:00:00 2001 From: Wojteg1337 Date: Fri, 17 May 2019 10:56:11 +0200 Subject: [PATCH 2/3] fix: add conditional export for platform specific module --- Libraries/HeapCapture/HeapCapture.js | 4 +++- Libraries/HeapCapture/NativeHeapCapture.js | 9 ++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Libraries/HeapCapture/HeapCapture.js b/Libraries/HeapCapture/HeapCapture.js index 90d6f3e44abedb..9cbabc60417487 100644 --- a/Libraries/HeapCapture/HeapCapture.js +++ b/Libraries/HeapCapture/HeapCapture.js @@ -22,7 +22,9 @@ const HeapCapture = { console.log('HeapCapture.captureHeap error: ' + e.toString()); error = e.toString(); } - NativeHeapCapture.captureComplete(path, error); + if (NativeHeapCapture) { + NativeHeapCapture.captureComplete(path, error); + } }, }; diff --git a/Libraries/HeapCapture/NativeHeapCapture.js b/Libraries/HeapCapture/NativeHeapCapture.js index 46607ea78413f6..459f350f612af5 100644 --- a/Libraries/HeapCapture/NativeHeapCapture.js +++ b/Libraries/HeapCapture/NativeHeapCapture.js @@ -12,6 +12,7 @@ import type {TurboModule} from 'RCTExport'; import * as TurboModuleRegistry from 'TurboModuleRegistry'; +import {Platform} from 'react-native'; export interface Spec extends TurboModule { // Common interface @@ -19,10 +20,8 @@ export interface Spec extends TurboModule { // Android only +captureComplete: (path: string, error: ?string) => void; - - // Events - +addListener: (eventName: string, handler: Function) => Object; - +removeListeners: (eventName: string, handler: Function) => void; } -export default TurboModuleRegistry.getEnforcing('HeapCapture'); +export default (Platform.OS === 'android' + ? TurboModuleRegistry.getEnforcing('HeapCapture') + : null); From 2cdd85fb778636c8a9bdb7aae35f1e510cfbf278 Mon Sep 17 00:00:00 2001 From: Wojteg1337 Date: Mon, 20 May 2019 10:29:18 +0200 Subject: [PATCH 3/3] fix: remove unnecesary comments --- Libraries/HeapCapture/NativeHeapCapture.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/Libraries/HeapCapture/NativeHeapCapture.js b/Libraries/HeapCapture/NativeHeapCapture.js index 459f350f612af5..2c50e9e906703c 100644 --- a/Libraries/HeapCapture/NativeHeapCapture.js +++ b/Libraries/HeapCapture/NativeHeapCapture.js @@ -15,10 +15,7 @@ import * as TurboModuleRegistry from 'TurboModuleRegistry'; import {Platform} from 'react-native'; export interface Spec extends TurboModule { - // Common interface +captureHeap: (path: string) => void; - - // Android only +captureComplete: (path: string, error: ?string) => void; }