1b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Copyright 2014 the V8 project authors. All rights reserved.
2b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Use of this source code is governed by a BSD-style license that can be
3b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// found in the LICENSE file.
4b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
5014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// Flags: --allow-natives-syntax
6b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
7b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
8b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch(function TestBasics() {
9b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var object = {
10b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    method() {
11b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch      return 42;
12b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    }
13b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  };
14b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(42, object.method());
15b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch})();
16b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
17b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
18b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch(function TestThis() {
19b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var object = {
20b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    method() {
21b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch      assertEquals(object, this);
22b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    }
23b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  };
24b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  object.method();
25b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch})();
26b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
27b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
28b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch(function TestDescriptor() {
29b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var object = {
30b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    method() {
31b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch      return 42;
32b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    }
33b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  };
34b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
35b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var desc = Object.getOwnPropertyDescriptor(object, 'method');
36b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertTrue(desc.enumerable);
37b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertTrue(desc.configurable);
38b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertTrue(desc.writable);
39b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals('function', typeof desc.value);
40b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
41b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(42, desc.value());
42b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch})();
43b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
44b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
45b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch(function TestProto() {
46b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var object = {
47b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    method() {}
48b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  };
49b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
50b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(Function.prototype, Object.getPrototypeOf(object.method));
51b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch})();
52b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
53b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
54b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch(function TestNotConstructable() {
55b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var object = {
56b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    method() {}
57b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  };
58b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
59b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertThrows(function() {
60b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    new object.method;
61b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  });
62b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch})();
63b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
64b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
65b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch(function TestFunctionName() {
66b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var object = {
67b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    method() {},
68b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    1() {},
69b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    2.0() {}
70b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  };
71b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var f = object.method;
72b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals('method', f.name);
73b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var g = object[1];
74b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals('1', g.name);
75b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var h = object[2];
76b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals('2', h.name);
77b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch})();
78b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
79b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
80b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch(function TestNoBinding() {
81b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var method = 'local';
82b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var calls = 0;
83b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var object = {
84b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    method() {
85b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch      calls++;
86b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch      assertEquals('local', method);
87b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    }
88b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  };
89b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  object.method();
90b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(1, calls);
91b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch})();
92b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
93b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
94b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch(function TestNoPrototype() {
95b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var object = {
96b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    method() {}
97b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  };
98b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var f = object.method;
99b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertFalse(f.hasOwnProperty('prototype'));
100b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(undefined, f.prototype);
101b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
102b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  f.prototype = 42;
103b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(42, f.prototype);
104b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch})();
105b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
106b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
107014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch(function TestNoRestrictedPropertiesStrict() {
108014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  var obj = {
109014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    method() { "use strict"; }
110014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  };
111014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertFalse(obj.method.hasOwnProperty("arguments"));
112014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertThrows(function() { return obj.method.arguments; }, TypeError);
113014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertThrows(function() { obj.method.arguments = {}; }, TypeError);
114014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
115014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertFalse(obj.method.hasOwnProperty("caller"));
116014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertThrows(function() { return obj.method.caller; }, TypeError);
117014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertThrows(function() { obj.method.caller = {}; }, TypeError);
118014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch})();
119014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
120014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
121014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch(function TestNoRestrictedPropertiesSloppy() {
122014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  var obj = {
123014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    method() {}
124014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  };
125014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertFalse(obj.method.hasOwnProperty("arguments"));
126014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertThrows(function() { return obj.method.arguments; }, TypeError);
127014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertThrows(function() { obj.method.arguments = {}; }, TypeError);
128014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
129014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertFalse(obj.method.hasOwnProperty("caller"));
130014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertThrows(function() { return obj.method.caller; }, TypeError);
131014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertThrows(function() { obj.method.caller = {}; }, TypeError);
132014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch})();
133014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
134014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
135b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch(function TestToString() {
136b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var object = {
137b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    method() { 42; }
138b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  };
139b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals('method() { 42; }', object.method.toString());
140b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch})();
141b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
142b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
143b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch(function TestOptimized() {
144b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var object = {
145b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    method() { return 42; }
146b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  };
147b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(42, object.method());
148b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(42, object.method());
149b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  %OptimizeFunctionOnNextCall(object.method);
150b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(42, object.method());
151b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertFalse(object.method.hasOwnProperty('prototype'));
152b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch})();
153b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
154b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
155b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch///////////////////////////////////////////////////////////////////////////////
156b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
157b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
158b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochvar GeneratorFunction = function*() {}.__proto__.constructor;
159014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdochvar GeneratorPrototype = Object.getPrototypeOf(function*() {}).prototype;
160b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
161b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
162b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction assertIteratorResult(value, done, result) {
163b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals({value: value, done: done}, result);
164b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
165b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
166b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
167b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch(function TestGeneratorBasics() {
168b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var object = {
169b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    *method() {
170b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch      yield 1;
171b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    }
172b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  };
173b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var g = object.method();
174b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertIteratorResult(1, false, g.next());
175b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertIteratorResult(undefined, true, g.next());
176b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch})();
177b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
178b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
179b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch(function TestGeneratorThis() {
180b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var object = {
181b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    *method() {
182b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch      yield this;
183b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    }
184b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  };
185b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var g = object.method();
186b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertIteratorResult(object, false, g.next());
187b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertIteratorResult(undefined, true, g.next());
188b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch})();
189b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
190b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
191b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch(function TestGeneratorSymbolIterator() {
192b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var object = {
193b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    *method() {}
194b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  };
195b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var g = object.method();
196b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(g, g[Symbol.iterator]());
197b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch})();
198b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
199b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
200b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch(function TestGeneratorDescriptor() {
201b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var object = {
202b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    *method() {
203b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch      yield 1;
204b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    }
205b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  };
206b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
207b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var desc = Object.getOwnPropertyDescriptor(object, 'method');
208b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertTrue(desc.enumerable);
209b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertTrue(desc.configurable);
210b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertTrue(desc.writable);
211b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals('function', typeof desc.value);
212b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
213b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var g = desc.value();
214b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertIteratorResult(1, false, g.next());
215b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertIteratorResult(undefined, true, g.next());
216b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch})();
217b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
218b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
219014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch(function TestGeneratorPrototypeDescriptor() {
220014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  var object = {
221014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    *method() {}
222014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  };
223014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
224014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  var desc = Object.getOwnPropertyDescriptor(object.method, 'prototype');
225014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertFalse(desc.enumerable);
226014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertFalse(desc.configurable);
227014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertTrue(desc.writable);
228014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertEquals(GeneratorPrototype, Object.getPrototypeOf(desc.value));
229014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch})();
230014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
231014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
232b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch(function TestGeneratorProto() {
233b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var object = {
234b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    *method() {}
235b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  };
236b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
237b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(GeneratorFunction.prototype,
238b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch               Object.getPrototypeOf(object.method));
239b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch})();
240b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
241b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
242342c50ce1624b485728b9a4fc41d8bbf37eb46cfBen Murdoch(function TestGeneratorNotConstructable() {
243b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var object = {
244b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    *method() {
245b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch      yield 1;
246b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    }
247b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  };
248b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
249342c50ce1624b485728b9a4fc41d8bbf37eb46cfBen Murdoch  assertThrows(()=>new object.method());
250b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch})();
251b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
252b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
253b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch(function TestGeneratorName() {
254b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var object = {
255b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    *method() {},
256b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    *1() {},
257b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    *2.0() {}
258b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  };
259b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var f = object.method;
260b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals('method', f.name);
261b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var g = object[1];
262b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals('1', g.name);
263b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var h = object[2];
264b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals('2', h.name);
265b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch})();
266b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
267b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
268b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch(function TestGeneratorNoBinding() {
269b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var method = 'local';
270b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var calls = 0;
271b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var object = {
272b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    *method() {
273b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch      calls++;
274b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch      assertEquals('local', method);
275b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    }
276b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  };
277b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var g = object.method();
278b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertIteratorResult(undefined, true, g.next());
279b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals(1, calls);
280b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch})();
281b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
282b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
283b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch(function TestGeneratorToString() {
284b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  var object = {
285b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    *method() { yield 1; }
286b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  };
287b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  assertEquals('*method() { yield 1; }', object.method.toString());
288b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch})();
289014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
290014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
291014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch(function TestProtoName() {
292014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  var object = {
293014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    __proto__() {
294014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      return 1;
295014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    }
296014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  };
297014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertEquals(Object.prototype, Object.getPrototypeOf(object));
298014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertEquals(1, object.__proto__());
299014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch})();
300014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
301014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
302014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch(function TestProtoName2() {
303014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  var p = {};
304014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  var object = {
305014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    __proto__() {
306014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      return 1;
307014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    },
308014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    __proto__: p
309014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  };
310014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertEquals(p, Object.getPrototypeOf(object));
311014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  assertEquals(1, object.__proto__());
312014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch})();
313