diff --git a/Libraries/Core/setUpBatchedBridge.js b/Libraries/Core/setUpBatchedBridge.js index 680c1398e45b..e9d33fe6ae3a 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 80% rename from Libraries/Utilities/HeapCapture.js rename to Libraries/HeapCapture/HeapCapture.js index 94ae18f11576..9cbabc604174 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,9 @@ const HeapCapture = { console.log('HeapCapture.captureHeap error: ' + e.toString()); error = e.toString(); } - require('../BatchedBridge/NativeModules').JSCHeapCapture.captureComplete( - path, - error, - ); + if (NativeHeapCapture) { + NativeHeapCapture.captureComplete(path, error); + } }, }; diff --git a/Libraries/HeapCapture/NativeHeapCapture.js b/Libraries/HeapCapture/NativeHeapCapture.js new file mode 100644 index 000000000000..2c50e9e90670 --- /dev/null +++ b/Libraries/HeapCapture/NativeHeapCapture.js @@ -0,0 +1,24 @@ +/** + * 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'; +import {Platform} from 'react-native'; + +export interface Spec extends TurboModule { + +captureHeap: (path: string) => void; + +captureComplete: (path: string, error: ?string) => void; +} + +export default (Platform.OS === 'android' + ? TurboModuleRegistry.getEnforcing('HeapCapture') + : null);