diff --git a/Libraries/BatchedBridge/MessageQueue.js b/Libraries/BatchedBridge/MessageQueue.js index 9d3b8c6d66914a..4309de35519cf6 100644 --- a/Libraries/BatchedBridge/MessageQueue.js +++ b/Libraries/BatchedBridge/MessageQueue.js @@ -215,8 +215,40 @@ class MessageQueue { this._queue[METHOD_IDS].push(methodID); if (__DEV__) { - // Any params sent over the bridge should be encodable as JSON - JSON.stringify(params); + // Validate that parameters passed over the bridge are + // folly-convertible. As a special case, if a prop value is a + // function it is permitted here, and special-cased in the + // conversion. + const isValidArgument = val => { + const t = typeof val; + if ( + t === 'undefined' || + t === 'null' || + t === 'boolean' || + t === 'number' || + t === 'string' + ) { + return true; + } + if (t === 'function' || t !== 'object') { + return false; + } + if (Array.isArray(val)) { + return val.every(isValidArgument); + } + for (const k in val) { + if (typeof val[k] !== 'function' && !isValidArgument(val[k])) { + return false; + } + } + return true; + }; + + invariant( + isValidArgument(params), + '%s is not usable as a native method argument', + params, + ); // The params object should not be mutated after being queued deepFreezeAndThrowOnMutationInDev((params: any));