@@ -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
@@ -128,9 +128,13 @@ function isDefined(symName) {
128
128
}
129
129
130
130
function resolveAlias ( symbol ) {
131
- var value = LibraryManager . library [ symbol ] ;
132
- if ( typeof value == 'string' && value [ 0 ] != '=' && LibraryManager . library . hasOwnProperty ( value ) ) {
133
- return value ;
131
+ while ( true ) {
132
+ var value = LibraryManager . library [ symbol ] ;
133
+ if ( typeof value == 'string' && value [ 0 ] != '=' && ( LibraryManager . library . hasOwnProperty ( value ) || WASM_EXPORTS . has ( value ) ) ) {
134
+ symbol = value ;
135
+ } else {
136
+ break ;
137
+ }
134
138
}
135
139
return symbol ;
136
140
}
@@ -639,6 +643,7 @@ function(${args}) {
639
643
} ) ;
640
644
641
645
let isFunction = false ;
646
+ let isNativeAlias = false ;
642
647
643
648
const postsetId = symbol + '__postset' ;
644
649
const postset = LibraryManager . library [ postsetId ] ;
@@ -654,13 +659,22 @@ function(${args}) {
654
659
655
660
if ( typeof snippet == 'string' ) {
656
661
if ( snippet [ 0 ] != '=' ) {
657
- if ( LibraryManager . library [ snippet ] ) {
662
+ if ( LibraryManager . library [ snippet ] || WASM_EXPORTS . has ( snippet ) ) {
658
663
// Redirection for aliases. We include the parent, and at runtime
659
664
// make ourselves equal to it. This avoid having duplicate
660
665
// functions with identical content.
661
- const aliasTarget = snippet ;
662
- snippet = mangleCSymbolName ( aliasTarget ) ;
663
- deps . push ( aliasTarget ) ;
666
+ const aliasTarget = resolveAlias ( snippet ) ;
667
+ if ( WASM_EXPORTS . has ( aliasTarget ) ) {
668
+ //printErr(`native alias: ${mangled} -> ${snippet}`);
669
+ //console.error(WASM_EXPORTS);
670
+ nativeAliases [ mangled ] = aliasTarget ;
671
+ snippet = undefined ;
672
+ isNativeAlias = true ;
673
+ } else {
674
+ //printErr(`js alias: ${mangled} -> ${snippet}`);
675
+ deps . push ( aliasTarget ) ;
676
+ snippet = mangleCSymbolName ( aliasTarget ) ;
677
+ }
664
678
}
665
679
}
666
680
} else if ( typeof snippet == 'object' ) {
@@ -728,15 +742,11 @@ function(${args}) {
728
742
contentText += ';' ;
729
743
}
730
744
} else if ( typeof snippet == 'undefined' ) {
731
- // wasmTable is kind of special. In the normal configuration we export
732
- // it from the wasm module under the name `__indirect_function_table`
733
- // but we declare it as an 'undefined' in `libcore.js`.
734
- // Since the normal export mechanism will declare this variable we don't
735
- // want the JS library version of this symbol be declared (otherwise
736
- // it would be a duplicate decl).
737
- // TODO(sbc): This is kind of hacky, we should come up with a better solution.
738
- var isDirectWasmExport = mangled == 'wasmTable' ;
739
- if ( isDirectWasmExport ) {
745
+ // For JS library functions that are simply aliases of native symbols,
746
+ // we don't need to generate anything here. Instead these get included
747
+ // and exported alongside native symbols.
748
+ // See `create_receiving` in `tools/emscripten.py`.
749
+ if ( isNativeAlias ) {
740
750
contentText = '' ;
741
751
} else {
742
752
contentText = `var ${ mangled } ;` ;
@@ -752,7 +762,7 @@ function(${args}) {
752
762
contentText = `var ${ mangled } = ${ snippet } ;` ;
753
763
}
754
764
755
- if ( MODULARIZE == 'instance' && ( EXPORT_ALL || EXPORTED_FUNCTIONS . has ( mangled ) ) && ! isStub ) {
765
+ if ( contentText && MODULARIZE == 'instance' && ( EXPORT_ALL || EXPORTED_FUNCTIONS . has ( mangled ) ) && ! isStub ) {
756
766
// In MODULARIZE=instance mode mark JS library symbols are exported at
757
767
// the point of declaration.
758
768
contentText = 'export ' + contentText ;
@@ -775,11 +785,11 @@ function(${args}) {
775
785
}
776
786
}
777
787
778
- let commentText = '' ;
779
- let docs = LibraryManager . library [ symbol + '__docs' ] ;
780
788
// Add the docs if they exist and if we are actually emitting a declaration.
781
789
// See the TODO about wasmTable above.
782
- if ( docs && contentText != '' ) {
790
+ let docs = LibraryManager . library [ symbol + '__docs' ] ;
791
+ let commentText = '' ;
792
+ if ( contentText != '' && docs ) {
783
793
commentText += docs + '\n' ;
784
794
}
785
795
@@ -886,6 +896,7 @@ var proxiedFunctionTable = [
886
896
'//FORWARDED_DATA:' +
887
897
JSON . stringify ( {
888
898
librarySymbols,
899
+ nativeAliases,
889
900
warnings : warningOccured ( ) ,
890
901
asyncFuncs,
891
902
libraryDefinitions : LibraryManager . libraryDefinitions ,
0 commit comments