Skip to content

Commit

Permalink
Forward VM version to inspector
Browse files Browse the repository at this point in the history
Reviewed By: bnham

Differential Revision: D6938018

fbshipit-source-id: c79853ddf835acab86a16ebd539874d29d3aa60a
  • Loading branch information
pakoito authored and Plo4ox committed Feb 17, 2018
1 parent dfc1340 commit b6d9f4a
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 14 deletions.
1 change: 1 addition & 0 deletions React/Inspector/RCTInspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
@interface RCTInspectorPage : NSObject
@property (nonatomic, readonly) NSInteger id;
@property (nonatomic, readonly) NSString *title;
@property (nonatomic, readonly) NSString *vm;
@end

@interface RCTInspector : NSObject
Expand Down
9 changes: 7 additions & 2 deletions React/Inspector/RCTInspector.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ virtual void onDisconnect() override {
@interface RCTInspectorPage () {
NSInteger _id;
NSString *_title;
NSString *_vm;
}
- (instancetype)initWithId:(NSInteger)id
title:(NSString *)title;
title:(NSString *)title
vm:(NSString *)vm;
@end

@interface RCTInspectorLocalConnection () {
Expand All @@ -64,7 +66,8 @@ @implementation RCTInspector
NSMutableArray<RCTInspectorPage *> *array = [NSMutableArray arrayWithCapacity:pages.size()];
for (size_t i = 0; i < pages.size(); i++) {
RCTInspectorPage *pageWrapper = [[RCTInspectorPage alloc] initWithId:pages[i].id
title:@(pages[i].title.c_str())];
title:@(pages[i].title.c_str())
vm:@(pages[i].vm.c_str())];
[array addObject:pageWrapper];

}
Expand All @@ -86,10 +89,12 @@ @implementation RCTInspectorPage

- (instancetype)initWithId:(NSInteger)id
title:(NSString *)title
vm:(NSString *)vm
{
if (self = [super init]) {
_id = id;
_title = title;
_vm = vm;
}
return self;
}
Expand Down
1 change: 1 addition & 0 deletions React/Inspector/RCTInspectorPackagerConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ - (NSArray *)pages
@"id": [@(page.id) stringValue],
@"title": page.title,
@"app": [[NSBundle mainBundle] bundleIdentifier],
@"vm": page.vm,
@"isLastBundleDownloadSuccess": bundleStatus == nil
? [NSNull null]
: @(bundleStatus.isLastBundleDownloadSuccess),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private Inspector(HybridData hybridData) {
public static class Page {
private final int mId;
private final String mTitle;
private final String mVM;

public int getId() {
return mId;
Expand All @@ -60,6 +61,10 @@ public String getTitle() {
return mTitle;
}

public String getVM() {
return mVM;
}

@Override
public String toString() {
return "Page{" +
Expand All @@ -69,9 +74,10 @@ public String toString() {
}

@DoNotStrip
private Page(int id, String title) {
private Page(int id, String title, String vm) {
mId = id;
mTitle = title;
mVM = vm;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ private JSONArray getPages() throws JSONException {
jsonPage.put("id", String.valueOf(page.getId()));
jsonPage.put("title", page.getTitle());
jsonPage.put("app", mPackageName);
jsonPage.put("vm", page.getVM());
jsonPage.put("isLastBundleDownloadSuccess", bundleStatus.isLastDownloadSucess);
jsonPage.put("bundleUpdateTimestamp", bundleStatus.updateTimestamp);
array.put(jsonPage);
Expand Down
8 changes: 4 additions & 4 deletions ReactAndroid/src/main/jni/react/jni/JInspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class RemoteConnection : public IRemoteConnection {

}

jni::local_ref<JPage::javaobject> JPage::create(int id, const std::string& title) {
static auto constructor = javaClassStatic()->getConstructor<JPage::javaobject(jint, jni::local_ref<jni::JString>)>();
return javaClassStatic()->newObject(constructor, id, jni::make_jstring(title));
jni::local_ref<JPage::javaobject> JPage::create(int id, const std::string& title, const std::string& vm) {
static auto constructor = javaClassStatic()->getConstructor<JPage::javaobject(jint, jni::local_ref<jni::JString>, jni::local_ref<jni::JString>)>();
return javaClassStatic()->newObject(constructor, id, jni::make_jstring(title), jni::make_jstring(vm));
}

void JRemoteConnection::onMessage(const std::string& message) const {
Expand Down Expand Up @@ -70,7 +70,7 @@ jni::local_ref<jni::JArrayClass<JPage::javaobject>> JInspector::getPages() {
std::vector<InspectorPage> pages = inspector_->getPages();
auto array = jni::JArrayClass<JPage::javaobject>::newArray(pages.size());
for (size_t i = 0; i < pages.size(); i++) {
(*array)[i] = JPage::create(pages[i].id, pages[i].title);
(*array)[i] = JPage::create(pages[i].id, pages[i].title, pages[i].vm);
}
return array;
}
Expand Down
2 changes: 1 addition & 1 deletion ReactAndroid/src/main/jni/react/jni/JInspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class JPage : public jni::JavaClass<JPage> {
public:
static constexpr auto kJavaDescriptor = "Lcom/facebook/react/bridge/Inspector$Page;";

static jni::local_ref<JPage::javaobject> create(int id, const std::string& title);
static jni::local_ref<JPage::javaobject> create(int id, const std::string& title, const std::string& vm);
};

class JRemoteConnection : public jni::JavaClass<JRemoteConnection> {
Expand Down
11 changes: 6 additions & 5 deletions ReactCommon/jsinspector/InspectorInterfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <mutex>
#include <unordered_map>
#include <tuple>

namespace facebook {
namespace react {
Expand All @@ -27,7 +28,7 @@ namespace {

class InspectorImpl : public IInspector {
public:
int addPage(const std::string& title, ConnectFunc connectFunc) override;
int addPage(const std::string& title, const std::string& vm, ConnectFunc connectFunc) override;
void removePage(int pageId) override;

std::vector<InspectorPage> getPages() const override;
Expand All @@ -38,15 +39,15 @@ class InspectorImpl : public IInspector {
private:
mutable std::mutex mutex_;
int nextPageId_{1};
std::unordered_map<int, std::string> titles_;
std::unordered_map<int, std::tuple<std::string, std::string>> titles_;
std::unordered_map<int, ConnectFunc> connectFuncs_;
};

int InspectorImpl::addPage(const std::string& title, ConnectFunc connectFunc) {
int InspectorImpl::addPage(const std::string& title, const std::string& vm, ConnectFunc connectFunc) {
std::lock_guard<std::mutex> lock(mutex_);

int pageId = nextPageId_++;
titles_[pageId] = title;
titles_[pageId] = std::make_tuple(title, vm);
connectFuncs_[pageId] = std::move(connectFunc);

return pageId;
Expand All @@ -64,7 +65,7 @@ std::vector<InspectorPage> InspectorImpl::getPages() const {

std::vector<InspectorPage> inspectorPages;
for (auto& it : titles_) {
inspectorPages.push_back(InspectorPage{it.first, it.second});
inspectorPages.push_back(InspectorPage{it.first, std::get<0>(it.second), std::get<1>(it.second)});
}

return inspectorPages;
Expand Down
3 changes: 2 additions & 1 deletion ReactCommon/jsinspector/InspectorInterfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class IDestructible {
struct InspectorPage {
const int id;
const std::string title;
const std::string vm;
};

/// IRemoteConnection allows the VM to send debugger messages to the client.
Expand Down Expand Up @@ -52,7 +53,7 @@ class IInspector : public IDestructible {
virtual ~IInspector() = 0;

/// addPage is called by the VM to add a page to the list of debuggable pages.
virtual int addPage(const std::string& title, ConnectFunc connectFunc) = 0;
virtual int addPage(const std::string& title, const std::string& vm, ConnectFunc connectFunc) = 0;

/// removePage is called by the VM to remove a page from the list of
/// debuggable pages.
Expand Down

0 comments on commit b6d9f4a

Please sign in to comment.