Browse Source

syntax (semicolons, extra colons), moving out from non-ES5 things catch (ex if ...), yield

Herbert Vojčík 13 years ago
parent
commit
ca6fafe878
1 changed files with 29 additions and 17 deletions
  1. 29 17
      lib-support/useful.js

+ 29 - 17
lib-support/useful.js

@@ -65,16 +65,18 @@ function _collector(result) { return function() { result.push.apply(result, argu
  @example
  collectYield(function () {for (var p in object) { if (object.hasOwnProperty(p) yield p; }});
  */
-function collectYield(f) {
+/*function collectYield(f) {
     var result = [];
     var gen = f();
     try {
         for(;;) { result.push(gen.next()); }
-    } catch (ex if ex instanceof StopIteration) {
-        //gen.close(); //strange, not needed
+    } catch (ex) {
+    	if (ex instanceof StopIteration) {
+    		//gen.close(); //strange, not needed
+    	} else throw ex;
     }
     return result;
-}
+}*/
 
 //from web; then edited
 /** Converts h,s,v (0-1) to rgb (0-255). Returns array [r, g, b]. */
@@ -178,8 +180,10 @@ page.testSuite = [
 	    try {
 	        _l.collectPrint(f);
 	        fail("Exception not thrown");
-	    } catch(ex if ex === "exception") {
-	        // pass
+	    } catch(ex) {
+	    	if (ex === "exception") {
+	    		// pass
+	    	} else throw ex;
 	    }
 	    assertEquals("Print not retained.", savedPrint, this.print);
 	},
@@ -190,13 +194,15 @@ page.testSuite = [
 	    try {
 	        _l.collectPrint(f);
 	        fail("Exception not thrown");
-	    } catch(ex if ex === undefined) {
-	        // pass
+	    } catch(ex) {
+	    	if (ex === undefined) {
+	    		// pass
+	    	} else throw ex;
 	    }
 	    assertEquals("Print not retained.", savedPrint, this.print);
 	},
 	
-	function collectYieldCollectsYieldedArguments() {
+	/*function collectYieldCollectsYieldedArguments() {
 	    var collected = _l.collectYield(function() {
 	        yield "Hello";
 	        yield 3;
@@ -224,8 +230,10 @@ page.testSuite = [
 	            yield "world";
 	        });
 	        fail("Exception not thrown.");
-	    } catch(ex if ex === "exception") {
-	        // pass
+	    } catch(ex) {
+	    	if (ex === "exception") {
+	    		// pass
+	    	} else throw ex;
 	    }
 	},
 	
@@ -237,8 +245,10 @@ page.testSuite = [
 	            yield "world";
 	        });
 	        fail("Exception not thrown.");
-	    } catch(ex if ex === undefined) {
-	        // pass
+	    } catch(ex) {
+	    	if (ex === undefined) {
+	    		// pass
+	    	} else throw ex;
 	    }
 	},
 	
@@ -253,11 +263,13 @@ page.testSuite = [
 	            } finally { finallyRun = true; }
 	        });
 	        fail("Exception not thrown.");
-	    } catch(ex if ex === "exception") {
-	        // pass
+	    } catch(ex) {
+	    	if (ex === "exception") {
+	    		// pass
+	    	} else throw ex;
 	    }
 	    assertTrue("Finally in f did not run.", finallyRun);
-	},
+	},*/
 	
 	function readonlyReadsCorrectlyAndIsDynamic() {
 	    var x = {hello: "world"};
@@ -280,7 +292,7 @@ page.testSuite = [
 	},
 	
 	function extendExtendsCorrectlyForAllCombinations() {
-	    var srcProto = { pro: "to" }
+	    var srcProto = { pro: "to" };
 	    var src = object(srcProto);
 	    src.a = "b"; src.c = "d";
 	    var dst = { pro: "fi", a: "bc", yes: "true" };