-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1006283-paramlist-data-type.patch
197 lines (177 loc) · 7.69 KB
/
1006283-paramlist-data-type.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
From 4fa2985cab58bbb25fd65c7fb0bf5000df8f2ebb Mon Sep 17 00:00:00 2001
From: Jordan Santell <[email protected]>
Date: Tue, 6 May 2014 12:02:38 -0700
Subject: Bug 1006283 - Set and display proper type on AudioParams for
web audio editor, r=vp
---
.../test/browser_audionode-actor-get-set-param.js | 4 ----
.../test/browser_wa_params_view_edit.js | 20 ++++++++++++++------
browser/devtools/webaudioeditor/test/head.js | 4 ++--
.../devtools/webaudioeditor/webaudioeditor-view.js | 13 +++++++++++--
toolkit/devtools/server/actors/webaudio.js | 9 ++-------
5 files changed, 29 insertions(+), 21 deletions(-)
diff --git a/browser/devtools/webaudioeditor/test/browser_audionode-actor-get-set-param.js b/browser/devtools/webaudioeditor/test/browser_audionode-actor-get-set-param.js
index ecfe79e..4748217 100644
--- a/browser/devtools/webaudioeditor/test/browser_audionode-actor-get-set-param.js
+++ b/browser/devtools/webaudioeditor/test/browser_audionode-actor-get-set-param.js
@@ -27,20 +27,16 @@ function spawnTest () {
ise(freq, 220, "AudioNode:setParam correctly sets a `number` AudioParam");
is(resSuccess, undefined, "AudioNode:setParam returns undefined for correctly set AudioParam");
resSuccess = yield oscNode.setParam("type", "square");
let type = yield oscNode.getParam("type");
ise(type, "square", "AudioNode:setParam correctly sets a `string` non-AudioParam");
is(resSuccess, undefined, "AudioNode:setParam returns undefined for correctly set AudioParam");
- resSuccess = yield oscNode.setParam("type", "\"triangle\"");
- type = yield oscNode.getParam("type");
- ise(type, "triangle", "AudioNode:setParam correctly removes quotes in `string` non-AudioParam");
-
try {
yield oscNode.setParam("frequency", "hello");
ok(false, "setParam with invalid types should throw");
} catch (e) {
ok(/is not a finite floating-point/.test(e.message), "AudioNode:setParam returns error with correct message when attempting an invalid assignment");
is(e.type, "TypeError", "AudioNode:setParam returns error with correct type when attempting an invalid assignment");
freq = yield oscNode.getParam("frequency");
ise(freq, 220, "AudioNode:setParam does not modify value when an error occurs");
diff --git a/browser/devtools/webaudioeditor/test/browser_wa_params_view_edit.js b/browser/devtools/webaudioeditor/test/browser_wa_params_view_edit.js
index d1ead4f..9a05d9e 100644
--- a/browser/devtools/webaudioeditor/test/browser_wa_params_view_edit.js
+++ b/browser/devtools/webaudioeditor/test/browser_wa_params_view_edit.js
@@ -14,29 +14,37 @@ function spawnTest() {
reload(target);
let [[dest, osc, gain], [[_, destID], [_, oscID], [_, gainID]]] = yield Promise.all([
get3(gFront, "create-node"),
get3Spread(panel.panelWin, EVENTS.UI_ADD_NODE_LIST)
]);
+ let setAndCheck = setAndCheckVariable(panel.panelWin, gVars);
checkVariableView(gVars, 1, {
"type": "\"sine\"",
"frequency": 440,
"detune": 0
- });
+ }, "default loaded string");
checkVariableView(gVars, 2, {
"gain": 0
- });
+ }, "default loaded number");
- yield modifyVariableView(panel.panelWin, gVars, 1, "type", "square");
+ yield setAndCheck(1, "type", "\"square\"", "\"square\"", "sets string as string");
- checkVariableView(gVars, 1, {
- "type": "\"square\""
- });
+ yield setAndCheck(2, "gain", 0.005, 0.005, "sets number as number");
yield teardown(panel);
finish();
}
+function setAndCheckVariable (panelWin, gVars) {
+ return Task.async(function (varNum, prop, value, expected, desc) {
+ yield modifyVariableView(panelWin, gVars, varNum, prop, value);
+ var props = {};
+ props[prop] = expected;
+ checkVariableView(gVars, varNum, props, desc);
+ });
+}
+
diff --git a/browser/devtools/webaudioeditor/test/head.js b/browser/devtools/webaudioeditor/test/head.js
index b9e310d..5863381 100644
--- a/browser/devtools/webaudioeditor/test/head.js
+++ b/browser/devtools/webaudioeditor/test/head.js
@@ -206,25 +206,25 @@ function waitForGraphRendered (front, nodeCount, edgeCount) {
if (nodes === nodeCount && edges === edgeCount) {
front.off(eventName, onGraphRendered);
deferred.resolve();
}
});
return deferred.promise;
}
-function checkVariableView (view, index, hash) {
+function checkVariableView (view, index, hash, description = "") {
let scope = view.getScopeAtIndex(index);
let variables = Object.keys(hash);
variables.forEach(variable => {
let aVar = scope.get(variable);
is(aVar.target.querySelector(".name").getAttribute("value"), variable,
"Correct property name for " + variable);
is(aVar.target.querySelector(".value").getAttribute("value"), hash[variable],
- "Correct property value of " + hash[variable] + " for " + variable);
+ "Correct property value of " + hash[variable] + " for " + variable + " " + description);
});
}
function modifyVariableView (win, view, index, prop, value) {
let deferred = Promise.defer();
let scope = view.getScopeAtIndex(index);
let aVar = scope.get(prop);
scope.expand();
diff --git a/browser/devtools/webaudioeditor/webaudioeditor-view.js b/browser/devtools/webaudioeditor/webaudioeditor-view.js
index 7c87c81..0e6e277 100644
--- a/browser/devtools/webaudioeditor/webaudioeditor-view.js
+++ b/browser/devtools/webaudioeditor/webaudioeditor-view.js
@@ -264,22 +264,31 @@ let WebAudioParamView = {
/**
* Executed when an audio param is changed in the UI.
*/
_onEval: Task.async(function* (variable, value) {
let ownerScope = variable.ownerView;
let node = getViewNodeById(ownerScope.actorID);
let propName = variable.name;
- let errorMessage = yield node.actor.setParam(propName, value);
+ let error;
+
+ // Cast value to proper type
+ try {
+ value = JSON.parse(value);
+ error = yield node.actor.setParam(propName, value);
+ }
+ catch (e) {
+ error = e;
+ }
// TODO figure out how to handle and display set param errors
// and enable `test/brorwser_wa_params_view_edit_error.js`
// Bug 994258
- if (!errorMessage) {
+ if (!error) {
ownerScope.get(propName).setGrip(value);
window.emit(EVENTS.UI_SET_PARAM, node.id, propName, value);
} else {
window.emit(EVENTS.UI_SET_PARAM_ERROR, node.id, propName, value);
}
}),
/**
diff --git a/toolkit/devtools/server/actors/webaudio.js b/toolkit/devtools/server/actors/webaudio.js
index 40a881b..8118ee6 100644
--- a/toolkit/devtools/server/actors/webaudio.js
+++ b/toolkit/devtools/server/actors/webaudio.js
@@ -150,30 +150,25 @@ let AudioNodeActor = exports.AudioNodeActor = protocol.ActorClass({
*/
isSource: method(function () {
return !!~this.type.indexOf("Source") || this.type === "OscillatorNode";
}, {
response: { source: RetVal("boolean") }
}),
/**
- * Changes a param on the audio node. Responds with a `string` that's either
- * an empty string `""` on success, or a description of the error upon
- * param set failure.
+ * Changes a param on the audio node. Responds with either `undefined`
+ * on success, or a description of the error upon param set failure.
*
* @param String param
* Name of the AudioParam to change.
* @param String value
* Value to change AudioParam to.
*/
setParam: method(function (param, value) {
- // Strip quotes because sometimes UIs include that for strings
- if (typeof value === "string") {
- value = value.replace(/[\'\"]*/g, "");
- }
try {
if (isAudioParam(this.node, param))
this.node[param].value = value;
else
this.node[param] = value;
return undefined;
} catch (e) {
return constructError(e);
--
1.8.4.2