Add tests for async functions

Closes #479
This commit is contained in:
Brian Terlson 2016-01-26 14:31:32 -08:00 committed by Leonardo Balter
parent b785fdf942
commit dbf251586e
110 changed files with 1620 additions and 0 deletions

View File

@ -0,0 +1,31 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
%AsyncFunction% creates functions with or without new and handles arguments
similarly to functions.
---*/
var AsyncFunction = async function foo() { }.constructor;
var fn;
fn = AsyncFunction("a", "await 1;");
assert.sameValue(fn.length, 1, "length with 1 argument, call");
fn = AsyncFunction("a,b", "await 1;");
assert.sameValue(fn.length, 2, "length with 2 arguments in one, call");
fn = AsyncFunction("a", "b", "await 1;");
assert.sameValue(fn.length, 2, "length with 2 arguments, call");
fn = new AsyncFunction("a", "await 1;");
assert.sameValue(fn.length, 1, "length with 1 argument, construct");
fn = new AsyncFunction("a,b", "await 1;");
assert.sameValue(fn.length, 2, "length with 2 arguments in one, construct");
fn = new AsyncFunction("a", "b", "await 1;");
assert.sameValue(fn.length, 2, "length with 2 arguments, construct");

View File

@ -0,0 +1,13 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
%AsyncFunction% is extensible
---*/
var AsyncFunction = async function() { }.constructor;
AsyncFunction.x = 1;
assert.sameValue(AsyncFunction.x, 1);

View File

@ -0,0 +1,15 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
%AsyncFunction% is a subclass of Function
---*/
async function foo() { };
var AsyncFunction = foo.constructor;
assert.sameValue(Object.getPrototypeOf(AsyncFunction), Function, "Prototype of constructor is Function");
assert.sameValue(Object.getPrototypeOf(AsyncFunction.prototype), Function.prototype, "Prototype of constructor's prototype is Function.prototype");
assert(foo instanceof Function, 'async function instance is instanceof Function');

View File

@ -0,0 +1,16 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
%AsyncFunction% has a length of 1 with writable false, enumerable false, configurable true.
includes: [propertyHelper.js]
---*/
var AsyncFunction = async function foo() { }.constructor;
assert.sameValue(AsyncFunction.length, 1);
verifyNotWritable(AsyncFunction, 'length');
verifyNotEnumerable(AsyncFunction, 'length');
verifyConfigurable(AsyncFunction, 'length');

View File

@ -0,0 +1,16 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
%AsyncFunction% has a name of "AsyncFunction".
includes: [propertyHelper.js]
---*/
var AsyncFunction = async function foo() { }.constructor;
assert.sameValue(AsyncFunction.name, "AsyncFunction");
verifyNotWritable(AsyncFunction, "name");
verifyNotEnumerable(AsyncFunction, "name");
verifyConfigurable(AsyncFunction, "name");

View File

@ -0,0 +1,14 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: AsyncFunction has a prototype property with writable false, enumerable false, configurable false.
includes: [propertyHelper.js]
---*/
var AsyncFunction = async function foo() { }.constructor;
verifyNotConfigurable(AsyncFunction, 'prototype');
verifyNotWritable(AsyncFunction, 'prototype');
verifyNotEnumerable(AsyncFunction, 'prototype');

View File

@ -0,0 +1,12 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
%AsyncFunction% exists and is a function
---*/
var AsyncFunction = async function foo() { }.constructor;
assert.sameValue(typeof AsyncFunction, "function");

View File

@ -0,0 +1,14 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
%AsyncFunctionPrototype% has a [[Extensible]] of true
---*/
var AsyncFunction = async function foo() { }.constructor;
AsyncFunction.prototype.x = 1;
assert.sameValue(AsyncFunction.prototype.x, 1);

View File

@ -0,0 +1,10 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: AsyncFunction.prototype has a [[prototype]] of Function.prototype
---*/
var AsyncFunction = async function foo() { }.constructor;
assert.sameValue(Object.getPrototypeOf(AsyncFunction.prototype), Function.prototype);

View File

