• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright JS Foundation and other contributors, http://js.foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/* This test checks async modifiers (nothing else). */
16
17function check_syntax_error (code)
18{
19  try {
20    eval (code)
21    assert (false)
22  } catch (e) {
23    assert (e instanceof SyntaxError)
24  }
25}
26
27check_syntax_error("function async f() {}")
28check_syntax_error("(a,b) async => 1")
29/* SyntaxError because arrow declaration is an assignment expression. */
30check_syntax_error("async * (a,b) => 1")
31check_syntax_error("({ *async f() {} })")
32check_syntax_error("class C { async static f() {} }")
33check_syntax_error("class C { * async f() {} }")
34check_syntax_error("class C { static * async f() {} }")
35
36
37function check_promise(p, value)
38{
39  assert(p instanceof Promise)
40
41  p.then(function(v) {
42    assert(v === value)
43  })
44}
45
46var o = {
47  async f() { return 1 },
48  async() { return 2 },
49  async *x() {}, /* Parser test, async iterators are needed to work. */
50}
51
52check_promise(o.f(), 1)
53assert(o.async() === 2)
54
55class C {
56  async f() { return 3 }
57  async *x() {} /* Parser test, async iterators are needed to work. */
58  static async f() { return 4 }
59  static async *y() {} /* Parser test, async iterators are needed to work. */
60  async() { return 5 }
61  static async() { return 6 }
62}
63
64var c = new C
65
66check_promise(c.f(), 3)
67check_promise(C.f(), 4)
68assert(c.async() === 5)
69assert(C.async() === 6)
70