Skip to content

Commit 7ea8e79

Browse files
committed
Add 'releaseObject' API
1 parent 39a2fc0 commit 7ea8e79

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

InjectedScript/InjectedScriptHost.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
var id = lastBoundObjectId++;
1919
idToWrappedObject.set(id, value);
2020

21-
if (!groupName) return;
2221
if (id < 0) return;
22+
if (groupName == null) return id;
2323

2424
idToObjectGroupName.set(id, groupName);
2525

@@ -31,6 +31,33 @@
3131
return id;
3232
};
3333

34+
InjectedScriptHost.prototype.unbind = function(id) {
35+
idToWrappedObject.delete(id);
36+
idToObjectGroupName.delete(id);
37+
};
38+
39+
InjectedScriptHost.prototype.releaseObject = function(objectId) {
40+
var parsedObjectId;
41+
try {
42+
parsedObjectId = JSON.parse(objectId);
43+
} catch (e) { return; }
44+
45+
this.unbind(parsedObjectId.id);
46+
};
47+
48+
InjectedScriptHost.prototype.releaseObjectGroup = function(groupName) {
49+
if (!groupName) return;
50+
51+
var group = nameToObjectGroup.get(groupName);
52+
if (!group) return;
53+
54+
group.forEach(function(id) {
55+
this.unbind(id);
56+
}, this);
57+
58+
nameToObjectGroup.delete(groupName);
59+
};
60+
3461
InjectedScriptHost.prototype.objectForId = function(id) {
3562
if (!Number(id)) return;
3663
return idToWrappedObject.get(id);

v8-debug.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ function sendCommand(name, attributes, userdata) {
182182
seq: 0,
183183
type: 'request',
184184
command: name,
185-
arguments: attributes || {}
185+
arguments: attributes
186186
};
187187
binding.sendCommand(JSON.stringify(message));
188188
};
@@ -256,9 +256,9 @@ V8Debug.prototype.enableWebkitProtocol = function() {
256256
InjectedScriptHost = this.runInDebugContext(InjectedScriptHostSource)(binding, DebuggerScript);
257257

258258
JavaScriptCallFrameSource = fs.readFileSync(JavaScriptCallFrameLink, 'utf8');
259-
JavaScriptCallFrame = this.runInDebugContext(JavaScriptCallFrameSource)(binding, DebuggerScript);
259+
JavaScriptCallFrame = this.runInDebugContext(JavaScriptCallFrameSource)(binding);
260260

261-
var injectedScript = InjectedScript(InjectedScriptHost, global, 1);
261+
var injectedScript = InjectedScript(InjectedScriptHost, global, process.pid);
262262

263263
this.registerAgentCommand = function(command, parameters, callback) {
264264
if (typeof parameters === 'function') {
@@ -274,8 +274,16 @@ V8Debug.prototype.enableWebkitProtocol = function() {
274274

275275
if (maximumLimit < 0) throw new Error('Incorrect stack trace limit.');
276276
var data = (maximumLimit << scopeBits) | scopeDetails;
277+
var currentCallFrame = DebuggerScript.currentCallFrame(execState, data);
278+
return new JavaScriptCallFrame(currentCallFrame);
279+
};
280+
281+
this.releaseObject = function(name) {
282+
return InjectedScriptHost.releaseObject(name);
283+
};
277284

278-
return JavaScriptCallFrame.currentCallFrame(execState, data);;
285+
this.releaseObjectGroup = function(name) {
286+
return InjectedScriptHost.releaseObjectGroup(name);
279287
};
280288

281289
this._webkitProtocolEnabled = true;
@@ -295,6 +303,8 @@ V8Debug.prototype.enableWebkitProtocol = function() {
295303
}
296304
};
297305

306+
V8Debug.prototype.releaseObject =
307+
V8Debug.prototype.releaseObjectGroup =
298308
V8Debug.prototype.wrapCallFrames =
299309
V8Debug.prototype.registerAgentCommand = function(command, parameters, callback) {
300310
throw new Error('Use "enableWebkitProtocol" before using this method');

0 commit comments

Comments
 (0)