1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 // This file relies on the fact that the following declarations have been made
9 // var $Function = global.Function;
11 // ----------------------------------------------------------------------------
14 // Generator functions and objects are specified by ES6, sections 15.19.3 and
17 function GeneratorObjectNext(value) {
18 if (!IS_GENERATOR(this)) {
19 throw MakeTypeError('incompatible_method_receiver',
20 ['[Generator].prototype.next', this]);
23 return %_GeneratorNext(this, value);
26 function GeneratorObjectThrow(exn) {
27 if (!IS_GENERATOR(this)) {
28 throw MakeTypeError('incompatible_method_receiver',
29 ['[Generator].prototype.throw', this]);
32 return %_GeneratorThrow(this, exn);
35 function GeneratorFunctionPrototypeConstructor(x) {
36 if (%_IsConstructCall()) {
37 throw MakeTypeError('not_constructor', ['GeneratorFunctionPrototype']);
41 function GeneratorFunctionConstructor(arg1) { // length == 1
42 var source = NewFunctionString(arguments, 'function*');
43 var global_receiver = %GlobalReceiver(global);
44 // Compile the string in the constructor and not a helper so that errors
45 // appear to come from here.
46 var f = %_CallFunction(global_receiver, %CompileString(source, true));
47 %FunctionMarkNameShouldPrintAsAnonymous(f);
52 function SetUpGenerators() {
53 %CheckIsBootstrapping();
54 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype;
55 InstallFunctions(GeneratorObjectPrototype,
56 DONT_ENUM | DONT_DELETE | READ_ONLY,
57 ["next", GeneratorObjectNext,
58 "throw", GeneratorObjectThrow]);
59 %SetProperty(GeneratorObjectPrototype, "constructor",
60 GeneratorFunctionPrototype, DONT_ENUM | DONT_DELETE | READ_ONLY);
61 %SetPrototype(GeneratorFunctionPrototype, $Function.prototype);
62 %SetCode(GeneratorFunctionPrototype, GeneratorFunctionPrototypeConstructor);
63 %SetProperty(GeneratorFunctionPrototype, "constructor",
64 GeneratorFunction, DONT_ENUM | DONT_DELETE | READ_ONLY);
65 %SetPrototype(GeneratorFunction, $Function);
66 %SetCode(GeneratorFunction, GeneratorFunctionConstructor);