Skip to content

Commit be5a83d

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: 13152 out/test/test.js
1 parent ee63c08 commit be5a83d

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/lib/libwebaudio.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,17 @@ var LibraryWebAudio = {
403403
emscripten_audio_worklet_post_function_1(audioContext, funcPtr, arg0)
404404
},
405405

406+
$emAudioWorkletPostMessage__internal: true,
407+
$emAudioWorkletPostMessage(audioContext, msg) {
408+
#if ASSERTIONS || WEBAUDIO_DEBUG
409+
if (audioContext) emAudioExpectContex(audioContext, 'emAudioWorkletPostMessage');
410+
#endif
411+
(audioContext ? EmAudio[audioContext].audioWorklet['port'] : port).postMessage(msg);
412+
},
413+
414+
$emscripten_audio_worklet_post_function_2__deps: ['$emAudioWorkletPostMessage'],
406415
$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"
416+
emAudioWorkletPostMessage(audioContext, {'_wsc': funcPtr, args: [arg0, arg1] }); // "WaSm Call"
408417
},
409418

410419
emscripten_audio_worklet_post_function_vii__deps: ['$emscripten_audio_worklet_post_function_2'],
@@ -417,8 +426,9 @@ var LibraryWebAudio = {
417426
emscripten_audio_worklet_post_function_2(audioContext, funcPtr, arg0, arg1);
418427
},
419428

429+
$emscripten_audio_worklet_post_function_3__deps: ['$emAudioWorkletPostMessage'],
420430
$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"
431+
emAudioWorkletPostMessage(audioContext, {'_wsc': funcPtr, args: [arg0, arg1, arg2] }); // "WaSm Call"
422432
},
423433
emscripten_audio_worklet_post_function_viii__deps: ['$emscripten_audio_worklet_post_function_3'],
424434
emscripten_audio_worklet_post_function_viii: (audioContext, funcPtr, arg0, arg1, arg2) => {
@@ -429,16 +439,15 @@ var LibraryWebAudio = {
429439
emscripten_audio_worklet_post_function_3(audioContext, funcPtr, arg0, arg1, arg2);
430440
},
431441

432-
emscripten_audio_worklet_post_function_sig__deps: ['$readEmAsmArgs'],
442+
emscripten_audio_worklet_post_function_sig__deps: ['$readEmAsmArgs', '$emAudioWorkletPostMessage'],
433443
emscripten_audio_worklet_post_function_sig: (audioContext, funcPtr, sigPtr, varargs) => {
434444
#if ASSERTIONS
435-
assert(audioContext >= 0);
436445
assert(funcPtr);
437446
assert(sigPtr);
438447
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.');
439448
assert(varargs);
440449
#endif
441-
(audioContext ? EmAudio[audioContext].audioWorklet['port'] : port).postMessage({'_wsc': funcPtr, args: readEmAsmArgs(sigPtr, varargs) });
450+
emAudioWorkletPostMessage(audioContext, {'_wsc': funcPtr, args: readEmAsmArgs(sigPtr, varargs)});
442451
}
443452
};
444453

0 commit comments

Comments
 (0)