Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions lib/js/src/rpc/RpcStruct.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,21 @@ class RpcStruct {
* @param {Boolean} isArray - Whether or not the given variable is an array to be iterated through.
*/
_validateType (tClass, obj, isArray = false) {
if (isArray) {
if (!Array.isArray(obj)) {
throw new Error(`${obj.name} must be an array containing items of type ${tClass.name}`);
} else {
for (const item of obj) {
this._validateType(tClass, item, false);
if (obj !== null) {
if (isArray) {
if (!Array.isArray(obj)) {
throw new Error(`${obj.name} must be an array containing items of type ${tClass.name}`);
} else {
for (const item of obj) {
this._validateType(tClass, item, false);
}
}
} else if (
(tClass.prototype instanceof Enum && tClass.keyForValue(obj) === null)
|| (tClass.prototype instanceof RpcStruct && obj.constructor !== tClass)
) {
throw new Error(`${obj.name} must be of type ${tClass.name}`);
}
} else if (
(tClass.prototype instanceof Enum && tClass.keyForValue(obj) === null)
|| (tClass.prototype instanceof RpcStruct && obj !== null && obj.constructor !== tClass)
) {
throw new Error(`${obj.name} must be of type ${tClass.name}`);
}
}
}
Expand Down