Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v10] RN debugger fixes #3368

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/browser/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@

import { keys, objectTypes } from './constants';
import { createMethods } from './util';
import { createAppRPC } from "./rpc";

function setupApp(app, info) {
app[keys.id] = info.id;
app[keys.realm] = info.realmId;
app[keys.type] = objectTypes.APP;
}

export default class App {
constructor(config) {
let info = createAppRPC(config);
setupApp(this, info);
}
}

createMethods(App.prototype, objectTypes.APP, [
Expand All @@ -36,7 +47,8 @@ export function createApp(realmId, info) {

// FIXME: This is currently necessary because util/createMethod expects
// the realm id to be present on any object that is used over rpc
appProxy[keys.realm] = "(App object)";
// appProxy[keys.realm] = "(App object)";
appProxy[keys.realm] = realmId;

appProxy[keys.id] = info.id;
appProxy[keys.type] = objectTypes.APP;
Expand Down
5 changes: 1 addition & 4 deletions lib/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import App, { createApp } from './app';
import Credentials, { createCredentials } from './credentials';
import * as rpc from './rpc';
import * as util from './util';
import { static as staticUserMethods } from '../user';
import { createSession } from './session';
import { invalidateCache } from './cache';

Expand Down Expand Up @@ -212,9 +211,7 @@ Object.defineProperties(Realm, {

for (let i = 0, len = debugHosts.length; i < len; i++) {
try {
let refreshAccessTokenCallback = staticUserMethods && staticUserMethods._refreshAccessToken ? staticUserMethods._refreshAccessToken.bind(User) : () => {};
// The session ID refers to the Realm constructor object in the RPC server.
Realm[keys.id] = createSession(refreshAccessTokenCallback, debugHosts[i] + ':' + debugPort);
Realm[keys.id] = rpc.createSession(debugHosts[i] + ":" + debugPort);
break;
} catch (e) {
// Only throw exception after all hosts have been tried.
Expand Down
12 changes: 12 additions & 0 deletions lib/browser/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ function beforeNotify(realm) {
invalidateCache(realm[keys.realm]);
}


export function createSession(host) {
sessionHost = host;
sessionId = sendRequest("create_session", null, host);

return sessionId;
}

export function createRealm(args) {
if (args) {
args = args.map((arg) => serialize(null, arg));
Expand All @@ -73,6 +81,10 @@ export function createRealm(args) {
return sendRequest('create_realm', { arguments: args, beforeNotify: serialize(null, beforeNotify) });
}

export function createAppRPC(config) {
return sendRequest("create_app", { arguments: [ serialize(null, config) ] });
}

export function asyncOpenRealm(id, config, callback) {
return deserialize(undefined, sendRequest('call_method', {
id,
Expand Down
24 changes: 24 additions & 0 deletions src/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,15 @@ RPCServer::RPCServer() {
setIncludesNativeCallStack(m_context, false);
}

m_requests["/create_session"] = [this](const json dict) {
RJSInitializeInContext(m_context);

jsc::String realm_string = "Realm";
JSObjectRef realm_constructor = jsc::Object::validated_get_constructor(m_context, JSContextGetGlobalObject(m_context), realm_string);

m_session_id = store_object(realm_constructor);
return (json){{"result", m_session_id}};
};
m_requests["/create_realm"] = [this](const json dict) {
JSObjectRef realm_constructor = get_realm_constructor();

Expand All @@ -270,6 +279,21 @@ RPCServer::RPCServer() {

return (json){{"result", serialize_json_value(realm_object)}};
};
m_requests["/create_app"] = [this](const json dict) {
JSObjectRef realm_constructor = get_realm_constructor();
JSObjectRef app_constructor = (JSObjectRef)jsc::Object::get_property(m_context, realm_constructor, "App");

json::array_t args = dict["arguments"];
size_t arg_count = args.size();
JSValueRef arg_values[arg_count];

for (size_t i = 0; i < arg_count; i++) {
arg_values[i] = deserialize_json_value(args[i]);
}

JSObjectRef app_object = jsc::Function::construct(m_context, app_constructor, arg_count, arg_values);
return (json){{"result", serialize_json_value(app_object)}};
};
m_requests["/create_user"] = [this](const json dict) {
JSObjectRef realm_constructor = get_realm_constructor();

Expand Down