diff --git a/src/embind/embind.js b/src/embind/embind.js index 3560ad27eae90..1597b296f193c 100644 --- a/src/embind/embind.js +++ b/src/embind/embind.js @@ -675,6 +675,23 @@ var LibraryEmbind = { return this['fromWireType']({{{ makeGetValue('pointer', '0', 'i32') }}}); }, + _embind_register_std_nullptr_t__sig: 'vpppDn', + _embind_register_std_nullptr_t__deps: ['$registerType'], + _embind_register_std_nullptr_t: function(rawType, name) { + + registerType(rawType, { + name: name, + 'fromWireType': function (value) { + return null; + }, + 'toWireType': function (destructors, value) { + return null; + }, + 'argPackAdvance': 8, + destructorFunction: null, // This type does not need a destructor + }); + }, + _embind_register_std_string__sig: 'vpp', _embind_register_std_string__deps: [ '$readLatin1String', '$registerType', diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index d6e35a4682a02..dccb66a9a9380 100644 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -78,6 +78,10 @@ void _embind_register_float( const char* name, size_t size); +void _embind_register_std_nullptr_t( + TYPEID nullptrType, + const char* name); + void _embind_register_std_string( TYPEID stringType, const char* name); diff --git a/system/lib/embind/bind.cpp b/system/lib/embind/bind.cpp index 732c8ae59d45e..64a0a17a8c295 100644 --- a/system/lib/embind/bind.cpp +++ b/system/lib/embind/bind.cpp @@ -9,6 +9,7 @@ #endif #include #include +#include #include #include #include @@ -142,6 +143,7 @@ EMSCRIPTEN_BINDINGS(builtin) { register_float("float"); register_float("double"); + _embind_register_std_nullptr_t(TypeID::get(), "std::nullptr_t"); _embind_register_std_string(TypeID::get(), "std::string"); _embind_register_std_string( TypeID>::get(), "std::basic_string"); diff --git a/test/embind/embind.test.js b/test/embind/embind.test.js index 2007aa3e7a342..aa953f2960b56 100644 --- a/test/embind/embind.test.js +++ b/test/embind/embind.test.js @@ -565,6 +565,10 @@ module({ assert.equal(undefined, cm.emval_test_return_void()); }); + test("nullptr_t return converts to null", function() { + assert.equal(null, cm.emval_test_return_null()); + }); + test("booleans can be marshalled", function() { assert.equal(false, cm.emval_test_not(true)); assert.equal(true, cm.emval_test_not(false)); diff --git a/test/embind/embind_test.cpp b/test/embind/embind_test.cpp index 1366e491ca178..fc011c0a612e2 100644 --- a/test/embind/embind_test.cpp +++ b/test/embind/embind_test.cpp @@ -3,6 +3,7 @@ // University of Illinois/NCSA Open Source License. Both these licenses can be // found in the LICENSE file. +#include #include #include #include @@ -74,6 +75,10 @@ val emval_test_passthrough(val v) { void emval_test_return_void() { } +std::nullptr_t emval_test_return_nullptr_t() { + return nullptr; +} + bool emval_test_not(bool b) { return !b; }