mirror of
https://github.com/tc39/test262.git
synced 2025-07-10 07:34:37 +02:00
Update tests concerning null-extending classes (#658)
The latest revision of ECMA262 makes special provisions for classes which extend the `null` value [1]. Update the relevant tests accordingly. [1] https://github.com/tc39/ecma262/issues/543
This commit is contained in:
parent
a2b3370b0b
commit
dee1526ca7
@ -1,6 +1,7 @@
|
|||||||
// Copyright (C) 2014 the V8 project authors. All rights reserved.
|
// Copyright (C) 2014 the V8 project authors. All rights reserved.
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
/*---
|
/*---
|
||||||
|
esid: sec-runtime-semantics-classdefinitionevaluation
|
||||||
es6id: 14.5.14
|
es6id: 14.5.14
|
||||||
description: >
|
description: >
|
||||||
Runtime Semantics: ClassDefinitionEvaluation
|
Runtime Semantics: ClassDefinitionEvaluation
|
||||||
@ -8,8 +9,6 @@ description: >
|
|||||||
If superclass is null, then
|
If superclass is null, then
|
||||||
Let protoParent be null.
|
Let protoParent be null.
|
||||||
Let constructorParent be the intrinsic object %FunctionPrototype%.
|
Let constructorParent be the intrinsic object %FunctionPrototype%.
|
||||||
|
|
||||||
`extends null` requires return override in the constructor
|
|
||||||
---*/
|
---*/
|
||||||
class Foo extends null {
|
class Foo extends null {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -1,21 +1,43 @@
|
|||||||
// Copyright (C) 2014 the V8 project authors. All rights reserved.
|
// Copyright (C) 2014 the V8 project authors. All rights reserved.
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
/*---
|
/*---
|
||||||
es6id: 14.5.14
|
esid: sec-runtime-semantics-classdefinitionevaluation
|
||||||
description: >
|
description: >
|
||||||
Runtime Semantics: ClassDefinitionEvaluation
|
The `this` value of a null-extending class is automatically initialized,
|
||||||
|
obviating the need for an explicit return value in the constructor.
|
||||||
|
info: |
|
||||||
|
The behavior under test was introduced in the "ES2017" revision of the
|
||||||
|
specification and conflicts with prior editions.
|
||||||
|
|
||||||
If superclass is null, then
|
Runtime Semantics: ClassDefinitionEvaluation
|
||||||
Let protoParent be null.
|
|
||||||
Let constructorParent be the intrinsic object %FunctionPrototype%.
|
|
||||||
|
|
||||||
`extends null` requires return override in the constructor
|
[...]
|
||||||
|
5. If ClassHeritageopt is not present, then
|
||||||
|
[...]
|
||||||
|
6. Else,
|
||||||
|
[...]
|
||||||
|
e. If superclass is null, then
|
||||||
|
i. Let protoParent be null.
|
||||||
|
ii. Let constructorParent be the intrinsic object %FunctionPrototype%.
|
||||||
|
[...]
|
||||||
|
15. If ClassHeritageopt is present and protoParent is not null, then set F's
|
||||||
|
[[ConstructorKind]] internal slot to "derived".
|
||||||
|
[...]
|
||||||
|
|
||||||
|
9.2.2 [[Construct]]
|
||||||
|
|
||||||
|
[...]
|
||||||
|
5. If kind is "base", then
|
||||||
|
a. Let thisArgument be ? OrdinaryCreateFromConstructor(newTarget,
|
||||||
|
"%ObjectPrototype%").
|
||||||
|
[...]
|
||||||
|
15. Return ? envRec.GetThisBinding().
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
class Foo extends null {
|
class Foo extends null {
|
||||||
constructor() {}
|
constructor() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.throws(ReferenceError, function() {
|
var foo = new Foo();
|
||||||
new Foo();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
assert.sameValue(Object.getPrototypeOf(foo), Foo);
|
||||||
|
@ -0,0 +1,67 @@
|
|||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-runtime-semantics-classdefinitionevaluation
|
||||||
|
description: >
|
||||||
|
The `this` value of a null-extending class is automatically initialized,
|
||||||
|
preventing the use of `super` from within the constructor.
|
||||||
|
info: |
|
||||||
|
Runtime Semantics: ClassDefinitionEvaluation
|
||||||
|
|
||||||
|
[...]
|
||||||
|
5. If ClassHeritageopt is not present, then
|
||||||
|
[...]
|
||||||
|
6. Else,
|
||||||
|
[...]
|
||||||
|
e. If superclass is null, then
|
||||||
|
i. Let protoParent be null.
|
||||||
|
ii. Let constructorParent be the intrinsic object %FunctionPrototype%.
|
||||||
|
[...]
|
||||||
|
15. If ClassHeritageopt is present and protoParent is not null, then set F's
|
||||||
|
[[ConstructorKind]] internal slot to "derived".
|
||||||
|
[...]
|
||||||
|
|
||||||
|
9.2.2 [[Construct]]
|
||||||
|
|
||||||
|
[...]
|
||||||
|
5. If kind is "base", then
|
||||||
|
a. Let thisArgument be ? OrdinaryCreateFromConstructor(newTarget,
|
||||||
|
"%ObjectPrototype%").
|
||||||
|
[...]
|
||||||
|
|
||||||
|
12.3.5.1 Runtime Semantics: Evaluation
|
||||||
|
|
||||||
|
SuperCall : super Arguments
|
||||||
|
|
||||||
|
[...]
|
||||||
|
6. Let result be ? Construct(func, argList, newTarget).
|
||||||
|
7. Let thisER be GetThisEnvironment( ).
|
||||||
|
8. Return ? thisER.BindThisValue(result).
|
||||||
|
|
||||||
|
8.1.1.3.1 BindThisValue
|
||||||
|
|
||||||
|
[...]
|
||||||
|
3. If envRec.[[ThisBindingStatus]] is "initialized", throw a ReferenceError
|
||||||
|
exception.
|
||||||
|
4. Set envRec.[[ThisValue]] to V.
|
||||||
|
5. Set envRec.[[ThisBindingStatus]] to "initialized".
|
||||||
|
[...]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var unreachable = 0;
|
||||||
|
var reachable = 0;
|
||||||
|
|
||||||
|
class C extends null {
|
||||||
|
constructor() {
|
||||||
|
reachable += 1;
|
||||||
|
super();
|
||||||
|
unreachable += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
new C();
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(reachable, 1);
|
||||||
|
assert.sameValue(unreachable, 0);
|
@ -0,0 +1,46 @@
|
|||||||
|
// Copyright (C) 2014 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-runtime-semantics-classdefinitionevaluation
|
||||||
|
description: >
|
||||||
|
The `this` value of a null-extending class is automatically initialized
|
||||||
|
info: |
|
||||||
|
The behavior under test was introduced in the "ES2017" revision of the
|
||||||
|
specification and conflicts with prior editions.
|
||||||
|
|
||||||
|
Runtime Semantics: ClassDefinitionEvaluation
|
||||||
|
|
||||||
|
[...]
|
||||||
|
5. If ClassHeritageopt is not present, then
|
||||||
|
[...]
|
||||||
|
6. Else,
|
||||||
|
[...]
|
||||||
|
e. If superclass is null, then
|
||||||
|
i. Let protoParent be null.
|
||||||
|
ii. Let constructorParent be the intrinsic object %FunctionPrototype%.
|
||||||
|
[...]
|
||||||
|
15. If ClassHeritageopt is present and protoParent is not null, then set F's
|
||||||
|
[[ConstructorKind]] internal slot to "derived".
|
||||||
|
[...]
|
||||||
|
|
||||||
|
9.2.2 [[Construct]]
|
||||||
|
|
||||||
|
[...]
|
||||||
|
5. If kind is "base", then
|
||||||
|
a. Let thisArgument be ? OrdinaryCreateFromConstructor(newTarget,
|
||||||
|
"%ObjectPrototype%").
|
||||||
|
[...]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var thisVal, instance;
|
||||||
|
|
||||||
|
class C extends null {
|
||||||
|
constructor() {
|
||||||
|
thisVal = this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
instance = new C();
|
||||||
|
|
||||||
|
assert.sameValue(instance instanceof C, true);
|
||||||
|
assert.sameValue(instance, thisVal);
|
@ -1,19 +1,41 @@
|
|||||||
// Copyright (C) 2014 the V8 project authors. All rights reserved.
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
/*---
|
/*---
|
||||||
es6id: 14.5.14_S6.e
|
esid: sec-runtime-semantics-classdefinitionevaluation
|
||||||
|
es6id: 14.5.14
|
||||||
description: >
|
description: >
|
||||||
Runtime Semantics: ClassDefinitionEvaluation
|
When a null-extending class does not specify a `constructor` method
|
||||||
|
definition, a method with zero parameters and an empty body is used
|
||||||
|
info: |
|
||||||
|
The behavior under test was introduced in the "ES2017" revision of the
|
||||||
|
specification and conflicts with prior editions.
|
||||||
|
|
||||||
If superclass is null, then
|
Runtime Semantics: ClassDefinitionEvaluation
|
||||||
Let protoParent be null.
|
|
||||||
Let constructorParent be the intrinsic object %FunctionPrototype%.
|
5. If ClassHeritageopt is not present, then
|
||||||
|
[...]
|
||||||
|
6. Else,
|
||||||
|
[...]
|
||||||
|
e. If superclass is null, then
|
||||||
|
i. Let protoParent be null.
|
||||||
|
ii. Let constructorParent be the intrinsic object %FunctionPrototype%.
|
||||||
|
[...]
|
||||||
|
7. Let proto be ObjectCreate(protoParent).
|
||||||
|
8. If ClassBodyopt is not present, let constructor be empty.
|
||||||
|
9. Else, let constructor be ConstructorMethod of ClassBody.
|
||||||
|
10. If constructor is empty, then
|
||||||
|
a. If ClassHeritageopt is present and protoParent is not null, then
|
||||||
|
[...]
|
||||||
|
b. Else,
|
||||||
|
i. Let constructor be the result of parsing the source text
|
||||||
|
|
||||||
|
constructor( ){ }
|
||||||
|
|
||||||
|
using the syntactic grammar with the goal symbol MethodDefinition.
|
||||||
|
[...]
|
||||||
---*/
|
---*/
|
||||||
class Foo extends null {
|
|
||||||
constructor() {
|
class Foo extends null {}
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.sameValue(Object.getPrototypeOf(Foo.prototype), null);
|
assert.sameValue(Object.getPrototypeOf(Foo.prototype), null);
|
||||||
assert.sameValue(Object.getPrototypeOf(Foo.prototype.constructor), Function.prototype);
|
assert.sameValue(Object.getPrototypeOf(Foo.prototype.constructor), Function.prototype);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user