Skip to content

Commit

Permalink
[react_native] JS files from D2027955: [react_native] Add bridge 'spy…
Browse files Browse the repository at this point in the history
… mode' to watch bridge traffic
  • Loading branch information
astreet committed Apr 29, 2015
1 parent 1cff06d commit 96850b7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Libraries/Utilities/MessageQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ var JSTimersExecution = require('JSTimersExecution');

var INTERNAL_ERROR = 'Error in MessageQueue implementation';

// Prints all bridge traffic to console.log
var DEBUG_SPY_MODE = false;

type ModulesConfig = {
[key:string]: {
moduleID: number;
Expand Down Expand Up @@ -263,6 +266,9 @@ var MessageQueueMixin = {
'both the success callback and the error callback.',
cbID
);
if (DEBUG_SPY_MODE) {
console.log('N->JS: Callback#' + cbID + '(' + JSON.stringify(args) + ')');
}
cb.apply(scope, args);
} catch(ie_requires_catch) {
throw ie_requires_catch;
Expand Down Expand Up @@ -292,6 +298,11 @@ var MessageQueueMixin = {
var moduleName = this._localModuleIDToModuleName[moduleID];

var methodName = this._localModuleNameToMethodIDToName[moduleName][methodID];
if (DEBUG_SPY_MODE) {
console.log(
'N->JS: ' + moduleName + '.' + methodName +
'(' + JSON.stringify(params) + ')');
}
var ret = jsCall(this._requireFunc(moduleName), methodName, params);

return ret;
Expand Down Expand Up @@ -460,6 +471,17 @@ var MessageQueueMixin = {
var ret = currentOutgoingItems[REQUEST_MODULE_IDS].length ||
currentOutgoingItems[RESPONSE_RETURN_VALUES].length ? currentOutgoingItems : null;

if (DEBUG_SPY_MODE && ret) {
for (var i = 0; i < currentOutgoingItems[0].length; i++) {
var moduleName = this._remoteModuleIDToModuleName[currentOutgoingItems[0][i]];
var methodName =
this._remoteModuleNameToMethodIDToName[moduleName][currentOutgoingItems[1][i]];
console.log(
'JS->N: ' + moduleName + '.' + methodName +
'(' + JSON.stringify(currentOutgoingItems[2][i]) + ')');
}
}

return ret;
},

Expand Down

0 comments on commit 96850b7

Please sign in to comment.