Skip to content

Commit

Permalink
[embind] Always enable assertions during TypeScript generation. (#21695)
Browse files Browse the repository at this point in the history
Fixes #21641
  • Loading branch information
brendandahl authored Sep 26, 2024
1 parent fafea90 commit 0aa6ad4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
25 changes: 16 additions & 9 deletions src/embind/embind_gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,9 @@ var LibraryEmbind = {
}
argStart = 2;
}
if (argsName.length)
assert(argsName.length == (argTypes.length - hasThis - 1), 'Argument names should match number of parameters.');
if (argsName.length && argsName.length != (argTypes.length - hasThis - 1))
throw new Error('Argument names should match number of parameters.');

const args = [];
for (let i = argStart, x = 0; i < argTypes.length; i++) {
if (x < argsName.length) {
Expand Down Expand Up @@ -619,7 +620,9 @@ var LibraryEmbind = {
setterContext) {
fieldName = readLatin1String(fieldName);
const readonly = setter === 0;
assert(readonly || getterReturnType === setterArgumentType, 'Mismatched getter and setter types are not supported.');
if (!(readonly || getterReturnType === setterArgumentType))
throw new error('Mismatched getter and setter types are not supported.');

whenDependentTypesAreResolved([], [classType], function(classType) {
classType = classType[0];
whenDependentTypesAreResolved([], [getterReturnType], function(types) {
Expand Down Expand Up @@ -720,7 +723,9 @@ var LibraryEmbind = {
setterContext
) {
const valueArray = tupleRegistrations[rawTupleType];
assert(getterReturnType === setterArgumentType, 'Mismatched getter and setter types are not supported.');
if (getterReturnType !== setterArgumentType)
throw new Error('Mismatched getter and setter types are not supported.');

valueArray.elementTypeIds.push(getterReturnType);
},
_embind_finalize_value_array__deps: ['$whenDependentTypesAreResolved', '$moduleDefinitions', '$tupleRegistrations'],
Expand Down Expand Up @@ -761,7 +766,9 @@ var LibraryEmbind = {
setterContext
) {
const valueObject = structRegistrations[structType];
assert(getterReturnType === setterArgumentType, 'Mismatched getter and setter types are not supported.');
if (getterReturnType !== setterArgumentType)
throw new Error('Mismatched getter and setter types are not supported.');

valueObject.fieldTypeIds.push(getterReturnType);
valueObject.fieldNames.push(readLatin1String(fieldName));
},
Expand Down Expand Up @@ -822,10 +829,10 @@ var LibraryEmbind = {
#endif

// Stub functions used by eval, but not needed for TS generation:
$makeLegalFunctionName: () => assert(false, 'stub function should not be called'),
$newFunc: () => assert(false, 'stub function should not be called'),
$runDestructors: () => assert(false, 'stub function should not be called'),
$createNamedFunction: () => assert(false, 'stub function should not be called'),
$makeLegalFunctionName: () => { throw new Error('stub function should not be called'); },
$newFunc: () => { throw new Error('stub function should not be called'); },
$runDestructors: () => { throw new Error('stub function should not be called'); },
$createNamedFunction: () => { throw new Error('stub function should not be called'); },
};

#if EMBIND_AOT
Expand Down
4 changes: 3 additions & 1 deletion test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -3384,7 +3384,9 @@ def test_embind_tsgen_ignore(self):
extra_args = ['-sMODULARIZE',
'--embed-file', 'fail.js',
'-sMINIMAL_RUNTIME=2',
'-sEXPORT_ES6=1']
'-sEXPORT_ES6=1',
'-sASSERTIONS=0',
'-sSTRICT=1']
self.emcc(test_file('other/embind_tsgen.cpp'), extra_args)
self.assertFileContents(test_file('other/embind_tsgen_ignore_2.d.ts'), read_file('embind_tsgen.d.ts'))
# Also test this separately since it conflicts with other settings.
Expand Down

0 comments on commit 0aa6ad4

Please sign in to comment.