async-iteration: add tests for AsyncGenerationFunction

This commit is contained in:
Valerie R Young 2018-02-12 14:12:16 -05:00 committed by Leo Balter
parent a19993e269
commit 510d6b7f44
19 changed files with 523 additions and 0 deletions

View File

@ -0,0 +1,14 @@
// Copyright (C) 2018 Valerie Young. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-properties-of-asyncgeneratorfunction
description: Object extensibility
info: |
The value of the [[Extensible]] internal slot of the AsyncGeneratorFunction
constructor is true.
features: [async-iteration]
---*/
var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor;
assert(Object.isExtensible(AsyncGeneratorFunction));

View File

@ -0,0 +1,34 @@
// Copyright (C) 2018 Valerie Young. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-properties-of-asyncgeneratorfunction
description: >
AsyncGenerator function instances are correctly reported as instances of the
AsyncGeneratorFunction intrinsic.
features: [async-iteration]
---*/
var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor;
async function* agDecl() {}
var agExpr = async function* () {};
assert(
agDecl instanceof AsyncGeneratorFunction,
'AsyncGenerators created via AsyncGeneratorDeclaration syntax are proper instances of AsyncGeneratorFunction'
);
assert(
agExpr instanceof AsyncGeneratorFunction,
'AsyncGenerators created via AsyncGeneratorExpression syntax are proper instances of AsyncGeneratorFunction'
);
assert(
new AsyncGeneratorFunction() instanceof AsyncGeneratorFunction,
'AsyncGenerators created via constructor invocation of AsyncGeneratorFunction are proper instances of AsyncGeneratorFunction'
);
assert(
AsyncGeneratorFunction() instanceof AsyncGeneratorFunction,
'AsyncGenerators created via function invocation of AsyncGeneratorFunction are proper instances of AsyncGeneratorFunction'
);

View File

@ -0,0 +1,42 @@
// Copyright (C) 2018 Valerie Young. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-asyncgeneratorfunction
description: Definition of instance `length` property
info: |
AsyncGeneratorFunction ( p1, p2, , pn, body )
...
3. Return CreateDynamicFunction(C, NewTarget, "async generator", args).
Runtime Semantics: CreateDynamicFunction
...
29. If kind is "async" or "async generator", then
a. If parameters Contains AwaitExpression is true, throw a SyntaxError
exception.
features: [async-iteration]
flags: [async]
---*/
var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor;
// AwaitExpression is permitted in function body.
AsyncGeneratorFunction('x = await 42');
assert.throws(SyntaxError, function() {
AsyncGeneratorFunction('x = await 42', '');
}, 'AwaitExpression not permitted in parameters');
var withinAsyncGenerator = async function*() {
AsyncGeneratorFunction('x = await 42', '');
};
withinAsyncGenerator().next().then(
function () {
throw new Test262Error("AwaitExpression not permitted when calling context is a async generator");
},
function (e) {
if (!(e instanceof SyntaxError)) {
throw new Test262Error("Expected SyntaxError but got " + e);
}
}
).then($DONE, $DONE);

View File

@ -0,0 +1,31 @@
// Copyright 2018 Valerie Young. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-asyncgeneratorfunction
description: The instance created by AsyncGeneratorFunction is not a constructor
info: |
AsyncGeneratorFunction ( p1, p2, , pn, body )
...
3. Return ? CreateDynamicFunction(C, NewTarget, "async generator", args).
Runtime Semantics: CreateDynamicFunction( constructor, newTarget, kind, args )
...
32. Let F be FunctionAllocate(proto, strict, kind).
...
FunctionAllocate ( functionPrototype, strict, functionKind )
// [[Construct]] and [[ConstructKind]] are not set for functionKind="async generators"
features: [async-iteration]
---*/
var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor;
var instance = AsyncGeneratorFunction();
assert.throws(TypeError, function() {
new instance();
})

View File

@ -0,0 +1,45 @@
// Copyright (C) 2018 Valerie Young. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-asyncgeneratorfunction
description: Definition of instance `length` property
info: |
AsyncGeneratorFunction ( p1, p2, , pn, body )
...
3. Return CreateDynamicFunction(C, NewTarget, "async generator", args).
Runtime Semantics: CreateDynamicFunction
...
// the parameter "args" is sliced into "parameters" and "body"
26. Perform FunctionInitialize(F, Normal, parameters, body, scope).
...
FunctionInitialize
...
2. Let len be the ExpectedArgumentCount of ParameterList.
3. Perform ! DefinePropertyOrThrow(F, "length",
PropertyDescriptor{[[Value]]: len, [[Writable]]: false, [[Enumerable]]:
false, [[Configurable]]: true}).
...
includes: [propertyHelper.js]
features: [async-iteration]
---*/
var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor;
var instance = AsyncGeneratorFunction()
verifyProperty(AsyncGeneratorFunction(), "length", {
value: 0,
enumerable: false,
writable: false,
configurable: true,
});
assert.sameValue(AsyncGeneratorFunction('').length, 0, "test 1");
assert.sameValue(AsyncGeneratorFunction('x').length, 0, "test 2");
assert.sameValue(AsyncGeneratorFunction('x', '').length, 1, "test 3");
assert.sameValue(AsyncGeneratorFunction('x', 'y', '').length, 2, "test 4");
assert.sameValue(AsyncGeneratorFunction('x, y', '').length, 2, "test 5");

