Skip to content

Commit 0226457

Browse files
committed
Fix 'runInDebugContext' method
1 parent de506f8 commit 0226457

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

v8-debug.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,14 @@ V8Debug.prototype._unwrapDebugCommandProcessor = function() {
163163

164164
V8Debug.prototype.register =
165165
V8Debug.prototype.registerCommand = function(name, func) {
166-
overrides.extendedProcessDebugJSONRequestHandles_[name] = func;
166+
var proto = this.get('DebugCommandProcessor.prototype');
167+
proto.extendedProcessDebugJSONRequestHandles_[name] = func;
167168
};
168169

169170
V8Debug.prototype.registerAsync =
170171
V8Debug.prototype.registerAsyncCommand = function(name, func) {
171-
overrides.extendedProcessDebugJSONRequestAsyncHandles_[name] = func;
172+
var proto = this.get('DebugCommandProcessor.prototype');
173+
proto.extendedProcessDebugJSONRequestAsyncHandles_[name] = func;
172174
};
173175

174176
V8Debug.prototype.command =
@@ -193,14 +195,13 @@ V8Debug.prototype.commandToEvent = function(request, response) {
193195
};
194196

195197
V8Debug.prototype.registerEvent = function(name) {
196-
overrides.extendedProcessDebugJSONRequestHandles_[name] = this.commandToEvent;
198+
var proto = this.get('DebugCommandProcessor.prototype');
199+
proto.extendedProcessDebugJSONRequestHandles_[name] = this.commandToEvent;
197200
};
198201

199202
V8Debug.prototype.get =
200203
V8Debug.prototype.runInDebugContext = function(script) {
201-
if (typeof script == 'function') script = script.toString() + '()';
202-
203-
script = /\);$/.test(script) ? script : '(' + script + ');';
204+
if (typeof script == 'function') script = '(' + script.toString() + ')()';
204205

205206
return binding.runScript(script);
206207
};
@@ -242,25 +243,25 @@ V8Debug.prototype.enableWebkitProtocol = function() {
242243
InjectedScriptHostSource,
243244
InjectedScriptHost;
244245

245-
function prepareSource(source) {
246-
return 'var ToggleMirrorCache = ToggleMirrorCache || function() {};\n' +
247-
'(function() {' +
248-
('' + source).replace(/^.*?"use strict";(\r?\n.*?)*\(/m, '\r\n"use strict";\nreturn (') +
249-
'}());';
250-
}
246+
this.runInDebugContext('ToggleMirrorCache = ToggleMirrorCache || function() {}');
251247

252-
DebuggerScriptSource = prepareSource(fs.readFileSync(DebuggerScriptLink, 'utf8'));
248+
DebuggerScriptSource = fs.readFileSync(DebuggerScriptLink, 'utf8');
253249
DebuggerScript = this.runInDebugContext(DebuggerScriptSource);
254250

255-
InjectedScriptSource = prepareSource(fs.readFileSync(InjectedScriptLink, 'utf8'));
251+
InjectedScriptSource = fs.readFileSync(InjectedScriptLink, 'utf8');
256252
InjectedScript = this.runInDebugContext(InjectedScriptSource);
257253

258-
InjectedScriptHostSource = prepareSource(fs.readFileSync(InjectedScriptHostLink, 'utf8'));
254+
InjectedScriptHostSource = fs.readFileSync(InjectedScriptHostLink, 'utf8');
259255
InjectedScriptHost = this.runInDebugContext(InjectedScriptHostSource)(binding, DebuggerScript);
260256

261257
var injectedScript = InjectedScript(InjectedScriptHost, global, 1);
262258

263259
this.registerAgentCommand = function(command, parameters, callback) {
260+
if (typeof parameters === 'function') {
261+
callback = parameters;
262+
parameters = [];
263+
}
264+
264265
this.registerCommand(command, new WebkitProtocolCallback(parameters, callback));
265266
};
266267

0 commit comments

Comments
 (0)