function-sent.js 2.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --harmony-function-sent


{
  function* g() { return function.sent }
  assertEquals({value: 42, done: true}, g().next(42));
}


{
  function* g() {
    try {
      yield function.sent;
    } finally {
      yield function.sent;
      return function.sent;
    }
  }

  {
25
    let x = g();
26 27 28 29 30 31
    assertEquals({value: 1, done: false}, x.next(1));
    assertEquals({value: 2, done: false}, x.next(2));
    assertEquals({value: 3, done: true}, x.next(3));
  }

  {
32
    let x = g();
33 34 35 36
    assertEquals({value: 1, done: false}, x.next(1));
    assertEquals({value: 2, done: false}, x.throw(2));
    assertEquals({value: 3, done: true}, x.next(3));
  }
37 38 39 40 41 42 43

  {
    let x = g();
    assertEquals({value: 1, done: false}, x.next(1));
    assertEquals({value: 2, done: false}, x.return(2));
    assertEquals({value: 3, done: true}, x.next(3));
  }
44 45 46 47 48 49 50 51
}


{
  function* inner() {
    try {
      yield function.sent;
    } finally {
52
      return 23;
53 54 55 56 57 58 59 60 61 62
    }
  }

  function* g() {
    yield function.sent;
    yield* inner();
    return function.sent;
  }

  {
63
    let x = g();
64 65 66 67 68 69
    assertEquals({value: 1, done: false}, x.next(1));
    assertEquals({value: undefined, done: false}, x.next(2));
    assertEquals({value: 3, done: true}, x.next(3));
  }

  {
70
    let x = g();
71 72 73 74
    assertEquals({value: 1, done: false}, x.next(1));
    assertEquals({value: undefined, done: false}, x.next(2));
    assertEquals({value: 42, done: true}, x.throw(42));
  }
75 76 77 78 79

  {
    let x = g();
    assertEquals({value: 1, done: false}, x.next(1));
    assertEquals({value: undefined, done: false}, x.next(2));
80
    assertEquals({value: 23, done: true}, x.return(42));
81
  }
82 83 84 85 86 87 88 89 90
}


assertThrows("function f() { return function.sent }", SyntaxError);
assertThrows("() => { return function.sent }", SyntaxError);
assertThrows("() => { function.sent }", SyntaxError);
assertThrows("() => function.sent", SyntaxError);
assertThrows("({*f() { function.sent }})", SyntaxError);
assertDoesNotThrow("({*f() { return function.sent }})");