Merge pull request #855 from anba/fix-async-sab-class-tests

Change tests for `extends null` and Intl legacy constructor semantics

Ref tc39/ecma262#781
Ref tc39/ecma402#84
This commit is contained in:
Leo Balter 2017-03-01 15:56:41 -05:00 committed by GitHub
commit 4546006977
14 changed files with 99 additions and 97 deletions

View File

@ -41,7 +41,7 @@ testWithTypedArrayConstructors(function(TA) {
compareArray( compareArray(
new TA([1, 2, 3, 4, 5]).copyWithin(0, 1, -Infinity), new TA([1, 2, 3, 4, 5]).copyWithin(0, 1, -Infinity),
[1, 2, 3, 4, 5] [1, 2, 3, 4, 5]
) ),
'[1, 2, 3, 4, 5].copyWithin(0, 1, -Infinity) -> [1, 2, 3, 4, 5]' '[1, 2, 3, 4, 5].copyWithin(0, 1, -Infinity) -> [1, 2, 3, 4, 5]'
); );
@ -57,7 +57,7 @@ testWithTypedArrayConstructors(function(TA) {
compareArray( compareArray(
new TA([1, 2, 3, 4, 5]).copyWithin(0, -2, -Infinity), new TA([1, 2, 3, 4, 5]).copyWithin(0, -2, -Infinity),
[1, 2, 3, 4, 5] [1, 2, 3, 4, 5]
) ),
'[1, 2, 3, 4, 5].copyWithin(0, -2, -Infinity) -> [1, 2, 3, 4, 5]' '[1, 2, 3, 4, 5].copyWithin(0, -2, -Infinity) -> [1, 2, 3, 4, 5]'
); );
@ -73,7 +73,7 @@ testWithTypedArrayConstructors(function(TA) {
compareArray( compareArray(
new TA([1, 2, 3, 4, 5]).copyWithin(0, -9, -Infinity), new TA([1, 2, 3, 4, 5]).copyWithin(0, -9, -Infinity),
[1, 2, 3, 4, 5] [1, 2, 3, 4, 5]
) ),
'[1, 2, 3, 4, 5].copyWithin(0, -9, -Infinity) -> [1, 2, 3, 4, 5]' '[1, 2, 3, 4, 5].copyWithin(0, -9, -Infinity) -> [1, 2, 3, 4, 5]'
); );
@ -89,7 +89,7 @@ testWithTypedArrayConstructors(function(TA) {
compareArray( compareArray(
new TA([1, 2, 3, 4, 5]).copyWithin(-3, -2, -Infinity), new TA([1, 2, 3, 4, 5]).copyWithin(-3, -2, -Infinity),
[1, 2, 3, 4, 5] [1, 2, 3, 4, 5]
) ),
'[1, 2, 3, 4, 5].copyWithin(-3, -2, -Infinity) -> [1, 2, 3, 4, 5]' '[1, 2, 3, 4, 5].copyWithin(-3, -2, -Infinity) -> [1, 2, 3, 4, 5]'
); );
@ -105,7 +105,7 @@ testWithTypedArrayConstructors(function(TA) {
compareArray( compareArray(
new TA([1, 2, 3, 4, 5]).copyWithin(-7, -8, -Infinity), new TA([1, 2, 3, 4, 5]).copyWithin(-7, -8, -Infinity),
[1, 2, 3, 4, 5] [1, 2, 3, 4, 5]
) ),
'[1, 2, 3, 4, 5].copyWithin(-7, -8, -Infinity) -> [1, 2, 3, 4, 5]' '[1, 2, 3, 4, 5].copyWithin(-7, -8, -Infinity) -> [1, 2, 3, 4, 5]'
); );
}); });

View File

