Skip to content

Commit

Permalink
devtools: introduce ability to subscribe/unsubscribe debugger events
Browse files Browse the repository at this point in the history
  • Loading branch information
darwin committed Sep 1, 2016
1 parent 75065e3 commit 1cb0a0c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
10 changes: 10 additions & 0 deletions resources/unpacked/devtools/front_end/dirac/dirac.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ Object.assign(window.dirac, (function() {
return loadLazyDirac().then(() => window.dirac.hasDefaultContext(...args));
}

function subscribeDebuggerEvents(...args) {
return loadLazyDirac().then(() => window.dirac.subscribeDebuggerEvents(...args));
}

function unsubscribeDebuggerEvents(...args) {
return loadLazyDirac().then(() => window.dirac.unsubscribeDebuggerEvents(...args));
}

function addConsoleMessageToMainTarget(...args) {
return loadLazyDirac().then(() => window.dirac.addConsoleMessageToMainTarget(...args));
}
Expand Down Expand Up @@ -199,6 +207,8 @@ Object.assign(window.dirac, (function() {
hasCurrentContext: hasCurrentContext,
evalInDefaultContext: evalInDefaultContext,
hasDefaultContext: hasDefaultContext,
subscribeDebuggerEvents: subscribeDebuggerEvents,
unsubscribeDebuggerEvents: unsubscribeDebuggerEvents,
addConsoleMessageToMainTarget: addConsoleMessageToMainTarget,
startListeningForWorkspaceChanges: startListeningForWorkspaceChanges,
stopListeningForWorkspaceChanges: stopListeningForWorkspaceChanges,
Expand Down
32 changes: 32 additions & 0 deletions resources/unpacked/devtools/front_end/dirac_lazy/dirac_lazy.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,36 @@ Object.assign(window.dirac, (function() {
evalInContext(lookupDefaultContext(), code, callback);
}

let debuggerEventsUnsubscriber = null;

function subscribeDebuggerEvents(callback) {
if (debuggerEventsUnsubscriber) {
return false;
}
const globalObjectClearedHandler = (...args) => {
callback("GlobalObjectCleared", ...args);
};

WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebInspector.DebuggerModel.Events.GlobalObjectCleared, globalObjectClearedHandler, this);

debuggerEventsUnsubscriber = () => {
WebInspector.targetManager.removeModelListener(WebInspector.DebuggerModel, WebInspector.DebuggerModel.Events.GlobalObjectCleared, globalObjectClearedHandler, this);
return true;
};

return true;
}

function unsubscribeDebuggerEvents() {
if (!debuggerEventsUnsubscriber) {
return false;
}

const res = debuggerEventsUnsubscriber();
debuggerEventsUnsubscriber = null;
return res;
}

// --- console ----------------------------------------------------------------------------------------------------------

function addConsoleMessageToMainTarget(level, text, parameters) {
Expand Down Expand Up @@ -771,6 +801,8 @@ Object.assign(window.dirac, (function() {
hasCurrentContext: hasCurrentContext,
evalInDefaultContext: evalInDefaultContext,
hasDefaultContext: hasDefaultContext,
subscribeDebuggerEvents: subscribeDebuggerEvents,
unsubscribeDebuggerEvents: unsubscribeDebuggerEvents,
addConsoleMessageToMainTarget: addConsoleMessageToMainTarget,
startListeningForWorkspaceChanges: startListeningForWorkspaceChanges,
stopListeningForWorkspaceChanges: stopListeningForWorkspaceChanges,
Expand Down
10 changes: 10 additions & 0 deletions resources/unpacked/devtools/front_end/externs.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,16 @@ var dirac = {
*/
hasDefaultContext: function() {},

/**
* @param {?} callback
* @return {boolean}
*/
subscribeDebuggerEvents: function(callback) {},
/**
* @return {boolean}
*/
unsubscribeDebuggerEvents: function() {},

/**
* @param {?} callFrame
* @return {!Promise<!dirac.ScopeInfo>}
Expand Down

0 comments on commit 1cb0a0c

Please sign in to comment.