Skip to content

Commit e4e5238

Browse files
committed
Add 'emitAgentEvent' method
1 parent bb33687 commit e4e5238

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

v8-debug.js

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ V8Debug.prototype._unshareSecurityToken = function() {
145145

146146
V8Debug.prototype._wrapDebugCommandProcessor = function() {
147147
var proto = this.get('DebugCommandProcessor.prototype');
148+
this._DebugCommandProcessor = proto;
148149
overrides.processDebugRequest_ = proto.processDebugRequest;
149150
extend(proto, overrides);
150151
overrides.extendedProcessDebugJSONRequestHandles_['disconnect'] = function(request, response) {
@@ -154,23 +155,30 @@ V8Debug.prototype._wrapDebugCommandProcessor = function() {
154155
};
155156

156157
V8Debug.prototype._unwrapDebugCommandProcessor = function() {
157-
var proto = this.get('DebugCommandProcessor.prototype');
158+
var proto = this._DebugCommandProcessor;
158159
proto.processDebugRequest = proto.processDebugRequest_;
159160
delete proto.processDebugRequest_;
160161
delete proto.extendedProcessDebugJSONRequest_;
161162
delete proto.extendedProcessDebugJSONRequestHandles_;
162163
delete proto.extendedProcessDebugJSONRequestAsyncHandles_;
164+
delete this._DebugCommandProcessor;
163165
};
164166

165167
V8Debug.prototype.register =
166168
V8Debug.prototype.registerCommand = function(name, func) {
167-
var proto = this.get('DebugCommandProcessor.prototype');
169+
var proto = this._DebugCommandProcessor;
168170
proto.extendedProcessDebugJSONRequestHandles_[name] = func;
169171
};
170172

173+
V8Debug.prototype.unregister =
174+
V8Debug.prototype.unregisterCommand = function(name, func) {
175+
var proto = this._DebugCommandProcessor;
176+
delete proto.extendedProcessDebugJSONRequestHandles_[name];
177+
};
178+
171179
V8Debug.prototype.registerAsync =
172180
V8Debug.prototype.registerAsyncCommand = function(name, func) {
173-
var proto = this.get('DebugCommandProcessor.prototype');
181+
var proto = this._DebugCommandProcessor;
174182
proto.extendedProcessDebugJSONRequestAsyncHandles_[name] = func;
175183
};
176184

@@ -196,7 +204,7 @@ V8Debug.prototype.commandToEvent = function(request, response) {
196204
};
197205

198206
V8Debug.prototype.registerEvent = function(name) {
199-
var proto = this.get('DebugCommandProcessor.prototype');
207+
var proto = this._DebugCommandProcessor;
200208
proto.extendedProcessDebugJSONRequestHandles_[name] = this.commandToEvent;
201209
};
202210

@@ -237,6 +245,8 @@ V8Debug.prototype.enableWebkitProtocol = function() {
237245

238246
if (this._webkitProtocolEnabled) return;
239247

248+
var nextTmpEventId = 1;
249+
240250
var DebuggerScriptSource,
241251
DebuggerScript,
242252
InjectedScriptSource,
@@ -266,7 +276,19 @@ V8Debug.prototype.enableWebkitProtocol = function() {
266276
parameters = [];
267277
}
268278

269-
this.registerCommand(command, new WebkitProtocolCallback(parameters, callback));
279+
this.registerCommand(command, new WebkitCommandCallback(parameters, callback));
280+
};
281+
282+
this.emitAgentEvent = function(command, callback) {
283+
var handlerName = 'tmpEvent-' + nextTmpEventId++;
284+
this.registerCommand(handlerName, function(request, response) {
285+
this.commandToEvent(request, response);
286+
response.event = command;
287+
288+
new WebkitEventCallback(callback)(request, response);
289+
}.bind(this));
290+
this.sendCommand(handlerName);
291+
this.unregisterCommand(handlerName);
270292
};
271293

272294
this.wrapCallFrames = function(execState, maximumLimit, scopeDetails) {
@@ -288,7 +310,7 @@ V8Debug.prototype.enableWebkitProtocol = function() {
288310

289311
this._webkitProtocolEnabled = true;
290312

291-
function WebkitProtocolCallback(argsList, callback) {
313+
function WebkitCommandCallback(argsList, callback) {
292314
return function(request, response) {
293315
InjectedScriptHost.execState = this.exec_state_;
294316

@@ -301,6 +323,16 @@ V8Debug.prototype.enableWebkitProtocol = function() {
301323
InjectedScriptHost.execState = null;
302324
}
303325
}
326+
327+
function WebkitEventCallback(callback) {
328+
return function(request, response) {
329+
InjectedScriptHost.execState = this.exec_state_;
330+
331+
callback.call(this, response, injectedScript, DebuggerScript);
332+
333+
InjectedScriptHost.execState = null;
334+
}
335+
}
304336
};
305337

306338
V8Debug.prototype.releaseObject =

0 commit comments

Comments
 (0)