Skip to content

Commit

Permalink
Fix NativeJSCHeapCapture
Browse files Browse the repository at this point in the history
Summary:
In D15393464, we introduced `NativeHeapCapture`, but it had a few problems:
1. It required `JSCHeapCapture` by doing `TurboModuleRegistry.get<Spec>('HeapCapture')`, when it should have done `TurboModuleRegistry.get<Spec>('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
  • Loading branch information
RSNara authored and facebook-github-bot committed Jan 14, 2020
1 parent 6bdfd84 commit 7e3a43c
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ObjCTurboModule&>(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<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "captureComplete", @selector(captureComplete:error:), args, count);
}


NativeHeapCaptureSpecJSI::NativeHeapCaptureSpecJSI(id<RCTTurboModule> instance, std::shared_ptr<CallInvoker> jsInvoker)
: ObjCTurboModule("HeapCapture", instance, jsInvoker) {

methodMap_["captureHeap"] = MethodMetadata {1, __hostFunction_NativeHeapCaptureSpecJSI_captureHeap};


methodMap_["captureComplete"] = MethodMetadata {2, __hostFunction_NativeHeapCaptureSpecJSI_captureComplete};



}

} // namespace react
Expand Down Expand Up @@ -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<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "captureComplete", @selector(captureComplete:error:), args, count);
}


NativeJSCHeapCaptureSpecJSI::NativeJSCHeapCaptureSpecJSI(id<RCTTurboModule> instance, std::shared_ptr<CallInvoker> jsInvoker)
: ObjCTurboModule("JSCHeapCapture", instance, jsInvoker) {

methodMap_["captureComplete"] = MethodMetadata {2, __hostFunction_NativeJSCHeapCaptureSpecJSI_captureComplete};



}

} // namespace react
Expand Down
39 changes: 19 additions & 20 deletions Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -1304,26 +1304,6 @@ namespace facebook {
};
} // namespace react
} // namespace facebook
@protocol NativeHeapCaptureSpec <RCTBridgeModule, RCTTurboModule>

- (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<RCTTurboModule> instance, std::shared_ptr<CallInvoker> jsInvoker);

};
} // namespace react
} // namespace facebook

namespace JS {
namespace NativeI18nManager {
Expand Down Expand Up @@ -1631,6 +1611,25 @@ namespace facebook {
};
} // namespace react
} // namespace facebook
@protocol NativeJSCHeapCaptureSpec <RCTBridgeModule, RCTTurboModule>

- (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<RCTTurboModule> instance, std::shared_ptr<CallInvoker> jsInvoker);

};
} // namespace react
} // namespace facebook
@protocol NativeJSCSamplingProfilerSpec <RCTBridgeModule, RCTTurboModule>

- (void)operationComplete:(double)token
Expand Down
6 changes: 3 additions & 3 deletions Libraries/HeapCapture/HeapCapture.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict';

import NativeHeapCapture from './NativeHeapCapture';
import NativeJSCHeapCapture from './NativeJSCHeapCapture';

const HeapCapture = {
captureHeap: function(path: string) {
Expand All @@ -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);
}
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Spec>('HeapCapture'): ?Spec);
export default (TurboModuleRegistry.get<Spec>('JSCHeapCapture'): ?Spec);
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
* directory of this source tree.
*
* <p>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);
}

0 comments on commit 7e3a43c

Please sign in to comment.