Skip to content

Commit 7b36fc8

Browse files
authored
Building with -sTEXTDECODER=2 when targeting -sAUDIO_WORKLET is not catastrophic (#25347)
Building with -sTEXTDECODER=2 when targeting -sAUDIO_WORKLET is not catastrophic since the user might very likely never attempt to interop any strings between JS and Wasm from the Audio Worklet thread. So leaving UTF8Decoder to be null there will be fine.
1 parent 353db4a commit 7b36fc8

27 files changed

+97
-95
lines changed

src/lib/libstrings.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
#endif
1010

1111
addToLibrary({
12+
// In -sAUDIO_WORKLET builds, TextDecoder will not exist in AudioWorkletGlobalScope,
13+
// so we cannot try to unconditionally initialize it in that build mode.
14+
#if TEXTDECODER == 2 && !AUDIO_WORKLET
1215
// TextDecoder constructor defaults to UTF-8
13-
#if TEXTDECODER == 2
1416
$UTF8Decoder: "new TextDecoder()",
1517
#else
16-
$UTF8Decoder: "globalThis.TextDecoder ? new TextDecoder() : undefined",
18+
$UTF8Decoder: "globalThis.TextDecoder && new TextDecoder()",
1719
#endif
1820

1921
$findStringEnd: (heapOrArray, idx, maxBytesToRead, ignoreNul) => {

src/lib/libwebaudio.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#if AUDIO_WORKLET && !WASM_WORKERS
2-
#error "Building with -sAUDIO_WORKLET also requires enabling -sWASM_WORKERS!"
2+
#error "Building with -sAUDIO_WORKLET also requires enabling -sWASM_WORKERS"
33
#endif
44
#if AUDIO_WORKLET && TEXTDECODER == 2
5-
#error "-sAUDIO_WORKLET does not support -sTEXTDECODER=2 since TextDecoder is not available in AudioWorkletGlobalScope! Use e.g. -sTEXTDECODER=1 when building with -sAUDIO_WORKLET"
5+
#warning "-sAUDIO_WORKLET does not support -sTEXTDECODER=2 since TextDecoder is not available in AudioWorkletGlobalScope. Text decoding will be unavailable in Audio Worklets. If you need string marshalling in Audio Worklets, build with -sTEXTDECODER=1."
66
#endif
77
#if AUDIO_WORKLET && SINGLE_FILE
88
#error "-sAUDIO_WORKLET does not support -sSINGLE_FILE"

test/codesize/audio_worklet_wasm.expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ var K = [], L = a => {
111111
}, P = (a, c, b, f) => {
112112
c = O[c];
113113
O[a].connect(c.destination || c, b, f);
114-
}, O = {}, Q = 0, R = globalThis.TextDecoder ? new TextDecoder : void 0, S = (a = 0) => {
114+
}, O = {}, Q = 0, R = globalThis.TextDecoder && new TextDecoder, S = (a = 0) => {
115115
for (var c = I, b = a, f = b + void 0; c[b] && !(b >= f); ) ++b;
116116
if (16 < b - a && c.buffer && R) return R.decode(c.slice(a, b));
117117
for (f = ""; a < b; ) {

test/codesize/test_codesize_cxx_ctors1.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 19676,
3-
"a.out.js.gz": 8151,
2+
"a.out.js": 19670,
3+
"a.out.js.gz": 8152,
44
"a.out.nodebug.wasm": 129509,
55
"a.out.nodebug.wasm.gz": 49243,
6-
"total": 149185,
7-
"total_gz": 57394,
6+
"total": 149179,
7+
"total_gz": 57395,
88
"sent": [
99
"__cxa_throw",
1010
"_abort_js",

test/codesize/test_codesize_cxx_ctors2.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 19653,
3-
"a.out.js.gz": 8138,
2+
"a.out.js": 19647,
3+
"a.out.js.gz": 8139,
44
"a.out.nodebug.wasm": 128936,
55
"a.out.nodebug.wasm.gz": 48884,
6-
"total": 148589,
7-
"total_gz": 57022,
6+
"total": 148583,
7+
"total_gz": 57023,
88
"sent": [
99
"__cxa_throw",
1010
"_abort_js",

test/codesize/test_codesize_cxx_except.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 23331,
3-
"a.out.js.gz": 9129,
2+
"a.out.js": 23325,
3+
"a.out.js.gz": 9128,
44
"a.out.nodebug.wasm": 171271,
55
"a.out.nodebug.wasm.gz": 57338,
6-
"total": 194602,
7-
"total_gz": 66467,
6+
"total": 194596,
7+
"total_gz": 66466,
88
"sent": [
99
"__cxa_begin_catch",
1010
"__cxa_end_catch",

test/codesize/test_codesize_cxx_except_wasm.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 19561,
3-
"a.out.js.gz": 8098,
2+
"a.out.js": 19555,
3+
"a.out.js.gz": 8099,
44
"a.out.nodebug.wasm": 144630,
55
"a.out.nodebug.wasm.gz": 54894,
6-
"total": 164191,
7-
"total_gz": 62992,
6+
"total": 164185,
7+
"total_gz": 62993,
88
"sent": [
99
"_abort_js",
1010
"_tzset_js",

test/codesize/test_codesize_cxx_except_wasm_legacy.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 19561,
3-
"a.out.js.gz": 8098,
2+
"a.out.js": 19555,
3+
"a.out.js.gz": 8099,
44
"a.out.nodebug.wasm": 142219,
55
"a.out.nodebug.wasm.gz": 54358,
6-
"total": 161780,
7-
"total_gz": 62456,
6+
"total": 161774,
7+
"total_gz": 62457,
88
"sent": [
99
"_abort_js",
1010
"_tzset_js",

test/codesize/test_codesize_cxx_mangle.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 23381,
3-
"a.out.js.gz": 9149,
2+
"a.out.js": 23375,
3+
"a.out.js.gz": 9148,
44
"a.out.nodebug.wasm": 235312,
55
"a.out.nodebug.wasm.gz": 78933,
6-
"total": 258693,
7-
"total_gz": 88082,
6+
"total": 258687,
7+
"total_gz": 88081,
88
"sent": [
99
"__cxa_begin_catch",
1010
"__cxa_end_catch",

test/codesize/test_codesize_cxx_noexcept.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 19676,
3-
"a.out.js.gz": 8151,
2+
"a.out.js": 19670,
3+
"a.out.js.gz": 8152,
44
"a.out.nodebug.wasm": 131926,
55
"a.out.nodebug.wasm.gz": 50238,
6-
"total": 151602,
7-
"total_gz": 58389,
6+
"total": 151596,
7+
"total_gz": 58390,
88
"sent": [
99
"__cxa_throw",
1010
"_abort_js",

0 commit comments

Comments
 (0)