@ -0,0 +1,17 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
%AsyncFunctionPrototype% has a Symbol.toStringTag property of "AsyncFunction"
includes: [propertyHelper.js]
---*/
var AsyncFunction = async function foo() { }.constructor;
var AFP = AsyncFunction.prototype;
assert.sameValue(AFP[Symbol.toStringTag], "AsyncFunction", "toStringTag value");
verifyNotWritable(AFP, Symbol.toStringTag);
verifyNotEnumerable(AFP, Symbol.toStringTag);
verifyConfigurable(AFP, Symbol.toStringTag);

View File

@ -0,0 +1,16 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Async function instances are not constructors and do not have a
[[Construct]] slot.
---*/
async function foo() { }
assert.throws(TypeError, function() {
new foo();
});

View File

@ -0,0 +1,16 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: Async function declarations have a name property
includes: [propertyHelper.js]
---*/
async function foo () { };
assert.sameValue(foo.name, "foo");
verifyNotWritable(foo, "name");
verifyNotEnumerable(foo, "name");
verifyConfigurable(foo, "name");

View File

@ -0,0 +1,22 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Async functions have a length property that is the number of expected
arguments.
includes: [propertyHelper.js]
---*/
async function l0() { }
async function l1(a) { }
async function l2(a, b) { }
assert.sameValue(l0.length, 0);
assert.sameValue(l1.length, 1);
assert.sameValue(l2.length, 2)
verifyNotWritable(l0, 'length');
verifyNotEnumerable(l0, 'length');
verifyConfigurable(l0, 'length');

View File

@ -0,0 +1,12 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Async function instances do not have a prototype property.
---*/
async function foo() { };
assert.sameValue(foo.prototype, undefined, 'foo.prototype should be undefined');
assert(!foo.hasOwnProperty('prototype'), 'foo.prototype should not exist');

View File

@ -0,0 +1,13 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
%AsyncFunction% is not exposed as a global
---*/
assert.throws(ReferenceError, function () {
AsyncFunction
}, "AsyncFunction should not be present as a global");

View File

@ -0,0 +1,15 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Function.prototype.toString on an async function created with the
AsyncFunction constructor.
features: [async-functions]
---*/
async function f() {}
var AsyncFunction = f.constructor;
var g = /* before */AsyncFunction("a", " /* a */ b, c /* b */ //", "/* c */ ; /* d */ //")/* after */;
assert.sameValue(g.toString(), "async function anonymous(a, /* a */ b, c /* b */ //\n) {/* c */ ; /* d */ //\n}");

View File

@ -0,0 +1,13 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: Function.prototype.toString on an async function declaration
features: [async-functions]
---*/
/* before */async function /* a */ f /* b */ ( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ }/* after */
assert.sameValue(f.toString(), "async function /* a */ f /* b */ ( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ }");

View File

@ -0,0 +1,13 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: Function.prototype.toString on an async function expression
features: [async-functions]
---*/
let f = /* before */async function /* a */ f /* b */ ( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ }/* after */;
assert.sameValue(f.toString(), "async function /* a */ f /* b */ ( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ }");

View File

