Fix v8 string conversion in case of null arguments.

This commit is contained in:
Oliver Buchtala 2013-01-25 14:07:06 +01:00
commit 65560a8664

View file

@ -14,6 +14,9 @@
%fragment("SWIGV8_valueToString", "header", fragment="SWIG_AsCharPtrAndSize") {
std::string* SWIGV8_valueToStringPtr(v8::Handle<v8::Value> val) {
if (!val->IsString()) return 0;
int alloc;
size_t size;
char* chars;
@ -48,17 +51,19 @@ namespace std {
%{
tmp = SWIGV8_valueToStringPtr($input);
$1 = *tmp;
delete tmp;
if (tmp == 0) { v8::ThrowException(v8::Exception::TypeError(v8::String::New("Null pointer."))); goto fail; }
if (tmp) delete tmp;
%}
%typemap(in, fragment="SWIGV8_valueToString") const string &
%{
$1 = SWIGV8_valueToStringPtr($input);
if ($1 == 0) { v8::ThrowException(v8::Exception::TypeError(v8::String::New("Null pointer."))); goto fail; }
%}
%typemap(freearg) const string &
%{
delete $1;
if ($1) delete $1;
%}
%typemap(out, fragment="SWIGV8_stringToValue") string