From 75db6744eb11c7638b4db3802f256c6b9d9db7cb Mon Sep 17 00:00:00 2001 From: Lucas Azzola Date: Sat, 19 Aug 2017 07:19:48 +1000 Subject: [PATCH] Add optional-catch-binding tests (#1167) --- features.txt | 4 ++ test/language/statements/try/S12.14_A16_T4.js | 21 ---------- .../try/optional-catch-binding-finally.js | 17 +++++++++ .../try/optional-catch-binding-lexical.js | 38 +++++++++++++++++++ .../try/optional-catch-binding-parens.js | 21 ++++++++++ .../try/optional-catch-binding-throws.js | 25 ++++++++++++ .../statements/try/optional-catch-binding.js | 17 +++++++++ 7 files changed, 122 insertions(+), 21 deletions(-) delete mode 100644 test/language/statements/try/S12.14_A16_T4.js create mode 100644 test/language/statements/try/optional-catch-binding-finally.js create mode 100644 test/language/statements/try/optional-catch-binding-lexical.js create mode 100644 test/language/statements/try/optional-catch-binding-parens.js create mode 100644 test/language/statements/try/optional-catch-binding-throws.js create mode 100644 test/language/statements/try/optional-catch-binding.js diff --git a/features.txt b/features.txt index d30744f6b5..abfde8e562 100644 --- a/features.txt +++ b/features.txt @@ -21,6 +21,10 @@ Symbol.asyncIterator object-rest object-spread +# Optional Catch Binding +# https://github.com/tc39/proposal-optional-catch-binding +optional-catch-binding + # RegExp s (dotAll) flag # https://github.com/tc39/proposal-regexp-dotall-flag regexp-dotall diff --git a/test/language/statements/try/S12.14_A16_T4.js b/test/language/statements/try/S12.14_A16_T4.js deleted file mode 100644 index 8b46842fbd..0000000000 --- a/test/language/statements/try/S12.14_A16_T4.js +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2009 the Sputnik authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -info: > - TryStatement: "try Block Catch" or "try Block Finally" or "try Block - Catch Finally" -es5id: 12.14_A16_T4 -description: > - Catch: "catch (Identifier ) Block". Checking if execution of - "catch" that takes no arguments fails -negative: - phase: early - type: SyntaxError ----*/ - -throw "Test262: This statement should not be evaluated."; - -// CHECK#1 -try{} -catch{} diff --git a/test/language/statements/try/optional-catch-binding-finally.js b/test/language/statements/try/optional-catch-binding-finally.js new file mode 100644 index 0000000000..531da49a2f --- /dev/null +++ b/test/language/statements/try/optional-catch-binding-finally.js @@ -0,0 +1,17 @@ +// Copyright (C) 2017 Lucas Azzola. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Lucas Azzola +esid: pending +description: try/catch/finally syntax with omission of the catch binding +features: [optional-catch-binding] +info: | + Optional Catch Binding + + Catch[Yield, Await, Return]: + (...) + catch Block[?Yield, ?Await, ?Return] +---*/ + +try {} catch {} finally {} diff --git a/test/language/statements/try/optional-catch-binding-lexical.js b/test/language/statements/try/optional-catch-binding-lexical.js new file mode 100644 index 0000000000..ad0f55aa5d --- /dev/null +++ b/test/language/statements/try/optional-catch-binding-lexical.js @@ -0,0 +1,38 @@ +// Copyright (C) 2017 Lucas Azzola. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Lucas Azzola +esid: pending +description: lexical environment runtime semantics for optional catch binding +features: [optional-catch-binding] +info: | + Runtime Semantics: CatchClauseEvaluation + + Catch : catch Block + Let oldEnv be the running execution context's LexicalEnvironment. + Let catchEnv be NewDeclarativeEnvironment(oldEnv). + Set the running execution context's LexicalEnvironment to catchEnv. + (...) + Set the running execution context's LexicalEnvironment to oldEnv. + Return Completion(B). +---*/ + +let x = 1; +let ranCatch = false; + +try { + x = 2; + throw new Error(); +} catch { + let x = 3; + let y = true; + ranCatch = true; +} + +assert(ranCatch, 'executed `catch` block'); +assert.sameValue(x, 2); + +assert.throws(ReferenceError, function() { + y; +}); diff --git a/test/language/statements/try/optional-catch-binding-parens.js b/test/language/statements/try/optional-catch-binding-parens.js new file mode 100644 index 0000000000..649a76bf86 --- /dev/null +++ b/test/language/statements/try/optional-catch-binding-parens.js @@ -0,0 +1,21 @@ +// Copyright (C) 2017 Lucas Azzola. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Lucas Azzola +esid: pending +description: > + It is a SyntaxError to have a try/catch statement with an empty CatchParameter +features: [optional-catch-binding] +info: | + Catch[Yield, Await, Return]: + catch ( CatchParameter[?Yield, ?Await] ) Block[?Yield, ?Await, ?Return] +negative: + phase: early + type: SyntaxError +---*/ + +throw "Test262: This statement should not be evaluated."; + +try {} catch () {} + diff --git a/test/language/statements/try/optional-catch-binding-throws.js b/test/language/statements/try/optional-catch-binding-throws.js new file mode 100644 index 0000000000..ee5b385e94 --- /dev/null +++ b/test/language/statements/try/optional-catch-binding-throws.js @@ -0,0 +1,25 @@ +// Copyright (C) 2017 Lucas Azzola. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Lucas Azzola +esid: pending +description: errors can be thrown from catch clause without binding +features: [optional-catch-binding] +info: | + Runtime Semantics: CatchClauseEvaluation + + Catch : catch Block + (...) + Let B be the result of evaluating Block. + (...) + Return Completion(B). +---*/ + +assert.throws(Test262Error, function() { + try { + throw new Error(); + } catch { + throw new Test262Error(); + } +}); diff --git a/test/language/statements/try/optional-catch-binding.js b/test/language/statements/try/optional-catch-binding.js new file mode 100644 index 0000000000..107dc57999 --- /dev/null +++ b/test/language/statements/try/optional-catch-binding.js @@ -0,0 +1,17 @@ +// Copyright (C) 2017 Lucas Azzola. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Lucas Azzola +esid: pending +description: try/catch syntax with omission of the catch binding +features: [optional-catch-binding] +info: | + Optional Catch Binding + + Catch[Yield, Await, Return]: + (...) + catch Block[?Yield, ?Await, ?Return] +---*/ + +try {} catch {}