• 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
16/* This file checks yield syntax errors. */
17
18function check_syntax_error(str)
19{
20  try {
21    eval(str);
22    assert(false);
23  } catch (e) {
24    assert(e instanceof SyntaxError);
25  }
26}
27
28function  *  gen()
29{
30  yield , yield
31
32  yield
33     , yield
34
35  (yield
36  )
37
38  yield[
39  1]
40}
41
42function*gen2()
43{
44  1 ?
45    yield
46  :
47    yield
48}
49
50var gen3 = function*(){
51  (yield)/[yield]
52}
53
54check_syntax_error("function *gen(){ yield % yield }");
55check_syntax_error("function *gen(){ (yield) % yield }");
56check_syntax_error("function *gen(){ yield % (yield) }");
57check_syntax_error("function *gen(){ (yield\n1) }");
58check_syntax_error("function *gen(){ function yield() {} }");
59check_syntax_error("function *gen(){ (yield)=>1 }");
60check_syntax_error("function *gen(){ yield => 1 }");
61check_syntax_error("function *gen(){ yi\\u0065ld 1 }");
62
63function *gen4() {
64  var f = function yield(i) {
65    if (i = 0)
66      return yield(i + 1)
67
68    return 39
69  }
70
71  return f(0)
72}
73
74assert(gen4().next().value === 39);
75
76(function *() {
77  () => yield
78  yield 1;
79})
80
81function *gen5() {
82  var o = {
83    ["f"]() { yield % yield }
84  }
85  yield 1;
86}
87