From 3d6db80593cd4260514a1876ca535e55b0d80076 Mon Sep 17 00:00:00 2001 From: roblabla Date: Thu, 13 Aug 2015 14:56:48 +0000 Subject: [PATCH] TypeArgs should default to an empty object in case it is undefined --- src/protocol.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/protocol.js b/src/protocol.js index d254f4e..d8f916b 100644 --- a/src/protocol.js +++ b/src/protocol.js @@ -20,7 +20,8 @@ NMProtocols.prototype.read = function(buffer, cursor, fieldInfo, rootNodes) { error: new Error("missing data type: " + fieldInfo.type) }; } - var readResults = type[0].call(this, buffer, cursor, fieldInfo.typeArgs, rootNodes); + var typeArgs = fieldInfo.typeArgs || {}; + var readResults = type[0].call(this, buffer, cursor, typeArgs, rootNodes); if(readResults == null) { throw new Error("Reader returned null : " + JSON.stringify(fieldInfo)); } @@ -35,7 +36,8 @@ NMProtocols.prototype.write = function(value, buffer, offset, fieldInfo, rootNod error: new Error("missing data type: " + fieldInfo.type) }; } - return type[1].call(this, value, buffer, offset, fieldInfo.typeArgs, rootNode); + var typeArgs = fieldInfo.typeArgs || {}; + return type[1].call(this, value, buffer, offset, typeArgs, rootNode); }; NMProtocols.prototype.sizeOf = function(value, fieldInfo, rootNode) { @@ -44,7 +46,8 @@ NMProtocols.prototype.sizeOf = function(value, fieldInfo, rootNode) { throw new Error("missing data type: " + fieldInfo.type); } if(typeof type[2] === 'function') { - return type[2].call(this, value, fieldInfo.typeArgs, rootNode); + var typeArgs = fieldInfo.typeArgs || {}; + return type[2].call(this, value, typeArgs, rootNode); } else { return type[2]; }