[Javascript] Fix handling of functions which take void*

Fixes #682
This commit is contained in:
Olly Betts 2022-03-07 13:24:37 +13:00 • committed by Olly Betts
commit 8dbcd710ff
5 changed files with 36 additions and 2 deletions

View file

@ -0,0 +1,28 @@
var voidtest = require("voidtest");
voidtest.globalfunc();
var f = new voidtest.Foo();
f.memberfunc();
voidtest.Foo.staticmemberfunc();
if (f.memberfunc() !== (function(){}())) {
throw new Error("f.memberfunc() didn't return same result as pure Javascript equivalent");
}
v1 = voidtest.vfunc1(f);
v2 = voidtest.vfunc2(f);
if (!voidtest.test_pointers_equal(v1, v2)) {
throw new Error("!voidtest.test_pointers_equal(v1, v2)");
}
v3 = voidtest.vfunc3(v1);
if (!voidtest.test_pointers_equal(v3.get_this(), f.get_this())) {
throw new Error("!voidtest.test_pointers_equal(v3.get_this(), f.get_this())");
}
v4 = voidtest.vfunc1(f);
if (!voidtest.test_pointers_equal(v4, v1)) {
throw new Error("!voidtest.test_pointers_equal(v4, v1)");
}
v3.memberfunc();

View file

@ -9,6 +9,7 @@ class Foo {
public:
Foo(void) { }
void memberfunc(void) { }
void* get_this() { return this; }
static void staticmemberfunc(void) { }
};
@ -18,4 +19,6 @@ void *vfunc2(Foo *f) { return f; }
Foo *vfunc3(void *f) { return (Foo *) f; }
Foo *vfunc4(Foo *f) { return f; }
bool test_pointers_equal(void *a, void *b) { return a == b; }
%}