Merge pull request #1822 from m000z0rz/fix-js-api-undefined-callbacks

(JS API) Allow undefined (optional) callbacks for Socket.connect and Socket.write
This commit is contained in:
zilmar 2020-06-18 09:36:56 +09:30 committed by GitHub
commit 760a3d6b00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

View File

@ -51,6 +51,7 @@ const _gprNames = [
// to them in Javascript so they don't get garbage collected before native code uses them.
const _strongBackingReferences = (function() {
const _references = [];
const noop = function () { };
return {
"add": function _strongBackingReferences_add(obj)
@ -67,6 +68,11 @@ const _strongBackingReferences = (function() {
},
"singleUseCallback": function _strongBackingReferences_singleUseCallback(callback)
{
if (callback === undefined)
{
return noop;
}
const singleUseCallback = function ()
{
callback.apply(undefined, arguments);
@ -896,7 +902,10 @@ function Socket(fd)
var _onconnect_base = function(){
connected = 1;
_onconnect();
if (_onconnect !== undefined)
{
_onconnect();
}
}
var _bufferSize = 2048