View File

@ -0,0 +1,28 @@
// Copyright (C) 2018 Valerie Young. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-asyncgeneratorfunction
description: Assignment of function `name` attribute
info: |
AsyncGeneratorFunction ( p1, p2, , pn, body )
...
3. Return CreateDynamicFunction(C, NewTarget, "async generator", args).
RuntimeSemantics: CreateDynamicFunction(constructor, newTarget, kind, args)
...
29. Perform SetFunctionName(F, "anonymous").
includes: [propertyHelper.js]
features: [async-iteration]
---*/
var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor;
var instance = AsyncGeneratorFunction()
verifyProperty(instance, "name", {
value: "anonymous",
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -0,0 +1,37 @@
// Copyright (C) 2018 Valerie Young. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-asyncgeneratorfunction
description: Definition of instance `prototype` property
info: |
AsyncGeneratorFunction ( p1, p2, , pn, body )
...
3. Return CreateDynamicFunction(C, NewTarget, "async generator", args).
Runtime Semantics: CreateDynamicFunction
...
37. Else if kind is "async generator", then
a. Let prototype be ObjectCreate(%AsyncGeneratorPrototype%).
b. Perform DefinePropertyOrThrow(F, "prototype",
PropertyDescriptor{[[Value]]: prototype, [[Writable]]: true,
[[Enumerable]]: false, [[Configurable]]: false}).
...
includes: [propertyHelper.js]
features: [async-iteration]
---*/
var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor;
var instance = AsyncGeneratorFunction();
assert.sameValue(typeof instance.prototype, 'object');
assert.sameValue(
Object.getPrototypeOf(instance.prototype),
Object.getPrototypeOf(instance).prototype
);
verifyProperty(instance, "prototype", {
enumerable: false,
writable: true,
configurable: false,
});

View File

@ -0,0 +1,42 @@
// Copyright (C) 2018 Valerie Young. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-asyncgeneratorfunction
description: Definition of instance `length` property
info: |
AsyncGeneratorFunction ( p1, p2, , pn, body )
...
3. Return CreateDynamicFunction(C, NewTarget, "async generator", args).
Runtime Semantics: CreateDynamicFunction
...
28. If kind is "generator" or "async generator", then
a. If parameters Contains YieldExpression is true, throw a SyntaxError
exception.
features: [async-iteration]
flags: [async]
---*/
var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor;
// YieldExpression is permitted in function body.
AsyncGeneratorFunction('x = yield');
assert.throws(SyntaxError, function() {
AsyncGeneratorFunction('x = yield', '');
}, 'YieldExpression not permitted generally');
var withinAsyncGenerator = async function*() {
AsyncGeneratorFunction('x = yield', '');
};
withinAsyncGenerator().next().then(
function () {
throw new Test262Error("YieldExpression not permitted when calling context is a async generator");
},
function (e) {
if (!(e instanceof SyntaxError)) {
throw new Test262Error("Expected SyntaxError but got " + e);
}
}
).then($DONE, $DONE);

View File

@ -0,0 +1,20 @@
// Copyright (C) 2018 Valerie Young. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-asyncgeneratorfunction
description: >
When invoked via the constructor invocation pattern without arguments, the
GeneratorFunction intrinsic returns a valid async generator with an empty body.
features: [async-iteration]
---*/
var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor;
var g = new AsyncGeneratorFunction();
var iter = g();
iter.next().then(function(result) {
assert.sameValue(result.value, undefined, 'Result `value`');
assert.sameValue(result.done, true, 'Result `done` flag');
}).then($DONE, $DONE)

View File

@ -0,0 +1,26 @@
// Copyright (C) 2018 Valerie Young. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-asyncgeneratorfunction
description: >
When invoked via the function invocation pattern with multiple arguments,
the AsyncGeneratorFunction intrinsic creates a valid generator whose body is the
last argument evaluated as source code and whose formal parameters are
defined by the preceeding arguments.
features: [async-iteration]
---*/
var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor;
var g = AsyncGeneratorFunction('x', 'y', 'yield x + y;');
var iter = g(2, 3);
iter.next().then(function(result) {
assert.sameValue(result.value, 5, 'First result `value`');
assert.sameValue(result.done, false, 'First result `done` flag');
}).then(undefined, $DONE)
iter.next().then(function(result) {
assert.sameValue(result.value, undefined, 'Final result `value`');
assert.sameValue(result.done, true, 'Final result `done` flag');
}).then($DONE, $DONE)

View File

@ -0,0 +1,19 @@
// Copyright (C) 2018 Valerie Young. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-asyncgeneratorfunction
description: >
When invoked via the function invocation pattern without arguments, the
AsyncGeneratorFunction intrinsic returns a valid generator with an empty body.
features: [async-iteration]
---*/
var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor;
var g = AsyncGeneratorFunction();
var iter = g();
iter.next().then(function(result) {
assert.sameValue(result.value, undefined, 'Result `value`');
assert.sameValue(result.done, true, 'Result `done` flag');
}).then($DONE, $DONE)

View File

@ -0,0 +1,28 @@
// Copyright (C) 2018 Valerie Young. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-asyncgeneratorfunction
description: >
When invoked via the function invocation pattern with a single argument,
the AsyncGeneratorFunction intrinsic creates a valid async generator whose body is the
first argument evaluated as source code.
features: [async-iteration]
flags: [async]
---*/
var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor;
var g = AsyncGeneratorFunction('yield 1;');
var iter = g();
var result;
iter.next().then(function(result) {
assert.sameValue(result.value, 1, 'First result `value`');
assert.sameValue(result.done, false, 'First result `done` flag');
}).then(undefined, $DONE)
iter.next().then(function(result) {
assert.sameValue(result.value, undefined, 'Final result `value`');
assert.sameValue(result.done, true, 'Final result `done` flag');
}).then($DONE, $DONE)

View File

@ -0,0 +1,19 @@
// Copyright (C) 2018 Valerie Young. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-asyncgeneratorfunction-length
description: >
This is a data property with a value of 1. This property has the attributes
{ [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [async-iteration]
---*/
var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor;
verifyProperty(AsyncGeneratorFunction, "length", {
value: 1,
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -0,0 +1,29 @@
// Copyright (C) 2018 Valerie Young. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-properties-of-asyncgeneratorfunction
description: Function "name" property
info: |
The value of the name property of the AsyncGeneratorFunction
is "AsyncGeneratorFunction".
17 ECMAScript Standard Built-in Objects:
Every built-in Function object, including constructors, that is not
identified as an anonymous function has a name property whose value is a
String.
Unless otherwise specified, the name property of a built-in Function object,
if it exists, has the attributes { [[Writable]]: false, [[Enumerable]]:
false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [async-iteration]
---*/
var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor;
verifyProperty(AsyncGeneratorFunction, "name", {
value: "AsyncGeneratorFunction",
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -0,0 +1,25 @@
// Copyright (C) 2018 Valerie Young. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-asyncgeneratorfunction-prototype-tostringtag
description: >
`Symbol.toStringTag` property descriptor
info: |
The initial value of the @@toStringTag property is the String
value "AsyncGeneratorFunction".
This property has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [async-iteration, Symbol.toStringTag]
---*/
var AsyncGeneratorFunctionPrototype = Object.getPrototypeOf(async function*() {});
verifyProperty(AsyncGeneratorFunctionPrototype, Symbol.toStringTag, {
value: 'AsyncGeneratorFunction',
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -0,0 +1,25 @@
// Copyright (C) 2018 Valerie Young. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-asyncgeneratorfunction-prototype-constructor
description: >
`constructor` property of the AsyncGeneratorFunction.prototype object
info: |
The initial value of AsyncGeneratorFunction.prototype.constructor is the intrinsic
object %AsyncGeneratorFunction%.
This property has the attributes { [[Writable]]: false, [[Enumerable]]:
false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [async-iteration]
---*/
var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor;
assert.sameValue(AsyncGeneratorFunction.prototype.constructor, AsyncGeneratorFunction);
verifyProperty(AsyncGeneratorFunction.prototype, "constructor", {
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -0,0 +1,14 @@
// Copyright (C) 2018 Valerie Young. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-properties-of-asyncgenerator-prototype
description: Object extensibility
info: |
The initial value of the [[Extensible]] internal slot of the
AsyncGeneratorFunction prototype object is true.
features: [async-iteration]
---*/
var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor;
assert(Object.isExtensible(AsyncGeneratorFunction.prototype));

View File

@ -0,0 +1,19 @@
// Copyright (C) 2018 Valerie Young. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: AsyncGeneratorFunction.prototype property descriptor
esid: sec-asyncgeneratorfunction-prototype
info: |
This property has the attributes { [[Writable]]: false, [[Enumerable]]:
false, [[Configurable]]: false }.
includes: [propertyHelper.js]
features: [async-iteration]
---*/
var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor;
verifyProperty(AsyncGeneratorFunction, "prototype", {
enumerable: false,
writable: false,
configurable: false,
});

View File

@ -0,0 +1,26 @@
// Copyright (C) 2018 Valerie Young. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-asyncgeneratorfunction-prototype-prototype
description: >
The value of AsyncGeneratorFunction.prototype.prototype is the
%AsyncGeneratorPrototype% intrinsic object.
This property has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [async-iteration]
---*/
var AsyncGeneratorFunctionPrototype = Object.getPrototypeOf(async function*() {});
assert.sameValue(
AsyncGeneratorFunctionPrototype.prototype,
Object.getPrototypeOf(async function*() {}.prototype)
);
verifyProperty(AsyncGeneratorFunctionPrototype, "prototype", {
enumerable: false,
writable: false,
configurable: true,
});