mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
1.8 KiB
102 lines
1.8 KiB
11 years ago
|
/*
|
||
|
* Bug noticed while doing underscore shimming, case fallthrough does not
|
||
|
* work correctly (it used to work but has broken at some point).
|
||
11 years ago
|
*
|
||
|
* The critical thing is that there are two case statements and the first
|
||
|
* case matches and falls through to the second (non-matching).
|
||
11 years ago
|
*/
|
||
|
|
||
|
/*===
|
||
|
matches 3
|
||
11 years ago
|
matches 3
|
||
|
matches 3
|
||
11 years ago
|
matches [object Date]
|
||
|
===*/
|
||
|
|
||
11 years ago
|
function test1a() {
|
||
11 years ago
|
var v = 2;
|
||
|
switch (v) {
|
||
|
case 1:
|
||
|
print('matches 1');
|
||
|
break;
|
||
|
case 2:
|
||
|
case 3:
|
||
|
print('matches 3');
|
||
|
break;
|
||
|
default:
|
||
|
print('matches default');
|
||
|
}
|
||
|
}
|
||
|
|
||
11 years ago
|
function test1b() {
|
||
|
var v = 2;
|
||
|
switch (v) {
|
||
|
case 1:
|
||
|
print('matches 1');
|
||
|
break;
|
||
|
case 3:
|
||
|
case 2:
|
||
|
print('matches 3');
|
||
|
break;
|
||
|
default:
|
||
|
print('matches default');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function test1c() {
|
||
|
var v = 2;
|
||
|
switch (v) {
|
||
|
case 1:
|
||
|
print('matches 1');
|
||
|
break;
|
||
|
case 2:
|
||
|
; // this is enough to stop triggering the bug
|
||
|
case 3:
|
||
|
print('matches 3');
|
||
|
break;
|
||
|
default:
|
||
|
print('matches default');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Check also with strings (originally found with this)
|
||
|
function test2a() {
|
||
11 years ago
|
var date = new Date(2014, 1, 2);
|
||
|
switch (Object.prototype.toString.call(date)) {
|
||
|
case '[object String]':
|
||
|
print('matches [object String]');
|
||
|
break;
|
||
|
case '[object Date]':
|
||
|
case '[object Boolean]':
|
||
|
print('matches [object Date]');
|
||
|
break;
|
||
|
default:
|
||
|
print('matches default');
|
||
|
}
|
||
|
}
|
||
|
|
||
11 years ago
|
try {
|
||
|
test1a();
|
||
|
} catch (e) {
|
||
|
print(e);
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
test1b();
|
||
|
} catch (e) {
|
||
|
print(e);
|
||
|
}
|
||
11 years ago
|
|
||
|
try {
|
||
11 years ago
|
test1c();
|
||
11 years ago
|
} catch (e) {
|
||
|
print(e);
|
||
|
}
|
||
|
|
||
|
try {
|
||
11 years ago
|
test2a();
|
||
11 years ago
|
} catch (e) {
|
||
|
print(e);
|
||
|
}
|
||
|
|