Refactor class fields templates and cases

This commit is contained in:
Daniel Ehrenberg 2017-07-13 21:10:41 +02:00 committed by Leo Balter
parent f1d7a67e11
commit f3f3b47306
No known key found for this signature in database
GPG Key ID: 2C75F319D398E36B
44 changed files with 1401 additions and 0 deletions

View File

@ -0,0 +1,70 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: prod-FieldDefinition
desc: Computed property names
info: |
ClassElement:
...
FieldDefinition ;
FieldDefinition:
ClassElementName Initializer_opt
ClassElementName:
PropertyName
template: default
includes: [propertyHelper.js]
features: [computed-property-names]
---*/
//- setup
var x = "b";
//- fields
static ["a"] = 39; [x] = 42; [10] = "meep"; ["not initialized"]
//- assertions
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "a"), false);
assert.sameValue(Object.hasOwnProperty.call(c, "a"), false);
verifyProperty(C, "a", {
value: 39,
enumerable: true,
writable: true,
configurable: true
});
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "b"), false);
assert.sameValue(Object.hasOwnProperty.call(C, "b"), false);
verifyProperty(c, "b", {
value: 42,
enumerable: true,
writable: true,
configurable: true
});
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "x"), false);
assert.sameValue(Object.hasOwnProperty.call(C, "x"), false);
assert.sameValue(Object.hasOwnProperty.call(c, "x"), false);
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "10"), false);
assert.sameValue(Object.hasOwnProperty.call(C, "10"), false);
verifyProperty(c, "10", {
value: "meep",
enumerable: true,
writable: true,
configurable: true
});
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "not initialized"), false);
assert.sameValue(Object.hasOwnProperty.call(C, "not initialized"), false);
verifyProperty(c, "not initialized", {
value: "meep",
enumerable: true,
writable: true,
configurable: true
});

View File

@ -0,0 +1,55 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: prod-FieldDefinition
desc: Computed property symbol names
info: |
ClassElement:
...
FieldDefinition ;
FieldDefinition:
ClassElementName Initializer_opt
ClassElementName:
PropertyName
template: default
includes: [propertyHelper.js]
features: [Symbol, computed-property-names]
---*/
//- setup
var x = Symbol();
var y = Symbol();
//- fields
[x]; [y] = 42
//- assertions
assert.sameValue(Object.hasOwnProperty.call(C.prototype, x), false);
assert.sameValue(Object.hasOwnProperty.call(C, x), false);
verifyProperty(c, x, {
value: undefined,
enumerable: true,
writable: true,
configurable: true
});
assert.sameValue(Object.hasOwnProperty.call(C.prototype, y), false);
assert.sameValue(Object.hasOwnProperty.call(C, y), false);
verifyProperty(c, y, {
value: 42,
enumerable: true,
writable: true,
configurable: true
});
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "x"), false);
assert.sameValue(Object.hasOwnProperty.call(C, "x"), false);
assert.sameValue(Object.hasOwnProperty.call(c, "x"), false);
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "y"), false);
assert.sameValue(Object.hasOwnProperty.call(C, "y"), false);
assert.sameValue(Object.hasOwnProperty.call(c, "y"), false);

View File

@ -0,0 +1,8 @@
# Conventions for the class fields templates and cases
Templates should produce a class named `C` and instantiate it to an object named `c`.
## Known template fields:
* fields: it should contain the list of class fields, inserted in the class body. Please, avoid closing a field with a trailing semi-colon, this might prevent ASI checks properly.
* assertions: it should contain the assertions to run after the class object is instantiated.

View File