@ -0,0 +1,15 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: Function.prototype.toString on an async method
features: [async-functions]
---*/
let f = { /* before */async f /* a */ ( /* b */ ) /* c */ { /* d */ }/* after */ }.f;
let g = { /* before */async /* a */ [ /* b */ "g" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ }.g;
assert.sameValue(f.toString(), "async f /* a */ ( /* b */ ) /* c */ { /* d */ }");
assert.sameValue(g.toString(), "async /* a */ [ /* b */ \"g\" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }");

View File

@ -0,0 +1,17 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Async arrow functions return promises
flags: [async]
---*/
var p = (async () => await 1 + await 2)();
assert(Object.getPrototypeOf(p) === Promise.prototype);
p.then(function (v) {
assert.sameValue(v, 3);
$DONE();
}, $DONE);

View File

@ -0,0 +1,12 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
It is a Syntax Error if ContainsUseStrict of AsyncConciseBody is *true* and IsSimpleParameterList of ArrowParameters is *false*.
negative: SyntaxError
---*/
async (x = 1) => {"use strict"}

View File

@ -0,0 +1,13 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a SyntaxError if FormalParameters contains arguments
negative: SyntaxError
flags: [onlyStrict]
---*/
async(arguments) => { }

View File

@ -0,0 +1,10 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a SyntaxError if FormalParameters' default expressions contains await
negative: SyntaxError
---*/
async(x = await) => { }

View File

@ -0,0 +1,10 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a SyntaxError if FormalParameters contains await
negative: SyntaxError
---*/
async(await) => { }

View File

@ -0,0 +1,11 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a syntax error if AsyncFunctionBody contains SuperCall is true
negative: SyntaxError
---*/
async(foo) => { super() };

View File

@ -0,0 +1,11 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a syntax error if AsyncFunctionBody contains SuperProperty is true
negative: SyntaxError
---*/
async(foo) => { super.prop };

View File

@ -0,0 +1,13 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
If strict mode, early error rules for StrictFormalParameters are applied
negative: SyntaxError
flags: [onlyStrict]
---*/
async(a, a) => { }

View File

@ -0,0 +1,12 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a SyntaxError if FormalParameters contains eval
negative: SyntaxError
flags: [onlyStrict]
---*/
async(eval) => { }

View File

@ -0,0 +1,11 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a SyntaxError if BoundNames of FormalParameters also occurs in the LexicallyDeclaredNames of AsyncFunctionBody
negative: SyntaxError
---*/
async(bar) => { let bar; }

View File

@ -0,0 +1,11 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a syntax error if FormalParameters contains SuperCall is true
negative: SyntaxError
---*/
async(foo = super()) => {}

View File

@ -0,0 +1,11 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a syntax error if FormalParameters contains SuperCall is true
negative: SyntaxError
---*/
async (foo = super.foo) => { }

View File

@ -0,0 +1,12 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
It is a Syntax Error if ContainsUseStrict of AsyncConciseBody is *true* and IsSimpleParameterList of ArrowParameters is *false*.
negative: SyntaxError
---*/
(async function (x = 1) {"use strict"})

View File

@ -0,0 +1,13 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
If the source code matching this production is strict code, it is a Syntax Error if BindingIdentifier is the IdentifierName arguments.
negative: SyntaxError
flags: [onlyStrict]
---*/
(async function arguments () { })

View File

@ -0,0 +1,12 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
If the source code matching this production is strict code, it is a Syntax Error if BindingIdentifier is the IdentifierName eval.
negative: SyntaxError
flags: [onlyStrict]
---*/
(async function eval () { })

View File

@ -0,0 +1,11 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a syntax error if AsyncFunctionBody contains SuperCall is true
negative: SyntaxError
---*/
(async function foo (foo) { super() })

View File

@ -0,0 +1,12 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a syntax error if AsyncFunctionBody contains SuperProperty is true
negative: SyntaxError
---*/
(async function foo (foo) { super.prop });

View File

@ -0,0 +1,12 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a SyntaxError if FormalParameters contains eval in strict mode
negative: SyntaxError
flags: [onlyStrict]
---*/
(async function foo (eval) { })

View File

@ -0,0 +1,11 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a SyntaxError if BoundNames of FormalParameters also occurs in the LexicallyDeclaredNames of AsyncFunctionBody
negative: SyntaxError
---*/
(async function foo (bar) { let bar; });

View File

@ -0,0 +1,11 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a syntax error if FormalParameters contains SuperCall is true
negative: SyntaxError
---*/
(async function foo (foo = super()) { var bar; });

View File

@ -0,0 +1,11 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a syntax error if FormalParameters contains SuperCall is true
negative: SyntaxError
---*/
(async function foo (foo = super.foo) { var bar; });

View File

@ -0,0 +1,12 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Async function expressions are not a simple assignment target.
negative: ReferenceError
---*/
(async function foo() { } = 1)

View File

@ -0,0 +1,12 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Async function expressions return promises
---*/
var p = async function() { }();
assert(p instanceof Promise, "async functions return promise instances");

View File

@ -0,0 +1,11 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Async function expressions are PrimaryExpressions
---*/
(async function foo() { }.prototype)

View File

@ -0,0 +1,13 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Await is allowed as a binding identifier in global scope
---*/
async function await() { return 1 }
assert(await instanceof Function);

View File

@ -0,0 +1,15 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Await is not allowed as an identifier in functions nested in async functions
negative: SyntaxError
---*/
async function foo() {
function await() {
}
}

View File

@ -0,0 +1,20 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Await can await any thenable. If the thenable's then is not callable,
await evaluates to the thenable
flags: [async]
---*/
async function foo() {
var thenable = { then: 42 };
var res = await thenable;
assert.sameValue(res, thenable);
}
foo().then($DONE, $DONE);

View File

@ -0,0 +1,31 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Await can await any thenable.
flags: [async]
---*/
var error = {};
var thenable = {
then: function (resolve, reject) {
throw error;
}
}
async function foo() {
var caught = false;
try {
await thenable;
} catch(e) {
caught = true;
assert.sameValue(e, error);
}
assert(caught);
}
foo().then($DONE, $DONE);

View File

@ -0,0 +1,21 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Await can await any thenable.
flags: [async]
---*/
var thenable = {
then: function (resolve, reject) {
resolve(42);
}
}
async function foo() {
assert.sameValue(await thenable, 42);
}
foo().then($DONE, $DONE);

View File

@ -0,0 +1,12 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Await is an identifier in a function
---*/
function foo(await) { return await; }
assert.sameValue(foo(1), 1);

View File

@ -0,0 +1,12 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Await in a generator is an identifier
---*/
function* foo(await) { yield await; };
assert.sameValue(foo(1).next().value, 1);

View File

@ -0,0 +1,12 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Await is an identifier in global scope
---*/
var await = 1;
assert.sameValue(await, 1);

View File

@ -0,0 +1,20 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Await is allowed as an identifier in functions nested in async functions
---*/
var await;
async function foo() {
function bar() {
await = 1;
}
bar();
}
foo();
assert.sameValue(await, 1);

View File

@ -0,0 +1,20 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Await is allowed as an identifier in generator functions nested in async functions
---*/
var await;
async function foo() {
function* bar() {
await = 1;
}
bar().next();
}
foo();
assert.sameValue(await, 1);

View File

@ -0,0 +1,23 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Await throws errors from rejected promises
---*/
async function foo() {
var err = {};
var caught = false;
try {
await Promise.reject(err);
} catch(e) {
caught = true;
assert.sameValue(e, err);
}
assert(caught);
}

View File

@ -0,0 +1,14 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
await is not a simple assignment target and cannot be assigned to.
negative: ReferenceError
---*/
async function foo() {
(await 1) = 1;
}

View File

@ -0,0 +1,14 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
await requries an operand.
negative: SyntaxError
---*/
async function foo() {
await;
}

View File

@ -0,0 +1,17 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Await's operand is a UnaryExpression
flags: [async]
---*/
async function foo() {
let x = 2;
let y = await Promise.resolve(2) * x
assert.sameValue(y, 4);
}
foo().then($DONE, $DONE);

View File

@ -0,0 +1,18 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Await's operand is a UnaryExpression
flags: [async]
---*/
async function foo() {
let x = 1;
let y = await x++;
assert.sameValue(y, 1);
assert.sameValue(x, 2);
}
foo().then($DONE, $DONE);

View File

@ -0,0 +1,26 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Super calls work in body of async methods
flags: [async]
---*/
var sup = {
method() {
return 'sup';
}
}
var child = {
__proto__: sup,
async method() {
var x = await super.method();
assert.sameValue(x, 'sup');
}
}
child.method().then($DONE, $DONE);

View File

@ -0,0 +1,27 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Super calls work in parameter list of async methods
flags: [async]
---*/
var sup = {
method() {
return 'sup';
}
}
var child = {
__proto__: sup,
async method(x = super.method()) {
var y = await x;
assert.sameValue(y, 'sup');
}
}
child.method().then($DONE, $DONE);

View File

@ -0,0 +1,13 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
It is a Syntax Error if ContainsUseStrict of AsyncConciseBody is *true* and IsSimpleParameterList of ArrowParameters is *false*.
negative: SyntaxError
---*/
({
foo(x = 1) {"use strict"}
});

View File

@ -0,0 +1,13 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a SyntaxError if FormalParameters contains arguments
negative: SyntaxError
flags: [onlyStrict]
---*/
!{
async foo (arguments) { }
}

View File

@ -0,0 +1,13 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a SyntaxError if FormalParameters' default expressions contains await
negative: SyntaxError
---*/
!{
async foo (x = await) { }
}

View File

@ -0,0 +1,12 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a SyntaxError if FormalParameters contains await
negative: SyntaxError
---*/
!{
async foo (await) { }
}

View File

@ -0,0 +1,12 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a SyntaxError if AsyncFunctionBody contains SuperCall is true
negative: SyntaxError
---*/
!{
async foo () { super() }
}

View File

@ -0,0 +1,13 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Early error rules for StrictFormalParameters are applied
negative: SyntaxError
---*/
!{
async foo(a, a) { }
}

View File

@ -0,0 +1,13 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a SyntaxError if FormalParameters contains eval in strict mode
negative: SyntaxError
flags: [onlyStrict]
---*/
!{
async foo(eval) { }
}

View File

@ -0,0 +1,13 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a SyntaxError if BoundNames of FormalParameters also occurs in the LexicallyDeclaredNames of AsyncFunctionBody
negative: SyntaxError
---*/
!{
async function foo(bar) { let bar; }
}

View File

@ -0,0 +1,12 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a syntax error if FormalParameters contains SuperCall is true
negative: SyntaxError
---*/
!{
async foo(foo = super()) { }
}

View File

@ -0,0 +1,15 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Async function method definitions return promises
---*/
var obj = {
async method() {}
}
var p = obj.method();
assert(p instanceof Promise, "async functions return promise instances");

View File

@ -0,0 +1,13 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Async functions return promises
---*/
async function foo() { };
var p = foo();
assert(p instanceof Promise, "async functions return promise instances");

View File

@ -0,0 +1,12 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
It is a Syntax Error if ContainsUseStrict of AsyncConciseBody is *true* and IsSimpleParameterList of ArrowParameters is *false*.
negative: SyntaxError
---*/
async function foo(x = 1){"use strict"}

View File

@ -0,0 +1,13 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a SyntaxError if FormalParameters contains arguments in strict mode
negative: SyntaxError
flags: [onlyStrict]
---*/
async function foo (arguments) { }

View File

@ -0,0 +1,10 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a SyntaxError if FormalParameters' default expressions contains await
negative: SyntaxError
---*/
async function foo (x = await) { }

View File

@ -0,0 +1,10 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a SyntaxError if FormalParameters contains await
negative: SyntaxError
---*/
async function foo (await) { }

View File

@ -0,0 +1,13 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
If the source code matching this production is strict code, it is a Syntax Error if BindingIdentifier is the IdentifierName arguments.
negative: SyntaxError
flags: [onlyStrict]
---*/
async function arguments () { }

View File

@ -0,0 +1,12 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
If the source code matching this production is strict code, it is a Syntax Error if BindingIdentifier is the IdentifierName eval.
negative: SyntaxError
flags: [onlyStrict]
---*/
async function eval () { }

View File

@ -0,0 +1,11 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a syntax error if AsyncFunctionBody contains SuperCall is true
negative: SyntaxError
---*/
async function foo (foo) { super() };

View File

@ -0,0 +1,11 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a syntax error if AsyncFunctionBody contains SuperProperty is true
negative: SyntaxError
---*/
async function foo (foo) { super.prop };

View File

@ -0,0 +1,13 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
If strict mode, early error rules for StrictFormalParameters are applied
negative: SyntaxError
flags: [onlyStrict]
---*/
async function foo(a, a) { }

View File

@ -0,0 +1,12 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a SyntaxError if FormalParameters contains eval in strict mode
negative: SyntaxError
flags: [onlyStrict]
---*/
async function foo (eval) { }

View File

@ -0,0 +1,11 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a SyntaxError if BoundNames of FormalParameters also occurs in the LexicallyDeclaredNames of AsyncFunctionBody
negative: SyntaxError
---*/
async function foo (bar) { let bar; }

View File

@ -0,0 +1,11 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a syntax error if FormalParameters contains SuperCall is true
negative: SyntaxError
---*/
async function foo (foo = super()) { let bar; }

View File

@ -0,0 +1,11 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: It is a syntax error if FormalParameters contains SuperCall is true
negative: SyntaxError
---*/
async function foo (foo = super.foo) { let bar; }

View File

@ -0,0 +1,12 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Async generators are not a thing (yet)
negative: SyntaxError
---*/
async function* foo() { }

View File

@ -0,0 +1,21 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
The return value of the async function resolves the promise
flags: [async]
---*/
async function foo() {
await Promise.resolve();
return 42;
}
foo().then(function (v) {
assert.sameValue(v, 42);
$DONE();
}, $DONE);

View File

@ -0,0 +1,19 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
The return value of the async function resolves the promise
flags: [async]
---*/
async function foo() {
return 42;
}
foo().then(function (v) {
assert.sameValue(v, 42);
$DONE();
}, $DONE);

View File

@ -0,0 +1,24 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Errors thrown from the async function body reject the returned promise
flags: [async]
---*/
async function foo() {
await Promise.resolve();
throw 1;
}
foo().then(function () {
$DONE("Should not be called");
}, function (e) {
assert.sameValue(e, 1);
$DONE();
});

View File

@ -0,0 +1,22 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Errors thrown from the async function body reject the returned promise
flags: [async]
---*/
async function foo() {
throw 1;
}
foo().then(function () {
$DONE("Should not be called");
}, function (e) {
assert.sameValue(e, 1);
$DONE();
});

View File

@ -0,0 +1,18 @@
// copyright 2016 microsoft, inc. all rights reserved.
// this code is governed by the bsd license found in the license file.
/*---
author: brian terlson <brian.terlson@microsoft.com>
esid: pending
description: >
async function bodies are executed immediately (unlike generators)
---*/
let called;
async function foo() {
called = true;
await new Promise();
}
foo();
assert(called);

View File

@ -0,0 +1,20 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
If a default expression throws, the promise is rejected.
info: >
This is different from generators which will throw the error out of the generator
when it is called.
flags: [async]
---*/
var y = null;
async function foo(x = y()) {}
foo().then(function () {
$DONE('promise should be rejected');
}, function () {
$DONE();
});

View File

@ -0,0 +1,22 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Mapped arguments object is used when the async function has a
simple parameter list.
flags: [noStrict, async]
---*/
async function foo(a) {
arguments[0] = 2;
assert.sameValue(a, 2);
a = 3;
assert.sameValue(arguments[0], 3);
}
foo(1).then($DONE, $DONE);

View File

@ -0,0 +1,17 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
The this value is set to the global object when not passed in sloppy mode.
flags: [noStrict, async]
---*/
var glob = this;
async function foo() {
assert.sameValue(this, glob);
}
foo().then($DONE, $DONE);

View File

@ -0,0 +1,18 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
The this value from the caller is present in the async function body
flags: [async]
---*/
async function foo(a) {
assert.sameValue(this, a)
}
var obj = {};
foo.call(obj, obj).then($DONE, $DONE);

View File

@ -0,0 +1,23 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Unmapped arguments object is used when the async function doesn't have a
simple parameter list.
flags: [async]
---*/
async function foo(a = 42) {
arguments[0] = 2;
assert.sameValue(a, 1);
a = 3;
assert.sameValue(arguments[0], 2);
}
foo(1).then($DONE, $DONE);

View File

@ -0,0 +1,17 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Declarations allow line breaks after function and after arguments list
---*/
async function
foo()
{
}
assert(foo instanceof Function);

View File

@ -0,0 +1,13 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: Async function declarations cannot have a line break after `async`
info: Reference error is thrown due to looking up async in strict mode
---*/
assert.throws(ReferenceError, function() {
async
function foo() {}
});

View File

@ -0,0 +1,15 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: Async function declaration returns a promise
flags: [async]
---*/
async function foo () { }
foo().then(function() {
$DONE();
})

View File

@ -0,0 +1,14 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
Async function expressions return promises
---*/
class Foo {
async method() {};
}
var p = new Foo().method();
assert(p instanceof Promise, "async functions return promise instances");

View File

@ -0,0 +1,13 @@
// Copyright 2016 Microsoft, Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
author: Brian Terlson <brian.terlson@microsoft.com>
esid: pending
description: >
It is a Syntax Error if ContainsUseStrict of AsyncConciseBody is *true* and IsSimpleParameterList of ArrowParameters is *false*.
negative: SyntaxError
---*/
class Foo {
async bar(x = 1) {"use strict"}
}

Some files were not shown because too many files have changed in this diff Show More