Skip to content

Commit 09fbb89

Browse files
authored
embind: Stub out val dependencies for TS generation. (#20074)
These dependencies are used by val but defined in embind.js. They aren't actually used during TS generation but need to be defined for linking.
1 parent 0f83fd4 commit 09fbb89

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/embind/embind_ts.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,11 @@ var LibraryEmbind = {
535535
const printer = new TsPrinter(moduleDefinitions);
536536
printer.print();
537537
},
538+
539+
// Stub functions used by eval, but not needed for TS generation:
540+
$makeLegalFunctionName: () => assert(false, 'stub function should not be called'),
541+
$newFunc: () => assert(false, 'stub function should not be called'),
542+
$runDestructors: () => assert(false, 'stub function should not be called'),
538543
};
539544

540545
DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.push('$embindEmitTypes');

test/other/embind_tsgen_val.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <emscripten/bind.h>
2+
#include <emscripten/val.h>
3+
4+
using namespace emscripten;
5+
6+
int global_fn(int, int) { return 0; }
7+
8+
EMSCRIPTEN_BINDINGS(Test) {
9+
function("global_fn", &global_fn);
10+
}
11+
12+
int main() {
13+
val::global("window").call<val>("setTimeout");
14+
// Main should not be run during TypeScript generation.
15+
abort();
16+
return 0;
17+
}

test/test_other.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2915,6 +2915,12 @@ def test_embind_tsgen(self):
29152915
self.assertNotExists('out.js')
29162916
self.assertFileContents(test_file('other/embind_tsgen.d.ts'), actual)
29172917

2918+
def test_embind_tsgen_val(self):
2919+
# Check that any dependencies from val still works with TS generation enabled.
2920+
self.run_process([EMCC, test_file('other/embind_tsgen_val.cpp'),
2921+
'-lembind', '--embind-emit-tsd', 'embind_tsgen_val.d.ts'])
2922+
self.assertExists('embind_tsgen_val.d.ts')
2923+
29182924
def test_emconfig(self):
29192925
output = self.run_process([emconfig, 'LLVM_ROOT'], stdout=PIPE).stdout.strip()
29202926
self.assertEqual(output, config.LLVM_ROOT)

0 commit comments

Comments
 (0)