obuchtala / swig

Branch for the development of SWIG's javascript target (v8 and jsc)
https://github.com/swig/swig
Other
25 stars 14 forks source link

ConvertPtr should accept JavaScript null #41

Closed ewmailing closed 10 years ago

ewmailing commented 10 years ago

ConvertPtr should allow JavaScript null to be a valid value.

It is common in C to accept NULL to functions for pointer parameters. extern void DoSomething(struct Foo* foo); ... DoSomething(NULL);

Thus, JavaScript null should be allowed: module.DoSomething(null);

But the current ConvertPtr definition accepts only objects.

I have a fix for JavaScriptCore at: https://github.com/ewmailing/swig In the branch JSnullptr

My guess is the v8 implementation in javascriptrun.swg should be: int SWIG_V8_ConvertPtr(v8::Handlev8::Value valRef, void* ptr, swig_type_info info, int flags) { v8::HandleScope scope;

/* special case: JavaScript null => C NULL pointer / if(!valRef->IsNULL()) { ptr=0; return SWIG_OK; } if(!valRef->IsObject()) { return SWIG_TypeError; } v8::Handlev8::Object objRef = valRef->ToObject(); return SWIG_V8_ConvertInstancePtr(objRef, ptr, info, flags); }

But I'm currently not in a good position to test v8.

obuchtala commented 10 years ago

Done via swig/swig@11963788e0d008e1c6e997577086cd8dd584c03f