Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/embind/embind.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,14 @@ var LibraryEmbind = {
// We are exposing a function with the same name as an existing function. Create an overload table and a function selector
// that routes between the two.
ensureOverloadTable(Module, name, name);
if (Module.hasOwnProperty(numArguments)) {
if (Module[name].overloadTable.hasOwnProperty(numArguments)) {
throwBindingError(`Cannot register multiple overloads of a function with the same number of arguments (${numArguments})!`);
}
// Add the new function into the overload table.
Module[name].overloadTable[numArguments] = value;
}
else {
} else {
Module[name] = value;
if (undefined !== numArguments) {
Module[name].numArguments = numArguments;
}
Module[name].argCount = numArguments;
}
},

Expand All @@ -147,8 +144,7 @@ var LibraryEmbind = {
// If there's an overload table for this symbol, replace the symbol in the overload table instead.
if (undefined !== Module[name].overloadTable && undefined !== numArguments) {
Module[name].overloadTable[numArguments] = value;
}
else {
} else {
Module[name] = value;
Module[name].argCount = numArguments;
}
Expand Down
8 changes: 4 additions & 4 deletions test/code_size/embind_hello_wasm.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.html": 552,
"a.html.gz": 380,
"a.js": 9727,
"a.js.gz": 4295,
"a.js": 9718,
"a.js.gz": 4291,
"a.wasm": 7730,
"a.wasm.gz": 3507,
"total": 18009,
"total_gz": 8182
"total": 18000,
"total_gz": 8178
}
22 changes: 22 additions & 0 deletions test/embind/test_embind_invalid_overload.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <functional>
#include <emscripten/bind.h>

using namespace emscripten;

int main() {
}

int foo(int a) {
return 0;
}

int foo(float a) {
return 0;
}

EMSCRIPTEN_BINDINGS(bindings) {
// Overloads in embind all need to have a unique number of arguments.
// This is invalid since both overloads take just one argument.
function("foo", select_overload<int(int)>(&foo));
function("foo", select_overload<int(float)>(&foo));
}
4 changes: 4 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -3127,6 +3127,10 @@ def test_embind_fail(self):
out = self.expect_fail([EMXX, test_file('embind/test_unsigned.cpp')])
self.assertContained("undefined symbol: _embind_register_function", out)

def test_embind_invalid_overload(self):
expected = 'BindingError: Cannot register multiple overloads of a function with the same number of arguments'
self.do_runf(test_file('embind/test_embind_invalid_overload.cpp'), expected, emcc_args=['-lembind'], assert_returncode=NON_ZERO)

def test_embind_asyncify(self):
create_file('post.js', '''
addOnPostRun(() => {
Expand Down
Loading