summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/language/statements/try/completion-values-fn-finally-abrupt.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/completion-values-fn-finally-abrupt.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/completion-values-fn-finally-abrupt.js')
-rw-r--r--js/src/tests/test262/language/statements/try/completion-values-fn-finally-abrupt.js81
1 files changed, 81 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/statements/try/completion-values-fn-finally-abrupt.js b/js/src/tests/test262/language/statements/try/completion-values-fn-finally-abrupt.js
new file mode 100644
index 0000000000..b81cbb7f71
--- /dev/null
+++ b/js/src/tests/test262/language/statements/try/completion-values-fn-finally-abrupt.js
@@ -0,0 +1,81 @@
+// Copyright (C) 2020 Salesforce.com. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-try-statement-runtime-semantics-evaluation
+description: >
+ Returns the correct completion values of try-catch-finally(Abrupt) in functions
+info: |
+ TryStatement : try Block Catch Finally
+
+ Let B be the result of evaluating Block.
+ If B.[[Type]] is throw, let C be CatchClauseEvaluation of Catch with argument B.[[Value]].
+ Else, let C be B.
+ Let F be the result of evaluating Finally.
+ If F.[[Type]] is normal, set F to C.
+ Return Completion(UpdateEmpty(F, undefined)).
+---*/
+
+var fn, count = {};
+
+// 1: try Abrupt, catch Abrupt, finally Abrupt; Completion: finally
+count.catch = 0;
+count.finally = 0;
+fn = function() {
+ try {
+ throw 'try';
+ } catch(e) {
+ count.catch += 1;
+ throw 'catch';
+ } finally {
+ count.finally += 1;
+ throw new Test262Error('finally'); // If F.[[Type]] is normal, set F to C.
+ }
+ return 'wat';
+};
+
+assert.throws(Test262Error, fn, '1: try Abrupt, catch Abrupt, finally Abrupt; Completion: finally');
+assert.sameValue(count.catch, 1, '1: catch count');
+assert.sameValue(count.finally, 1, '1: finally count');
+
+// 2: try Abrupt, catch Return, finally Abrupt; Completion: finally
+count.catch = 0;
+count.finally = 0;
+fn = function() {
+ try {
+ throw 'try';
+ } catch(e) {
+ count.catch += 1;
+ return 'catch';
+ } finally {
+ count.finally += 1;
+ throw new Test262Error('finally'); // If F.[[Type]] is normal, set F to C.
+ }
+ return 'wat';
+};
+
+assert.throws(Test262Error, fn, '2: try Abrupt, catch Return, finally Abrupt; Completion: finally');
+assert.sameValue(count.catch, 1, '2: catch count');
+assert.sameValue(count.finally, 1, '2: fiinally count');
+
+// 3: try Return, catch Return, finally Abrupt; Completion: finally
+count.catch = 0;
+count.finally = 0;
+fn = function() {
+ try {
+ return 'try';
+ } catch(e) {
+ count.catch += 1;
+ return 'catch';
+ } finally {
+ count.finally += 1;
+ throw new Test262Error('finally'); // If F.[[Type]] is normal, set F to C.
+ }
+ return 'wat';
+};
+
+assert.throws(Test262Error, fn, '3: try Normal, catch Normal, finally Abrupt; Completion: finally');
+assert.sameValue(count.catch, 0, '3: catch count');
+assert.sameValue(count.finally, 1, '3: fiinally count');
+
+reportCompare(0, 0);