@@ -40,7 +40,7 @@ import {
40
40
warningOccured ,
41
41
localFile ,
42
42
} from './utility.mjs' ;
43
- import { LibraryManager , librarySymbols } from './modules.mjs' ;
43
+ import { LibraryManager , librarySymbols , nativeAliases } from './modules.mjs' ;
44
44
45
45
const addedLibraryItems = { } ;
46
46
@@ -637,6 +637,7 @@ function(${args}) {
637
637
} ) ;
638
638
639
639
let isFunction = false ;
640
+ let isNativeAlias = false ;
640
641
let aliasTarget ;
641
642
642
643
const postsetId = symbol + '__postset' ;
@@ -653,13 +654,19 @@ function(${args}) {
653
654
654
655
if ( typeof snippet == 'string' ) {
655
656
if ( snippet [ 0 ] != '=' ) {
656
- if ( LibraryManager . library [ snippet ] ) {
657
+ if ( LibraryManager . library [ snippet ] || WASM_EXPORTS . has ( snippet ) ) {
657
658
// Redirection for aliases. We include the parent, and at runtime
658
659
// make ourselves equal to it. This avoid having duplicate
659
660
// functions with identical content.
660
661
aliasTarget = snippet ;
661
- snippet = mangleCSymbolName ( aliasTarget ) ;
662
- deps . push ( aliasTarget ) ;
662
+ if ( WASM_EXPORTS . has ( snippet ) ) {
663
+ nativeAliases [ mangled ] = snippet ;
664
+ snippet = undefined ;
665
+ isNativeAlias = true ;
666
+ } else {
667
+ deps . push ( aliasTarget ) ;
668
+ snippet = mangleCSymbolName ( aliasTarget ) ;
669
+ }
663
670
}
664
671
}
665
672
} else if ( typeof snippet == 'object' ) {
@@ -729,15 +736,11 @@ function(${args}) {
729
736
contentText += ';' ;
730
737
}
731
738
} else if ( typeof snippet == 'undefined' ) {
732
- // wasmTable is kind of special. In the normal configuration we export
733
- // it from the wasm module under the name `__indirect_function_table`
734
- // but we declare it as an 'undefined' in `libcore.js`.
735
- // Since the normal export mechanism will declare this variable we don't
736
- // want the JS library version of this symbol be declared (otherwise
737
- // it would be a duplicate decl).
738
- // TODO(sbc): This is kind of hacky, we should come up with a better solution.
739
- var isDirectWasmExport = mangled == 'wasmTable' ;
740
- if ( isDirectWasmExport ) {
739
+ // For JS library functions that are simply aliases of native symbols,
740
+ // we don't need to generate anything here. Instead these get included
741
+ // and exported alongside native symbols.
742
+ // See `create_receiving` in `tools/emscripten.py`.
743
+ if ( isNativeAlias ) {
741
744
contentText = '' ;
742
745
} else {
743
746
contentText = `var ${ mangled } ;` ;
@@ -891,6 +894,7 @@ var proxiedFunctionTable = [
891
894
'//FORWARDED_DATA:' +
892
895
JSON . stringify ( {
893
896
librarySymbols,
897
+ nativeAliases,
894
898
warnings : warningOccured ( ) ,
895
899
asyncFuncs,
896
900
libraryDefinitions : LibraryManager . libraryDefinitions ,
0 commit comments