Make mismatched-marker reporting work
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Tue, 10 May 2011 12:58:59 -0600
changeset 101 95523848c7f8
parent 100 92484a18d548
child 102 babf18ca1062
Make mismatched-marker reporting work

Apparently I a) didn't understand how Regexp.exec() works and b) didn't
pay close enough attention to what might throw exceptions in the catch
block.
autoimplementation.html
--- a/autoimplementation.html	Mon May 09 16:30:29 2011 -0600
+++ b/autoimplementation.html	Tue May 10 12:58:59 2011 -0600
@@ -1433,8 +1433,8 @@
 		specCell.firstChild.removeAttribute("spellcheck");
 		specCell.lastChild.style.color = "red";
 		specCell.lastChild.style.fontWeight = "bold";
-		specCell.lastChild.textContent = "Note, exception: " + e;
-		if ("stack" in e) {
+		specCell.lastChild.textContent = "Exception: " + e;
+		if (typeof e == "object" && "stack" in e) {
 			specCell.lastChild.textContent += " (stack: " + e.stack + ")";
 		}
 
@@ -1454,7 +1454,7 @@
 		specCell.lastChild.appendChild(document.createElement("div"));
 		specCell.lastChild.lastChild.style.color = "red";
 		specCell.lastChild.lastChild.style.fontWeight = "bold";
-		specCell.lastChild.lastChild.textContent = "Note, last run produced different markup: " + oldValue;
+		specCell.lastChild.lastChild.textContent = "Last run produced different markup: " + oldValue;
 
 		var button = document.createElement("button");
 		specCell.lastChild.lastChild.appendChild(button);
@@ -1523,7 +1523,7 @@
 		browserCell.lastChild.style.color = "red";
 		browserCell.lastChild.style.fontWeight = "bold";
 		browserCell.lastChild.textContent = "Exception: " + e;
-		if ("stack" in e) {
+		if (typeof e == "object" && "stack" in e) {
 			specCell.lastChild.textContent += " (stack: " + e.stack + ")";
 		}
 		if (testDiv && testDiv.parentNode != browserCell) {
@@ -1602,24 +1602,29 @@
 }
 
 function setupCell(cell, test) {
+	cell.innerHTML = "<div></div><div></div>";
+
 	// A variety of checks to avoid simple errors.  Not foolproof, of course.
-	var startMarkers = /\{|\[|data-start/.exec(test);
-	if (!startMarkers) {
-		startMarkers = [];
+	var re = /\{|\[|data-start/g;
+	var markers = [];
+	var marker;
+	while (marker = re.exec(test)) {
+		markers.push(marker);
 	}
-	if (startMarkers.length != 1) {
-		throw "Need exactly one start marker ([ or { or data-start), found " + startMarkers.length;
+	if (markers.length != 1) {
+		throw "Need exactly one start marker ([ or { or data-start), found " + markers.length;
 	}
 
-	var endMarkers = /\}|\]|data-end/.exec(test);
-	if (!endMarkers) {
-		endMarkers = [];
+	var re = /\}|\]|data-end/g;
+	var markers = [];
+	var marker;
+	while (marker = re.exec(test)) {
+		markers.push(marker);
 	}
-	if (endMarkers.length != 1) {
-		throw "Need exactly one end marker (] or } or data-end), found " + endMarkers.length;
+	if (markers.length != 1) {
+		throw "Need exactly one end marker (] or } or data-end), found " + markers.length;
 	}
 
-	cell.innerHTML = "<div></div><div></div>";
 	var node = cell.firstChild;
 	node.innerHTML = test;