From e6500f83445b9b4639f157e5b2c51b5d027664a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Fri, 10 Feb 2017 16:52:53 +0100 Subject: [PATCH] Update tests for classes extending null Per https://github.com/tc39/ecma262/pull/781 --- ...ion-null-proto-contains-return-override.js | 22 +++++++--- ...tion-null-proto-missing-return-override.js | 28 ++++++------- .../class-definition-null-proto-super.js | 35 +++++++--------- .../class-definition-null-proto-this.js | 41 ++++++++----------- .../subclass/class-definition-null-proto.js | 24 ++++------- 5 files changed, 69 insertions(+), 81 deletions(-) diff --git a/test/language/statements/class/subclass/class-definition-null-proto-contains-return-override.js b/test/language/statements/class/subclass/class-definition-null-proto-contains-return-override.js index bfc962a4017..9a5b1ec6df9 100644 --- a/test/language/statements/class/subclass/class-definition-null-proto-contains-return-override.js +++ b/test/language/statements/class/subclass/class-definition-null-proto-contains-return-override.js @@ -4,18 +4,30 @@ esid: sec-runtime-semantics-classdefinitionevaluation es6id: 14.5.14 description: > - Runtime Semantics: ClassDefinitionEvaluation + The constructor of a null-extending class can contain an explicit return value. +info: | + Runtime Semantics: ClassDefinitionEvaluation - If superclass is null, then - Let protoParent be null. - Let constructorParent be the intrinsic object %FunctionPrototype%. + [...] + 15. If ClassHeritageopt is present, then set F's [[ConstructorKind]] internal slot to "derived". + [...] + + 9.2.2 [[Construct]] + + [...] + 13. If result.[[Type]] is return, then + a. If Type(result.[[Value]]) is Object, return NormalCompletion(result.[[Value]]). + [...] ---*/ +var obj; + class Foo extends null { constructor() { - return {}; + return obj = {}; } } var f = new Foo(); +assert.sameValue(f, obj); assert.sameValue(Object.getPrototypeOf(f), Object.prototype); diff --git a/test/language/statements/class/subclass/class-definition-null-proto-missing-return-override.js b/test/language/statements/class/subclass/class-definition-null-proto-missing-return-override.js index fdf78ae5a2d..bcafe87ca0a 100644 --- a/test/language/statements/class/subclass/class-definition-null-proto-missing-return-override.js +++ b/test/language/statements/class/subclass/class-definition-null-proto-missing-return-override.js @@ -3,12 +3,9 @@ /*--- esid: sec-runtime-semantics-classdefinitionevaluation description: > - The `this` value of a null-extending class is automatically initialized, - obviating the need for an explicit return value in the constructor. + The `this` value of a null-extending class isn't automatically initialized, + which makes it necessary to have 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. - Runtime Semantics: ClassDefinitionEvaluation [...] @@ -18,24 +15,25 @@ info: | [...] b. Let superclass be the result of evaluating ClassHeritage. [...] - 15. If ClassHeritageopt is present and superclass is not null, then set F's - [[ConstructorKind]] internal slot to "derived". + 15. If ClassHeritageopt is present, 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(). + + 8.1.1.3.4 GetThisBinding ( ) + [...] + 3. If envRec.[[ThisBindingStatus]] is "uninitialized", throw a ReferenceError exception. + [...] ---*/ class Foo extends null { - constructor() {} + constructor() { + } } -var foo = new Foo(); - -assert.sameValue(Object.getPrototypeOf(foo), Foo.prototype); +assert.throws(ReferenceError, function() { + new C(); +}); diff --git a/test/language/statements/class/subclass/class-definition-null-proto-super.js b/test/language/statements/class/subclass/class-definition-null-proto-super.js index 87c2084e3e7..0dbcaf06908 100644 --- a/test/language/statements/class/subclass/class-definition-null-proto-super.js +++ b/test/language/statements/class/subclass/class-definition-null-proto-super.js @@ -3,8 +3,8 @@ /*--- 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. + Attempting to call `super()` in a null-extending class throws a TypeError, + because %FunctionPrototype% cannot be called as constructor function. info: | Runtime Semantics: ClassDefinitionEvaluation @@ -14,17 +14,12 @@ info: | 6. Else, [...] b. Let superclass be the result of evaluating ClassHeritage. + [...] + e. If superclass is null, then + [...] + ii. Let constructorParent be the intrinsic object %FunctionPrototype%. [...] - 15. If ClassHeritageopt is present and superclass 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. Let constructorInfo be the result of performing DefineMethod for constructor with arguments proto and constructorParent as the optional functionPrototype argument. [...] 12.3.5.1 Runtime Semantics: Evaluation @@ -32,17 +27,15 @@ info: | SuperCall : super Arguments [...] - 6. Let result be ? Construct(func, argList, newTarget). - 7. Let thisER be GetThisEnvironment( ). - 8. Return ? thisER.BindThisValue(result). + 3. Let func be ? GetSuperConstructor(). + 4. Let argList be ArgumentListEvaluation of Arguments. + [...] - 8.1.1.3.1 BindThisValue + 12.3.5.2 Runtime Semantics: GetSuperConstructor ( ) [...] - 3. If envRec.[[ThisBindingStatus]] is "initialized", throw a ReferenceError - exception. - 4. Set envRec.[[ThisValue]] to V. - 5. Set envRec.[[ThisBindingStatus]] to "initialized". + 5. Let superConstructor be ! activeFunction.[[GetPrototypeOf]](). + 6. If IsConstructor(superConstructor) is false, throw a TypeError exception. [...] ---*/ @@ -52,7 +45,7 @@ var reachable = 0; class C extends null { constructor() { reachable += 1; - super(); + super(unreachable += 1); unreachable += 1; } } diff --git a/test/language/statements/class/subclass/class-definition-null-proto-this.js b/test/language/statements/class/subclass/class-definition-null-proto-this.js index c581700c9c8..9c73dca5637 100644 --- a/test/language/statements/class/subclass/class-definition-null-proto-this.js +++ b/test/language/statements/class/subclass/class-definition-null-proto-this.js @@ -3,42 +3,37 @@ /*--- esid: sec-runtime-semantics-classdefinitionevaluation description: > - The `this` value of a null-extending class is automatically initialized + The `this` value of a null-extending class isn't 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, - [...] - b. Let superclass be the result of evaluating ClassHeritage. - [...] - 15. If ClassHeritageopt is present and superclass is not null, then set F's - [[ConstructorKind]] internal slot to "derived". + 15. If ClassHeritageopt is present, then set F's [[ConstructorKind]] internal slot to "derived". [...] - 9.2.2 [[Construct]] + 12.2.2.1 Runtime Semantics: Evaluation + PrimaryExpression : this + 1. Return ? ResolveThisBinding( ). + 8.3.4 ResolveThisBinding ( ) + [...] + 2. Return ? envRec.GetThisBinding(). + + 8.1.1.3.4 GetThisBinding ( ) [...] - 5. If kind is "base", then - a. Let thisArgument be ? OrdinaryCreateFromConstructor(newTarget, - "%ObjectPrototype%"). + 3. If envRec.[[ThisBindingStatus]] is "uninitialized", throw a ReferenceError exception. [...] ---*/ -var thisVal, instance; - class C extends null { constructor() { - thisVal = this; + // Use an arrow function to access the `this` binding of the class constructor. + assert.throws(ReferenceError, () => { + this; + }); } } -instance = new C(); - -assert.sameValue(instance instanceof C, true); -assert.sameValue(instance, thisVal); +assert.throws(ReferenceError, function() { + new C(); +}); diff --git a/test/language/statements/class/subclass/class-definition-null-proto.js b/test/language/statements/class/subclass/class-definition-null-proto.js index 5acaecaa38d..486f646fa8d 100644 --- a/test/language/statements/class/subclass/class-definition-null-proto.js +++ b/test/language/statements/class/subclass/class-definition-null-proto.js @@ -4,32 +4,21 @@ esid: sec-runtime-semantics-classdefinitionevaluation es6id: 14.5.14 description: > - When a null-extending class does not specify a `constructor` method - definition, a method with zero parameters and an empty body is used + The prototype of a null-extending class is %FunctionPrototype%, the prototype of + its "prototype" property is `null`. 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, [...] b. Let superclass be the result of evaluating ClassHeritage. [...] - 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 superclass 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. + e. If superclass is null, then + i. Let protoParent be null. + ii. Let constructorParent be the intrinsic object %FunctionPrototype%. [...] ---*/ @@ -37,3 +26,4 @@ class Foo extends null {} assert.sameValue(Object.getPrototypeOf(Foo.prototype), null); assert.sameValue(Object.getPrototypeOf(Foo.prototype.constructor), Function.prototype); +assert.sameValue(Foo, Foo.prototype.constructor);