From 96850b7429503ec831f0d170da61ff13e22b7f34 Mon Sep 17 00:00:00 2001 From: Andy Street Date: Wed, 29 Apr 2015 11:54:26 -0700 Subject: [PATCH] [react_native] JS files from D2027955: [react_native] Add bridge 'spy mode' to watch bridge traffic --- Libraries/Utilities/MessageQueue.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Libraries/Utilities/MessageQueue.js b/Libraries/Utilities/MessageQueue.js index 576aaa991..97658c235 100644 --- a/Libraries/Utilities/MessageQueue.js +++ b/Libraries/Utilities/MessageQueue.js @@ -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; @@ -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; @@ -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; @@ -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; },