Skip to content

Commit e817b60

Browse files
committed
Merge branch 'main' into roll-and-repoint-tests
2 parents 3d62df6 + 65dc9d0 commit e817b60

File tree

95 files changed

+701
-454
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+701
-454
lines changed

.circleci/config.yml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ commands:
142142
cd ~/emsdk
143143
./emsdk install tot
144144
./emsdk activate tot
145+
# Write the version of clang into a file for use in the ccache key
146+
./upstream/bin/clang --version > clang_version.txt
147+
echo "clang version:"
148+
cat ~/emsdk/clang_version.txt
145149
# Remove the emsdk version of emscripten to save space in the
146150
# persistent workspace and to avoid any confusion with the version
147151
# we are trying to test.
@@ -171,7 +175,7 @@ commands:
171175
command: |
172176
./emcc --clear-cache
173177
- pip-install
174-
- run: apt-get install -q -y ninja-build
178+
- run: apt-get install -q -y ninja-build ccache
175179
- run:
176180
name: embuilder build ALL
177181
command: |
@@ -196,6 +200,12 @@ commands:
196200
command: |
197201
./embuilder build MINIMAL --pic --lto
198202
./test/runner test_hello_world
203+
- run:
204+
name: "Ccache stats"
205+
command: |
206+
ccache --print-stats
207+
ccache --zero-stats
208+
199209
persist:
200210
description: "Persist the emsdk, libraries, and engines"
201211
steps:
@@ -209,6 +219,19 @@ commands:
209219
- vms/
210220
- wasi-sdk/
211221
- .jsvu/
222+
- when:
223+
# Only the main branch will store its cache results, and only the non-main branches
224+
# will use cached results. This prevents untrusted PRs from polluting caches used
225+
# by other branches.
226+
condition:
227+
equal: [ "main", << pipeline.git.branch >> ]
228+
steps:
229+
- save_cache:
230+
name: "Save Ccache cache"
231+
paths:
232+
- ~/.ccache
233+
key: clang-{{ checksum "~/emsdk/clang_version.txt" }}
234+
212235
prepare-for-tests:
213236
description: "Setup emscripten tests"
214237
steps:
@@ -543,6 +566,7 @@ jobs:
543566
environment:
544567
EMCC_CORES: 16
545568
EMCC_USE_NINJA: 1
569+
EM_COMPILER_WRAPPER: "ccache"
546570
steps:
547571
- checkout
548572
- run:
@@ -570,6 +594,14 @@ jobs:
570594
tar xvf wasi-sysroot-11.0.tar.gz -C ~/wasi-sdk/
571595
- install-v8
572596
- install-emsdk
597+
- when:
598+
condition:
599+
not:
600+
equal: [ "main", << pipeline.git.branch >> ]
601+
steps:
602+
- restore_cache:
603+
name: "Restore Ccache cache"
604+
key: clang-{{ checksum "~/emsdk/clang_version.txt" }}
573605
- build-libs
574606
- run:
575607
name: Clean build directory
@@ -714,6 +746,8 @@ jobs:
714746
wasmfs.test_fs_llseek_rawfs
715747
wasmfs.test_freetype
716748
minimal0.test_utf
749+
minimal0.test_static_variable
750+
minimal0.test_stack_overflow
717751
omitexports0.test_asyncify_longjmp
718752
omitexports0.test_emscripten_api
719753
strict.test_no_declare_asm_module_exports

