Skip to content

Commit

Permalink
Ignore Apollo DevTools interval check for MessageQueue.spy (#313)
Browse files Browse the repository at this point in the history
* Ignore Apollo DevTools interval check for MessageQueue.spy

* Check JSTimers as module name in isIntervalMatch
  • Loading branch information
jhen0409 authored Feb 5, 2019
1 parent 8cdfb1c commit 89bff60
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions app/worker/apollo.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ export function handleApolloClient(modules) {

initBackend(bridge, hook, getSafeAsyncStorage(modules.AsyncStorage));
}, 1000);
return interval;
}
5 changes: 2 additions & 3 deletions app/worker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ const setupRNDebugger = async message => {
self.__RND_INTERVAL__ = setInterval(function() {}, 100); // eslint-disable-line

const modules = await getRequiredModules(message.moduleSize);
const apolloCheckInterval = handleApolloClient(modules);
if (modules) {
ignoreRNDIntervalSpy(modules);
ignoreRNDIntervalSpy(modules, [apolloCheckInterval]);
checkAvailableDevMenuMethods(modules, message.networkInspect);
reportDefaultReactDevToolsPort(modules);
}

handleApolloClient(modules);
};

const messageHandlers = {
Expand Down
15 changes: 8 additions & 7 deletions app/worker/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,28 +81,29 @@ export const getRequiredModules = async size => {
};

const TO_JS = 0;
const isRNDInterval = info =>
const isIntervalMatch = (intervalIdList, info) =>
info.type === TO_JS &&
info.module === 'JSTimersExecution' &&
(info.module === 'JSTimersExecution' || info.module === 'JSTimers') &&
info.method === 'callTimers' &&
info.args &&
info.args[0] &&
info.args[0][0] === self.__RND_INTERVAL__;
intervalIdList.includes(info.args[0][0]);

export const ignoreRNDIntervalSpy = async ({ MessageQueue }) => {
export const ignoreRNDIntervalSpy = async ({ MessageQueue }, intervals = []) => {
if (MessageQueue.__empty) return;
// Wrap spy function if it already set
const intervalIdList = [self.__RND_INTERVAL__].concat(intervals);
if (MessageQueue.prototype.__spy) {
const originalSpyFn = MessageQueue.prototype.__spy;
MessageQueue.prototype.__spy = info => {
if (isRNDInterval(info)) return;
if (isIntervalMatch(intervalIdList, info)) return;
return originalSpyFn(info);
};
}
MessageQueue.spy = spyOrToggle => {
if (spyOrToggle === true) {
MessageQueue.prototype.__spy = info => {
if (isRNDInterval(info)) return;
if (isIntervalMatch(intervalIdList, info)) return;
console.log(
`${info.type === TO_JS ? 'N->JS' : 'JS->N'} : ` +
`${info.module ? `${info.module}.` : ''}${info.method}` +
Expand All @@ -113,7 +114,7 @@ export const ignoreRNDIntervalSpy = async ({ MessageQueue }) => {
MessageQueue.prototype.__spy = null;
} else {
MessageQueue.prototype.__spy = info => {
if (isRNDInterval(info)) return;
if (isIntervalMatch(intervalIdList, info)) return;
return spyOrToggle(info);
};
}
Expand Down

0 comments on commit 89bff60

Please sign in to comment.