Skip to content

Commit 94d1e77

Browse files
authored
Use var and undefined in libwebaudio.js. NFC (#24814)
The convention for JS library code is to use var for better minification. The use of `void 0` instead of `undefined` I believe is a minor code size optimization, but its somewhat obscure and (as you can see from the fact that the code expectations didn't change) it an optimization that is already performed on the generated code anyway. Split out from #24732
1 parent 9886169 commit 94d1e77

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

src/lib/libwebaudio.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#error "-sAUDIO_WORKLET does not support -sSINGLE_FILE"
99
#endif
1010

11-
let LibraryWebAudio = {
11+
var LibraryWebAudio = {
1212
$EmAudio: {},
1313
$EmAudioCounter: 0,
1414

@@ -54,16 +54,16 @@ let LibraryWebAudio = {
5454
// this avoids the user needing to manually add the dependency on the command line.
5555
emscripten_create_audio_context__deps: ['$emscriptenRegisterAudioObject', '$emscriptenGetAudioObject'],
5656
emscripten_create_audio_context: (options) => {
57-
let ctx = window.AudioContext || window.webkitAudioContext;
57+
var ctx = window.AudioContext || window.webkitAudioContext;
5858
#if ASSERTIONS
5959
if (!ctx) console.error('emscripten_create_audio_context failed! Web Audio is not supported.');
6060
#endif
6161
options >>= 2;
6262

63-
let opts = options ? {
64-
latencyHint: HEAPU32[options] ? UTF8ToString(HEAPU32[options]) : void 0,
65-
sampleRate: HEAP32[options+1] || void 0
66-
} : void 0;
63+
var opts = options ? {
64+
latencyHint: HEAPU32[options] ? UTF8ToString(HEAPU32[options]) : undefined,
65+
sampleRate: HEAP32[options+1] || undefined
66+
} : undefined;
6767

6868
#if WEBAUDIO_DEBUG
6969
console.log(`Creating new WebAudio context with parameters:`);
@@ -146,8 +146,8 @@ let LibraryWebAudio = {
146146
assert(EmAudio[contextHandle] instanceof (window.AudioContext || window.webkitAudioContext), `Called emscripten_start_wasm_audio_worklet_thread_async() on a context handle ${contextHandle} that is not an AudioContext, but of type ${typeof EmAudio[contextHandle]}`);
147147
#endif
148148

149-
let audioContext = EmAudio[contextHandle],
150-
audioWorklet = audioContext.audioWorklet;
149+
var audioContext = EmAudio[contextHandle];
150+
var audioWorklet = audioContext.audioWorklet;
151151

152152
#if ASSERTIONS
153153
assert(stackLowestAddress != 0, 'AudioWorklets require a dedicated stack space for audio data marshalling between Wasm and JS!');
@@ -162,7 +162,7 @@ let LibraryWebAudio = {
162162
console.log(`emscripten_start_wasm_audio_worklet_thread_async() adding audioworklet.js...`);
163163
#endif
164164

165-
let audioWorkletCreationFailed = () => {
165+
var audioWorkletCreationFailed = () => {
166166
#if ASSERTIONS || WEBAUDIO_DEBUG
167167
console.error(`emscripten_start_wasm_audio_worklet_thread_async() addModule() failed!`);
168168
#endif
@@ -208,10 +208,10 @@ let LibraryWebAudio = {
208208

209209
$_EmAudioDispatchProcessorCallback__deps: ['$getWasmTableEntry'],
210210
$_EmAudioDispatchProcessorCallback: (e) => {
211-
let data = e.data;
211+
var data = e.data;
212212
// '_wsc' is short for 'wasm call', trying to use an identifier name that
213213
// will never conflict with user code
214-
let wasmCall = data['_wsc'];
214+
var wasmCall = data['_wsc'];
215215
wasmCall && getWasmTableEntry(wasmCall)(...data.args);
216216
},
217217

@@ -223,7 +223,7 @@ let LibraryWebAudio = {
223223
#endif
224224

225225
options >>= 2;
226-
let audioParams = [],
226+
var audioParams = [],
227227
numAudioParams = HEAPU32[options+1],
228228
audioParamDescriptors = HEAPU32[options+2] >> 2,
229229
i = 0;
@@ -265,21 +265,21 @@ let LibraryWebAudio = {
265265
options >>= 2;
266266

267267
function readChannelCountArray(heapIndex, numOutputs) {
268-
let channelCounts = [];
268+
var channelCounts = [];
269269
while (numOutputs--) channelCounts.push(HEAPU32[heapIndex++]);
270270
return channelCounts;
271271
}
272272

273-
let opts = options ? {
273+
var opts = options ? {
274274
numberOfInputs: HEAP32[options],
275275
numberOfOutputs: HEAP32[options+1],
276-
outputChannelCount: HEAPU32[options+2] ? readChannelCountArray(HEAPU32[options+2]>>2, HEAP32[options+1]) : void 0,
276+
outputChannelCount: HEAPU32[options+2] ? readChannelCountArray(HEAPU32[options+2]>>2, HEAP32[options+1]) : undefined,
277277
processorOptions: {
278278
callback,
279279
userData,
280280
samplesPerChannel: emscriptenGetContextQuantumSize(contextHandle),
281281
}
282-
} : void 0;
282+
} : undefined;
283283

284284
#if WEBAUDIO_DEBUG
285285
console.log(`Creating AudioWorkletNode "${UTF8ToString(name)}" on context=${contextHandle} with options:`);

test/code_size/audio_worklet_wasm.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ var N = [], O = a => {
135135
if (G[c + 2]) {
136136
var m = G[c + 2] >> 2;
137137
c = M[c + 1];
138-
let w = [];
139-
for (;c--; ) w.push(G[m++]);
138+
for (var w = []; c--; ) w.push(G[m++]);
140139
m = w;
141140
} else m = void 0;
142141
d = {
@@ -155,8 +154,7 @@ var N = [], O = a => {
155154
return T;
156155
}, da = (a, b, c, d) => {
157156
b >>= 2;
158-
let e = [], h = G[b + 1], f = G[b + 2] >> 2, m = 0;
159-
for (;h--; ) e.push({
157+
for (var e = [], h = G[b + 1], f = G[b + 2] >> 2, m = 0; h--; ) e.push({
160158
name: m++,
161159
defaultValue: I[f++],
162160
minValue: I[f++],
@@ -175,10 +173,10 @@ var N = [], O = a => {
175173
});
176174
}, ea = () => !1, fa = 1, ha = a => {
177175
a = a.data;
178-
let b = a._wsc;
176+
var b = a._wsc;
179177
b && C.get(b)(...a.A);
180178
}, ia = a => E(a), ja = (a, b, c, d, e) => {
181-
let h = S[a], f = h.audioWorklet, m = () => {
179+
var h = S[a], f = h.audioWorklet, m = () => {
182180
C.get(d)(a, 0, e);
183181
};
184182
if (!f) return m();
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 519,
33
"a.html.gz": 357,
4-
"a.js": 3853,
5-
"a.js.gz": 2045,
4+
"a.js": 3851,
5+
"a.js.gz": 2048,
66
"a.wasm": 1288,
77
"a.wasm.gz": 860,
8-
"total": 5660,
9-
"total_gz": 3262
8+
"total": 5658,
9+
"total_gz": 3265
1010
}

0 commit comments

Comments
 (0)