Add support for Map/Set property types on Debug

This commit is contained in:
Nick O'Leary
2021-06-29 11:09:30 +01:00
parent 58023b4bf0
commit 48ac50e1c9
3 changed files with 112 additions and 12 deletions

View File

@@ -806,6 +806,7 @@ function encodeObject(msg,opts) {
});
} else {
var isArray = util.isArray(msg.msg);
var needsStringify = isArray;
if (isArray) {
msg.format = "array["+msg.msg.length+"]";
if (msg.msg.length > debuglength) {
@@ -817,8 +818,26 @@ function encodeObject(msg,opts) {
length: msg.msg.length
}
}
} else if (msg.msg && msg.msg.constructor.name === "Set") {
msg.format = "set["+msg.msg.size+"]";
msg.msg = {
__enc__: true,
type: "set",
data: Array.from(msg.msg).slice(0,debuglength),
length: msg.msg.size
}
needsStringify = true;
} else if (msg.msg && msg.msg.constructor.name === "Map") {
msg.format = "map";
msg.msg = {
__enc__: true,
type: "map",
data: Object.fromEntries(Array.from(msg.msg.entries()).slice(0,debuglength)),
length: msg.msg.size
}
needsStringify = true;
}
if (isArray || (msg.format === "Object")) {
if (needsStringify || (msg.format === "Object")) {
msg.msg = safeJSONStringify(msg.msg, function(key, value) {
if (key === '_req' || key === '_res') {
value = {
@@ -868,6 +887,20 @@ function encodeObject(msg,opts) {
value = "[internal]"
} else if (value.constructor.name === "Socket") {
value = "[internal]"
} else if (value.constructor.name === "Set") {
value = {
__enc__: true,
type: "set",
data: Array.from(value).slice(0,debuglength),
length: value.size
}
} else if (value.constructor.name === "Map") {
value = {
__enc__: true,
type: "map",
data: Object.fromEntries(Array.from(value.entries()).slice(0,debuglength)),
length: value.size
}
}
} else if (value === undefined) {
value = {