| 1 |
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
description: If an initializer returns an abrupt completion, other initializers should not execute |
| 6 |
esid: sec-ecmascript-function-objects-construct-argumentslist-newtarget |
| 7 |
info: | |
| 8 |
[[Construct]] ( argumentsList, newTarget) |
| 9 |
... |
| 10 |
8. If kind is "base", then |
| 11 |
a. Perform OrdinaryCallBindThis(F, calleeContext, thisArgument). |
| 12 |
b. Let result be InitializeInstanceFields(thisArgument, F). |
| 13 |
c. If result is an abrupt completion, then |
| 14 |
i. Remove calleeContext from execution context stack and restore callerContext as the running execution context. |
| 15 |
ii. Return Completion(result). |
| 16 |
... |
| 17 |
|
| 18 |
ClassTail : ClassHeritage { ClassBody } |
| 19 |
... |
| 20 |
34. For each item fieldRecord in order from staticFields, |
| 21 |
a. Perform ? DefineField(F, field). |
| 22 |
... |
| 23 |
|
| 24 |
features: [class-fields-public, class-static-fields-public, class] |
| 25 |
---*/ |
| 26 |
|
| 27 |
function abruptCompletion() { |
| 28 |
throw new Test262Error(); |
| 29 |
} |
| 30 |
|
| 31 |
let neverExecuted = false; |
| 32 |
|
| 33 |
function sideEffect() { |
| 34 |
neverExecuted = true; |
| 35 |
} |
| 36 |
|
| 37 |
class C { |
| 38 |
a = abruptCompletion(); |
| 39 |
b = sideEffect(); |
| 40 |
} |
| 41 |
|
| 42 |
assert.throws(Test262Error, function() { |
| 43 |
let c = new C(); |
| 44 |
}, 'field initializer should end with abrupt completion'); |
| 45 |
assert.sameValue(neverExecuted, false); |
| 46 |
|
| 47 |
assert.throws(Test262Error, function() { |
| 48 |
class D { |
| 49 |
static a = abruptCompletion(); |
| 50 |
static b = sideEffect(); |
| 51 |
} |
| 52 |
}, 'static field initializer should end with abrupt completion'); |
| 53 |
assert.sameValue(neverExecuted, false); |
| 54 |
|
| 55 |
reportCompare(0, 0); |