Skip to content

Commit 8c0fe77

Browse files
authored
Add missing function dependency for embind class constructor. (#17152)
* Add missing function dependency for embind class constructor. The `craftInvokerFunction` was not being generated if embind was used for a class binding without ever using a `function` binding. Fixes #17143
1 parent e3136a8 commit 8c0fe77

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/embind/embind.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2075,7 +2075,8 @@ var LibraryEmbind = {
20752075

20762076
_embind_register_class_constructor__deps: [
20772077
'$heap32VectorToArray', '$embind__requireFunction', '$runDestructors',
2078-
'$throwBindingError', '$whenDependentTypesAreResolved', '$registeredTypes'],
2078+
'$throwBindingError', '$whenDependentTypesAreResolved', '$registeredTypes',
2079+
'$craftInvokerFunction'],
20792080
_embind_register_class_constructor: function(
20802081
rawClassType,
20812082
argCount,

tests/test_other.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2465,6 +2465,33 @@ def test_embind_asyncify(self):
24652465
self.run_process([EMXX, 'main.cpp', '-lembind', '-sASYNCIFY', '--post-js', 'post.js'])
24662466
self.assertContained('done', self.run_js('a.out.js'))
24672467

2468+
def test_embind_no_function(self):
2469+
create_file('post.js', '''
2470+
Module['onRuntimeInitialized'] = function() {
2471+
out((new Module['MyClass'](42)).x);
2472+
};
2473+
''')
2474+
create_file('main.cpp', r'''
2475+
#include <emscripten.h>
2476+
#include <emscripten/bind.h>
2477+
using namespace emscripten;
2478+
class MyClass {
2479+
public:
2480+
MyClass(int x) : x(x) {}
2481+
2482+
int getX() const {return x;}
2483+
void setX(int newX) {x = newX;}
2484+
private:
2485+
int x;
2486+
};
2487+
EMSCRIPTEN_BINDINGS(my_module) {
2488+
class_<MyClass>("MyClass")
2489+
.constructor<int>()
2490+
.property("x", &MyClass::getX, &MyClass::setX);
2491+
}
2492+
''')
2493+
self.do_runf('main.cpp', '42', emcc_args=['-lembind', '--post-js', 'post.js'])
2494+
24682495
def test_embind_closure_no_dynamic_execution(self):
24692496
create_file('post.js', '''
24702497
Module['onRuntimeInitialized'] = function() {

0 commit comments

Comments
 (0)