summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/language/statements/try/S12.14_A15.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/language/statements/try/S12.14_A15.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/language/statements/try/S12.14_A15.js')
-rw-r--r--js/src/tests/test262/language/statements/try/S12.14_A15.js94
1 files changed, 94 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/statements/try/S12.14_A15.js b/js/src/tests/test262/language/statements/try/S12.14_A15.js
new file mode 100644
index 0000000000..bc4f85154d
--- /dev/null
+++ b/js/src/tests/test262/language/statements/try/S12.14_A15.js
@@ -0,0 +1,94 @@
+// Copyright 2009 the Sputnik authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+info: |
+ Using "try" with "catch" or "finally" statement within/without a "switch"
+ statement
+es5id: 12.14_A15
+description: Insert try/catch/finally to switch statement
+---*/
+
+// CHECK#1
+function SwitchTest1(value){
+ var result = 0;
+ try{
+ switch(value) {
+ case 1:
+ result += 4;
+ throw result;
+ break;
+ default:
+ result += 32;
+ break;
+ case 4:
+ result += 64;
+ throw "ex";
+ }
+ return result;
+ }
+ catch(e){
+ if ((value===1)&&(e!==4)) throw new Test262Error('#1.1: Exception ===4. Actual: Exception ==='+ e );
+ if ((value===4)&&(e!=="ex")) throw new Test262Error('#1.2: Exception ==="ex". Actual: Exception ==='+ e );
+ }
+ finally{
+ return result;
+ }
+}
+if (SwitchTest1(1)!==4) throw new Test262Error('#1.3: SwitchTest1(1)===4. Actual: SwitchTest1(1)==='+ SwitchTest1(1) );
+if (SwitchTest1(4)!==64) throw new Test262Error('#1.4: SwitchTest1(4)===64. Actual: SwitchTest1(4)==='+ SwitchTest1(4) );
+
+// CHECK#2
+var c2=0;
+function SwitchTest2(value){
+ var result = 0;
+ switch(value) {
+ case 0:
+ try{
+ result += 2;
+ break;
+ }
+ finally{
+ c2=1;
+ }
+ case 1:
+ result += 4;
+ break;
+ default:
+ result += 32;
+ break;
+ }
+ return result;
+}
+if (SwitchTest2(1)!==4) throw new Test262Error('#2.1: SwitchTest1(1)===4. Actual: SwitchTest1(1)==='+ SwitchTest1(1) );
+if (c2===1) throw new Test262Error('#2.2: Evaluate finally block');
+if (SwitchTest2(0)!==2) throw new Test262Error('#2.3: SwitchTest1(0)===2. Actual: SwitchTest1(0)==='+ SwitchTest1(0) );
+if (c2!==1) throw new Test262Error('#2.4: "finally" block must be evaluated');
+
+// CHECK#3
+function SwitchTest3(value){
+ var result = 0;
+ switch(value) {
+ case 0:
+ try{
+ result += 2;
+ throw "ex";
+ }
+ finally{
+ break;
+ }
+ default:
+ result += 32;
+ break;
+ }
+ return result;
+}
+try{
+ var x3=SwitchTest3(0);
+ if (x3!==2) throw new Test262Error('#3.1: x3===2. Actual: x3==='+x3);
+}
+catch(e){
+ throw new Test262Error('#3.2: Catching exception inside function does not lead to throwing exception outside this function');
+}
+
+reportCompare(0, 0);