File tree 5 files changed +26
-17
lines changed
5 files changed +26
-17
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,9 @@ See docs/process.md for more on how version tagging works.
46
46
` MIN_CHROME_VERSION ` will now result in build-time error. All of these
47
47
browser versions are at least 8 years old now so the hope is that nobody
48
48
is intending to target them today. (#20924 )
49
+ - C++ objects passed into embind's val via constructors, methods, and call
50
+ function will not be automatically destroyed after the function call. This
51
+ makes the behavior consistent for invocations.
49
52
50
53
3.1.51 - 12/13/23
51
54
-----------------
Original file line number Diff line number Diff line change @@ -678,9 +678,6 @@ var LibraryEmbind = {
678
678
'argPackAdvance' : GenericWireTypeSize ,
679
679
'readValueFromPointer' : simpleReadValueFromPointer ,
680
680
destructorFunction : null , // This type does not need a destructor
681
-
682
- // TODO: do we need a deleteObject here? write a test where
683
- // emval is passed into JS via an interface
684
681
} ) ;
685
682
} ,
686
683
@@ -1311,11 +1308,6 @@ var LibraryEmbind = {
1311
1308
} ,
1312
1309
'argPackAdvance' : GenericWireTypeSize ,
1313
1310
'readValueFromPointer' : readPointer ,
1314
- 'deleteObject' ( handle ) {
1315
- if ( handle !== null ) {
1316
- handle [ 'delete' ] ( ) ;
1317
- }
1318
- } ,
1319
1311
'fromWireType' : RegisteredPointer_fromWireType ,
1320
1312
} ) ;
1321
1313
} ,
Original file line number Diff line number Diff line change @@ -335,9 +335,6 @@ var LibraryEmVal = {
335
335
offset += types [ i ] [ 'argPackAdvance' ] ;
336
336
}
337
337
var rv = kind === /* CONSTRUCTOR */ 1 ? reflectConstruct ( func , argN ) : func . apply ( obj , argN ) ;
338
- for ( var i = 0 ; i < argCount ; ++ i ) {
339
- types [ i ] . deleteObject ?. ( argN [ i ] ) ;
340
- }
341
338
return emval_returnValue ( retType , destructorsRef , rv ) ;
342
339
} ;
343
340
#else
@@ -362,12 +359,6 @@ var LibraryEmVal = {
362
359
var invoker = kind === /* CONSTRUCTOR */ 1 ? 'new func' : 'func.call' ;
363
360
functionBody +=
364
361
` var rv = ${ invoker } (${ argsList . join ( ", " ) } );\n` ;
365
- for ( var i = 0 ; i < argCount ; ++ i ) {
366
- if ( types [ i ] [ 'deleteObject' ] ) {
367
- functionBody +=
368
- ` argType${ i } .deleteObject(arg${ i } );\n` ;
369
- }
370
- }
371
362
if ( ! retType . isVoid ) {
372
363
params . push ( "emval_returnValue" ) ;
373
364
args . push ( emval_returnValue ) ;
Original file line number Diff line number Diff line change @@ -707,6 +707,10 @@ module({
707
707
cm . emval_test_take_and_return_std_string_const_ref ( "foobar" ) ;
708
708
} ) ;
709
709
710
+ test ( "val callback arguments are not destroyed" , function ( ) {
711
+ cm . emval_test_callback_arg_lifetime ( function ( ) { } ) ;
712
+ } ) ;
713
+
710
714
test ( "can get global" , function ( ) {
711
715
/*jshint evil:true*/
712
716
assert . equal ( ( new Function ( "return this;" ) ) ( ) , cm . embind_test_getglobal ( ) ) ;
Original file line number Diff line number Diff line change @@ -127,6 +127,22 @@ unsigned emval_test_sum(val v) {
127
127
return rv;
128
128
}
129
129
130
+ struct DestructorCounter {
131
+ static int count;
132
+ ~DestructorCounter () {
133
+ count++;
134
+ };
135
+ };
136
+
137
+ int DestructorCounter::count = 0 ;
138
+
139
+ void emval_test_callback_arg_lifetime (val callback) {
140
+ DestructorCounter dc;
141
+ int destructorCount = DestructorCounter::count;
142
+ callback (dc);
143
+ assert (destructorCount == DestructorCounter::count);
144
+ }
145
+
130
146
std::string get_non_ascii_string (bool embindStdStringUTF8Support) {
131
147
if (embindStdStringUTF8Support) {
132
148
// ASCII
@@ -1828,6 +1844,9 @@ EMSCRIPTEN_BINDINGS(tests) {
1828
1844
function (" const_ref_adder" , &const_ref_adder);
1829
1845
function (" emval_test_sum" , &emval_test_sum);
1830
1846
1847
+ class_<DestructorCounter>(" DestructorCounter" );
1848
+ function (" emval_test_callback_arg_lifetime" , &emval_test_callback_arg_lifetime);
1849
+
1831
1850
function (" get_non_ascii_string" , &get_non_ascii_string);
1832
1851
function (" get_non_ascii_wstring" , &get_non_ascii_wstring);
1833
1852
function (" get_literal_wstring" , &get_literal_wstring);
You can’t perform that action at this time.
0 commit comments