diff options
| -rw-r--r-- | threads.js | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -681,6 +681,15 @@ Process.prototype.doYield = function () { // Process Exception Handling +Process.prototype.checkIfList = function (maybeList) { + if (!(maybeList instanceof List)) { + var error = {name: 'list error', message: 'expecting a list'}; + this.handleError(error); + maybeList = new List(); + } + return maybeList; +}; + Process.prototype.handleError = function (error, element) { var m = element; this.stop(); @@ -1232,15 +1241,19 @@ Process.prototype.reportCONS = function (car, cdr) { }; Process.prototype.reportCDR = function (list) { + list = this.checkIfList(list); return list.cdr(); }; Process.prototype.doAddToList = function (element, list) { + list = this.checkIfList(list); list.add(element); }; Process.prototype.doDeleteFromList = function (index, list) { var idx = index; + list = this.checkIfList(list); + if (this.inputOption(index) === 'all') { return list.clear(); } @@ -1255,6 +1268,8 @@ Process.prototype.doDeleteFromList = function (index, list) { Process.prototype.doInsertInList = function (element, index, list) { var idx = index; + list = this.checkIfList(list); + if (index === '') { return null; } @@ -1269,6 +1284,8 @@ Process.prototype.doInsertInList = function (element, index, list) { Process.prototype.doReplaceInList = function (index, list, element) { var idx = index; + list = this.checkIfList(list); + if (index === '') { return null; } @@ -1283,6 +1300,8 @@ Process.prototype.doReplaceInList = function (index, list, element) { Process.prototype.reportListItem = function (index, list) { var idx = index; + list = this.checkIfList(list); + if (index === '') { return ''; } @@ -1296,10 +1315,12 @@ Process.prototype.reportListItem = function (index, list) { }; Process.prototype.reportListLength = function (list) { + list = this.checkIfList(list); return list.length(); }; Process.prototype.reportListContainsItem = function (list, element) { + list = this.checkIfList(list); return list.contains(element); }; @@ -1582,6 +1603,8 @@ Process.prototype.reportMap = function (reporter, list) { // documented in each of the variants' code (linked or arrayed) below var next; + list = this.checkIfList(list); + if (list.isLinked) { // this.context.inputs: // [0] - reporter |
