Skip to content

Commit 4391048

Browse files
authored
embind: Support strings for names of FunctionDefinitions for TS generation. (#20136)
`_embind_register_class_constructor` was calling `createFunctionDefinition` with a string instead of a ptr to a string on the heap. This caused `readLatinString` to try and construct a string from the whole heap. On lower memory limits v8 handled this fine, but with higher limits the string became too large. The test still passed with the bug since the constructor name is not actually used in the .d.ts output file.
1 parent 789d45d commit 4391048

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/embind/embind_ts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ var LibraryEmbind = {
260260
$createFunctionDefinition__deps: ['$FunctionDefinition', '$heap32VectorToArray', '$readLatin1String', '$Argument', '$whenDependentTypesAreResolved'],
261261
$createFunctionDefinition: (name, argCount, rawArgTypesAddr, hasThis, cb) => {
262262
const argTypes = heap32VectorToArray(argCount, rawArgTypesAddr);
263-
name = readLatin1String(name);
263+
name = typeof name === 'string' ? name : readLatin1String(name);
264264

265265
whenDependentTypesAreResolved([], argTypes, function(argTypes) {
266266
const returnType = argTypes[0];

test/test_other.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2921,7 +2921,11 @@ def test_jspi_add_function(self):
29212921
def test_embind_tsgen(self):
29222922
# These extra arguments are not related to TS binding generation but we want to
29232923
# verify that they do not interfere with it.
2924-
extra_args = ['-o', 'out.html', '-sMODULARIZE']
2924+
extra_args = ['-o',
2925+
'out.html',
2926+
'-sMODULARIZE',
2927+
'-sALLOW_MEMORY_GROWTH=1',
2928+
'-sMAXIMUM_MEMORY=4GB']
29252929
self.run_process([EMCC, test_file('other/embind_tsgen.cpp'),
29262930
'-lembind', '--embind-emit-tsd', 'embind_tsgen.d.ts'] + extra_args)
29272931
actual = read_file('embind_tsgen.d.ts')

0 commit comments

Comments
 (0)