@ -38,7 +38,7 @@ testWithTypedArrayConstructors(function(TA) {
assert( assert(
compareArray( compareArray(
new TA([1, 2, 3, 4, 5]).copyWithin(0, -Infinity), new TA([1, 2, 3, 4, 5]).copyWithin(0, -Infinity),
[0, 1, 2, 3] [1, 2, 3, 4, 5]
), ),
'[1, 2, 3, 4, 5]).copyWithin(0, -Infinity) -> [1, 2, 3, 4, 5]' '[1, 2, 3, 4, 5]).copyWithin(0, -Infinity) -> [1, 2, 3, 4, 5]'
); );

View File

@ -69,7 +69,7 @@ testWithTypedArrayConstructors(function(TA) {
assert(compareArray(sample, [1, 2, 42, 43]), "sample is SAB-backed, offset: 2, result: " + sample); assert(compareArray(sample, [1, 2, 42, 43]), "sample is SAB-backed, offset: 2, result: " + sample);
assert.sameValue(result, undefined, "returns undefined"); assert.sameValue(result, undefined, "returns undefined");
var sab1 = new SharedArrayBuffer(2 * TA.BYTES_PER_ELEMENT); var sab1 = new SharedArrayBuffer(2 * other.BYTES_PER_ELEMENT);
src = new other(sab1); src = new other(sab1);
src[0] = 42; src[0] = 42;
src[1] = 43; src[1] = 43;

View File

@ -3,12 +3,17 @@
/*--- /*---
es5id: 12.1.1_1 es5id: 12.1.1_1
description: Tests that the this-value is ignored in DateTimeFormat. description: >
Tests that the this-value is ignored in DateTimeFormat, if the this-value
isn't a DateTimeFormat instance.
author: Norbert Lindenberg author: Norbert Lindenberg
includes: [testIntl.js] includes: [testIntl.js]
---*/ ---*/
testWithIntlConstructors(function (Constructor) { testWithIntlConstructors(function (Constructor) {
if (Constructor === Intl.DateTimeFormat)
return true;
var obj, newObj; var obj, newObj;
// variant 1: use constructor in a "new" expression // variant 1: use constructor in a "new" expression

View File

@ -12,4 +12,4 @@ author: Norbert Lindenberg
includes: [testBuiltInObject.js] includes: [testBuiltInObject.js]
---*/ ---*/
testBuiltInObject(new Intl.DateTimeFormat().format, true, false, [], 0); testBuiltInObject(new Intl.DateTimeFormat().format, true, false, [], 1);

View File

@ -3,12 +3,17 @@
/*--- /*---
es5id: 11.1.1_1 es5id: 11.1.1_1
description: Tests that the this-value is ignored in NumberFormat. description: >
Tests that the this-value is ignored in NumberFormat, if the this-value
isn't a NumberFormat instance.
author: Norbert Lindenberg author: Norbert Lindenberg
includes: [testIntl.js] includes: [testIntl.js]
---*/ ---*/
testWithIntlConstructors(function (Constructor) { testWithIntlConstructors(function (Constructor) {
if (Constructor === Intl.NumberFormat)
return true;
var obj, newObj; var obj, newObj;
// variant 1: use constructor in a "new" expression // variant 1: use constructor in a "new" expression

View File

@ -16,11 +16,12 @@ var sup = {
} }
var child = { var child = {
__proto__: sup,
async method() { async method() {
var x = await super.method(); var x = await super.method();
assert.sameValue(x, 'sup'); assert.sameValue(x, 'sup');
} }
} }
Object.setPrototypeOf(child, sup);
child.method().then($DONE, $DONE); child.method().then($DONE, $DONE);

View File

@ -16,12 +16,13 @@ var sup = {
} }
var child = { var child = {
__proto__: sup,
async method(x = super.method()) { async method(x = super.method()) {
var y = await x; var y = await x;
assert.sameValue(y, 'sup'); assert.sameValue(y, 'sup');
} }
} }
Object.setPrototypeOf(child, sup);
child.method().then($DONE, $DONE); child.method().then($DONE, $DONE);

View File

@ -23,12 +23,14 @@ assert.throws(TypeError, function() {
}); });
var calledExecutor = false; var calledExecutor = false;
var executorArguments;
var prom1 = new Prom(function(resolve) { var prom1 = new Prom(function() {
calledExecutor = true; calledExecutor = true;
assert.sameValue(arguments.length, 2); executorArguments = arguments;
assert(arguments[0] === Promise.resolve);
assert(arguments[1] === Promise.reject);
}); });
assert(calledExecutor); assert(calledExecutor);
assert.sameValue(executorArguments.length, 2);
assert.sameValue(typeof executorArguments[0], "function");
assert.sameValue(typeof executorArguments[1], "function");

View File

@ -4,18 +4,30 @@
esid: sec-runtime-semantics-classdefinitionevaluation esid: sec-runtime-semantics-classdefinitionevaluation
es6id: 14.5.14 es6id: 14.5.14
description: > description: >
The constructor of a null-extending class can contain an explicit return value.
info: |
Runtime Semantics: ClassDefinitionEvaluation Runtime Semantics: ClassDefinitionEvaluation
If superclass is null, then [...]
Let protoParent be null. 15. If ClassHeritageopt is present, then set F's [[ConstructorKind]] internal slot to "derived".
Let constructorParent be the intrinsic object %FunctionPrototype%. [...]
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 { class Foo extends null {
constructor() { constructor() {
return {}; return obj = {};
} }
} }
var f = new Foo(); var f = new Foo();
assert.sameValue(f, obj);
assert.sameValue(Object.getPrototypeOf(f), Object.prototype); assert.sameValue(Object.getPrototypeOf(f), Object.prototype);

View File

@ -3,12 +3,9 @@
/*--- /*---
esid: sec-runtime-semantics-classdefinitionevaluation esid: sec-runtime-semantics-classdefinitionevaluation
description: > description: >
The `this` value of a null-extending class is automatically initialized, The `this` value of a null-extending class isn't automatically initialized,
obviating the need for an explicit return value in the constructor. which makes it necessary to have an explicit return value in the constructor.
info: | info: |
The behavior under test was introduced in the "ES2017" revision of the
specification and conflicts with prior editions.
Runtime Semantics: ClassDefinitionEvaluation Runtime Semantics: ClassDefinitionEvaluation
[...] [...]
@ -18,24 +15,25 @@ info: |
[...] [...]
b. Let superclass be the result of evaluating ClassHeritage. b. Let superclass be the result of evaluating ClassHeritage.
[...] [...]
15. If ClassHeritageopt is present and superclass is not null, then set F's 15. If ClassHeritageopt is present, then set F's [[ConstructorKind]] internal slot to "derived".
[[ConstructorKind]] internal slot to "derived".
[...] [...]
9.2.2 [[Construct]] 9.2.2 [[Construct]]
[...]
5. If kind is "base", then
a. Let thisArgument be ? OrdinaryCreateFromConstructor(newTarget,
"%ObjectPrototype%").
[...] [...]
15. Return ? envRec.GetThisBinding(). 15. Return ? envRec.GetThisBinding().
8.1.1.3.4 GetThisBinding ( )
[...]
3. If envRec.[[ThisBindingStatus]] is "uninitialized", throw a ReferenceError exception.
[...]
---*/ ---*/
class Foo extends null { class Foo extends null {
constructor() {} constructor() {
}
} }
var foo = new Foo(); assert.throws(ReferenceError, function() {
new C();
assert.sameValue(Object.getPrototypeOf(foo), Foo.prototype); });

View File

@ -3,8 +3,8 @@
/*--- /*---
esid: sec-runtime-semantics-classdefinitionevaluation esid: sec-runtime-semantics-classdefinitionevaluation
description: > description: >
The `this` value of a null-extending class is automatically initialized, Attempting to call `super()` in a null-extending class throws a TypeError,
preventing the use of `super` from within the constructor. because %FunctionPrototype% cannot be called as constructor function.
info: | info: |
Runtime Semantics: ClassDefinitionEvaluation Runtime Semantics: ClassDefinitionEvaluation
@ -15,16 +15,11 @@ info: |
[...] [...]
b. Let superclass be the result of evaluating ClassHeritage. b. Let superclass be the result of evaluating ClassHeritage.
[...] [...]
15. If ClassHeritageopt is present and superclass is not null, then set F's e. If superclass is null, then
[[ConstructorKind]] internal slot to "derived".
[...] [...]
ii. Let constructorParent be the intrinsic object %FunctionPrototype%.
9.2.2 [[Construct]]
[...] [...]
5. If kind is "base", then 15. Let constructorInfo be the result of performing DefineMethod for constructor with arguments proto and constructorParent as the optional functionPrototype argument.
a. Let thisArgument be ? OrdinaryCreateFromConstructor(newTarget,
"%ObjectPrototype%").
[...] [...]
12.3.5.1 Runtime Semantics: Evaluation 12.3.5.1 Runtime Semantics: Evaluation
@ -32,17 +27,15 @@ info: |
SuperCall : super Arguments SuperCall : super Arguments
[...] [...]
6. Let result be ? Construct(func, argList, newTarget). 3. Let func be ? GetSuperConstructor().
7. Let thisER be GetThisEnvironment( ). 4. Let argList be ArgumentListEvaluation of Arguments.
8. Return ? thisER.BindThisValue(result). [...]
8.1.1.3.1 BindThisValue 12.3.5.2 Runtime Semantics: GetSuperConstructor ( )
[...] [...]
3. If envRec.[[ThisBindingStatus]] is "initialized", throw a ReferenceError 5. Let superConstructor be ! activeFunction.[[GetPrototypeOf]]().
exception. 6. If IsConstructor(superConstructor) is false, throw a TypeError exception.
4. Set envRec.[[ThisValue]] to V.
5. Set envRec.[[ThisBindingStatus]] to "initialized".
[...] [...]
---*/ ---*/
@ -52,7 +45,7 @@ var reachable = 0;
class C extends null { class C extends null {
constructor() { constructor() {
reachable += 1; reachable += 1;
super(); super(unreachable += 1);
unreachable += 1; unreachable += 1;
} }
} }

View File

@ -3,42 +3,37 @@
/*--- /*---
esid: sec-runtime-semantics-classdefinitionevaluation esid: sec-runtime-semantics-classdefinitionevaluation
description: > 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: | info: |
The behavior under test was introduced in the "ES2017" revision of the
specification and conflicts with prior editions.
Runtime Semantics: ClassDefinitionEvaluation Runtime Semantics: ClassDefinitionEvaluation
[...] [...]
5. If ClassHeritageopt is not present, then 15. If ClassHeritageopt is present, then set F's [[ConstructorKind]] internal slot to "derived".
[...]
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".
[...] [...]
9.2.2 [[Construct]] 12.2.2.1 Runtime Semantics: Evaluation
PrimaryExpression : this
1. Return ? ResolveThisBinding( ).
8.3.4 ResolveThisBinding ( )
[...] [...]
5. If kind is "base", then 2. Return ? envRec.GetThisBinding().
a. Let thisArgument be ? OrdinaryCreateFromConstructor(newTarget,
"%ObjectPrototype%"). 8.1.1.3.4 GetThisBinding ( )
[...]
3. If envRec.[[ThisBindingStatus]] is "uninitialized", throw a ReferenceError exception.
[...] [...]
---*/ ---*/
var thisVal, instance;
class C extends null { class C extends null {
constructor() { constructor() {
thisVal = this; // Use an arrow function to access the `this` binding of the class constructor.
assert.throws(ReferenceError, () => {
this;
});
} }
} }
instance = new C(); assert.throws(ReferenceError, function() {
new C();
assert.sameValue(instance instanceof C, true); });
assert.sameValue(instance, thisVal);

View File

@ -4,32 +4,21 @@
esid: sec-runtime-semantics-classdefinitionevaluation esid: sec-runtime-semantics-classdefinitionevaluation
es6id: 14.5.14 es6id: 14.5.14
description: > description: >
When a null-extending class does not specify a `constructor` method The prototype of a null-extending class is %FunctionPrototype%, the prototype of
definition, a method with zero parameters and an empty body is used its "prototype" property is `null`.
info: | info: |
The behavior under test was introduced in the "ES2017" revision of the
specification and conflicts with prior editions.
Runtime Semantics: ClassDefinitionEvaluation Runtime Semantics: ClassDefinitionEvaluation
[...]
5. If ClassHeritageopt is not present, then 5. If ClassHeritageopt is not present, then
[...] [...]
6. Else, 6. Else,
[...] [...]
b. Let superclass be the result of evaluating ClassHeritage. b. Let superclass be the result of evaluating ClassHeritage.
[...] [...]
7. Let proto be ObjectCreate(protoParent). e. If superclass is null, then
8. If ClassBodyopt is not present, let constructor be empty. i. Let protoParent be null.
9. Else, let constructor be ConstructorMethod of ClassBody. ii. Let constructorParent be the intrinsic object %FunctionPrototype%.
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.
[...] [...]
---*/ ---*/
@ -37,3 +26,4 @@ class Foo extends null {}
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);
assert.sameValue(Foo, Foo.prototype.constructor);