@ -0,0 +1,30 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/fields-same-line-async-gen-
name: field definitions after an async generator in the same line
features: [class-fields, async-iteration]
flags: [async]
---*/
class C {
async *m() { return 42; } /*{ fields }*/;
}
var c = new C();
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
assert.sameValue(c.m, C.prototype.m);
verifyProperty(C.prototype, "m", {
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/
c.m().next().then(function(v) {
assert.sameValue(v, 42);
}, $DONE).then($DONE, $DONE);

View File

@ -0,0 +1,30 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/fields-same-line-async-method-
name: field definitions after an async method in the same line
features: [class-fields, async-functions]
flags: [async]
---*/
class C {
async m() { return 42; } /*{ fields }*/;
}
var c = new C();
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
assert.sameValue(c.m, C.prototype.m);
verifyProperty(C.prototype, "m", {
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/
c.m().then(function(v) {
assert.sameValue(v, 42);
}, $DONE).then($DONE, $DONE);

View File

@ -0,0 +1,26 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/fields-after-same-line-gen-
name: field definitions after a generator in the same line
features: [class-fields]
---*/
class C {
*m() { return 42; } /*{ fields }*/;
}
var c = new C();
assert.sameValue(c.m().next().value, 42);
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
assert.sameValue(c.m, C.prototype.m);
verifyProperty(C.prototype, "m", {
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/

View File

@ -0,0 +1,26 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/fields-after-same-line-method-
name: field definitions after a method in the same line
features: [class-fields]
---*/
class C {
m() { return 42; } /*{ fields }*/;
}
var c = new C();
assert.sameValue(c.m(), 42);
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
assert.sameValue(c.m, C.prototype.m);
verifyProperty(C.prototype, "m", {
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/

View File

@ -0,0 +1,30 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/fields-after-same-line-static-async-gen-
name: field definitions after a static async generator in the same line
features: [class-fields, async-iteration]
flags: [async]
---*/
class C {
static async *m() { return 42; } /*{ fields }*/;
}
var c = new C();
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "m"), false);
verifyProperty(C, "m", {
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/
C.m().next().then(function(v) {
assert.sameValue(v, 42);
}, $DONE).then($DONE, $DONE);

View File

@ -0,0 +1,30 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/fields-after-same-line-static-async-method-
name: field definitions after a static async method in the same line
features: [class-fields, async-functions]
flags: [async]
---*/
class C {
static async m() { return 42; } /*{ fields }*/;
}
var c = new C();
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "m"), false);
verifyProperty(C, "m", {
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/
C.m().then(function(v) {
assert.sameValue(v, 42);
}, $DONE).then($DONE, $DONE);

View File

@ -0,0 +1,26 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/fields-after-same-line-static-gen-
name: field definitions after a static generator in the same line
features: [class-fields]
---*/
class C {
static *m() { return 42; } /*{ fields }*/;
}
var c = new C();
assert.sameValue(C.m().next().value, 42);
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "m"), false);
verifyProperty(C, "m", {
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/

View File

@ -0,0 +1,26 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/fields-after-same-line-static-method-
name: field definitions after a static method in the same line
features: [class-fields]
---*/
class C {
static m() { return 42; } /*{ fields }*/;
}
var c = new C();
assert.sameValue(C.m(), 42);
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "m"), false);
verifyProperty(C, "m", {
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/

View File

@ -0,0 +1,62 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/fields-multiple-definitions-
name: multiple fields definitions
features: [class-fields]
---*/
class C {
foo = "foobar";
m() { return 42 }
/*{ fields }*/
m2() { return 39 }
bar = "barbaz";
}
var c = new C();
assert.sameValue(c.m(), 42);
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
assert.sameValue(c.m, C.prototype.m);
verifyProperty(C.prototype, "m", {
enumerable: false,
configurable: true,
writable: true,
});
assert.sameValue(c.m2(), 39);
assert.sameValue(Object.hasOwnProperty.call(c, "m2"), false);
assert.sameValue(c.m2, C.prototype.m2);
verifyProperty(C.prototype, "m2", {
enumerable: false,
configurable: true,
writable: true,
});
assert.sameValue(c.foo, "foobar");
assert.sameValue(Object.hasOwnProperty.call(C, "foo"), false);
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "foo"), false);
verifyProperty(c, "foo", {
value: "foobar",
enumerable: false,
configurable: true,
writable: true,
});
assert.sameValue(c.bar, "barbaz");
assert.sameValue(Object.hasOwnProperty.call(C, "bar"), false);
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "bar"), false);
verifyProperty(c, "bar", {
value: "barbaz",
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/

View File

@ -0,0 +1,44 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/fields-multiple-stacked-definitions-
name: multiple stacked fields definitions through ASI
features: [class-fields]
---*/
class C {
/*{ fields }*/
foo = "foobar"
bar = "barbaz";
}
var c = new C();
assert.sameValue(c.m(), 42);
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
assert.sameValue(c.m, C.prototype.m);
assert.sameValue(c.foo, "foobar");
assert.sameValue(Object.hasOwnProperty.call(C, "foo"), false);
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "foo"), false);
verifyProperty(c, "foo", {
value: "foobar",
enumerable: false,
configurable: true,
writable: true,
});
assert.sameValue(c.bar, "barbaz");
assert.sameValue(Object.hasOwnProperty.call(C, "bar"), false);
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "bar"), false);
verifyProperty(c, "bar", {
value: "barbaz",
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/

View File

@ -0,0 +1,27 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/fields-new-no-sc-line-method-
name: field definitions followed by a method in a new line without a semicolon
features: [class-fields]
---*/
class C {
/*{ fields }*/
m() { return 42; }
}
var c = new C();
assert.sameValue(c.m(), 42);
assert.sameValue(c.m, C.prototype.m);
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
verifyProperty(C.prototype, "m", {
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/

View File

@ -0,0 +1,27 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/fields-new-sc-line-gen-
name: field definitions followed by a method in a new line with a semicolon
features: [class-fields, generators]
---*/
class C {
/*{ fields }*/;
*m() { return 42; }
}
var c = new C();
assert.sameValue(c.g().next().value, 42);
assert.sameValue(c.m, C.prototype.m);
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
verifyProperty(C.prototype, "m", {
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/

View File

@ -0,0 +1,27 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/fields-new-sc-line-method-
name: field definitions followed by a method in a new line with a semicolon
features: [class-fields]
---*/
class C {
/*{ fields }*/;
m() { return 42; }
}
var c = new C();
assert.sameValue(c.m(), 42);
assert.sameValue(c.m, C.prototype.m);
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
verifyProperty(C.prototype, "m", {
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/

View File

@ -0,0 +1,16 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/fields-regular-definitions-
name: regular fields defintion
features: [class-fields]
---*/
class C {
/*{ fields }*/
}
var c = new C();
/*{ assertions }*/

View File

@ -0,0 +1,26 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/fields-same-line-gen-
name: field definitions followed by a generator method in the same line
features: [class-fields, generators]
---*/
class C {
/*{ fields }*/; *m() { return 42; }
}
var c = new C();
assert.sameValue(c.m().next().value, 42);
assert.sameValue(c.m, C.prototype.m);
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
verifyProperty(C.prototype, "m", {
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/

View File

@ -0,0 +1,26 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/fields-same-line-method-
name: field definitions followed by a method in the same line
features: [class-fields]
---*/
class C {
/*{ fields }*/; m() { return 42; }
}
var c = new C();
assert.sameValue(c.m(), 42);
assert.sameValue(c.m, C.prototype.m);
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
verifyProperty(C.prototype, "m", {
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/

View File

@ -0,0 +1,18 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/fields-wrapped-in-sc-
name: fields definition wrapped in semicolons
features: [class-fields]
---*/
class C {
;;;;
;;;;;;/*{ fields }*/;;;;;;;
;;;;
}
var c = new C();
/*{ assertions }*/

View File

@ -0,0 +1,30 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/fields-same-line-async-gen-
name: field definitions after an async generator in the same line
features: [class-fields, async-iteration]
flags: [async]
---*/
var C = class {
async *m() { return 42; } /*{ fields }*/;
}
var c = new C();
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
assert.sameValue(c.m, C.prototype.m);
verifyProperty(C.prototype, "m", {
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/
c.m().next().then(function(v) {
assert.sameValue(v, 42);
}, $DONE).then($DONE, $DONE);

View File

@ -0,0 +1,30 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/fields-same-line-async-method-
name: field definitions after an async method in the same line
features: [class-fields, async-functions]
flags: [async]
---*/
var C = class {
async m() { return 42; } /*{ fields }*/;
}
var c = new C();
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
assert.sameValue(c.m, C.prototype.m);
verifyProperty(C.prototype, "m", {
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/
c.m().then(function(v) {
assert.sameValue(v, 42);
}, $DONE).then($DONE, $DONE);

View File

@ -0,0 +1,26 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/fields-after-same-line-gen-
name: field definitions after a generator in the same line
features: [class-fields]
---*/
var C = class {
*m() { return 42; } /*{ fields }*/;
}
var c = new C();
assert.sameValue(c.m().next().value, 42);
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
assert.sameValue(c.m, C.prototype.m);
verifyProperty(C.prototype, "m", {
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/

View File

@ -0,0 +1,26 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/fields-after-same-line-method-
name: field definitions after a method in the same line
features: [class-fields]
---*/
var C = class {
m() { return 42; } /*{ fields }*/;
}
var c = new C();
assert.sameValue(c.m(), 42);
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
assert.sameValue(c.m, C.prototype.m);
verifyProperty(C.prototype, "m", {
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/

View File

@ -0,0 +1,30 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/fields-after-same-line-static-async-gen-
name: field definitions after a static async generator in the same line
features: [class-fields, async-iteration]
flags: [async]
---*/
var C = class {
static async *m() { return 42; } /*{ fields }*/;
}
var c = new C();
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "m"), false);
verifyProperty(C, "m", {
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/
C.m().next().then(function(v) {
assert.sameValue(v, 42);
}, $DONE).then($DONE, $DONE);

View File

@ -0,0 +1,30 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/fields-after-same-line-static-async-method-
name: field definitions after a static async method in the same line
features: [class-fields, async-functions]
flags: [async]
---*/
var C = class {
static async m() { return 42; } /*{ fields }*/;
}
var c = new C();
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "m"), false);
verifyProperty(C, "m", {
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/
C.m().then(function(v) {
assert.sameValue(v, 42);
}, $DONE).then($DONE, $DONE);

View File

@ -0,0 +1,26 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/fields-after-same-line-static-gen-
name: field definitions after a static generator in the same line
features: [class-fields]
---*/
var C = class {
static *m() { return 42; } /*{ fields }*/;
}
var c = new C();
assert.sameValue(C.m().next().value, 42);
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "m"), false);
verifyProperty(C, "m", {
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/

View File

@ -0,0 +1,26 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/fields-after-same-line-static-method-
name: field definitions after a static method in the same line
features: [class-fields]
---*/
var C = class {
static m() { return 42; } /*{ fields }*/;
}
var c = new C();
assert.sameValue(C.m(), 42);
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "m"), false);
verifyProperty(C, "m", {
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/

View File

@ -0,0 +1,62 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/fields-multiple-definitions-
name: multiple fields definitions
features: [class-fields]
---*/
var C = class {
foo = "foobar";
m() { return 42 }
/*{ fields }*/
m2() { return 39 }
bar = "barbaz";
}
var c = new C();
assert.sameValue(c.m(), 42);
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
assert.sameValue(c.m, C.prototype.m);
verifyProperty(C.prototype, "m", {
enumerable: false,
configurable: true,
writable: true,
});
assert.sameValue(c.m2(), 39);
assert.sameValue(Object.hasOwnProperty.call(c, "m2"), false);
assert.sameValue(c.m2, C.prototype.m2);
verifyProperty(C.prototype, "m2", {
enumerable: false,
configurable: true,
writable: true,
});
assert.sameValue(c.foo, "foobar");
assert.sameValue(Object.hasOwnProperty.call(C, "foo"), false);
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "foo"), false);
verifyProperty(c, "foo", {
value: "foobar",
enumerable: false,
configurable: true,
writable: true,
});
assert.sameValue(c.bar, "barbaz");
assert.sameValue(Object.hasOwnProperty.call(C, "bar"), false);
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "bar"), false);
verifyProperty(c, "bar", {
value: "barbaz",
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/

View File

@ -0,0 +1,44 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/fields-multiple-stacked-definitions-
name: multiple stacked fields definitions through ASI
features: [class-fields]
---*/
var C = class {
/*{ fields }*/
foo = "foobar"
bar = "barbaz";
}
var c = new C();
assert.sameValue(c.m(), 42);
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
assert.sameValue(c.m, C.prototype.m);
assert.sameValue(c.foo, "foobar");
assert.sameValue(Object.hasOwnProperty.call(C, "foo"), false);
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "foo"), false);
verifyProperty(c, "foo", {
value: "foobar",
enumerable: false,
configurable: true,
writable: true,
});
assert.sameValue(c.bar, "barbaz");
assert.sameValue(Object.hasOwnProperty.call(C, "bar"), false);
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "bar"), false);
verifyProperty(c, "bar", {
value: "barbaz",
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/

View File

@ -0,0 +1,27 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/fields-new-no-sc-line-method-
name: field definitions followed by a method in a new line without a semicolon
features: [class-fields]
---*/
var C = class {
/*{ fields }*/
m() { return 42; }
}
var c = new C();
assert.sameValue(c.m(), 42);
assert.sameValue(c.m, C.prototype.m);
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
verifyProperty(C.prototype, "m", {
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/

View File

@ -0,0 +1,27 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/fields-new-sc-line-gen-
name: field definitions followed by a method in a new line with a semicolon
features: [class-fields, generators]
---*/
var C = class {
/*{ fields }*/;
*m() { return 42; }
}
var c = new C();
assert.sameValue(c.g().next().value, 42);
assert.sameValue(c.m, C.prototype.m);
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
verifyProperty(C.prototype, "m", {
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/

View File

@ -0,0 +1,27 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/fields-new-sc-line-method-
name: field definitions followed by a method in a new line with a semicolon
features: [class-fields]
---*/
var C = class {
/*{ fields }*/;
m() { return 42; }
}
var c = new C();
assert.sameValue(c.m(), 42);
assert.sameValue(c.m, C.prototype.m);
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
verifyProperty(C.prototype, "m", {
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/

View File

@ -0,0 +1,16 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/fields-regular-definitions-
name: regular fields defintion
features: [class-fields]
---*/
var C = class {
/*{ fields }*/
}
var c = new C();
/*{ assertions }*/

View File

@ -0,0 +1,26 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/fields-same-line-gen-
name: field definitions followed by a generator method in the same line
features: [class-fields, generators]
---*/
var C = class {
/*{ fields }*/; *m() { return 42; }
}
var c = new C();
assert.sameValue(c.m().next().value, 42);
assert.sameValue(c.m, C.prototype.m);
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
verifyProperty(C.prototype, "m", {
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/

View File

@ -0,0 +1,26 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/fields-same-line-method-
name: field definitions followed by a method in the same line
features: [class-fields]
---*/
var C = class {
/*{ fields }*/; m() { return 42; }
}
var c = new C();
assert.sameValue(c.m(), 42);
assert.sameValue(c.m, C.prototype.m);
assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
verifyProperty(C.prototype, "m", {
enumerable: false,
configurable: true,
writable: true,
});
/*{ assertions }*/

View File

@ -0,0 +1,18 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/fields-wrapped-in-sc-
name: fields definition wrapped in semicolons
features: [class-fields]
---*/
var C = class {
;;;;
;;;;;;/*{ fields }*/;;;;;;;
;;;;
}
var c = new C();
/*{ assertions }*/

View File

@ -0,0 +1,16 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/fields-new-no-sc-line-gen-
name: ASI prevents a following generator method
features: [class-fields, generators]
negative:
type: SyntaxError
phase: early
---*/
class C {
/*{ fields }*/
*m() { return 42; }
}

16
src/class-fields/info.txt Normal file
View File

@ -0,0 +1,16 @@
ClassElement:
MethodDefinition
static MethodDefinition
FieldDefinition ;
static FieldDefinition ;
;
FieldDefinition:
ClassElementName Initializer_opt
ClassElementName:
PropertyName
PrivateName
PrivateName ::
# IdentifierName

View File

@ -0,0 +1,57 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: prod-FieldDefinition
desc: Literal property names
info: |
ClassElement:
...
FieldDefinition ;
FieldDefinition:
ClassElementName Initializer_opt
ClassElementName:
PropertyName
template: default
includes: [propertyHelper.js]
---*/
//- setup
const fn = function() {}
//- fields
a; b = 42;
c = fn
//- assertions
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "a"), false);
assert.sameValue(Object.hasOwnProperty.call(C, "a"), false);
verifyProperty(c, "a", {
value: undefined,
enumerable: true,
writable: true,
configurable: true
});
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "b"), false);
assert.sameValue(Object.hasOwnProperty.call(C, "b"), false);
verifyProperty(c, "b", {
value: 42,
enumerable: true,
writable: true,
configurable: true
});
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "c"), false);
assert.sameValue(Object.hasOwnProperty.call(C, "c"), false);
verifyProperty(c, "c", {
value: fn,
enumerable: true,
writable: true,
configurable: true
});

View File

@ -0,0 +1,40 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: prod-FieldDefinition
desc: Static Computed property names
info: |
ClassElement:
...
FieldDefinition ;
static FieldDefinition ;
FieldDefinition:
ClassElementName Initializer_opt
ClassElementName:
PropertyName
template: default
includes: [propertyHelper.js]
features: [computed-property-names]
---*/
//- fields
static ["a"] = 42; ["a"] = 39
//- assertions
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "a"), false);
verifyProperty(C, "a", {
value: 42,
enumerable: true,
writable: true,
configurable: true
});
verifyProperty(c, "a", {
value: 39,
enumerable: true,
writable: true,
configurable: true
});

View File

@ -0,0 +1,55 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: prod-FieldDefinition
desc: Static computed property symbol names
info: |
ClassElement:
...
FieldDefinition ;
FieldDefinition:
ClassElementName Initializer_opt
ClassElementName:
PropertyName
template: default
includes: [propertyHelper.js]
features: [Symbol, computed-property-names]
---*/
//- setup
var x = Symbol();
var y = Symbol();
//- fields
[x]; [y] = 42
//- assertions
assert.sameValue(Object.hasOwnProperty.call(C.prototype, x), false);
assert.sameValue(Object.hasOwnProperty.call(C, x), false);
verifyProperty(c, x, {
value: undefined,
enumerable: true,
writable: true,
configurable: true
});
assert.sameValue(Object.hasOwnProperty.call(C.prototype, y), false);
assert.sameValue(Object.hasOwnProperty.call(C, y), false);
verifyProperty(c, y, {
value: 42,
enumerable: true,
writable: true,
configurable: true
});
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "x"), false);
assert.sameValue(Object.hasOwnProperty.call(C, "x"), false);
assert.sameValue(Object.hasOwnProperty.call(c, "x"), false);
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "y"), false);
assert.sameValue(Object.hasOwnProperty.call(C, "y"), false);
assert.sameValue(Object.hasOwnProperty.call(c, "y"), false);

View File

@ -0,0 +1,57 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: prod-FieldDefinition
desc: Static literal property names
info: |
ClassElement:
...
FieldDefinition ;
FieldDefinition:
ClassElementName Initializer_opt
ClassElementName:
PropertyName
template: default
includes: [propertyHelper.js]
---*/
//- setup
const fn = function() {}
//- fields
static a; b = 42;
static c = fn
//- assertions
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "a"), false);
assert.sameValue(Object.hasOwnProperty.call(c, "a"), false);
verifyProperty(C, "a", {
value: undefined,
enumerable: true,
writable: true,
configurable: true
});
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "b"), false);
assert.sameValue(Object.hasOwnProperty.call(C, "b"), false);
verifyProperty(c, "b", {
value: 42,
enumerable: true,
writable: true,
configurable: true
});
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "c"), false);
assert.sameValue(Object.hasOwnProperty.call(c, "c"), false);
verifyProperty(C, "c", {
value: fn,
enumerable: true,
writable: true,
configurable: true
});

View File

@ -0,0 +1,33 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: prod-FieldDefinition
desc: String literal names
info: |
ClassElement:
...
FieldDefinition ;
FieldDefinition:
ClassElementName Initializer_opt
ClassElementName:
PropertyName
template: default
includes: [propertyHelper.js]
---*/
//- fields
'a'; "b"; 'c' = 39;
"d" = 42
//- assertions
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "a"), false);
assert.sameValue(Object.hasOwnProperty.call(C, "a"), false);
verifyProperty(c, "a", {
value: 42,
enumerable: true,
writable: true,
configurable: true
});