Skip to content

Commit 0aa6ad4

Browse files
authored
[embind] Always enable assertions during TypeScript generation. (#21695)
Fixes #21641
1 parent fafea90 commit 0aa6ad4

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/embind/embind_gen.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,9 @@ var LibraryEmbind = {
476476
}
477477
argStart = 2;
478478
}
479-
if (argsName.length)
480-
assert(argsName.length == (argTypes.length - hasThis - 1), 'Argument names should match number of parameters.');
479+
if (argsName.length && argsName.length != (argTypes.length - hasThis - 1))
480+
throw new Error('Argument names should match number of parameters.');
481+
481482
const args = [];
482483
for (let i = argStart, x = 0; i < argTypes.length; i++) {
483484
if (x < argsName.length) {
@@ -619,7 +620,9 @@ var LibraryEmbind = {
619620
setterContext) {
620621
fieldName = readLatin1String(fieldName);
621622
const readonly = setter === 0;
622-
assert(readonly || getterReturnType === setterArgumentType, 'Mismatched getter and setter types are not supported.');
623+
if (!(readonly || getterReturnType === setterArgumentType))
624+
throw new error('Mismatched getter and setter types are not supported.');
625+
623626
whenDependentTypesAreResolved([], [classType], function(classType) {
624627
classType = classType[0];
625628
whenDependentTypesAreResolved([], [getterReturnType], function(types) {
@@ -720,7 +723,9 @@ var LibraryEmbind = {
720723
setterContext
721724
) {
722725
const valueArray = tupleRegistrations[rawTupleType];
723-
assert(getterReturnType === setterArgumentType, 'Mismatched getter and setter types are not supported.');
726+
if (getterReturnType !== setterArgumentType)
727+
throw new Error('Mismatched getter and setter types are not supported.');
728+
724729
valueArray.elementTypeIds.push(getterReturnType);
725730
},
726731
_embind_finalize_value_array__deps: ['$whenDependentTypesAreResolved', '$moduleDefinitions', '$tupleRegistrations'],
@@ -761,7 +766,9 @@ var LibraryEmbind = {
761766
setterContext
762767
) {
763768
const valueObject = structRegistrations[structType];
764-
assert(getterReturnType === setterArgumentType, 'Mismatched getter and setter types are not supported.');
769+
if (getterReturnType !== setterArgumentType)
770+
throw new Error('Mismatched getter and setter types are not supported.');
771+
765772
valueObject.fieldTypeIds.push(getterReturnType);
766773
valueObject.fieldNames.push(readLatin1String(fieldName));
767774
},
@@ -822,10 +829,10 @@ var LibraryEmbind = {
822829
#endif
823830

824831
// Stub functions used by eval, but not needed for TS generation:
825-
$makeLegalFunctionName: () => assert(false, 'stub function should not be called'),
826-
$newFunc: () => assert(false, 'stub function should not be called'),
827-
$runDestructors: () => assert(false, 'stub function should not be called'),
828-
$createNamedFunction: () => assert(false, 'stub function should not be called'),
832+
$makeLegalFunctionName: () => { throw new Error('stub function should not be called'); },
833+
$newFunc: () => { throw new Error('stub function should not be called'); },
834+
$runDestructors: () => { throw new Error('stub function should not be called'); },
835+
$createNamedFunction: () => { throw new Error('stub function should not be called'); },
829836
};
830837

831838
#if EMBIND_AOT

test/test_other.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3384,7 +3384,9 @@ def test_embind_tsgen_ignore(self):
33843384
extra_args = ['-sMODULARIZE',
33853385
'--embed-file', 'fail.js',
33863386
'-sMINIMAL_RUNTIME=2',
3387-
'-sEXPORT_ES6=1']
3387+
'-sEXPORT_ES6=1',
3388+
'-sASSERTIONS=0',
3389+
'-sSTRICT=1']
33883390
self.emcc(test_file('other/embind_tsgen.cpp'), extra_args)
33893391
self.assertFileContents(test_file('other/embind_tsgen_ignore_2.d.ts'), read_file('embind_tsgen.d.ts'))
33903392
# Also test this separately since it conflicts with other settings.

0 commit comments

Comments
 (0)