Skip to content

Commit 7f8e2b4

Browse files
committed
Extract emAudioWorkletPostMessage helper. NFC
This avoids duplication and also means we can add consistent checks on the audio context that is passed in. Its also a code size win. We don't have a specific code size test that references these functions but I ran `browser.test_audio_worklet_post_function_closure` before and after this change and got these results: Before: 13297 out/test/test.js After: 13031 out/test/test.js
1 parent ee63c08 commit 7f8e2b4

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/lib/libwebaudio.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -383,14 +383,24 @@ var LibraryWebAudio = {
383383
srcNode.connect(dstNode.destination || dstNode, outputIndex, inputIndex);
384384
},
385385

386+
$emAudioWorkletPostMessage__internal: true,
387+
$emAudioWorkletPostMessage(audioContext, msg) {
388+
#if ASSERTIONS || WEBAUDIO_DEBUG
389+
if (audioContext) emAudioExpectContex(audioContext, 'emAudioWorkletPostMessage');
390+
#endif
391+
(audioContext ? EmAudio[audioContext].audioWorklet['port'] : port).postMessage(msg);
392+
},
393+
386394
emscripten_current_thread_is_audio_worklet: () => ENVIRONMENT_IS_AUDIO_WORKLET,
387395

396+
emscripten_audio_worklet_post_function_v__deps: ['$emAudioWorkletPostMessage'],
388397
emscripten_audio_worklet_post_function_v: (audioContext, funcPtr) => {
389-
(audioContext ? EmAudio[audioContext].audioWorklet['port'] : port).postMessage({'_wsc': funcPtr, args: [] }); // "WaSm Call"
398+
emAudioWorkletPostMessage(audioContext, {'_wsc': funcPtr, args: [] }); // "WaSm Call"
390399
},
391400

401+
$emscripten_audio_worklet_post_function_1__deps: ['$emAudioWorkletPostMessage'],
392402
$emscripten_audio_worklet_post_function_1: (audioContext, funcPtr, arg0) => {
393-
(audioContext ? EmAudio[audioContext].audioWorklet['port'] : port).postMessage({'_wsc': funcPtr, args: [arg0] }); // "WaSm Call"
403+
emAudioWorkletPostMessage(audioContext, {'_wsc': funcPtr, args: [arg0] }); // "WaSm Call"
394404
},
395405

396406
emscripten_audio_worklet_post_function_vi__deps: ['$emscripten_audio_worklet_post_function_1'],
@@ -403,8 +413,9 @@ var LibraryWebAudio = {
403413
emscripten_audio_worklet_post_function_1(audioContext, funcPtr, arg0)
404414
},
405415

416+
$emscripten_audio_worklet_post_function_2__deps: ['$emAudioWorkletPostMessage'],
406417
$emscripten_audio_worklet_post_function_2: (audioContext, funcPtr, arg0, arg1) => {
407-
(audioContext ? EmAudio[audioContext].audioWorklet['port'] : port).postMessage({'_wsc': funcPtr, args: [arg0, arg1] }); // "WaSm Call"
418+
emAudioWorkletPostMessage(audioContext, {'_wsc': funcPtr, args: [arg0, arg1] }); // "WaSm Call"
408419
},
409420

410421
emscripten_audio_worklet_post_function_vii__deps: ['$emscripten_audio_worklet_post_function_2'],
@@ -417,8 +428,9 @@ var LibraryWebAudio = {
417428
emscripten_audio_worklet_post_function_2(audioContext, funcPtr, arg0, arg1);
418429
},
419430

431+
$emscripten_audio_worklet_post_function_3__deps: ['$emAudioWorkletPostMessage'],
420432
$emscripten_audio_worklet_post_function_3: (audioContext, funcPtr, arg0, arg1, arg2) => {
421-
(audioContext ? EmAudio[audioContext].audioWorklet['port'] : port).postMessage({'_wsc': funcPtr, args: [arg0, arg1, arg2] }); // "WaSm Call"
433+
emAudioWorkletPostMessage(audioContext, {'_wsc': funcPtr, args: [arg0, arg1, arg2] }); // "WaSm Call"
422434
},
423435
emscripten_audio_worklet_post_function_viii__deps: ['$emscripten_audio_worklet_post_function_3'],
424436
emscripten_audio_worklet_post_function_viii: (audioContext, funcPtr, arg0, arg1, arg2) => {
@@ -429,16 +441,15 @@ var LibraryWebAudio = {
429441
emscripten_audio_worklet_post_function_3(audioContext, funcPtr, arg0, arg1, arg2);
430442
},
431443

432-
emscripten_audio_worklet_post_function_sig__deps: ['$readEmAsmArgs'],
444+
emscripten_audio_worklet_post_function_sig__deps: ['$readEmAsmArgs', '$emAudioWorkletPostMessage'],
433445
emscripten_audio_worklet_post_function_sig: (audioContext, funcPtr, sigPtr, varargs) => {
434446
#if ASSERTIONS
435-
assert(audioContext >= 0);
436447
assert(funcPtr);
437448
assert(sigPtr);
438449
assert(UTF8ToString(sigPtr)[0] != 'v', 'Do NOT specify the return argument in the signature string for a call to emscripten_audio_worklet_post_function_sig(), just pass the function arguments.');
439450
assert(varargs);
440451
#endif
441-
(audioContext ? EmAudio[audioContext].audioWorklet['port'] : port).postMessage({'_wsc': funcPtr, args: readEmAsmArgs(sigPtr, varargs) });
452+
emAudioWorkletPostMessage(audioContext, {'_wsc': funcPtr, args: readEmAsmArgs(sigPtr, varargs)});
442453
}
443454
};
444455

0 commit comments

Comments
 (0)