Derived class constructor checks are executed after leaving the function body (#3129)

This commit is contained in:
André Bargull 2021-08-04 18:58:24 +02:00 committed by GitHub
parent 5a6577bcc9
commit b74b15c49c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 244 additions and 0 deletions

View File

@ -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");

View File

@ -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");

View File

@ -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();
});

View File

@ -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();
});

View File

@ -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();
});

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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();
});