Permalink
Browse files

Fix a bug in continue in an untamed context. Add a test case to test it

  • Loading branch information...
maxtaco committed Nov 29, 2011
1 parent af0ea3b commit 0bc145580c78981628df2c93dcfb6f88e9aa086e
Showing with 71 additions and 26 deletions.
  1. +10 −0 lib/ast.js
  2. +3 −1 notes/cps-v2-notes.js
  3. +1 −1 package.json
  4. +24 −24 test/cases/11.tjs
  5. +33 −0 test/cases/36.tjs
View
@@ -1484,6 +1484,16 @@ function ContinueStatement (startLine, targetLabel) {
//-----------------------------------------
+ that.passThrough = function (eng) {
+ var ret = eng.newOutput ();
+ var lbl = "";
+ if (this._targetLabel) { lbl = this._targetLabel; }
+ ret.addLine ("continue " + lbl + ";");
+ return ret;
+ };
+
+ //-----------------------------------------
+
that.compile = function (eng) {
var fn = eng.fnFresh ();
var ret = eng.newOutput (fn);
View
@@ -62,7 +62,9 @@ A(block) {
function bar (x) {
if (x) {
if (x == 3) {
- return x;
+ if (y == 4) {
+ return x;
+ }
x++;
} else {
x += 3
View
@@ -2,7 +2,7 @@
"author" : "Max Krohn <max@okcupid.com>",
"name" : "tamejs",
"description" : "JavaScript-to-JavaScript code rewriter for taming async-callback-style code",
- "version" : "0.4.6",
+ "version" : "0.4.7",
"keywords" : [
"tame",
"libasync",
View
@@ -11,31 +11,31 @@ exports["another test of continue and break"] = {
run : function (cb) {
- foo : while (i < 100) {
-
- await { setTimeout (defer (), 10*Math.random()); }
-
- if (i == 10) {
- i += 2;
- res |= (1 << 20);
- continue foo;
+ foo : while (i < 100) {
+
+ await { setTimeout (defer (), 10*Math.random()); }
+
+ if (i == 10) {
+ i += 2;
+ res |= (1 << 20);
+ continue foo;
+ }
+
+ res |= (1 << i);
+
+ if (i == 3) {
+ i++;
+ res |= (1 << 21);
+ }
+
+ if (i == 13) {
+ res |= (1 << 22);
+ break foo;
+ }
+ i++;
}
-
- res |= (1 << i);
-
- if (i == 3) {
- i++;
- res |= (1 << 21);
- }
-
- if (i == 13) {
- res |= (1 << 22);
- break foo;
- }
- i++;
- }
- res |= (1 << 23);
- cb();
+ res |= (1 << 23);
+ cb();
},
check : function () {
View
@@ -0,0 +1,33 @@
+// -*- mode: javascript; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+
+"use strict";
+
+var assert = require ("assert");
+
+var sum = 0;
+var i = 0;
+
+exports["another test of continue and break (no tame)"] = {
+
+ run : function (cb) {
+
+ while (i < 100) {
+ i++;
+
+ if (i == 4) {
+ continue;
+ }
+ sum += i;
+
+ if (i == 10) {
+ break;
+ }
+ }
+ cb();
+ },
+
+ check : function () {
+ assert.ok ((sum == 51 && i == 10), "continues / breaks ok!");
+ }
+
+};

0 comments on commit 0bc1455

Please sign in to comment.