emrun.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,9 @@ def create_emrun_safe_firefox_profile():
229229
temp_firefox_profile_dir = tempfile.mkdtemp(prefix='temp_emrun_firefox_profile_')
230230
with open(os.path.join(temp_firefox_profile_dir, 'prefs.js'), 'w') as f:
231231
f.write('''
232-
// Lift the default max 20 workers limit to something higher to avoid hangs when page needs to spawn a lot of threads.
233-
user_pref("dom.workers.maxPerDomain", 100);
232+
// Old Firefox browsers have a maxPerDomain limit of 20. Newer Firefox browsers default to 512. Match the new
233+
// default here to help test spawning a lot of threads also on older Firefox versions.
234+
user_pref("dom.workers.maxPerDomain", 512);
234235
// Always allow opening popups
235236
user_pref("browser.popups.showPopupBlocker", false);
236237
user_pref("dom.disable_open_during_load", false);

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default [{
2727
'**/test/',
2828
'src/polyfill/',
2929
'src/lib/',
30+
'src/minimum_runtime_check.js',
3031
'src/runtime_*.js',
3132
'src/shell*.js',
3233
'src/modularize.js',

site/source/docs/tools_reference/settings_reference.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,6 +2511,18 @@ full documentation in site/source/docs/api_reference/wasm_audio_worklets.rst
25112511

25122512
Default value: 0
25132513

2514+
.. _audio_worklet_support_audio_params:
2515+
2516+
AUDIO_WORKLET_SUPPORT_AUDIO_PARAMS
2517+
==================================
2518+
2519+
If true, enables utilizing k- and a-rate AudioParams based properties in
2520+
Wasm Audio Worklet code. If false, AudioParams are not used. Set to false
2521+
for a tiny improvement to code size and AudioWorklet CPU performance when
2522+
audio synthesis is synchronized using custom WebAssembly Memory-based means.
2523+
2524+
Default value: true
2525+
25142526
.. _webaudio_debug:
25152527

25162528
WEBAUDIO_DEBUG

src/audio_worklet.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ var instantiatePromise;
1818

1919
if (ENVIRONMENT_IS_AUDIO_WORKLET) {
2020

21+
#if AUDIO_WORKLET_SUPPORT_AUDIO_PARAMS
2122
function createWasmAudioWorkletProcessor(audioParams) {
23+
#else
24+
function createWasmAudioWorkletProcessor() {
25+
#endif
2226
class WasmAudioWorkletProcessor extends AudioWorkletProcessor {
2327
constructor(args) {
2428
super();
@@ -76,9 +80,11 @@ function createWasmAudioWorkletProcessor(audioParams) {
7680
stackRestore(oldStackPtr);
7781
}
7882

83+
#if AUDIO_WORKLET_SUPPORT_AUDIO_PARAMS
7984
static get parameterDescriptors() {
8085
return audioParams;
8186
}
87+
#endif
8288

8389
/**
8490
* Marshals all inputs and parameters to the Wasm memory on the thread's
@@ -87,7 +93,13 @@ function createWasmAudioWorkletProcessor(audioParams) {
8793
*
8894
* @param {Object} parameters
8995
*/
96+
#if AUDIO_WORKLET_SUPPORT_AUDIO_PARAMS
9097
process(inputList, outputList, parameters) {
98+
#else
99+
/** @suppress {checkTypes} */
100+
process(inputList, outputList) {
101+
#endif
102+
91103
#if ALLOW_MEMORY_GROWTH
92104
// Recreate the output views if the heap has changed
93105
// TODO: add support for GROWABLE_ARRAYBUFFERS
@@ -117,11 +129,13 @@ function createWasmAudioWorkletProcessor(audioParams) {
117129
}
118130
stackMemoryData += outputViewsNeeded * this.bytesPerChannel;
119131
var numParams = 0;
132+
#if AUDIO_WORKLET_SUPPORT_AUDIO_PARAMS
120133
for (entry in parameters) {
121134
++numParams;
122135
stackMemoryStruct += {{{ C_STRUCTS.AudioParamFrame.__size__ }}};
123136
stackMemoryData += parameters[entry].byteLength;
124137
}
138+
#endif
125139
var oldStackPtr = stackSave();
126140
#if ASSERTIONS
127141
console.assert(oldStackPtr == this.ctorOldStackPtr, 'AudioWorklet stack address has unexpectedly moved');
@@ -158,6 +172,7 @@ function createWasmAudioWorkletProcessor(audioParams) {
158172
}
159173
}
160174

175+
#if AUDIO_WORKLET_SUPPORT_AUDIO_PARAMS
161176
// Copy parameters descriptor structs and data to Wasm. 'paramsPtr' is the
162177
// start of the C callback's input AudioParamFrame.
163178
var /*const*/ paramsPtr = structPtr;
@@ -170,6 +185,9 @@ function createWasmAudioWorkletProcessor(audioParams) {
170185
HEAPF32.set(subentry, {{{ getHeapOffset('dataPtr', 'float') }}});
171186
dataPtr += subentry.length * {{{ getNativeTypeSize('float') }}};
172187
}
188+
#else
189+
var paramsPtr = 0;
190+
#endif
173191

174192
// Copy output audio descriptor structs to Wasm. 'outputsPtr' is the start
175193
// of the C callback's output AudioSampleFrame. 'dataPtr' will now be
@@ -261,7 +279,11 @@ class BootstrapMessages extends AudioWorkletProcessor {
261279
// '_wpn' is short for 'Worklet Processor Node', using an identifier
262280
// that will never conflict with user messages
263281
// Register a real AudioWorkletProcessor that will actually do audio processing.
282+
#if AUDIO_WORKLET_SUPPORT_AUDIO_PARAMS
264283
registerProcessor(d['_wpn'], createWasmAudioWorkletProcessor(d.audioParams));
284+
#else
285+
registerProcessor(d['_wpn'], createWasmAudioWorkletProcessor());
286+
#endif
265287
#if WEBAUDIO_DEBUG
266288
console.log(`Registered a new WasmAudioWorkletProcessor "${d['_wpn']}" with AudioParams: ${d.audioParams}`);
267289
#endif

src/cpuprofiler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ function cpuprofiler_add_hooks() {
756756
emscriptenCpuProfiler.initialize();
757757
}
758758

759-
if (typeof document != 'undefined') {
759+
if (globalThis.document) {
760760
emscriptenCpuProfiler.initialize();
761761
}
762762

src/deterministic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Date.now = deterministicNow;
2020
// Setting performance.now to deterministicNow doesn't work so we instead
2121
// use a helper function in parseTools (getPerformanceNow()) to call it
2222
// directly.
23-
// if (typeof performance == 'object') performance.now = Date.now;
23+
// if (globalThis.performance) performance.now = Date.now;
2424

2525
Module['thisProgram'] = 'thisProgram'; // for consistency between different builds than between runs of the same build
2626

src/emrun_postjs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* emcc is run with `--emrun`
88
*/
99

10-
if (typeof window == "object" && (typeof ENVIRONMENT_IS_PTHREAD == 'undefined' || !ENVIRONMENT_IS_PTHREAD)) {
10+
if (globalThis.window && (typeof ENVIRONMENT_IS_PTHREAD == 'undefined' || !ENVIRONMENT_IS_PTHREAD)) {
1111
var emrun_register_handlers = () => {
1212
// When C code exit()s, we may still have remaining stdout and stderr
1313
// messages in flight. In that case, we can't close the browser until all
@@ -89,7 +89,7 @@ if (typeof window == "object" && (typeof ENVIRONMENT_IS_PTHREAD == 'undefined' |
8989
http.send(data); // XXX this does not work in workers, for some odd reason (issue #2681)
9090
};
9191

92-
if (typeof document != 'undefined') {
92+
if (globalThis.document) {
9393
emrun_register_handlers();
9494
}
9595
}

src/emrun_prejs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
// Route URL GET parameters to argc+argv
11-
if (typeof window == 'object') {
11+
if (globalThis.window) {
1212
Module['arguments'] = window.location.search.slice(1).trim().split('&');
1313
for (let i = 0; i < Module['arguments'].length; ++i) {
1414
Module['arguments'][i] = decodeURI(Module['arguments'][i]);

src/lib/libaddfunction.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,16 @@ addToLibrary({
7777
return code;
7878
})),
7979

80+
#if !WASM2JS || WASM == 2
8081
// Wraps a JS function as a wasm function with a given signature.
81-
#if !WASM2JS
8282
$convertJsFunctionToWasm__deps: [
8383
'$uleb128EncodeWithLen',
8484
#if WASM_JS_TYPES
8585
'$sigToWasmTypes',
8686
#endif
8787
'$generateTypePack'
8888
],
89-
#endif
9089
$convertJsFunctionToWasm: (func, sig) => {
91-
#if WASM2JS
92-
// return func;
93-
#else // WASM2JS
94-
9590
#if ASSERTIONS && !WASM_BIGINT
9691
assert(!sig.includes('j'), 'i64 not permitted in function signatures when WASM_BIGINT is disabled');
9792
#endif
@@ -100,7 +95,7 @@ addToLibrary({
10095
// "WebAssembly.Function" constructor.
10196
// Otherwise, construct a minimal wasm module importing the JS function and
10297
// re-exporting it.
103-
if (typeof WebAssembly.Function == "function") {
98+
if (WebAssembly.Function) {
10499
return new WebAssembly.Function(sigToWasmTypes(sig), func);
105100
}
106101
#endif
@@ -135,8 +130,8 @@ addToLibrary({
135130
var instance = new WebAssembly.Instance(module, { 'e': { 'f': func } });
136131
var wrappedFunc = instance.exports['f'];
137132
return wrappedFunc;
138-
#endif // WASM2JS
139133
},
134+
#endif // !WASM2JS && WASM != 2
140135

141136
$freeTableIndexes: [],
142137

@@ -192,18 +187,21 @@ addToLibrary({
192187
* 'sig' parameter is required if the function being added is a JS function.
193188
*/
194189
$addFunction__docs: '/** @param {string=} sig */',
195-
$addFunction__deps: ['$convertJsFunctionToWasm', '$getFunctionAddress',
190+
$addFunction__deps: ['$getFunctionAddress',
196191
'$functionsInTableMap', '$getEmptyTableSlot',
197192
'$setWasmTableEntry',
193+
#if !WASM2JS || WASM == 2
194+
'$convertJsFunctionToWasm',
195+
#endif
198196
#if ASSERTIONS >= 2
199197
'$getWasmTableEntry', '$wasmTable',
200198
#endif
201199
],
202200

203201
$addFunction: (func, sig) => {
204-
#if ASSERTIONS
202+
#if ASSERTIONS
205203
assert(typeof func != 'undefined');
206-
#endif // ASSERTIONS
204+
#endif // ASSERTIONS
207205
// Check if the function is already in the table, to ensure each function
208206
// gets a unique index.
209207
var rtn = getFunctionAddress(func);
@@ -213,17 +211,20 @@ addToLibrary({
213211

214212
// It's not in the table, add it now.
215213

216-
#if ASSERTIONS >= 2
214+
#if ASSERTIONS >= 2
217215
// Make sure functionsInTableMap is actually up to date, that is, that this
218216
// function is not actually in the wasm Table despite not being tracked in
219217
// functionsInTableMap.
220218
for (var i = 0; i < wasmTable.length; i++) {
221219
assert(getWasmTableEntry(i) != func, 'function in Table but not functionsInTableMap');
222220
}
223-
#endif
221+
#endif
224222

225223
var ret = getEmptyTableSlot();
226224

225+
#if WASM2JS && WASM != 2
226+
setWasmTableEntry(ret, func);
227+
#else
227228
// Set the new value.
228229
try {
229230
// Attempting to call this with JS function will cause of table.set() to fail
@@ -232,12 +233,13 @@ addToLibrary({
232233
if (!(err instanceof TypeError)) {
233234
throw err;
234235
}
235-
#if ASSERTIONS
236+
#if ASSERTIONS
236237
assert(typeof sig != 'undefined', 'Missing signature argument to addFunction: ' + func);
237-
#endif
238+
#endif
238239
var wrapped = convertJsFunctionToWasm(func, sig);
239240
setWasmTableEntry(ret, wrapped);
240241
}
242+
#endif
241243

242244
functionsInTableMap.set(func, ret);
243245

0 commit comments

Comments
 (0)