summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGubolin <gubolin@fantasymail.de>2014-11-03 17:59:29 +0100
committerGubolin <gubolin@fantasymail.de>2014-11-03 17:59:29 +0100
commit7ca756e509c8a53bc93d43cc9366e19789c0d697 (patch)
tree19096b01bfb7b0b0f7fe2f126341fdd157c94743
parent5f3279990be3478fde79b94f7dbd5d7da80df84b (diff)
downloadsnap-7ca756e509c8a53bc93d43cc9366e19789c0d697.tar.gz
snap-7ca756e509c8a53bc93d43cc9366e19789c0d697.zip
throw an non-js error if "list" is not List (fix #533)
-rw-r--r--threads.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/threads.js b/threads.js
index 6a59f3c..e225fd9 100644
--- a/threads.js
+++ b/threads.js
@@ -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