1425bb815Sopenharmony_ci/* Copyright JS Foundation and other contributors, http://js.foundation
2425bb815Sopenharmony_ci *
3425bb815Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4425bb815Sopenharmony_ci * you may not use this file except in compliance with the License.
5425bb815Sopenharmony_ci * You may obtain a copy of the License at
6425bb815Sopenharmony_ci *
7425bb815Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8425bb815Sopenharmony_ci *
9425bb815Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10425bb815Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS
11425bb815Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12425bb815Sopenharmony_ci * See the License for the specific language governing permissions and
13425bb815Sopenharmony_ci * limitations under the License.
14425bb815Sopenharmony_ci */
15425bb815Sopenharmony_ci
16425bb815Sopenharmony_ci/* This file checks core generator operations. */
17425bb815Sopenharmony_ci
18425bb815Sopenharmony_cifunction check_syntax_error (code)
19425bb815Sopenharmony_ci{
20425bb815Sopenharmony_ci  try {
21425bb815Sopenharmony_ci    eval (code)
22425bb815Sopenharmony_ci    assert (false)
23425bb815Sopenharmony_ci  } catch (e) {
24425bb815Sopenharmony_ci    assert (e instanceof SyntaxError)
25425bb815Sopenharmony_ci  }
26425bb815Sopenharmony_ci}
27425bb815Sopenharmony_ci
28425bb815Sopenharmony_cicheck_syntax_error ("({ * })")
29425bb815Sopenharmony_cicheck_syntax_error ("({ *, b:4 })")
30425bb815Sopenharmony_cicheck_syntax_error ("({ *a:4 })")
31425bb815Sopenharmony_cicheck_syntax_error ("({ *['a']:4 })")
32425bb815Sopenharmony_cicheck_syntax_error ("({ *a(yield) {} })")
33425bb815Sopenharmony_cicheck_syntax_error ("({ get *a() {} })")
34425bb815Sopenharmony_cicheck_syntax_error ("({ set *b(v) {} })")
35425bb815Sopenharmony_ci
36425bb815Sopenharmony_cicheck_syntax_error ("class C { * }")
37425bb815Sopenharmony_cicheck_syntax_error ("class C { static * }")
38425bb815Sopenharmony_cicheck_syntax_error ("class C { *() {} }")
39425bb815Sopenharmony_cicheck_syntax_error ("class C { static * () {} }")
40425bb815Sopenharmony_cicheck_syntax_error ("class C { *['a'] {} }")
41425bb815Sopenharmony_ci
42425bb815Sopenharmony_cifunction check_result(result, value, done)
43425bb815Sopenharmony_ci{
44425bb815Sopenharmony_ci  assert(result.value === value)
45425bb815Sopenharmony_ci  assert(result.done === done)
46425bb815Sopenharmony_ci}
47425bb815Sopenharmony_ci
48425bb815Sopenharmony_cifunction postfix(a) { return a + "b" }
49425bb815Sopenharmony_ci
50425bb815Sopenharmony_civar o = {
51425bb815Sopenharmony_ci  * a () {
52425bb815Sopenharmony_ci    yield 1
53425bb815Sopenharmony_ci    return 2
54425bb815Sopenharmony_ci  },
55425bb815Sopenharmony_ci  *2(x) {
56425bb815Sopenharmony_ci    yield x + 1
57425bb815Sopenharmony_ci    return x + 2
58425bb815Sopenharmony_ci  },
59425bb815Sopenharmony_ci  *[postfix("a")]() {
60425bb815Sopenharmony_ci    var o = { get yield() { return 3 + 2 } }
61425bb815Sopenharmony_ci
62425bb815Sopenharmony_ci    yield o.yield
63425bb815Sopenharmony_ci    return 6
64425bb815Sopenharmony_ci  },
65425bb815Sopenharmony_ci  *yield() {
66425bb815Sopenharmony_ci    var o = { yield:7 }
67425bb815Sopenharmony_ci
68425bb815Sopenharmony_ci    yield o.yield
69425bb815Sopenharmony_ci    return 8
70425bb815Sopenharmony_ci  }
71425bb815Sopenharmony_ci}
72425bb815Sopenharmony_ci
73425bb815Sopenharmony_civar f = o.a()
74425bb815Sopenharmony_cicheck_result(f.next(), 1, false)
75425bb815Sopenharmony_cicheck_result(f.next(), 2, true)
76425bb815Sopenharmony_ci
77425bb815Sopenharmony_civar f = o[2](2)
78425bb815Sopenharmony_cicheck_result(f.next(), 3, false)
79425bb815Sopenharmony_cicheck_result(f.next(), 4, true)
80425bb815Sopenharmony_ci
81425bb815Sopenharmony_civar f = o.ab()
82425bb815Sopenharmony_cicheck_result(f.next(), 5, false)
83425bb815Sopenharmony_cicheck_result(f.next(), 6, true)
84425bb815Sopenharmony_ci
85425bb815Sopenharmony_civar f = o.yield()
86425bb815Sopenharmony_cicheck_result(f.next(), 7, false)
87425bb815Sopenharmony_cicheck_result(f.next(), 8, true)
88425bb815Sopenharmony_ci
89425bb815Sopenharmony_ciclass C {
90425bb815Sopenharmony_ci  * a () {
91425bb815Sopenharmony_ci    yield 1
92425bb815Sopenharmony_ci    return 2
93425bb815Sopenharmony_ci  }
94425bb815Sopenharmony_ci
95425bb815Sopenharmony_ci  *3(x) {
96425bb815Sopenharmony_ci    yield x + 1
97425bb815Sopenharmony_ci    return x + 2
98425bb815Sopenharmony_ci  }
99425bb815Sopenharmony_ci
100425bb815Sopenharmony_ci  *[postfix("a")]() {
101425bb815Sopenharmony_ci    var o = { get yield() { return 3 + 2 } }
102425bb815Sopenharmony_ci
103425bb815Sopenharmony_ci    yield o.yield
104425bb815Sopenharmony_ci    return 6
105425bb815Sopenharmony_ci  }
106425bb815Sopenharmony_ci
107425bb815Sopenharmony_ci  static *yield() {
108425bb815Sopenharmony_ci    var o = { yield:7 }
109425bb815Sopenharmony_ci
110425bb815Sopenharmony_ci    yield o.yield
111425bb815Sopenharmony_ci    return 8
112425bb815Sopenharmony_ci  }
113425bb815Sopenharmony_ci
114425bb815Sopenharmony_ci  static * [postfix("b") ] (v = 9) {
115425bb815Sopenharmony_ci    return v
116425bb815Sopenharmony_ci  }
117425bb815Sopenharmony_ci}
118425bb815Sopenharmony_ci
119425bb815Sopenharmony_civar c = new C
120425bb815Sopenharmony_ci
121425bb815Sopenharmony_civar f = c.a()
122425bb815Sopenharmony_cicheck_result(f.next(), 1, false)
123425bb815Sopenharmony_cicheck_result(f.next(), 2, true)
124425bb815Sopenharmony_ci
125425bb815Sopenharmony_civar f = c[3](2)
126425bb815Sopenharmony_cicheck_result(f.next(), 3, false)
127425bb815Sopenharmony_cicheck_result(f.next(), 4, true)
128425bb815Sopenharmony_ci
129425bb815Sopenharmony_civar f = c.ab()
130425bb815Sopenharmony_cicheck_result(f.next(), 5, false)
131425bb815Sopenharmony_cicheck_result(f.next(), 6, true)
132425bb815Sopenharmony_ci
133425bb815Sopenharmony_civar f = C.yield()
134425bb815Sopenharmony_cicheck_result(f.next(), 7, false)
135425bb815Sopenharmony_cicheck_result(f.next(), 8, true)
136425bb815Sopenharmony_ci
137425bb815Sopenharmony_civar f = C.bb()
138425bb815Sopenharmony_cicheck_result(f.next(), 9, true)
139