Skip to content

Commit 934a07b

Browse files
committed
[embind] Fix type in overloadTable error checking. NFC
1 parent ff27062 commit 934a07b

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

src/embind/embind.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ var LibraryEmbind = {
124124
// We are exposing a function with the same name as an existing function. Create an overload table and a function selector
125125
// that routes between the two.
126126
ensureOverloadTable(Module, name, name);
127-
if (Module.hasOwnProperty(numArguments)) {
127+
if (Module[name].overloadTable.hasOwnProperty(numArguments)) {
128128
throwBindingError(`Cannot register multiple overloads of a function with the same number of arguments (${numArguments})!`);
129129
}
130130
// Add the new function into the overload table.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 552,
33
"a.html.gz": 380,
4-
"a.js": 9727,
5-
"a.js.gz": 4295,
4+
"a.js": 9732,
5+
"a.js.gz": 4296,
66
"a.wasm": 7730,
77
"a.wasm.gz": 3507,
8-
"total": 18009,
9-
"total_gz": 8182
8+
"total": 18014,
9+
"total_gz": 8183
1010
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <functional>
2+
#include <emscripten/bind.h>
3+
4+
using namespace emscripten;
5+
6+
int main() {
7+
}
8+
9+
int foo(int a) {
10+
return 0;
11+
}
12+
13+
int foo(float a) {
14+
return 0;
15+
}
16+
17+
EMSCRIPTEN_BINDINGS(bindings) {
18+
// Overloads in embind all need to have a unique number of arguments.
19+
// This is invalid since both overloads take just one argument.
20+
function("foo", select_overload<int(int)>(&foo));
21+
function("foo", select_overload<int(float)>(&foo));
22+
}

test/test_other.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3127,6 +3127,10 @@ def test_embind_fail(self):
31273127
out = self.expect_fail([EMXX, test_file('embind/test_unsigned.cpp')])
31283128
self.assertContained("undefined symbol: _embind_register_function", out)
31293129

3130+
def test_embind_invalid_overload(self):
3131+
err = self.expect_fail([EMCC, test_file('embind/test_embind_invalid_overload.cpp'), '-lembind', '-c'])
3132+
self.assertContained('BindingError: Cannot register multiple overloads of a function with the same number of arguments (1)!', err)
3133+
31303134
def test_embind_asyncify(self):
31313135
create_file('post.js', '''
31323136
addOnPostRun(() => {

0 commit comments

Comments
 (0)