diff --git a/test/language/statements/class/subclass/derived-class-return-override-catch-finally-arrow.js b/test/language/statements/class/subclass/derived-class-return-override-catch-finally-arrow.js new file mode 100644 index 0000000000..87a1754a11 --- /dev/null +++ b/test/language/statements/class/subclass/derived-class-return-override-catch-finally-arrow.js @@ -0,0 +1,27 @@ +// Copyright (C) 2021 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-function-objects-construct-argumentslist-newtarget +description: > + `super()` in finally block is executed before checking for missing `super()` + call when `return` is in a catch block. The `super()` call is performed + through an arrow function. +---*/ + +class C extends class {} { + constructor() { + var f = () => super(); + + try { + throw null; + } catch(e) { + return; + } finally { + f(); + } + } +} + +var o = new C(); +assert.sameValue(typeof o, "object"); diff --git a/test/language/statements/class/subclass/derived-class-return-override-catch-finally.js b/test/language/statements/class/subclass/derived-class-return-override-catch-finally.js new file mode 100644 index 0000000000..f1e1259072 --- /dev/null +++ b/test/language/statements/class/subclass/derived-class-return-override-catch-finally.js @@ -0,0 +1,24 @@ +// Copyright (C) 2021 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-function-objects-construct-argumentslist-newtarget +description: > + `super()` in finally block is executed before checking for missing `super()` + call when `return` is in a catch block. +---*/ + +class C extends class {} { + constructor() { + try { + throw null; + } catch(e) { + return; + } finally { + super(); + } + } +} + +var o = new C(); +assert.sameValue(typeof o, "object"); diff --git a/test/language/statements/class/subclass/derived-class-return-override-catch-super-arrow.js b/test/language/statements/class/subclass/derived-class-return-override-catch-super-arrow.js new file mode 100644 index 0000000000..dd4c8178fe --- /dev/null +++ b/test/language/statements/class/subclass/derived-class-return-override-catch-super-arrow.js @@ -0,0 +1,25 @@ +// Copyright (C) 2021 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-function-objects-construct-argumentslist-newtarget +description: > + TypeError from `return 0` is not catchable with `super` called in catch block + from an arrow function. +---*/ + +class C extends class {} { + constructor() { + var f = () => super(); + + try { + return 0; + } catch(e) { + f(); + } + } +} + +assert.throws(TypeError, function() { + new C(); +}); diff --git a/test/language/statements/class/subclass/derived-class-return-override-catch-super.js b/test/language/statements/class/subclass/derived-class-return-override-catch-super.js new file mode 100644 index 0000000000..b392bf10e6 --- /dev/null +++ b/test/language/statements/class/subclass/derived-class-return-override-catch-super.js @@ -0,0 +1,22 @@ +// Copyright (C) 2021 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-function-objects-construct-argumentslist-newtarget +description: > + TypeError from `return 0` is not catchable with `super` in catch block. +---*/ + +class C extends class {} { + constructor() { + try { + return 0; + } catch(e) { + super(); + } + } +} + +assert.throws(TypeError, function() { + new C(); +}); diff --git a/test/language/statements/class/subclass/derived-class-return-override-catch.js b/test/language/statements/class/subclass/derived-class-return-override-catch.js new file mode 100644 index 0000000000..1dfce64ccc --- /dev/null +++ b/test/language/statements/class/subclass/derived-class-return-override-catch.js @@ -0,0 +1,24 @@ +// Copyright (C) 2021 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-function-objects-construct-argumentslist-newtarget +description: > + TypeError from `return 0` is not catchable. +---*/ + +class C extends class {} { + constructor() { + super(); + + try { + return 0; + } catch(e) { + return; + } + } +} + +assert.throws(TypeError, function() { + new C(); +}); diff --git a/test/language/statements/class/subclass/derived-class-return-override-finally-super-arrow.js b/test/language/statements/class/subclass/derived-class-return-override-finally-super-arrow.js new file mode 100644 index 0000000000..81c6bcc5ea --- /dev/null +++ b/test/language/statements/class/subclass/derived-class-return-override-finally-super-arrow.js @@ -0,0 +1,25 @@ +// Copyright (C) 2021 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-function-objects-construct-argumentslist-newtarget +description: > + `super()` in finally block is executed before checking for missing `super()` + call when `return` is in a try block. The `super()` call is performed + through an arrow function. +---*/ + +class C extends class {} { + constructor() { + var f = () => super(); + + try { + return; + } finally { + f(); + } + } +} + +var o = new C(); +assert.sameValue(typeof o, "object"); diff --git a/test/language/statements/class/subclass/derived-class-return-override-finally-super.js b/test/language/statements/class/subclass/derived-class-return-override-finally-super.js new file mode 100644 index 0000000000..e22bc10167 --- /dev/null +++ b/test/language/statements/class/subclass/derived-class-return-override-finally-super.js @@ -0,0 +1,22 @@ +// Copyright (C) 2021 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-function-objects-construct-argumentslist-newtarget +description: > + `super()` in finally block is executed before checking for missing `super()` + call when `return` is in a try block. +---*/ + +class C extends class {} { + constructor() { + try { + return; + } finally { + super(); + } + } +} + +var o = new C(); +assert.sameValue(typeof o, "object"); diff --git a/test/language/statements/class/subclass/derived-class-return-override-for-of-arrow.js b/test/language/statements/class/subclass/derived-class-return-override-for-of-arrow.js new file mode 100644 index 0000000000..79c11f5a58 --- /dev/null +++ b/test/language/statements/class/subclass/derived-class-return-override-for-of-arrow.js @@ -0,0 +1,38 @@ +// Copyright (C) 2021 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-function-objects-construct-argumentslist-newtarget +description: > + ReferenceError when returning from a derived class constructor without calling + `super()` is thrown after the function body has been left, so an iterator + return handler can still call `super()`. +---*/ + +var iter = { + [Symbol.iterator]() { + return this; + }, + next() { + return {done: false}; + }, + return() { + // Calls |super()|. + this.f(); + + return {done: true}; + }, +}; + +class C extends class {} { + constructor() { + iter.f = () => super(); + + for (var k of iter) { + return; + } + } +} + +var o = new C(); +assert.sameValue(typeof o, "object"); diff --git a/test/language/statements/class/subclass/derived-class-return-override-for-of.js b/test/language/statements/class/subclass/derived-class-return-override-for-of.js new file mode 100644 index 0000000000..473ad712dc --- /dev/null +++ b/test/language/statements/class/subclass/derived-class-return-override-for-of.js @@ -0,0 +1,37 @@ +// Copyright (C) 2021 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-function-objects-construct-argumentslist-newtarget +description: > + TypeError from `return 0` is thrown after the function body has been left, so + an error thrown from an iterator has precedence. +---*/ + +var error = new Test262Error(); + +var iter = { + [Symbol.iterator]() { + return this; + }, + next() { + return {done: false}; + }, + return() { + throw error; + }, +}; + +class C extends class {} { + constructor() { + super(); + + for (var k of iter) { + return 0; + } + } +} + +assert.throws(Test262Error, function() { + new C(); +});