From 7e3a43c23d028a4481bc455dd28c391a81ff1a94 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Tue, 14 Jan 2020 07:54:08 -0800 Subject: [PATCH] Fix NativeJSCHeapCapture Summary: In D15393464, we introduced `NativeHeapCapture`, but it had a few problems: 1. It required `JSCHeapCapture` by doing `TurboModuleRegistry.get('HeapCapture')`, when it should have done `TurboModuleRegistry.get('JSCHeapCapture')`. 2. It had an additional method `captureHeap`, which didn't exist on the Android NativeModule. This diff corrects those mistakes. Changelog: [Both][Fixed] - Fix JSCHeapCapture Reviewed By: PeteTheHeat Differential Revision: D19383511 fbshipit-source-id: 30e69afbcdba673f3f32c16bde4f0342568ab97d --- .../FBReactNativeSpec-generated.mm | 47 ++++++++----------- .../FBReactNativeSpec/FBReactNativeSpec.h | 39 ++++++++------- Libraries/HeapCapture/HeapCapture.js | 6 +-- ...HeapCapture.js => NativeJSCHeapCapture.js} | 6 +-- .../specs/NativeJSCHeapCaptureSpec.java | 29 ++++++++++++ 5 files changed, 72 insertions(+), 55 deletions(-) rename Libraries/HeapCapture/{NativeHeapCapture.js => NativeJSCHeapCapture.js} (76%) create mode 100644 ReactAndroid/src/main/java/com/facebook/fbreact/specs/NativeJSCHeapCaptureSpec.java diff --git a/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm b/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm index bce1dea35f5dce..a9a9a4c4329de2 100644 --- a/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm +++ b/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm @@ -1204,33 +1204,6 @@ + (RCTManagedPointer *)JS_NativeFrameRateLogger_SpecSetGlobalOptionsOptions:(id) - } - - } // namespace react -} // namespace facebook -namespace facebook { - namespace react { - - - static facebook::jsi::Value __hostFunction_NativeHeapCaptureSpecJSI_captureHeap(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { - return static_cast(turboModule).invokeObjCMethod(rt, VoidKind, "captureHeap", @selector(captureHeap:), args, count); - } - - static facebook::jsi::Value __hostFunction_NativeHeapCaptureSpecJSI_captureComplete(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { - return static_cast(turboModule).invokeObjCMethod(rt, VoidKind, "captureComplete", @selector(captureComplete:error:), args, count); - } - - - NativeHeapCaptureSpecJSI::NativeHeapCaptureSpecJSI(id instance, std::shared_ptr jsInvoker) - : ObjCTurboModule("HeapCapture", instance, jsInvoker) { - - methodMap_["captureHeap"] = MethodMetadata {1, __hostFunction_NativeHeapCaptureSpecJSI_captureHeap}; - - - methodMap_["captureComplete"] = MethodMetadata {2, __hostFunction_NativeHeapCaptureSpecJSI_captureComplete}; - - - } } // namespace react @@ -1522,6 +1495,26 @@ + (RCTManagedPointer *)JS_NativeImageStore_SpecAddImageFromBase64ErrorCallbackEr + } + + } // namespace react +} // namespace facebook +namespace facebook { + namespace react { + + + static facebook::jsi::Value __hostFunction_NativeJSCHeapCaptureSpecJSI_captureComplete(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeObjCMethod(rt, VoidKind, "captureComplete", @selector(captureComplete:error:), args, count); + } + + + NativeJSCHeapCaptureSpecJSI::NativeJSCHeapCaptureSpecJSI(id instance, std::shared_ptr jsInvoker) + : ObjCTurboModule("JSCHeapCapture", instance, jsInvoker) { + + methodMap_["captureComplete"] = MethodMetadata {2, __hostFunction_NativeJSCHeapCaptureSpecJSI_captureComplete}; + + + } } // namespace react diff --git a/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h b/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h index 6bf1ef4a9934c4..c2d82d8f05f51c 100644 --- a/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h +++ b/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h @@ -1304,26 +1304,6 @@ namespace facebook { }; } // namespace react } // namespace facebook -@protocol NativeHeapCaptureSpec - -- (void)captureHeap:(NSString *)path; -- (void)captureComplete:(NSString *)path - error:(NSString * _Nullable)error; - -@end -namespace facebook { - namespace react { - /** - * ObjC++ class for module 'HeapCapture' - */ - - class JSI_EXPORT NativeHeapCaptureSpecJSI : public ObjCTurboModule { - public: - NativeHeapCaptureSpecJSI(id instance, std::shared_ptr jsInvoker); - - }; - } // namespace react -} // namespace facebook namespace JS { namespace NativeI18nManager { @@ -1631,6 +1611,25 @@ namespace facebook { }; } // namespace react } // namespace facebook +@protocol NativeJSCHeapCaptureSpec + +- (void)captureComplete:(NSString *)path + error:(NSString * _Nullable)error; + +@end +namespace facebook { + namespace react { + /** + * ObjC++ class for module 'JSCHeapCapture' + */ + + class JSI_EXPORT NativeJSCHeapCaptureSpecJSI : public ObjCTurboModule { + public: + NativeJSCHeapCaptureSpecJSI(id instance, std::shared_ptr jsInvoker); + + }; + } // namespace react +} // namespace facebook @protocol NativeJSCSamplingProfilerSpec - (void)operationComplete:(double)token diff --git a/Libraries/HeapCapture/HeapCapture.js b/Libraries/HeapCapture/HeapCapture.js index 9cbabc60417487..903343a05b0601 100644 --- a/Libraries/HeapCapture/HeapCapture.js +++ b/Libraries/HeapCapture/HeapCapture.js @@ -10,7 +10,7 @@ 'use strict'; -import NativeHeapCapture from './NativeHeapCapture'; +import NativeJSCHeapCapture from './NativeJSCHeapCapture'; const HeapCapture = { captureHeap: function(path: string) { @@ -22,8 +22,8 @@ const HeapCapture = { console.log('HeapCapture.captureHeap error: ' + e.toString()); error = e.toString(); } - if (NativeHeapCapture) { - NativeHeapCapture.captureComplete(path, error); + if (NativeJSCHeapCapture) { + NativeJSCHeapCapture.captureComplete(path, error); } }, }; diff --git a/Libraries/HeapCapture/NativeHeapCapture.js b/Libraries/HeapCapture/NativeJSCHeapCapture.js similarity index 76% rename from Libraries/HeapCapture/NativeHeapCapture.js rename to Libraries/HeapCapture/NativeJSCHeapCapture.js index 5d778e44771467..05e941f17e7b83 100644 --- a/Libraries/HeapCapture/NativeHeapCapture.js +++ b/Libraries/HeapCapture/NativeJSCHeapCapture.js @@ -14,11 +14,7 @@ import type {TurboModule} from '../TurboModule/RCTExport'; import * as TurboModuleRegistry from '../TurboModule/TurboModuleRegistry'; export interface Spec extends TurboModule { - // Common interface - +captureHeap: (path: string) => void; - - // Android only +captureComplete: (path: string, error: ?string) => void; } -export default (TurboModuleRegistry.get('HeapCapture'): ?Spec); +export default (TurboModuleRegistry.get('JSCHeapCapture'): ?Spec); diff --git a/ReactAndroid/src/main/java/com/facebook/fbreact/specs/NativeJSCHeapCaptureSpec.java b/ReactAndroid/src/main/java/com/facebook/fbreact/specs/NativeJSCHeapCaptureSpec.java new file mode 100644 index 00000000000000..f74a8a12912e92 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/fbreact/specs/NativeJSCHeapCaptureSpec.java @@ -0,0 +1,29 @@ +/** + * 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. + * + *

Generated by an internal genrule from Flow types. + * + * @generated + * @nolint + */ + +package com.facebook.fbreact.specs; + +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactContextBaseJavaModule; +import com.facebook.react.bridge.ReactMethod; +import com.facebook.react.bridge.ReactModuleWithSpec; +import com.facebook.react.turbomodule.core.interfaces.TurboModule; +import javax.annotation.Nullable; + +public abstract class NativeJSCHeapCaptureSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule { + public NativeJSCHeapCaptureSpec(ReactApplicationContext reactContext) { + super(reactContext); + } + + @ReactMethod + public abstract void captureComplete(String path, @Nullable String error); +}