[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
parent 314df0f71e
commit 8dbcd710ff
5 changed files with 36 additions and 2 deletions

View File

@ -7,6 +7,9 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.1.0 (in progress)
===========================
2022-03-07: olly
[Javascript] #682 Fix handling of functions which take void*.
2022-03-06: olly
SWIG should now reliably exit with status 0 if the run was
successful and status 1 if there was an error (or a warning and

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; }
%}

View File

@ -122,7 +122,7 @@ SWIGRUNTIME int SWIG_JSC_ConvertInstancePtr(JSContextRef context, JSObjectRef ob
}
assert(ptr);
*ptr = NULL;
if (cdata->info == info) {
if (!info || cdata->info == info) {
*ptr = cdata->swigCObject;
} else {
swig_cast_info *tc = SWIG_TypeCheckStruct(cdata->info, info);

View File

@ -178,7 +178,7 @@ SWIGRUNTIME int SWIG_V8_ConvertInstancePtr(SWIGV8_OBJECT objRef, void **ptr, swi
if(cdata == NULL) {
return SWIG_ERROR;
}
if(cdata->info != info) {
if(info && cdata->info != info) {
swig_cast_info *tc = SWIG_TypeCheckStruct(cdata->info, info);
if (!tc && cdata->info->name) {
tc = SWIG_TypeCheck(cdata->info->name, info);