@@ -31,7 +31,7 @@ function mangleCSymbolName(f) {
31
31
function splitter ( array , filter ) {
32
32
const splitOut = array . filter ( filter ) ;
33
33
const leftIn = array . filter ( ( x ) => ! filter ( x ) ) ;
34
- return { leftIn, splitOut } ;
34
+ return { leftIn, splitOut} ;
35
35
}
36
36
37
37
function escapeJSONKey ( x ) {
@@ -54,7 +54,7 @@ function stringifyWithFunctions(obj) {
54
54
// Handle JS method syntax where the function property starts with its own
55
55
// name. e.g. foo(a) {},
56
56
if ( typeof value === 'function' && str . startsWith ( key ) ) {
57
- rtn += str + ',\n'
57
+ rtn += str + ',\n' ;
58
58
} else {
59
59
rtn += escapeJSONKey ( key ) + ':' + str + ',\n' ;
60
60
}
@@ -98,7 +98,7 @@ function getTransitiveDeps(symbol) {
98
98
}
99
99
100
100
function shouldPreprocess ( fileName ) {
101
- var content = read ( fileName ) . trim ( )
101
+ var content = read ( fileName ) . trim ( ) ;
102
102
return content . startsWith ( '#preprocess\n' ) || content . startsWith ( '#preprocess\r\n' ) ;
103
103
}
104
104
@@ -157,7 +157,10 @@ function runJSify() {
157
157
return modifyJSFunction ( snippet , ( args , body , async_ , oneliner ) => {
158
158
let argLines = args . split ( '\n' ) ;
159
159
argLines = argLines . map ( ( line ) => line . split ( '//' ) [ 0 ] ) ;
160
- const argNames = argLines . join ( ' ' ) . split ( ',' ) . map ( ( name ) => name . trim ( ) ) ;
160
+ const argNames = argLines
161
+ . join ( ' ' )
162
+ . split ( ',' )
163
+ . map ( ( name ) => name . trim ( ) ) ;
161
164
const newArgs = [ ] ;
162
165
let innerArgs = [ ] ;
163
166
let argConversions = '' ;
@@ -198,9 +201,9 @@ function runJSify() {
198
201
return `${ async_ } (${ args } ) => {
199
202
${ argConversions }
200
203
return ${ makeReturn64 ( body ) } ;
201
- }`
204
+ }` ;
202
205
}
203
- return `${ async_ } (${ args } ) => ${ makeReturn64 ( body ) } ;`
206
+ return `${ async_ } (${ args } ) => ${ makeReturn64 ( body ) } ;` ;
204
207
}
205
208
return `\
206
209
${ async_ } function(${ args } ) {
@@ -243,22 +246,27 @@ ${argConversions}
243
246
244
247
// apply LIBRARY_DEBUG if relevant
245
248
if ( LIBRARY_DEBUG && ! isJsOnlySymbol ( symbol ) ) {
246
- snippet = modifyJSFunction ( snippet , ( args , body , async ) => `\
249
+ snippet = modifyJSFunction (
250
+ snippet ,
251
+ ( args , body , async ) => `\
247
252
function(${ args } ) {
248
253
var ret = (() => { if (runtimeDebug) err("[library call:${ mangled } : " + Array.prototype.slice.call(arguments).map(prettyPrint) + "]");
249
254
${ body }
250
255
})();
251
256
if (runtimeDebug && typeof ret != "undefined") err(" [ return:" + prettyPrint(ret));
252
257
return ret;
253
- }` ) ;
258
+ }` ,
259
+ ) ;
254
260
}
255
261
256
262
const sig = LibraryManager . library [ symbol + '__sig' ] ;
257
263
const i53abi = LibraryManager . library [ symbol + '__i53abi' ] ;
258
- if ( sig &&
259
- ( ( i53abi && sig . includes ( 'j' ) ) || ( ( MEMORY64 || CAN_ADDRESS_2GB ) && sig . includes ( 'p' ) ) ) ) {
264
+ if (
265
+ sig &&
266
+ ( ( i53abi && sig . includes ( 'j' ) ) || ( ( MEMORY64 || CAN_ADDRESS_2GB ) && sig . includes ( 'p' ) ) )
267
+ ) {
260
268
snippet = handleI64Signatures ( symbol , snippet , sig , i53abi ) ;
261
- i53ConversionDeps . forEach ( ( d ) => deps . push ( d ) )
269
+ i53ConversionDeps . forEach ( ( d ) => deps . push ( d ) ) ;
262
270
}
263
271
264
272
const proxyingMode = LibraryManager . library [ symbol + '__proxy' ] ;
@@ -274,23 +282,27 @@ function(${args}) {
274
282
body = `return ${ body } ` ;
275
283
}
276
284
const rtnType = sig && sig . length ? sig [ 0 ] : null ;
277
- const proxyFunc = ( MEMORY64 && rtnType == 'p' ) ? 'proxyToMainThreadPtr' : 'proxyToMainThread' ;
285
+ const proxyFunc =
286
+ MEMORY64 && rtnType == 'p' ? 'proxyToMainThreadPtr' : 'proxyToMainThread' ;
278
287
deps . push ( '$' + proxyFunc ) ;
279
288
return `
280
289
function(${ args } ) {
281
290
if (ENVIRONMENT_IS_PTHREAD)
282
291
return ${ proxyFunc } (${ proxiedFunctionTable . length } , 0, ${ + sync } ${ args ? ', ' : '' } ${ args } );
283
292
${ body }
284
- }\n`
293
+ }\n` ;
285
294
} ) ;
286
295
} else if ( WASM_WORKERS && ASSERTIONS ) {
287
296
// In ASSERTIONS builds add runtime checks that proxied functions are not attempted to be called in Wasm Workers
288
297
// (since there is no automatic proxying architecture available)
289
- snippet = modifyJSFunction ( snippet , ( args , body ) => `
298
+ snippet = modifyJSFunction (
299
+ snippet ,
300
+ ( args , body ) => `
290
301
function(${ args } ) {
291
302
assert(!ENVIRONMENT_IS_WASM_WORKER, "Attempted to call proxied function '${ mangled } ' in a Wasm Worker, but in Wasm Worker enabled builds, proxied function architecture is not available!");
292
303
${ body }
293
- }\n` ) ;
304
+ }\n` ,
305
+ ) ;
294
306
}
295
307
proxiedFunctionTable . push ( mangled ) ;
296
308
}
@@ -328,7 +340,9 @@ function(${args}) {
328
340
// of argument.
329
341
if ( LINK_AS_CXX && ! WASM_EXCEPTIONS && symbol . startsWith ( '__cxa_find_matching_catch_' ) ) {
330
342
if ( DISABLE_EXCEPTION_THROWING ) {
331
- error ( 'DISABLE_EXCEPTION_THROWING was set (likely due to -fno-exceptions), which means no C++ exception throwing support code is linked in, but exception catching code appears. Either do not set DISABLE_EXCEPTION_THROWING (if you do want exception throwing) or compile all source files with -fno-except (so that no exceptions support code is required); also make sure DISABLE_EXCEPTION_CATCHING is set to the right value - if you want exceptions, it should be off, and vice versa.' ) ;
343
+ error (
344
+ 'DISABLE_EXCEPTION_THROWING was set (likely due to -fno-exceptions), which means no C++ exception throwing support code is linked in, but exception catching code appears. Either do not set DISABLE_EXCEPTION_THROWING (if you do want exception throwing) or compile all source files with -fno-except (so that no exceptions support code is required); also make sure DISABLE_EXCEPTION_CATCHING is set to the right value - if you want exceptions, it should be off, and vice versa.' ,
345
+ ) ;
332
346
return ;
333
347
}
334
348
if ( ! ( symbol in LibraryManager . library ) ) {
@@ -374,9 +388,10 @@ function(${args}) {
374
388
let isAsyncFunction = false ;
375
389
if ( ASYNCIFY ) {
376
390
const original = LibraryManager . library [ symbol ] ;
377
- if ( typeof original == 'function' ) {
378
- isAsyncFunction = LibraryManager . library [ symbol + '__async' ] ||
379
- original . constructor . name == 'AsyncFunction'
391
+ if ( typeof original == 'function' ) {
392
+ isAsyncFunction =
393
+ LibraryManager . library [ symbol + '__async' ] ||
394
+ original . constructor . name == 'AsyncFunction' ;
380
395
}
381
396
if ( isAsyncFunction ) {
382
397
asyncFuncs . push ( symbol ) ;
@@ -388,11 +403,17 @@ function(${args}) {
388
403
var value = LibraryManager . library [ symbol ] ;
389
404
var resolvedSymbol = symbol ;
390
405
// Resolve aliases before looking up deps
391
- if ( typeof value == 'string' && value [ 0 ] != '=' && LibraryManager . library . hasOwnProperty ( value ) ) {
406
+ if (
407
+ typeof value == 'string' &&
408
+ value [ 0 ] != '=' &&
409
+ LibraryManager . library . hasOwnProperty ( value )
410
+ ) {
392
411
resolvedSymbol = value ;
393
412
}
394
413
var transtiveDeps = getTransitiveDeps ( resolvedSymbol ) ;
395
- symbolDeps [ symbol ] = transtiveDeps . filter ( ( d ) => ! isJsOnlySymbol ( d ) && ! ( d in LibraryManager . library ) ) ;
414
+ symbolDeps [ symbol ] = transtiveDeps . filter (
415
+ ( d ) => ! isJsOnlySymbol ( d ) && ! ( d in LibraryManager . library ) ,
416
+ ) ;
396
417
}
397
418
return ;
398
419
}
@@ -419,8 +440,13 @@ function(${args}) {
419
440
if ( dependent ) msg += ` (referenced by ${ dependent } )` ;
420
441
if ( ERROR_ON_UNDEFINED_SYMBOLS ) {
421
442
error ( msg ) ;
422
- warnOnce ( 'To disable errors for undefined symbols use `-sERROR_ON_UNDEFINED_SYMBOLS=0`' ) ;
423
- warnOnce ( mangled + ' may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library' ) ;
443
+ warnOnce (
444
+ 'To disable errors for undefined symbols use `-sERROR_ON_UNDEFINED_SYMBOLS=0`' ,
445
+ ) ;
446
+ warnOnce (
447
+ mangled +
448
+ ' may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library' ,
449
+ ) ;
424
450
} else if ( VERBOSE || WARN_ON_UNDEFINED_SYMBOLS ) {
425
451
warn ( msg ) ;
426
452
}
@@ -508,7 +534,7 @@ function(${args}) {
508
534
}
509
535
510
536
if ( VERBOSE ) {
511
- printErr ( `adding ${ symbol } (referenced by ${ dependent } )` )
537
+ printErr ( `adding ${ symbol } (referenced by ${ dependent } )` ) ;
512
538
}
513
539
const deps_list = deps . join ( "','" ) ;
514
540
const identDependents = symbol + `__deps: ['${ deps_list } ']` ;
@@ -521,15 +547,23 @@ function(${args}) {
521
547
// in library.js and library_pthread.js. These happen before deps are
522
548
// processed so depending on it via `__deps` doesn't work.
523
549
if ( dep === '$noExitRuntime' ) {
524
- error ( 'noExitRuntime cannot be referenced via __deps mechanism. Use DEFAULT_LIBRARY_FUNCS_TO_INCLUDE or EXPORTED_RUNTIME_METHODS' )
550
+ error (
551
+ 'noExitRuntime cannot be referenced via __deps mechanism. Use DEFAULT_LIBRARY_FUNCS_TO_INCLUDE or EXPORTED_RUNTIME_METHODS' ,
552
+ ) ;
525
553
}
526
554
return addFromLibrary ( dep , `${ symbol } , referenced by ${ dependent } ` , dep === aliasTarget ) ;
527
555
}
528
556
let contentText ;
529
557
if ( isFunction ) {
530
558
// Emit the body of a JS library function.
531
- if ( ( USE_ASAN || USE_LSAN || UBSAN_RUNTIME ) && LibraryManager . library [ symbol + '__noleakcheck' ] ) {
532
- contentText = modifyJSFunction ( snippet , ( args , body ) => `(${ args } ) => withBuiltinMalloc(() => {${ body } })` ) ;
559
+ if (
560
+ ( USE_ASAN || USE_LSAN || UBSAN_RUNTIME ) &&
561
+ LibraryManager . library [ symbol + '__noleakcheck' ]
562
+ ) {
563
+ contentText = modifyJSFunction (
564
+ snippet ,
565
+ ( args , body ) => `(${ args } ) => withBuiltinMalloc(() => {${ body } })` ,
566
+ ) ;
533
567
deps . push ( '$withBuiltinMalloc' ) ;
534
568
} else {
535
569
contentText = snippet ; // Regular JS function that will be executed in the context of the calling thread.
@@ -552,7 +586,8 @@ function(${args}) {
552
586
// emits
553
587
// 'var foo;[code here verbatim];'
554
588
contentText = 'var ' + mangled + snippet ;
555
- if ( snippet [ snippet . length - 1 ] != ';' && snippet [ snippet . length - 1 ] != '}' ) contentText += ';' ;
589
+ if ( snippet [ snippet . length - 1 ] != ';' && snippet [ snippet . length - 1 ] != '}' )
590
+ contentText += ';' ;
556
591
} else if ( typeof snippet == 'undefined' ) {
557
592
contentText = `var ${ mangled } ;` ;
558
593
} else {
@@ -593,13 +628,18 @@ function(${args}) {
593
628
594
629
let commentText = '' ;
595
630
if ( force ) {
596
- commentText += '/** @suppress {duplicate } */\n'
631
+ commentText += '/** @suppress {duplicate } */\n' ;
597
632
}
598
633
if ( LibraryManager . library [ symbol + '__docs' ] ) {
599
634
commentText += LibraryManager . library [ symbol + '__docs' ] + '\n' ;
600
635
}
601
636
602
- const depsText = ( deps ? deps . map ( addDependency ) . filter ( ( x ) => x != '' ) . join ( '\n' ) + '\n' : '' ) ;
637
+ const depsText = deps
638
+ ? deps
639
+ . map ( addDependency )
640
+ . filter ( ( x ) => x != '' )
641
+ . join ( '\n' ) + '\n'
642
+ : '' ;
603
643
return depsText + commentText + contentText ;
604
644
}
605
645
@@ -608,7 +648,7 @@ function(${args}) {
608
648
}
609
649
610
650
function includeFile ( fileName , needsPreprocess = true ) {
611
- print ( getIncludeFile ( fileName , needsPreprocess ) )
651
+ print ( getIncludeFile ( fileName , needsPreprocess ) ) ;
612
652
}
613
653
614
654
function finalCombiner ( ) {
@@ -672,26 +712,31 @@ var proxiedFunctionTable = [
672
712
includeFile ( fileName , shouldPreprocess ( fileName ) ) ;
673
713
}
674
714
675
- print ( '//FORWARDED_DATA:' + JSON . stringify ( {
676
- librarySymbols,
677
- warnings,
678
- asyncFuncs,
679
- ATINITS : ATINITS . join ( '\n' ) ,
680
- ATMAINS : STRICT ? '' : ATMAINS . join ( '\n' ) ,
681
- ATEXITS : ATEXITS . join ( '\n' ) ,
682
- } ) ) ;
715
+ print (
716
+ '//FORWARDED_DATA:' +
717
+ JSON . stringify ( {
718
+ librarySymbols,
719
+ warnings,
720
+ asyncFuncs,
721
+ ATINITS : ATINITS . join ( '\n' ) ,
722
+ ATMAINS : STRICT ? '' : ATMAINS . join ( '\n' ) ,
723
+ ATEXITS : ATEXITS . join ( '\n' ) ,
724
+ } ) ,
725
+ ) ;
683
726
}
684
727
685
728
for ( const sym of symbolsNeeded ) {
686
729
symbolHandler ( sym ) ;
687
730
}
688
731
689
732
if ( symbolsOnly ) {
690
- print ( JSON . stringify ( {
691
- deps : symbolDeps ,
692
- asyncFuncs,
693
- extraLibraryFuncs,
694
- } ) ) ;
733
+ print (
734
+ JSON . stringify ( {
735
+ deps : symbolDeps ,
736
+ asyncFuncs,
737
+ extraLibraryFuncs,
738
+ } ) ,
739
+ ) ;
695
740
} else {
696
741
finalCombiner ( ) ;
697
742
}
0 commit comments