mirror of https://github.com/tc39/test262.git
Added cases to cover public static field initializer operations with 'this' biding. (#2283)
* Added cases to cover public static field initializer operations with 'this' biding. * Added initializer that throws. * Adding missing ';' * Fixing broken test static-field-initializer-error.js. 'function' keyword was missing.
This commit is contained in:
parent
134652ea3c
commit
51b3953d61
|
@ -0,0 +1,59 @@
|
|||
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
desc: this in static field initializers refers to class constructor
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
ClassElement :
|
||||
...
|
||||
static FieldDefinition ;
|
||||
|
||||
FieldDefinition :
|
||||
ClassElementName Initializer_opt
|
||||
|
||||
ClassDefinitionEvaluation:
|
||||
...
|
||||
|
||||
27. Let staticFields be a new empty List.
|
||||
28. For each ClassElement e in order from elements,
|
||||
a. If IsStatic of e is false, then
|
||||
...
|
||||
b. Else,
|
||||
i. Let field be the result of performing PropertyDefinitionEvaluation for m ClassElementEvaluation for e with arguments F and false.
|
||||
c. If field is an abrupt completion, then
|
||||
...
|
||||
d. If field is not empty,
|
||||
i. If IsStatic of e is false, append field to instanceFields.
|
||||
ii. Otherwise, append field to staticFields.
|
||||
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
...
|
||||
|
||||
DefineField(receiver, fieldRecord)
|
||||
1. Assert: Type(receiver) is Object.
|
||||
2. Assert: fieldRecord is a Record as created by ClassFieldDefinitionEvaluation.
|
||||
3. Let name be fieldRecord.[[Name]].
|
||||
4. Let initializer be fieldRecord.[[Initializer]].
|
||||
5. If initializer is not empty, then
|
||||
a. Let initValue be ? Call(initializer, receiver).
|
||||
6. Else, let initValue be undefined.
|
||||
7. If fieldRecord.[[IsAnonymousFunctionDefinition]] is true, then
|
||||
a. Let hasNameProperty be ? HasOwnProperty(initValue, "name").
|
||||
b. If hasNameProperty is false, perform SetFunctionName(initValue, fieldName).
|
||||
8. If fieldName is a Private Name,
|
||||
a. Perform ? PrivateFieldAdd(fieldName, receiver, initValue).
|
||||
9. Else,
|
||||
a. Assert: IsPropertyKey(fieldName) is true.
|
||||
b. Perform ? CreateDataPropertyOrThrow(receiver, fieldName, initValue).
|
||||
10. Return.
|
||||
template: default
|
||||
features: [class-static-fields-public]
|
||||
---*/
|
||||
|
||||
//- elements
|
||||
static f = () => this;
|
||||
//- assertions
|
||||
assert.sameValue(C.f(), C);
|
|
@ -0,0 +1,63 @@
|
|||
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
desc: Static fields initializer has `this` biding
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
ClassElement :
|
||||
...
|
||||
static FieldDefinition ;
|
||||
|
||||
FieldDefinition :
|
||||
ClassElementName Initializer_opt
|
||||
|
||||
ClassDefinitionEvaluation:
|
||||
...
|
||||
|
||||
27. Let staticFields be a new empty List.
|
||||
28. For each ClassElement e in order from elements,
|
||||
a. If IsStatic of e is false, then
|
||||
...
|
||||
b. Else,
|
||||
i. Let field be the result of performing PropertyDefinitionEvaluation for m ClassElementEvaluation for e with arguments F and false.
|
||||
c. If field is an abrupt completion, then
|
||||
...
|
||||
d. If field is not empty,
|
||||
i. If IsStatic of e is false, append field to instanceFields.
|
||||
ii. Otherwise, append field to staticFields.
|
||||
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
...
|
||||
|
||||
DefineField(receiver, fieldRecord)
|
||||
1. Assert: Type(receiver) is Object.
|
||||
2. Assert: fieldRecord is a Record as created by ClassFieldDefinitionEvaluation.
|
||||
3. Let name be fieldRecord.[[Name]].
|
||||
4. Let initializer be fieldRecord.[[Initializer]].
|
||||
5. If initializer is not empty, then
|
||||
a. Let initValue be ? Call(initializer, receiver).
|
||||
6. Else, let initValue be undefined.
|
||||
7. If fieldRecord.[[IsAnonymousFunctionDefinition]] is true, then
|
||||
a. Let hasNameProperty be ? HasOwnProperty(initValue, "name").
|
||||
b. If hasNameProperty is false, perform SetFunctionName(initValue, fieldName).
|
||||
8. If fieldName is a Private Name,
|
||||
a. Perform ? PrivateFieldAdd(fieldName, receiver, initValue).
|
||||
9. Else,
|
||||
a. Assert: IsPropertyKey(fieldName) is true.
|
||||
b. Perform ? CreateDataPropertyOrThrow(receiver, fieldName, initValue).
|
||||
10. Return.
|
||||
template: default
|
||||
features: [class-static-fields-public]
|
||||
---*/
|
||||
|
||||
//- elements
|
||||
static f = 'test';
|
||||
static g = this.f + '262';
|
||||
static h = eval('this.g') + 'test';
|
||||
//- assertions
|
||||
assert.sameValue(C.f, 'test');
|
||||
assert.sameValue(C.g, 'test262');
|
||||
assert.sameValue(C.h, 'test262test');
|
|
@ -0,0 +1,65 @@
|
|||
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
desc: Static fields can be redeclared
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
ClassElement :
|
||||
...
|
||||
static FieldDefinition ;
|
||||
|
||||
FieldDefinition :
|
||||
ClassElementName Initializer_opt
|
||||
|
||||
ClassDefinitionEvaluation:
|
||||
...
|
||||
|
||||
27. Let staticFields be a new empty List.
|
||||
28. For each ClassElement e in order from elements,
|
||||
a. If IsStatic of e is false, then
|
||||
...
|
||||
b. Else,
|
||||
i. Let field be the result of performing PropertyDefinitionEvaluation for m ClassElementEvaluation for e with arguments F and false.
|
||||
c. If field is an abrupt completion, then
|
||||
...
|
||||
d. If field is not empty,
|
||||
i. If IsStatic of e is false, append field to instanceFields.
|
||||
ii. Otherwise, append field to staticFields.
|
||||
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
...
|
||||
|
||||
DefineField(receiver, fieldRecord)
|
||||
1. Assert: Type(receiver) is Object.
|
||||
2. Assert: fieldRecord is a Record as created by ClassFieldDefinitionEvaluation.
|
||||
3. Let name be fieldRecord.[[Name]].
|
||||
4. Let initializer be fieldRecord.[[Initializer]].
|
||||
5. If initializer is not empty, then
|
||||
a. Let initValue be ? Call(initializer, receiver).
|
||||
6. Else, let initValue be undefined.
|
||||
7. If fieldRecord.[[IsAnonymousFunctionDefinition]] is true, then
|
||||
a. Let hasNameProperty be ? HasOwnProperty(initValue, "name").
|
||||
b. If hasNameProperty is false, perform SetFunctionName(initValue, fieldName).
|
||||
8. If fieldName is a Private Name,
|
||||
a. Perform ? PrivateFieldAdd(fieldName, receiver, initValue).
|
||||
9. Else,
|
||||
a. Assert: IsPropertyKey(fieldName) is true.
|
||||
b. Perform ? CreateDataPropertyOrThrow(receiver, fieldName, initValue).
|
||||
10. Return.
|
||||
template: default
|
||||
features: [class-static-fields-public]
|
||||
---*/
|
||||
|
||||
//- elements
|
||||
static f = 'test';
|
||||
static f = this.f + '262';
|
||||
static g() {
|
||||
return 45;
|
||||
};
|
||||
static g = this.g();
|
||||
//- assertions
|
||||
assert.sameValue(C.f, 'test262');
|
||||
assert.sameValue(C.g, 45);
|
|
@ -0,0 +1,63 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/static-field-init-this-inside-arrow-function.case
|
||||
// - src/class-elements/default/cls-expr.template
|
||||
/*---
|
||||
description: this in static field initializers refers to class constructor (field definitions in a class expression)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-fields-public, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
ClassElement :
|
||||
...
|
||||
static FieldDefinition ;
|
||||
|
||||
FieldDefinition :
|
||||
ClassElementName Initializer_opt
|
||||
|
||||
ClassDefinitionEvaluation:
|
||||
...
|
||||
|
||||
27. Let staticFields be a new empty List.
|
||||
28. For each ClassElement e in order from elements,
|
||||
a. If IsStatic of e is false, then
|
||||
...
|
||||
b. Else,
|
||||
i. Let field be the result of performing PropertyDefinitionEvaluation for m ClassElementEvaluation for e with arguments F and false.
|
||||
c. If field is an abrupt completion, then
|
||||
...
|
||||
d. If field is not empty,
|
||||
i. If IsStatic of e is false, append field to instanceFields.
|
||||
ii. Otherwise, append field to staticFields.
|
||||
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
...
|
||||
|
||||
DefineField(receiver, fieldRecord)
|
||||
1. Assert: Type(receiver) is Object.
|
||||
2. Assert: fieldRecord is a Record as created by ClassFieldDefinitionEvaluation.
|
||||
3. Let name be fieldRecord.[[Name]].
|
||||
4. Let initializer be fieldRecord.[[Initializer]].
|
||||
5. If initializer is not empty, then
|
||||
a. Let initValue be ? Call(initializer, receiver).
|
||||
6. Else, let initValue be undefined.
|
||||
7. If fieldRecord.[[IsAnonymousFunctionDefinition]] is true, then
|
||||
a. Let hasNameProperty be ? HasOwnProperty(initValue, "name").
|
||||
b. If hasNameProperty is false, perform SetFunctionName(initValue, fieldName).
|
||||
8. If fieldName is a Private Name,
|
||||
a. Perform ? PrivateFieldAdd(fieldName, receiver, initValue).
|
||||
9. Else,
|
||||
a. Assert: IsPropertyKey(fieldName) is true.
|
||||
b. Perform ? CreateDataPropertyOrThrow(receiver, fieldName, initValue).
|
||||
10. Return.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
var C = class {
|
||||
static f = () => this;
|
||||
}
|
||||
|
||||
assert.sameValue(C.f(), C);
|
|
@ -0,0 +1,67 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/static-field-init-with-this.case
|
||||
// - src/class-elements/default/cls-expr.template
|
||||
/*---
|
||||
description: Static fields initializer has `this` biding (field definitions in a class expression)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-fields-public, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
ClassElement :
|
||||
...
|
||||
static FieldDefinition ;
|
||||
|
||||
FieldDefinition :
|
||||
ClassElementName Initializer_opt
|
||||
|
||||
ClassDefinitionEvaluation:
|
||||
...
|
||||
|
||||
27. Let staticFields be a new empty List.
|
||||
28. For each ClassElement e in order from elements,
|
||||
a. If IsStatic of e is false, then
|
||||
...
|
||||
b. Else,
|
||||
i. Let field be the result of performing PropertyDefinitionEvaluation for m ClassElementEvaluation for e with arguments F and false.
|
||||
c. If field is an abrupt completion, then
|
||||
...
|
||||
d. If field is not empty,
|
||||
i. If IsStatic of e is false, append field to instanceFields.
|
||||
ii. Otherwise, append field to staticFields.
|
||||
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
...
|
||||
|
||||
DefineField(receiver, fieldRecord)
|
||||
1. Assert: Type(receiver) is Object.
|
||||
2. Assert: fieldRecord is a Record as created by ClassFieldDefinitionEvaluation.
|
||||
3. Let name be fieldRecord.[[Name]].
|
||||
4. Let initializer be fieldRecord.[[Initializer]].
|
||||
5. If initializer is not empty, then
|
||||
a. Let initValue be ? Call(initializer, receiver).
|
||||
6. Else, let initValue be undefined.
|
||||
7. If fieldRecord.[[IsAnonymousFunctionDefinition]] is true, then
|
||||
a. Let hasNameProperty be ? HasOwnProperty(initValue, "name").
|
||||
b. If hasNameProperty is false, perform SetFunctionName(initValue, fieldName).
|
||||
8. If fieldName is a Private Name,
|
||||
a. Perform ? PrivateFieldAdd(fieldName, receiver, initValue).
|
||||
9. Else,
|
||||
a. Assert: IsPropertyKey(fieldName) is true.
|
||||
b. Perform ? CreateDataPropertyOrThrow(receiver, fieldName, initValue).
|
||||
10. Return.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
var C = class {
|
||||
static f = 'test';
|
||||
static g = this.f + '262';
|
||||
static h = eval('this.g') + 'test';
|
||||
}
|
||||
|
||||
assert.sameValue(C.f, 'test');
|
||||
assert.sameValue(C.g, 'test262');
|
||||
assert.sameValue(C.h, 'test262test');
|
|
@ -0,0 +1,69 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/static-field-redeclaration.case
|
||||
// - src/class-elements/default/cls-expr.template
|
||||
/*---
|
||||
description: Static fields can be redeclared (field definitions in a class expression)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-fields-public, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
ClassElement :
|
||||
...
|
||||
static FieldDefinition ;
|
||||
|
||||
FieldDefinition :
|
||||
ClassElementName Initializer_opt
|
||||
|
||||
ClassDefinitionEvaluation:
|
||||
...
|
||||
|
||||
27. Let staticFields be a new empty List.
|
||||
28. For each ClassElement e in order from elements,
|
||||
a. If IsStatic of e is false, then
|
||||
...
|
||||
b. Else,
|
||||
i. Let field be the result of performing PropertyDefinitionEvaluation for m ClassElementEvaluation for e with arguments F and false.
|
||||
c. If field is an abrupt completion, then
|
||||
...
|
||||
d. If field is not empty,
|
||||
i. If IsStatic of e is false, append field to instanceFields.
|
||||
ii. Otherwise, append field to staticFields.
|
||||
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
...
|
||||
|
||||
DefineField(receiver, fieldRecord)
|
||||
1. Assert: Type(receiver) is Object.
|
||||
2. Assert: fieldRecord is a Record as created by ClassFieldDefinitionEvaluation.
|
||||
3. Let name be fieldRecord.[[Name]].
|
||||
4. Let initializer be fieldRecord.[[Initializer]].
|
||||
5. If initializer is not empty, then
|
||||
a. Let initValue be ? Call(initializer, receiver).
|
||||
6. Else, let initValue be undefined.
|
||||
7. If fieldRecord.[[IsAnonymousFunctionDefinition]] is true, then
|
||||
a. Let hasNameProperty be ? HasOwnProperty(initValue, "name").
|
||||
b. If hasNameProperty is false, perform SetFunctionName(initValue, fieldName).
|
||||
8. If fieldName is a Private Name,
|
||||
a. Perform ? PrivateFieldAdd(fieldName, receiver, initValue).
|
||||
9. Else,
|
||||
a. Assert: IsPropertyKey(fieldName) is true.
|
||||
b. Perform ? CreateDataPropertyOrThrow(receiver, fieldName, initValue).
|
||||
10. Return.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
var C = class {
|
||||
static f = 'test';
|
||||
static f = this.f + '262';
|
||||
static g() {
|
||||
return 45;
|
||||
};
|
||||
static g = this.g();
|
||||
}
|
||||
|
||||
assert.sameValue(C.f, 'test262');
|
||||
assert.sameValue(C.g, 45);
|
|
@ -0,0 +1,63 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/static-field-init-this-inside-arrow-function.case
|
||||
// - src/class-elements/default/cls-decl.template
|
||||
/*---
|
||||
description: this in static field initializers refers to class constructor (field definitions in a class declaration)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-fields-public, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
ClassElement :
|
||||
...
|
||||
static FieldDefinition ;
|
||||
|
||||
FieldDefinition :
|
||||
ClassElementName Initializer_opt
|
||||
|
||||
ClassDefinitionEvaluation:
|
||||
...
|
||||
|
||||
27. Let staticFields be a new empty List.
|
||||
28. For each ClassElement e in order from elements,
|
||||
a. If IsStatic of e is false, then
|
||||
...
|
||||
b. Else,
|
||||
i. Let field be the result of performing PropertyDefinitionEvaluation for m ClassElementEvaluation for e with arguments F and false.
|
||||
c. If field is an abrupt completion, then
|
||||
...
|
||||
d. If field is not empty,
|
||||
i. If IsStatic of e is false, append field to instanceFields.
|
||||
ii. Otherwise, append field to staticFields.
|
||||
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
...
|
||||
|
||||
DefineField(receiver, fieldRecord)
|
||||
1. Assert: Type(receiver) is Object.
|
||||
2. Assert: fieldRecord is a Record as created by ClassFieldDefinitionEvaluation.
|
||||
3. Let name be fieldRecord.[[Name]].
|
||||
4. Let initializer be fieldRecord.[[Initializer]].
|
||||
5. If initializer is not empty, then
|
||||
a. Let initValue be ? Call(initializer, receiver).
|
||||
6. Else, let initValue be undefined.
|
||||
7. If fieldRecord.[[IsAnonymousFunctionDefinition]] is true, then
|
||||
a. Let hasNameProperty be ? HasOwnProperty(initValue, "name").
|
||||
b. If hasNameProperty is false, perform SetFunctionName(initValue, fieldName).
|
||||
8. If fieldName is a Private Name,
|
||||
a. Perform ? PrivateFieldAdd(fieldName, receiver, initValue).
|
||||
9. Else,
|
||||
a. Assert: IsPropertyKey(fieldName) is true.
|
||||
b. Perform ? CreateDataPropertyOrThrow(receiver, fieldName, initValue).
|
||||
10. Return.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
class C {
|
||||
static f = () => this;
|
||||
}
|
||||
|
||||
assert.sameValue(C.f(), C);
|
|
@ -0,0 +1,67 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/static-field-init-with-this.case
|
||||
// - src/class-elements/default/cls-decl.template
|
||||
/*---
|
||||
description: Static fields initializer has `this` biding (field definitions in a class declaration)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-fields-public, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
ClassElement :
|
||||
...
|
||||
static FieldDefinition ;
|
||||
|
||||
FieldDefinition :
|
||||
ClassElementName Initializer_opt
|
||||
|
||||
ClassDefinitionEvaluation:
|
||||
...
|
||||
|
||||
27. Let staticFields be a new empty List.
|
||||
28. For each ClassElement e in order from elements,
|
||||
a. If IsStatic of e is false, then
|
||||
...
|
||||
b. Else,
|
||||
i. Let field be the result of performing PropertyDefinitionEvaluation for m ClassElementEvaluation for e with arguments F and false.
|
||||
c. If field is an abrupt completion, then
|
||||
...
|
||||
d. If field is not empty,
|
||||
i. If IsStatic of e is false, append field to instanceFields.
|
||||
ii. Otherwise, append field to staticFields.
|
||||
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
...
|
||||
|
||||
DefineField(receiver, fieldRecord)
|
||||
1. Assert: Type(receiver) is Object.
|
||||
2. Assert: fieldRecord is a Record as created by ClassFieldDefinitionEvaluation.
|
||||
3. Let name be fieldRecord.[[Name]].
|
||||
4. Let initializer be fieldRecord.[[Initializer]].
|
||||
5. If initializer is not empty, then
|
||||
a. Let initValue be ? Call(initializer, receiver).
|
||||
6. Else, let initValue be undefined.
|
||||
7. If fieldRecord.[[IsAnonymousFunctionDefinition]] is true, then
|
||||
a. Let hasNameProperty be ? HasOwnProperty(initValue, "name").
|
||||
b. If hasNameProperty is false, perform SetFunctionName(initValue, fieldName).
|
||||
8. If fieldName is a Private Name,
|
||||
a. Perform ? PrivateFieldAdd(fieldName, receiver, initValue).
|
||||
9. Else,
|
||||
a. Assert: IsPropertyKey(fieldName) is true.
|
||||
b. Perform ? CreateDataPropertyOrThrow(receiver, fieldName, initValue).
|
||||
10. Return.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
class C {
|
||||
static f = 'test';
|
||||
static g = this.f + '262';
|
||||
static h = eval('this.g') + 'test';
|
||||
}
|
||||
|
||||
assert.sameValue(C.f, 'test');
|
||||
assert.sameValue(C.g, 'test262');
|
||||
assert.sameValue(C.h, 'test262test');
|
|
@ -0,0 +1,58 @@
|
|||
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Class evaluation is incomplete when initializer resutls in an abrupt completition
|
||||
esid: sec-define-field
|
||||
info: |
|
||||
ClassDefinitionEvaluation:
|
||||
...
|
||||
|
||||
27. Let staticFields be a new empty List.
|
||||
28. For each ClassElement e in order from elements,
|
||||
a. If IsStatic of e is false, then
|
||||
...
|
||||
b. Else,
|
||||
i. Let field be the result of performing PropertyDefinitionEvaluation for m ClassElementEvaluation for e with arguments F and false.
|
||||
c. If field is an abrupt completion, then
|
||||
...
|
||||
d. If field is not empty,
|
||||
i. If IsStatic of e is false, append field to instanceFields.
|
||||
ii. Otherwise, append field to staticFields.
|
||||
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
...
|
||||
|
||||
DefineField(receiver, fieldRecord)
|
||||
1. Assert: Type(receiver) is Object.
|
||||
2. Assert: fieldRecord is a Record as created by ClassFieldDefinitionEvaluation.
|
||||
3. Let name be fieldRecord.[[Name]].
|
||||
4. Let initializer be fieldRecord.[[Initializer]].
|
||||
5. If initializer is not empty, then
|
||||
a. Let initValue be ? Call(initializer, receiver).
|
||||
6. Else, let initValue be undefined.
|
||||
7. If fieldRecord.[[IsAnonymousFunctionDefinition]] is true, then
|
||||
a. Let hasNameProperty be ? HasOwnProperty(initValue, "name").
|
||||
b. If hasNameProperty is false, perform SetFunctionName(initValue, fieldName).
|
||||
8. If fieldName is a Private Name,
|
||||
a. Perform ? PrivateFieldAdd(fieldName, receiver, initValue).
|
||||
9. Else,
|
||||
a. Assert: IsPropertyKey(fieldName) is true.
|
||||
b. Perform ? CreateDataPropertyOrThrow(receiver, fieldName, initValue).
|
||||
10. Return.
|
||||
features: [class-static-fields-public, class]
|
||||
---*/
|
||||
|
||||
function initThrows() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
class C {
|
||||
static f = initThrows();
|
||||
static g;
|
||||
};
|
||||
|
||||
assert(false, 'this should never execute');
|
||||
}, 'static field initializer should throw exception');
|
|
@ -0,0 +1,69 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/static-field-redeclaration.case
|
||||
// - src/class-elements/default/cls-decl.template
|
||||
/*---
|
||||
description: Static fields can be redeclared (field definitions in a class declaration)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-fields-public, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
ClassElement :
|
||||
...
|
||||
static FieldDefinition ;
|
||||
|
||||
FieldDefinition :
|
||||
ClassElementName Initializer_opt
|
||||
|
||||
ClassDefinitionEvaluation:
|
||||
...
|
||||
|
||||
27. Let staticFields be a new empty List.
|
||||
28. For each ClassElement e in order from elements,
|
||||
a. If IsStatic of e is false, then
|
||||
...
|
||||
b. Else,
|
||||
i. Let field be the result of performing PropertyDefinitionEvaluation for m ClassElementEvaluation for e with arguments F and false.
|
||||
c. If field is an abrupt completion, then
|
||||
...
|
||||
d. If field is not empty,
|
||||
i. If IsStatic of e is false, append field to instanceFields.
|
||||
ii. Otherwise, append field to staticFields.
|
||||
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
...
|
||||
|
||||
DefineField(receiver, fieldRecord)
|
||||
1. Assert: Type(receiver) is Object.
|
||||
2. Assert: fieldRecord is a Record as created by ClassFieldDefinitionEvaluation.
|
||||
3. Let name be fieldRecord.[[Name]].
|
||||
4. Let initializer be fieldRecord.[[Initializer]].
|
||||
5. If initializer is not empty, then
|
||||
a. Let initValue be ? Call(initializer, receiver).
|
||||
6. Else, let initValue be undefined.
|
||||
7. If fieldRecord.[[IsAnonymousFunctionDefinition]] is true, then
|
||||
a. Let hasNameProperty be ? HasOwnProperty(initValue, "name").
|
||||
b. If hasNameProperty is false, perform SetFunctionName(initValue, fieldName).
|
||||
8. If fieldName is a Private Name,
|
||||
a. Perform ? PrivateFieldAdd(fieldName, receiver, initValue).
|
||||
9. Else,
|
||||
a. Assert: IsPropertyKey(fieldName) is true.
|
||||
b. Perform ? CreateDataPropertyOrThrow(receiver, fieldName, initValue).
|
||||
10. Return.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
class C {
|
||||
static f = 'test';
|
||||
static f = this.f + '262';
|
||||
static g() {
|
||||
return 45;
|
||||
};
|
||||
static g = this.g();
|
||||
}
|
||||
|
||||
assert.sameValue(C.f, 'test262');
|
||||
assert.sameValue(C.g, 45);
|
Loading…
Reference in New Issue