forked from jsantell/firefox-patches
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1019964-call-watcher-weak-ref.patch
140 lines (126 loc) · 4.79 KB
/
1019964-call-watcher-weak-ref.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
From 7a169cbcf6bc4dd42dffb871aa8ec72885a307ed Mon Sep 17 00:00:00 2001
From: Jordan Santell <[email protected]>
Date: Mon, 16 Jun 2014 08:03:52 -0700
Subject: Bug 1019964 - Add an option to CallWatcher to only store weak references. r=vp
---
toolkit/devtools/server/actors/call-watcher.js | 36 +++++++++++++++++++++-----
toolkit/devtools/server/actors/webaudio.js | 3 ++-
2 files changed, 32 insertions(+), 7 deletions(-)
diff --git a/toolkit/devtools/server/actors/call-watcher.js b/toolkit/devtools/server/actors/call-watcher.js
index 3c986d9..cc2eddc 100644
--- a/toolkit/devtools/server/actors/call-watcher.js
+++ b/toolkit/devtools/server/actors/call-watcher.js
@@ -68,25 +68,47 @@ let FunctionCallActor = protocol.ActorClass({
* The called function's arguments.
* @param any result
* The value returned by the function call.
*/
initialize: function(conn, [window, global, caller, type, name, stack, args, result]) {
protocol.Actor.prototype.initialize.call(this, conn);
this.details = {
- window: window,
- caller: caller,
type: type,
name: name,
stack: stack,
- args: args,
- result: result
};
+ // Store a weak reference to all objects so we don't
+ // prevent natural GC if `holdWeak` was passed into
+ // setup as truthy. Used in the Web Audio Editor.
+ if (this._holdWeak) {
+ let weakRefs = {
+ window: Cu.getWeakReference(window),
+ caller: Cu.getWeakReference(caller),
+ result: Cu.getWeakReference(result),
+ args: Cu.getWeakReference(args)
+ };
+
+ Object.defineProperties(this.details, {
+ window: { get: () => weakRefs.window.get() },
+ caller: { get: () => weakRefs.caller.get() },
+ result: { get: () => weakRefs.result.get() },
+ args: { get: () => weakRefs.args.get() }
+ });
+ }
+ // Otherwise, hold strong references to the objects.
+ else {
+ this.details.window = window;
+ this.details.caller = caller;
+ this.details.result = result;
+ this.details.args = args;
+ }
+
this.meta = {
global: -1,
previews: { caller: "", args: "" }
};
if (global == "WebGLRenderingContext") {
this.meta.global = CallWatcherFront.CANVAS_WEBGL_CONTEXT;
} else if (global == "CanvasRenderingContext2D") {
@@ -241,42 +263,44 @@ let CallWatcherActor = exports.CallWatcherActor = protocol.ActorClass({
this.finalize();
},
/**
* Starts waiting for the current tab actor's document global to be
* created, in order to instrument the specified objects and become
* aware of everything the content does with them.
*/
- setup: method(function({ tracedGlobals, tracedFunctions, startRecording, performReload }) {
+ setup: method(function({ tracedGlobals, tracedFunctions, startRecording, performReload, holdWeak }) {
if (this._initialized) {
return;
}
this._initialized = true;
this._functionCalls = [];
this._tracedGlobals = tracedGlobals || [];
this._tracedFunctions = tracedFunctions || [];
+ this._holdWeak = !!holdWeak;
this._contentObserver = new ContentObserver(this.tabActor);
on(this._contentObserver, "global-created", this._onGlobalCreated);
on(this._contentObserver, "global-destroyed", this._onGlobalDestroyed);
if (startRecording) {
this.resumeRecording();
}
if (performReload) {
this.tabActor.window.location.reload();
}
}, {
request: {
tracedGlobals: Option(0, "nullable:array:string"),
tracedFunctions: Option(0, "nullable:array:string"),
startRecording: Option(0, "boolean"),
- performReload: Option(0, "boolean")
+ performReload: Option(0, "boolean"),
+ holdWeak: Option(0, "boolean")
},
oneway: true
}),
/**
* Stops listening for document global changes and puts this actor
* to hibernation. This method is called automatically just before the
* actor is destroyed.
diff --git a/toolkit/devtools/server/actors/webaudio.js b/toolkit/devtools/server/actors/webaudio.js
index 9e7523a..b3fc7e5 100644
--- a/toolkit/devtools/server/actors/webaudio.js
+++ b/toolkit/devtools/server/actors/webaudio.js
@@ -313,17 +313,18 @@ let WebAudioActor = exports.WebAudioActor = protocol.ActorClass({
this._initialized = true;
this._callWatcher = new CallWatcherActor(this.conn, this.tabActor);
this._callWatcher.onCall = this._onContentFunctionCall;
this._callWatcher.setup({
tracedGlobals: AUDIO_GLOBALS,
startRecording: true,
- performReload: reload
+ performReload: reload,
+ holdWeak: true
});
}, {
request: { reload: Option(0, "boolean") },
oneway: true
}),
/**
* Invoked whenever an instrumented function is called, like an AudioContext
--
1.8.4.2