Skip to content

Commit 29ac528

Browse files
committed
Merge remote-tracking branch 'origin/main' into arsnyder16-fcoverage
2 parents 12d5e88 + 4647567 commit 29ac528

File tree

112 files changed

+252
-176
lines changed

Some content is hidden

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

112 files changed

+252
-176
lines changed

embuilder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
'libnoexit',
8989
'libwebgpu',
9090
'libwebgpu_cpp',
91+
'bullet',
9192
]
9293

9394
# Additional tasks on top of MINIMAL_TASKS that are necessary for PIC testing on

src/closure-externs/modularize-externs.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// Due to the way MODULARIZE works, Closure is run on generated code that does not define _scriptName,
2-
// but only after MODULARIZE has finished, _scriptName is injected to the generated code.
3-
// Therefore it cannot be minified.
1+
// In MODULARIZE mode the JS code may be executed later, after `document.currentScript` is gone, so we store
2+
// it to `_scriptName` outside the wrapper function. Therefore, it cannot be minified.
3+
// In EXPORT_ES6 mode we use `import.meta.url` and for Node.js CommonJS builds we use `__filename`.
4+
45
/**
56
* @suppress {duplicate, undefinedVars}
67
*/

src/lib/libcore.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,11 +1642,6 @@ addToLibrary({
16421642
$jstoi_q__docs: '/** @suppress {checkTypes} */',
16431643
$jstoi_q: (str) => parseInt(str),
16441644

1645-
// Converts a JS string to an integer base-10, with signaling error
1646-
// handling (throws a JS exception on error). E.g. jstoi_s("123abc")
1647-
// throws an exception.
1648-
$jstoi_s: 'Number',
1649-
16501645
#if LINK_AS_CXX
16511646
// libunwind
16521647

src/lib/libembind_gen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ var LibraryEmbind = {
347347
out.push('\n};\n\n');
348348
}
349349
},
350-
$TsPrinter__deps: ['$OptionalType'],
350+
$TsPrinter__deps: ['$OptionalType', '$ClassDefinition'],
351351
$TsPrinter: class {
352352
constructor(definitions) {
353353
this.definitions = definitions;

src/lib/liblegacy.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ legacyFuncs = {
116116
// Legacy names for runtime `out`/`err` symbols.
117117
$print: 'out',
118118
$printErr: 'err',
119+
120+
// Converts a JS string to an integer base-10. Despite _s, which
121+
// suggests signaling error handling, this returns NaN on error.
122+
// (This was a mistake in the original implementation, and kept
123+
// to avoid breakage.)
124+
$jstoi_s: 'Number',
119125
};
120126

121127
if (WARN_DEPRECATED && !INCLUDE_FULL_LIBRARY) {

src/postlibrary.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
function processModuleArgs()
66
#endif
77
{
8-
#if IMPORTED_MEMORY
8+
#if IMPORTED_MEMORY && !WASM_ESM_INTEGRATION
9+
// With WASM_ESM_INTEGRATION this has to happen at the top level and not
10+
// delayed until processModuleArgs.
911
initMemory();
1012
#endif
1113

src/preamble.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ if (typeof WebAssembly != 'object') {
4646

4747
// Wasm globals
4848

49-
#if !WASM_ESM_INTEGRATION
49+
#if !WASM_ESM_INTEGRATION || IMPORTED_MEMORY
5050
var wasmMemory;
5151
#endif
5252

src/runtime_init_memory.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function initMemory() {
2222
} else
2323
#endif
2424
{
25-
var INITIAL_MEMORY = {{{ makeModuleReceiveExpr('INITIAL_MEMORY', INITIAL_MEMORY) }}}
25+
var INITIAL_MEMORY = {{{ makeModuleReceiveExpr('INITIAL_MEMORY', INITIAL_MEMORY) }}};
2626

2727
#if ASSERTIONS
2828
assert(INITIAL_MEMORY >= {{{STACK_SIZE}}}, 'INITIAL_MEMORY should be larger than STACK_SIZE, was ' + INITIAL_MEMORY + '! (STACK_SIZE=' + {{{STACK_SIZE}}} + ')');
@@ -56,3 +56,6 @@ function initMemory() {
5656
updateMemoryViews();
5757
}
5858

59+
#if WASM_ESM_INTEGRATION
60+
initMemory();
61+
#endif

src/shell.js

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -139,24 +139,32 @@ var quit_ = (status, toThrow) => {
139139
throw toThrow;
140140
};
141141

142-
#if SHARED_MEMORY && !MODULARIZE
142+
#if EXPORT_ES6
143+
var _scriptName = import.meta.url;
144+
#else
145+
#if ENVIRONMENT_MAY_BE_WEB
146+
#if !MODULARIZE
143147
// In MODULARIZE mode _scriptName needs to be captured already at the very top of the page immediately when the page is parsed, so it is generated there
144148
// before the page load. In non-MODULARIZE modes generate it here.
145-
var _scriptName = (typeof document != 'undefined') ? document.currentScript?.src : undefined;
149+
var _scriptName = typeof document != 'undefined' ? document.currentScript?.src : undefined;
150+
#endif // !MODULARIZE
151+
#elif ENVIRONMENT_MAY_BE_NODE || ENVIRONMENT_MAY_BE_WORKER
152+
var _scriptName;
153+
#endif // ENVIRONMENT_MAY_BE_WEB
146154

147155
#if ENVIRONMENT_MAY_BE_NODE
148-
if (ENVIRONMENT_IS_NODE) {
149-
#if EXPORT_ES6
150-
_scriptName = typeof __filename != 'undefined' ? __filename : import.meta.url
151-
#else
156+
if (typeof __filename != 'undefined') { // Node
152157
_scriptName = __filename;
153-
#endif
154158
} else
155159
#endif // ENVIRONMENT_MAY_BE_NODE
160+
#if ENVIRONMENT_MAY_BE_WORKER
156161
if (ENVIRONMENT_IS_WORKER) {
157162
_scriptName = self.location.href;
158163
}
159-
#endif // SHARED_MEMORY && !MODULARIZE
164+
#elif ENVIRONMENT_MAY_BE_NODE
165+
/*no-op*/{}
166+
#endif // ENVIRONMENT_MAY_BE_WORKER
167+
#endif // EXPORT_ES6
160168

161169
// `/` should be present at the end if `scriptDirectory` is not empty
162170
var scriptDirectory = '';
@@ -197,11 +205,8 @@ if (ENVIRONMENT_IS_NODE) {
197205
var nodePath = require('path');
198206

199207
#if EXPORT_ES6
200-
// EXPORT_ES6 + ENVIRONMENT_IS_NODE always requires use of import.meta.url,
201-
// since there's no way getting the current absolute path of the module when
202-
// support for that is not available.
203-
if (!import.meta.url.startsWith('data:')) {
204-
scriptDirectory = nodePath.dirname(require('url').fileURLToPath(import.meta.url)) + '/';
208+
if (_scriptName.startsWith('file:')) {
209+
scriptDirectory = nodePath.dirname(require('url').fileURLToPath(_scriptName)) + '/';
205210
}
206211
#else
207212
scriptDirectory = __dirname + '/';
@@ -335,28 +340,11 @@ if (ENVIRONMENT_IS_SHELL) {
335340
// ENVIRONMENT_IS_NODE.
336341
#if ENVIRONMENT_MAY_BE_WEB || ENVIRONMENT_MAY_BE_WORKER
337342
if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
338-
if (ENVIRONMENT_IS_WORKER) { // Check worker, not web, since window could be polyfilled
339-
scriptDirectory = self.location.href;
340-
} else if (typeof document != 'undefined' && document.currentScript) { // web
341-
scriptDirectory = document.currentScript.src;
342-
}
343-
#if MODULARIZE
344-
// When MODULARIZE, this JS may be executed later, after document.currentScript
345-
// is gone, so we saved it, and we use it here instead of any other info.
346-
if (_scriptName) {
347-
scriptDirectory = _scriptName;
348-
}
349-
#endif
350-
// blob urls look like blob:http://site.com/etc/etc and we cannot infer anything from them.
351-
// otherwise, slice off the final part of the url to find the script directory.
352-
// if scriptDirectory does not contain a slash, lastIndexOf will return -1,
353-
// and scriptDirectory will correctly be replaced with an empty string.
354-
// If scriptDirectory contains a query (starting with ?) or a fragment (starting with #),
355-
// they are removed because they could contain a slash.
356-
if (scriptDirectory.startsWith('blob:')) {
357-
scriptDirectory = '';
358-
} else {
359-
scriptDirectory = scriptDirectory.slice(0, scriptDirectory.replace(/[?#].*/, '').lastIndexOf('/')+1);
343+
try {
344+
scriptDirectory = new URL('.', _scriptName).href; // includes trailing slash
345+
} catch {
346+
// Must be a `blob:` or `data:` URL (e.g. `blob:http://site.com/etc/etc`), we cannot
347+
// infer anything from them.
360348
}
361349

362350
#if ENVIRONMENT && ASSERTIONS

src/shell_minimal.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ var ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && self.name?.startsWith('em-
134134
#if !MODULARIZE
135135
// In MODULARIZE mode _scriptName needs to be captured already at the very top of the page immediately when the page is parsed, so it is generated there
136136
// before the page load. In non-MODULARIZE modes generate it here.
137-
var _scriptName = (typeof document != 'undefined') ? document.currentScript?.src : undefined;
137+
var _scriptName = typeof document != 'undefined' ? document.currentScript?.src : undefined;
138138
#endif
139139

140140
#if ENVIRONMENT_MAY_BE_NODE
@@ -145,9 +145,11 @@ if (ENVIRONMENT_IS_NODE) {
145145
// Under node we set `workerData` to `em-pthread` to signal that the worker
146146
// is hosting a pthread.
147147
ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && worker_threads['workerData'] == 'em-pthread'
148+
#if !EXPORT_ES6
148149
_scriptName = __filename;
149-
} else
150150
#endif
151+
} else
152+
#endif // ENVIRONMENT_MAY_BE_NODE
151153
if (ENVIRONMENT_IS_WORKER) {
152154
_scriptName = self.location.href;
153155
}

src/wasm_worker.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ if (ENVIRONMENT_IS_NODE) {
3434
Object.assign(global, {
3535
self: global,
3636
require,
37+
#if !EXPORT_ES6
38+
// `vm.runInThisContext` global scope lacks `__filename` and `__dirname`
3739
__filename,
3840
__dirname,
41+
#endif
3942
Worker: nodeWorkerThreads.Worker,
4043
importScripts: (f) => vm.runInThisContext(fs.readFileSync(f, 'utf8'), {filename: f}),
4144
postMessage: (msg) => parentPort.postMessage(msg),
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3996
1+
3934

test/common.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,16 +1393,20 @@ def build(self, filename, libraries=None, includes=None, force_c=False, emcc_arg
13931393
assert shared.suffix(filename) != '.c', 'force_c is not needed for source files ending in .c'
13941394
compiler.append('-xc')
13951395

1396+
all_emcc_args = self.get_emcc_args(main_file=True)
1397+
if emcc_args:
1398+
all_emcc_args += emcc_args
13961399
if not output_suffix:
1397-
output_suffix = '.mjs' if emcc_args and '-sEXPORT_ES6' in emcc_args else '.js'
1400+
if '-sEXPORT_ES6' in all_emcc_args or '-sWASM_ESM_INTEGRATION' in all_emcc_args:
1401+
output_suffix = '.mjs'
1402+
else:
1403+
output_suffix = '.js'
13981404

13991405
if output_basename:
14001406
output = output_basename + output_suffix
14011407
else:
14021408
output = shared.unsuffixed_basename(filename) + output_suffix
1403-
cmd = compiler + [filename, '-o', output] + self.get_emcc_args(main_file=True)
1404-
if emcc_args:
1405-
cmd += emcc_args
1409+
cmd = compiler + [filename, '-o', output] + all_emcc_args
14061410
if libraries:
14071411
cmd += libraries
14081412
if includes:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8237
1+
8208
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
19928
1+
19920
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8226
1+
8196
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
19906
1+
19898
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9227
1+
9203
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
23665
1+
23657
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8178
1+
8156
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
19821
1+
19813
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8178
1+
8156
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
19821
1+
19813
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8244
1+
8217
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20003
1+
19994
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9270
1+
9246
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
23780
1+
23772
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8237
1+
8208
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
19928
1+
19920
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3413
1+
3387
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7329
1+
7320
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7527
1+
7499
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
18510
1+
18501
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2668
1+
2640
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5714
1+
5703
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7805
1+
7785
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20758
1+
20761
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2534
1+
2510
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6528
1+
6536
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2193
1+
2170
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4508
1+
4497
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2149
1+
2128
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4450
1+
4439
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2149
1+
2128
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4450
1+
4439
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2149
1+
2128
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4450
1+
4439
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
11753
1+
11735
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
27782
1+
27774
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1545
1+
1520
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3338
1+
3325
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3673
1+
3626
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6732
1+
6690
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2149
1+
2128
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4450
1+
4439
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1736
1+
1713
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3713
1+
3700
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1769
1+
1745
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3756
1+
3743
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2190
1+
2171
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4579
1+
4569
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2342
1+
2323
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4864
1+
4854
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2035
1+
2013
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4277
1+
4265
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1999
1+
1977

0 commit comments

Comments
 (0)