mirror of
https://github.com/tc39/test262.git
synced 2025-06-15 03:20:30 +02:00
14.5 Class Definitions
- 14.5.1 Static Semantics: Early Errors - 14.5.3 Static Semantics: ConstructorMethod - 14.5.14 Runtime Semantics: ClassDefinitionEvaluation
This commit is contained in:
parent
3907f4d5b3
commit
29e2990d9b
@ -1,18 +0,0 @@
|
|||||||
// Copyright (C) 2014 the V8 project authors. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
/*---
|
|
||||||
es6id: 14.5
|
|
||||||
description: >
|
|
||||||
class subclassing null
|
|
||||||
---*/
|
|
||||||
var N = null;
|
|
||||||
|
|
||||||
class Foo extends N {
|
|
||||||
constructor(x, y) {
|
|
||||||
assert.sameValue(x, 1, "The value of `x` is `1`");
|
|
||||||
assert.sameValue(y, 2, "The value of `y` is `2`");
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
new Foo(1,2);
|
|
@ -0,0 +1,35 @@
|
|||||||
|
// Copyright (C) 2014 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5.14
|
||||||
|
description: >
|
||||||
|
10. If constructor is empty, then,
|
||||||
|
a. If ClassHeritageopt is present, then
|
||||||
|
i. Let constructor be the result of parsing the String "constructor(... args){ super (...args);}" using the syntactic grammar with the goal symbol MethodDefinition.
|
||||||
|
---*/
|
||||||
|
var args;
|
||||||
|
|
||||||
|
class A {
|
||||||
|
constructor() {
|
||||||
|
args = arguments;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class B extends A {
|
||||||
|
/*
|
||||||
|
The missing constructor is created by the runtime:
|
||||||
|
|
||||||
|
constructor(...args) {
|
||||||
|
super(...args);
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
new B(0, 1, 2);
|
||||||
|
|
||||||
|
|
||||||
|
assert.sameValue(args[0], 0);
|
||||||
|
assert.sameValue(args[1], 1);
|
||||||
|
assert.sameValue(args[2], 2);
|
||||||
|
|
@ -0,0 +1,22 @@
|
|||||||
|
// Copyright (C) 2014 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5.14
|
||||||
|
description: >
|
||||||
|
Runtime Semantics: ClassDefinitionEvaluation
|
||||||
|
|
||||||
|
If superclass is null, then
|
||||||
|
Let protoParent be null.
|
||||||
|
Let constructorParent be the intrinsic object %FunctionPrototype%.
|
||||||
|
|
||||||
|
`extends null` requires return override in the constructor
|
||||||
|
---*/
|
||||||
|
class Foo extends null {
|
||||||
|
constructor() {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var f = new Foo();
|
||||||
|
|
||||||
|
assert.sameValue(Object.getPrototypeOf(f), Object.prototype);
|
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright (C) 2014 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5.14
|
||||||
|
description: >
|
||||||
|
Runtime Semantics: ClassDefinitionEvaluation
|
||||||
|
|
||||||
|
If superclass is null, then
|
||||||
|
Let protoParent be null.
|
||||||
|
Let constructorParent be the intrinsic object %FunctionPrototype%.
|
||||||
|
|
||||||
|
`extends null` requires return override in the constructor
|
||||||
|
---*/
|
||||||
|
class Foo extends null {
|
||||||
|
constructor() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.throws(ReferenceError, function() {
|
||||||
|
new Foo();
|
||||||
|
});
|
||||||
|
|
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright (C) 2014 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5.14_S6.e
|
||||||
|
description: >
|
||||||
|
Runtime Semantics: ClassDefinitionEvaluation
|
||||||
|
|
||||||
|
If superclass is null, then
|
||||||
|
Let protoParent be null.
|
||||||
|
Let constructorParent be the intrinsic object %FunctionPrototype%.
|
||||||
|
---*/
|
||||||
|
class Foo extends null {
|
||||||
|
constructor() {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(Object.getPrototypeOf(Foo.prototype), null);
|
||||||
|
assert.sameValue(Object.getPrototypeOf(Foo.prototype.constructor), Function.prototype);
|
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright (C) 2014 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5.14_S6.g.i
|
||||||
|
description: >
|
||||||
|
Runtime Semantics: ClassDefinitionEvaluation
|
||||||
|
|
||||||
|
If superclass has a [[FunctionKind]] internal slot whose value is "generator", throw a TypeError exception.
|
||||||
|
---*/
|
||||||
|
function * G() {}
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
class A extends G {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
@ -12,7 +12,7 @@ class Base {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
class Derived extends Base {}
|
class Derived extends Base {}
|
||||||
var object = new Derived;
|
var object = new Derived();
|
||||||
assert.sameValue(calls, 1, "The value of `calls` is `1`");
|
assert.sameValue(calls, 1, "The value of `calls` is `1`");
|
||||||
|
|
||||||
calls = 0;
|
calls = 0;
|
@ -0,0 +1,30 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 9.2.2
|
||||||
|
description: >
|
||||||
|
[[Construct]] ( argumentsList, newTarget)
|
||||||
|
|
||||||
|
...
|
||||||
|
13. If result.[[type]] is return, then
|
||||||
|
...
|
||||||
|
c. If result.[[value]] is not undefined, throw a TypeError exception.
|
||||||
|
...
|
||||||
|
|
||||||
|
`return true;`
|
||||||
|
|
||||||
|
---*/
|
||||||
|
class Base {
|
||||||
|
constructor() {}
|
||||||
|
}
|
||||||
|
class Derived extends Base {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
new Derived();
|
||||||
|
});
|
@ -0,0 +1,40 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 9.2.2
|
||||||
|
description: >
|
||||||
|
[[Construct]] ( argumentsList, newTarget)
|
||||||
|
|
||||||
|
...
|
||||||
|
13. If result.[[type]] is return, then
|
||||||
|
...
|
||||||
|
c. If result.[[value]] is not undefined, ...
|
||||||
|
14. Else, ReturnIfAbrupt(result).
|
||||||
|
15. Return envRec.GetThisBinding().
|
||||||
|
|
||||||
|
`return (empty);` Should be the same as `return undefined;`
|
||||||
|
---*/
|
||||||
|
var calls = 0;
|
||||||
|
class Base {
|
||||||
|
constructor() {
|
||||||
|
this.prop = 1;
|
||||||
|
calls++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class Derived extends Base {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var object = new Derived();
|
||||||
|
|
||||||
|
// super is called
|
||||||
|
assert.sameValue(calls, 1, "The value of `calls` is `1`, because `super()`");
|
||||||
|
|
||||||
|
// undefined was returned
|
||||||
|
assert.sameValue(object.prop, 1);
|
||||||
|
assert.sameValue(object instanceof Derived, true);
|
||||||
|
assert.sameValue(object instanceof Base, true);
|
@ -0,0 +1,30 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 9.2.2
|
||||||
|
description: >
|
||||||
|
[[Construct]] ( argumentsList, newTarget)
|
||||||
|
|
||||||
|
...
|
||||||
|
13. If result.[[type]] is return, then
|
||||||
|
...
|
||||||
|
c. If result.[[value]] is not undefined, throw a TypeError exception.
|
||||||
|
...
|
||||||
|
|
||||||
|
`return null;`
|
||||||
|
|
||||||
|
---*/
|
||||||
|
class Base {
|
||||||
|
constructor() {}
|
||||||
|
}
|
||||||
|
class Derived extends Base {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
new Derived();
|
||||||
|
});
|
@ -0,0 +1,30 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 9.2.2
|
||||||
|
description: >
|
||||||
|
[[Construct]] ( argumentsList, newTarget)
|
||||||
|
|
||||||
|
...
|
||||||
|
13. If result.[[type]] is return, then
|
||||||
|
...
|
||||||
|
c. If result.[[value]] is not undefined, throw a TypeError exception.
|
||||||
|
...
|
||||||
|
|
||||||
|
`return 0;`
|
||||||
|
|
||||||
|
---*/
|
||||||
|
class Base {
|
||||||
|
constructor() {}
|
||||||
|
}
|
||||||
|
class Derived extends Base {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
new Derived();
|
||||||
|
});
|
@ -0,0 +1,40 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 9.2.2
|
||||||
|
description: >
|
||||||
|
[[Construct]] ( argumentsList, newTarget)
|
||||||
|
|
||||||
|
...
|
||||||
|
13. If result.[[type]] is return, then
|
||||||
|
a. If Type(result.[[value]]) is Object, return NormalCompletion(result.[[value]]).
|
||||||
|
...
|
||||||
|
...
|
||||||
|
|
||||||
|
`return {};`
|
||||||
|
|
||||||
|
---*/
|
||||||
|
var calls = 0;
|
||||||
|
class Base {
|
||||||
|
constructor() {
|
||||||
|
this.prop = 1;
|
||||||
|
calls++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class Derived extends Base {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var object = new Derived();
|
||||||
|
|
||||||
|
// super is called
|
||||||
|
assert.sameValue(calls, 1, "The value of `calls` is `1`, because `super()`");
|
||||||
|
|
||||||
|
// But the this object was discarded.
|
||||||
|
assert.sameValue(typeof object.prop, "undefined");
|
||||||
|
assert.sameValue(object instanceof Derived, false);
|
||||||
|
assert.sameValue(object instanceof Base, false);
|
@ -0,0 +1,30 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 9.2.2
|
||||||
|
description: >
|
||||||
|
[[Construct]] ( argumentsList, newTarget)
|
||||||
|
|
||||||
|
...
|
||||||
|
13. If result.[[type]] is return, then
|
||||||
|
...
|
||||||
|
c. If result.[[value]] is not undefined, throw a TypeError exception.
|
||||||
|
...
|
||||||
|
|
||||||
|
`return "";`
|
||||||
|
|
||||||
|
---*/
|
||||||
|
class Base {
|
||||||
|
constructor() {}
|
||||||
|
}
|
||||||
|
class Derived extends Base {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
new Derived();
|
||||||
|
});
|
@ -0,0 +1,30 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 9.2.2
|
||||||
|
description: >
|
||||||
|
[[Construct]] ( argumentsList, newTarget)
|
||||||
|
|
||||||
|
...
|
||||||
|
13. If result.[[type]] is return, then
|
||||||
|
...
|
||||||
|
c. If result.[[value]] is not undefined, throw a TypeError exception.
|
||||||
|
...
|
||||||
|
|
||||||
|
`return Symbol();`
|
||||||
|
|
||||||
|
---*/
|
||||||
|
class Base {
|
||||||
|
constructor() {}
|
||||||
|
}
|
||||||
|
class Derived extends Base {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
return Symbol();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
new Derived();
|
||||||
|
});
|
@ -0,0 +1,41 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 9.2.2
|
||||||
|
description: >
|
||||||
|
[[Construct]] ( argumentsList, newTarget)
|
||||||
|
|
||||||
|
...
|
||||||
|
13. If result.[[type]] is return, then
|
||||||
|
...
|
||||||
|
b. If kind is "base", return NormalCompletion(thisArgument).
|
||||||
|
...
|
||||||
|
...
|
||||||
|
|
||||||
|
`return this;`
|
||||||
|
|
||||||
|
---*/
|
||||||
|
var calls = 0;
|
||||||
|
class Base {
|
||||||
|
constructor() {
|
||||||
|
this.prop = 1;
|
||||||
|
calls++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class Derived extends Base {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var object = new Derived();
|
||||||
|
|
||||||
|
// super is called
|
||||||
|
assert.sameValue(calls, 1, "The value of `calls` is `1`, because `super()`");
|
||||||
|
|
||||||
|
// The this object was returned.
|
||||||
|
assert.sameValue(object.prop, 1);
|
||||||
|
assert.sameValue(object instanceof Derived, true);
|
||||||
|
assert.sameValue(object instanceof Base, true);
|
@ -0,0 +1,41 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 9.2.2
|
||||||
|
description: >
|
||||||
|
[[Construct]] ( argumentsList, newTarget)
|
||||||
|
|
||||||
|
...
|
||||||
|
13. If result.[[type]] is return, then
|
||||||
|
...
|
||||||
|
c. If result.[[value]] is not undefined, ...
|
||||||
|
14. Else, ReturnIfAbrupt(result).
|
||||||
|
15. Return envRec.GetThisBinding().
|
||||||
|
|
||||||
|
`return undefined;`
|
||||||
|
|
||||||
|
---*/
|
||||||
|
var calls = 0;
|
||||||
|
class Base {
|
||||||
|
constructor() {
|
||||||
|
this.prop = 1;
|
||||||
|
calls++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class Derived extends Base {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var object = new Derived();
|
||||||
|
|
||||||
|
// super is called
|
||||||
|
assert.sameValue(calls, 1, "The value of `calls` is `1`, because `super()`");
|
||||||
|
|
||||||
|
// undefined was returned
|
||||||
|
assert.sameValue(object.prop, 1);
|
||||||
|
assert.sameValue(object instanceof Derived, true);
|
||||||
|
assert.sameValue(object instanceof Base, true);
|
@ -0,0 +1,23 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5.1
|
||||||
|
description: >
|
||||||
|
The opposite of:
|
||||||
|
|
||||||
|
ClassTail : ClassHeritageopt { ClassBody }
|
||||||
|
|
||||||
|
It is a Syntax Error if ClassHeritage is not present and the following algorithm evaluates to true:
|
||||||
|
1. Let constructor be ConstructorMethod of ClassBody.
|
||||||
|
2. If constructor is empty, return false.
|
||||||
|
3. Return HasDirectSuper of constructor.
|
||||||
|
---*/
|
||||||
|
class A {}
|
||||||
|
class B extends A {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
assert.sameValue(typeof B, "function");
|
@ -0,0 +1,23 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5.1
|
||||||
|
description: >
|
||||||
|
No restrictions on SuperProperty
|
||||||
|
---*/
|
||||||
|
class A {
|
||||||
|
constructor() {
|
||||||
|
super.toString();
|
||||||
|
}
|
||||||
|
dontDoThis() {
|
||||||
|
super.makeBugs = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
assert.sameValue(typeof A, "function");
|
||||||
|
|
||||||
|
var a = new A();
|
||||||
|
|
||||||
|
a.dontDoThis();
|
||||||
|
assert.sameValue(a.makeBugs, 1);
|
@ -0,0 +1,35 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5
|
||||||
|
description: >
|
||||||
|
ClassDeclaration:
|
||||||
|
class BindingIdentifier ClassTail
|
||||||
|
|
||||||
|
ClassTail:
|
||||||
|
... { ClassBodyopt }
|
||||||
|
|
||||||
|
ClassBody[Yield] :
|
||||||
|
ClassElementList[?Yield]
|
||||||
|
|
||||||
|
|
||||||
|
ClassElementList[Yield] :
|
||||||
|
ClassElement[?Yield]
|
||||||
|
ClassElementList[?Yield] ClassElement[?Yield]
|
||||||
|
|
||||||
|
ClassElement[Yield] :
|
||||||
|
MethodDefinition[?Yield]
|
||||||
|
static MethodDefinition[?Yield]
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
---*/
|
||||||
|
class A {
|
||||||
|
method() {}
|
||||||
|
static method() {}
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(typeof A, "function");
|
||||||
|
assert.sameValue(typeof A.prototype.method, "function");
|
||||||
|
assert.sameValue(typeof A.method, "function");
|
@ -0,0 +1,30 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5
|
||||||
|
description: >
|
||||||
|
ClassDeclaration:
|
||||||
|
class BindingIdentifier ClassTail
|
||||||
|
|
||||||
|
ClassTail:
|
||||||
|
... { ClassBodyopt }
|
||||||
|
|
||||||
|
ClassBody[Yield] :
|
||||||
|
ClassElementList[?Yield]
|
||||||
|
|
||||||
|
|
||||||
|
ClassElementList[Yield] :
|
||||||
|
ClassElement[?Yield]
|
||||||
|
ClassElementList[?Yield] ClassElement[?Yield]
|
||||||
|
|
||||||
|
ClassElement[Yield] :
|
||||||
|
MethodDefinition[?Yield]
|
||||||
|
...
|
||||||
|
|
||||||
|
---*/
|
||||||
|
class A {
|
||||||
|
[1]() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(typeof A, "function");
|
||||||
|
assert.sameValue(typeof A.prototype[1], "function");
|
@ -0,0 +1,30 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5
|
||||||
|
description: >
|
||||||
|
ClassDeclaration:
|
||||||
|
class BindingIdentifier ClassTail
|
||||||
|
|
||||||
|
ClassTail:
|
||||||
|
... { ClassBodyopt }
|
||||||
|
|
||||||
|
ClassBody[Yield] :
|
||||||
|
ClassElementList[?Yield]
|
||||||
|
|
||||||
|
|
||||||
|
ClassElementList[Yield] :
|
||||||
|
ClassElement[?Yield]
|
||||||
|
ClassElementList[?Yield] ClassElement[?Yield]
|
||||||
|
|
||||||
|
ClassElement[Yield] :
|
||||||
|
MethodDefinition[?Yield]
|
||||||
|
...
|
||||||
|
|
||||||
|
---*/
|
||||||
|
class A {
|
||||||
|
*[1]() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(typeof A, "function");
|
||||||
|
assert.sameValue(typeof A.prototype[1], "function");
|
@ -0,0 +1,54 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5
|
||||||
|
description: >
|
||||||
|
ClassHeritage[Yield] :
|
||||||
|
extends LeftHandSideExpression[?Yield]
|
||||||
|
|
||||||
|
LeftHandSideExpression :
|
||||||
|
NewExpression
|
||||||
|
...
|
||||||
|
|
||||||
|
NewExpression :
|
||||||
|
MemberExpression
|
||||||
|
...
|
||||||
|
|
||||||
|
MemberExpression :
|
||||||
|
PrimaryExpression
|
||||||
|
...
|
||||||
|
|
||||||
|
PrimaryExpression :
|
||||||
|
IdentifierReference
|
||||||
|
...
|
||||||
|
|
||||||
|
ClassDeclaration:
|
||||||
|
class BindingIdentifier ClassTail
|
||||||
|
|
||||||
|
ClassTail:
|
||||||
|
... { ClassBodyopt }
|
||||||
|
|
||||||
|
ClassBody[Yield] :
|
||||||
|
ClassElementList[?Yield]
|
||||||
|
|
||||||
|
|
||||||
|
ClassElementList[Yield] :
|
||||||
|
ClassElement[?Yield]
|
||||||
|
ClassElementList[?Yield] ClassElement[?Yield]
|
||||||
|
|
||||||
|
ClassElement[Yield] :
|
||||||
|
MethodDefinition[?Yield]
|
||||||
|
static MethodDefinition[?Yield]
|
||||||
|
;
|
||||||
|
|
||||||
|
---*/
|
||||||
|
class A {}
|
||||||
|
class B extends A {
|
||||||
|
method() {}
|
||||||
|
static method() {}
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(typeof B, "function");
|
||||||
|
assert.sameValue(typeof B.prototype.method, "function");
|
||||||
|
assert.sameValue(typeof B.method, "function");
|
@ -0,0 +1,39 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5
|
||||||
|
description: >
|
||||||
|
ClassExpression[Yield,GeneratorParameter] :
|
||||||
|
class BindingIdentifier[?Yield]opt ClassTail[?Yield,?GeneratorParameter]
|
||||||
|
|
||||||
|
ClassDeclaration:
|
||||||
|
class BindingIdentifier ClassTail
|
||||||
|
|
||||||
|
ClassTail:
|
||||||
|
... { ClassBodyopt }
|
||||||
|
|
||||||
|
ClassBody[Yield] :
|
||||||
|
ClassElementList[?Yield]
|
||||||
|
|
||||||
|
|
||||||
|
ClassElementList[Yield] :
|
||||||
|
ClassElement[?Yield]
|
||||||
|
ClassElementList[?Yield] ClassElement[?Yield]
|
||||||
|
|
||||||
|
ClassElement[Yield] :
|
||||||
|
MethodDefinition[?Yield]
|
||||||
|
static MethodDefinition[?Yield]
|
||||||
|
;
|
||||||
|
|
||||||
|
---*/
|
||||||
|
var A = class B {
|
||||||
|
method() {}
|
||||||
|
static method() {}
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(typeof A, "function");
|
||||||
|
assert.sameValue(typeof A.prototype.method, "function");
|
||||||
|
assert.sameValue(typeof A.method, "function");
|
||||||
|
|
||||||
|
assert.sameValue(typeof B, "undefined");
|
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5
|
||||||
|
description: >
|
||||||
|
ClassExpression[Yield,GeneratorParameter] :
|
||||||
|
class BindingIdentifier[?Yield]opt ClassTail[?Yield,?GeneratorParameter]
|
||||||
|
|
||||||
|
ClassTail[Yield,GeneratorParameter] :
|
||||||
|
[~GeneratorParameter] ClassHeritage[?Yield]opt { ClassBody[?Yield]opt }
|
||||||
|
[+GeneratorParameter] ClassHeritageopt { ClassBodyopt }
|
||||||
|
---*/
|
||||||
|
class A {}
|
||||||
|
var B = class extends A {}
|
||||||
|
|
||||||
|
assert.sameValue(typeof B, "function");
|
10
test/language/statements/class/syntax/class-expression.js
Normal file
10
test/language/statements/class/syntax/class-expression.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5
|
||||||
|
description: >
|
||||||
|
ClassExpression
|
||||||
|
---*/
|
||||||
|
var A = class {}
|
||||||
|
|
||||||
|
assert.sameValue(typeof A, "function");
|
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5.1
|
||||||
|
description: >
|
||||||
|
The opposite of:
|
||||||
|
|
||||||
|
ClassBody : ClassElementList
|
||||||
|
|
||||||
|
It is a Syntax Error if PrototypePropertyNameList of ClassElementList contains more than one occurrence of "constructor".
|
||||||
|
---*/
|
||||||
|
class A {
|
||||||
|
constructor() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(typeof A, "function");
|
||||||
|
|
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5.1
|
||||||
|
description: >
|
||||||
|
ClassTail : ClassHeritageopt { ClassBody }
|
||||||
|
|
||||||
|
It is a Syntax Error if ClassHeritage is not present and the following algorithm evaluates to true:
|
||||||
|
1. Let constructor be ConstructorMethod of ClassBody.
|
||||||
|
2. If constructor is empty, return false.
|
||||||
|
3. Return HasDirectSuper of constructor.
|
||||||
|
---*/
|
||||||
|
class A {
|
||||||
|
constructor() {}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5.1
|
||||||
|
description: >
|
||||||
|
ClassBody : ClassElementList
|
||||||
|
|
||||||
|
It is a Syntax Error if PrototypePropertyNameList of ClassElementList contains more than one occurrence of "constructor".
|
||||||
|
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
class A {
|
||||||
|
constructor() {}
|
||||||
|
constructor() {}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5.1
|
||||||
|
description: >
|
||||||
|
ClassTail : ClassHeritageopt { ClassBody }
|
||||||
|
|
||||||
|
It is a Syntax Error if ClassHeritage is not present and the following algorithm evaluates to true:
|
||||||
|
1. Let constructor be ConstructorMethod of ClassBody.
|
||||||
|
2. If constructor is empty, return false.
|
||||||
|
3. Return HasDirectSuper of constructor.
|
||||||
|
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
class A {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5.1
|
||||||
|
description: >
|
||||||
|
ClassElement : MethodDefinition
|
||||||
|
|
||||||
|
It is a Syntax Error if PropName of MethodDefinition is not "constructor" and HasDirectSuper of MethodDefinition is true.
|
||||||
|
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
class A {
|
||||||
|
method() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5.1
|
||||||
|
description: >
|
||||||
|
ClassElement : MethodDefinition
|
||||||
|
|
||||||
|
It is a Syntax Error if PropName of MethodDefinition is not "constructor" and HasDirectSuper of MethodDefinition is true.
|
||||||
|
|
||||||
|
(GeneratorMethod)
|
||||||
|
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
class A {
|
||||||
|
* method() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5.1
|
||||||
|
description: >
|
||||||
|
ClassElement : MethodDefinition
|
||||||
|
|
||||||
|
It is a Syntax Error if PropName of MethodDefinition is "constructor" and SpecialMethod of MethodDefinition is true.
|
||||||
|
|
||||||
|
(GeneratorMethod)
|
||||||
|
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
class A {
|
||||||
|
* constructor() {}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5.1
|
||||||
|
description: >
|
||||||
|
ClassElement : MethodDefinition
|
||||||
|
|
||||||
|
It is a Syntax Error if PropName of MethodDefinition is not "constructor" and HasDirectSuper of MethodDefinition is true.
|
||||||
|
|
||||||
|
(get)
|
||||||
|
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
class A {
|
||||||
|
get method() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5.1
|
||||||
|
description: >
|
||||||
|
ClassElement : MethodDefinition
|
||||||
|
|
||||||
|
It is a Syntax Error if PropName of MethodDefinition is "constructor" and SpecialMethod of MethodDefinition is true.
|
||||||
|
|
||||||
|
(get)
|
||||||
|
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
class A {
|
||||||
|
get constructor() {}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5.1
|
||||||
|
description: >
|
||||||
|
ClassElement : MethodDefinition
|
||||||
|
|
||||||
|
It is a Syntax Error if PropName of MethodDefinition is not "constructor" and HasDirectSuper of MethodDefinition is true.
|
||||||
|
|
||||||
|
(set)
|
||||||
|
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
class A {
|
||||||
|
set method(_) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5.1
|
||||||
|
description: >
|
||||||
|
ClassElement : MethodDefinition
|
||||||
|
|
||||||
|
It is a Syntax Error if PropName of MethodDefinition is "constructor" and SpecialMethod of MethodDefinition is true.
|
||||||
|
|
||||||
|
(set)
|
||||||
|
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
class A {
|
||||||
|
set constructor(_) {}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5.1
|
||||||
|
description: >
|
||||||
|
ClassElement : static MethodDefinition
|
||||||
|
|
||||||
|
It is a Syntax Error if HasDirectSuper of MethodDefinition is true.
|
||||||
|
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
class A {
|
||||||
|
static method() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5.1
|
||||||
|
description: >
|
||||||
|
ClassElement : static MethodDefinition
|
||||||
|
|
||||||
|
It is a Syntax Error if HasDirectSuper of MethodDefinition is true.
|
||||||
|
|
||||||
|
(get)
|
||||||
|
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
class A {
|
||||||
|
static get method() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5.1
|
||||||
|
description: >
|
||||||
|
ClassElement : static MethodDefinition
|
||||||
|
|
||||||
|
It is a Syntax Error if PropName of MethodDefinition is "prototype".
|
||||||
|
|
||||||
|
(get)
|
||||||
|
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
class A {
|
||||||
|
static get prototype() {}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5.1
|
||||||
|
description: >
|
||||||
|
ClassElement : static MethodDefinition
|
||||||
|
|
||||||
|
It is a Syntax Error if PropName of MethodDefinition is "prototype".
|
||||||
|
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
class A {
|
||||||
|
static prototype() {}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5.1
|
||||||
|
description: >
|
||||||
|
ClassElement : static MethodDefinition
|
||||||
|
|
||||||
|
It is a Syntax Error if HasDirectSuper of MethodDefinition is true.
|
||||||
|
|
||||||
|
(set)
|
||||||
|
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
class A {
|
||||||
|
static set method(_) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 14.5.1
|
||||||
|
description: >
|
||||||
|
ClassElement : static MethodDefinition
|
||||||
|
|
||||||
|
It is a Syntax Error if PropName of MethodDefinition is "prototype".
|
||||||
|
|
||||||
|
(set)
|
||||||
|
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
class A {
|
||||||
|
static set prototype() {}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 13.1.1
|
||||||
|
description: >
|
||||||
|
Block : { StatementList }
|
||||||
|
|
||||||
|
It is a Syntax Error if the LexicallyDeclaredNames of StatementList contains any duplicate entries.
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
{
|
||||||
|
class A {}
|
||||||
|
class A {}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 15.1.1
|
||||||
|
description: >
|
||||||
|
ScriptBody : StatementList
|
||||||
|
|
||||||
|
It is a Syntax Error if the LexicallyDeclaredNames of StatementList contains any duplicate entries.
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
class A {}
|
||||||
|
class A {}
|
Loading…
x
Reference in New Issue
Block a user