/*===
test1 1
100
test2 1
100
test3 1
100
===*/

/* In Duktape 0.9.0 a tailcall from inside a switch was allowed.
 * This means that the tailcall would be made even if the catch
 * stack contained catcher entries for the callstack entry being
 * reused by the tailcall.  With assertions enabled, the test below
 * would fail in duk_js_call.c:1788:
 *
 *     for (i = 0; i < thr->catchstack_top; i++) {
 *         DUK_ASSERT(thr->catchstack[i].callstack_index < our_callstack_index);
 *     }
 */

function tailcalled(x) {
    print('tailcalled', x);
    return x * 100;
}

function test1(x) {
    print('test1', x);
    return tailcalled(x);
}

function test2(x) {
    var t;

    print('test2', x);
    switch (x) {
    case 1:
        t = tailcalled(x); return t;
    default:
        t = tailcalled(x); return t;
    }
}

function test3(x) {
    print('test3', x);
    switch (x) {
    case 1:
        return tailcalled(x);
    default:
        return tailcalled(x);
    }
}


try {
    print(test1(1));
} catch (e) {
    print(e);
}

try {
    print(test2(1));
} catch (e) {
    print(e);
}

try {
    print(test3(1));
} catch (e) {
    print(e);
}

@@ -11,66 +11,86 @@
 1 1%0A
-100%0Atest2 1%0A100%0Atest3 1%0A100%0A===*/%0A%0A/* In Duktape 0.9.0 a t
+tailcalled 1%0A100%0Atest2 1%0Atailcalled 1%0A100%0Atest3 1%0Atailcalled 1%0A100%0A===*/%0A%0A/* T
 ailc
@@ -112,16 +112,15 @@
  a s
-witch wa
+iwthc i
 s al
@@ -128,63 +128,21 @@
 owed
-.%0A * This means that the tailcall would be made even if
+: even though
  the
@@ -151,47 +151,51 @@
 atch
-%0A *
  stack
- contained catcher entries for
+%0A * will contain entries referring to
  the
@@ -220,112 +220,252 @@
 eing
-%0A *
  reused
- by the tailcall.  With assertions enabled, the test below%0A * would fail in duk_js_call.c:1788
+,%0A * this is not a problem because the entries are not error catching.%0A * In Duktape 0.9.0 there was an incorrection assertion in duk_js_call.c%0A * which would also trigger an assertion error when tailcall was made%0A * from inside a switch
 :%0A *
@@ -606,16 +606,61 @@
 *     %7D%0A
+ *%0A * This has been fixed in Duktape 0.10.0.%0A
  */%0A%0Afun

test case fix