Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: src/generator.js

Issue 1097703002: Wrap JSON and generator implementation in functions. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/json.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function() {
6
5 "use strict"; 7 "use strict";
6 8
7 // This file relies on the fact that the following declarations have been made 9 %CheckIsBootstrapping();
8 // in runtime.js: 10
9 // var $Function = global.Function; 11 var GlobalFunction = global.Function;
10 12
11 // ---------------------------------------------------------------------------- 13 // ----------------------------------------------------------------------------
12 14
13
14 // Generator functions and objects are specified by ES6, sections 15.19.3 and 15 // Generator functions and objects are specified by ES6, sections 15.19.3 and
15 // 15.19.4. 16 // 15.19.4.
16 17
17 function GeneratorObjectNext(value) { 18 function GeneratorObjectNext(value) {
18 if (!IS_GENERATOR(this)) { 19 if (!IS_GENERATOR(this)) {
19 throw MakeTypeError(kIncompatibleMethodReceiver, 20 throw MakeTypeError(kIncompatibleMethodReceiver,
20 '[Generator].prototype.next', this); 21 '[Generator].prototype.next', this);
21 } 22 }
22 23
23 var continuation = %GeneratorGetContinuation(this); 24 var continuation = %GeneratorGetContinuation(this);
24 if (continuation > 0) { 25 if (continuation > 0) {
25 // Generator is suspended. 26 // Generator is suspended.
26 if (DEBUG_IS_ACTIVE) %DebugPrepareStepInIfStepping(this); 27 if (DEBUG_IS_ACTIVE) %DebugPrepareStepInIfStepping(this);
27 try { 28 try {
28 return %_GeneratorNext(this, value); 29 return %_GeneratorNext(this, value);
29 } catch (e) { 30 } catch (e) {
30 %GeneratorClose(this); 31 %GeneratorClose(this);
31 throw e; 32 throw e;
32 } 33 }
33 } else if (continuation == 0) { 34 } else if (continuation == 0) {
34 // Generator is already closed. 35 // Generator is already closed.
35 return { value: void 0, done: true }; 36 return { value: void 0, done: true };
36 } else { 37 } else {
37 // Generator is running. 38 // Generator is running.
38 throw MakeTypeError(kGeneratorRunning); 39 throw MakeTypeError(kGeneratorRunning);
39 } 40 }
40 } 41 }
41 42
43
42 function GeneratorObjectThrow(exn) { 44 function GeneratorObjectThrow(exn) {
43 if (!IS_GENERATOR(this)) { 45 if (!IS_GENERATOR(this)) {
44 throw MakeTypeError(kIncompatibleMethodReceiver, 46 throw MakeTypeError(kIncompatibleMethodReceiver,
45 '[Generator].prototype.throw', this); 47 '[Generator].prototype.throw', this);
46 } 48 }
47 49
48 var continuation = %GeneratorGetContinuation(this); 50 var continuation = %GeneratorGetContinuation(this);
49 if (continuation > 0) { 51 if (continuation > 0) {
50 // Generator is suspended. 52 // Generator is suspended.
51 try { 53 try {
52 return %_GeneratorThrow(this, exn); 54 return %_GeneratorThrow(this, exn);
53 } catch (e) { 55 } catch (e) {
54 %GeneratorClose(this); 56 %GeneratorClose(this);
55 throw e; 57 throw e;
56 } 58 }
57 } else if (continuation == 0) { 59 } else if (continuation == 0) {
58 // Generator is already closed. 60 // Generator is already closed.
59 throw exn; 61 throw exn;
60 } else { 62 } else {
61 // Generator is running. 63 // Generator is running.
62 throw MakeTypeError(kGeneratorRunning); 64 throw MakeTypeError(kGeneratorRunning);
63 } 65 }
64 } 66 }
65 67
68
66 function GeneratorObjectIterator() { 69 function GeneratorObjectIterator() {
67 return this; 70 return this;
68 } 71 }
69 72
73
70 function GeneratorFunctionConstructor(arg1) { // length == 1 74 function GeneratorFunctionConstructor(arg1) { // length == 1
71 var source = NewFunctionString(arguments, 'function*'); 75 var source = NewFunctionString(arguments, 'function*');
72 var global_proxy = %GlobalProxy(global); 76 var global_proxy = %GlobalProxy(global);
73 // Compile the string in the constructor and not a helper so that errors 77 // Compile the string in the constructor and not a helper so that errors
74 // appear to come from here. 78 // appear to come from here.
75 var f = %_CallFunction(global_proxy, %CompileString(source, true)); 79 var f = %_CallFunction(global_proxy, %CompileString(source, true));
76 %FunctionMarkNameShouldPrintAsAnonymous(f); 80 %FunctionMarkNameShouldPrintAsAnonymous(f);
77 return f; 81 return f;
78 } 82 }
79 83
84 // ----------------------------------------------------------------------------
80 85
81 function SetUpGenerators() { 86 // Both Runtime_GeneratorNext and Runtime_GeneratorThrow are supported by
82 %CheckIsBootstrapping(); 87 // neither Crankshaft nor TurboFan, disable optimization of wrappers here.
88 %NeverOptimizeFunction(GeneratorObjectNext);
89 %NeverOptimizeFunction(GeneratorObjectThrow);
83 90
84 // Both Runtime_GeneratorNext and Runtime_GeneratorThrow are supported by 91 // Set up non-enumerable functions on the generator prototype object.
85 // neither Crankshaft nor TurboFan, disable optimization of wrappers here. 92 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype;
86 %NeverOptimizeFunction(GeneratorObjectNext); 93 InstallFunctions(GeneratorObjectPrototype,
87 %NeverOptimizeFunction(GeneratorObjectThrow); 94 DONT_ENUM,
95 ["next", GeneratorObjectNext,
96 "throw", GeneratorObjectThrow]);
88 97
89 // Set up non-enumerable functions on the generator prototype object. 98 %FunctionSetName(GeneratorObjectIterator, '[Symbol.iterator]');
90 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype; 99 %AddNamedProperty(GeneratorObjectPrototype, symbolIterator,
91 InstallFunctions(GeneratorObjectPrototype, 100 GeneratorObjectIterator, DONT_ENUM | DONT_DELETE | READ_ONLY);
92 DONT_ENUM, 101 %AddNamedProperty(GeneratorObjectPrototype, "constructor",
93 ["next", GeneratorObjectNext, 102 GeneratorFunctionPrototype, DONT_ENUM | READ_ONLY);
94 "throw", GeneratorObjectThrow]); 103 %AddNamedProperty(GeneratorObjectPrototype,
104 symbolToStringTag, "Generator", DONT_ENUM | READ_ONLY);
105 %InternalSetPrototype(GeneratorFunctionPrototype, GlobalFunction.prototype);
106 %AddNamedProperty(GeneratorFunctionPrototype,
107 symbolToStringTag, "GeneratorFunction", DONT_ENUM | READ_ONLY);
108 %AddNamedProperty(GeneratorFunctionPrototype, "constructor",
109 GeneratorFunction, DONT_ENUM | READ_ONLY);
110 %InternalSetPrototype(GeneratorFunction, GlobalFunction);
111 %SetCode(GeneratorFunction, GeneratorFunctionConstructor);
95 112
96 %FunctionSetName(GeneratorObjectIterator, '[Symbol.iterator]'); 113 })();
97 %AddNamedProperty(GeneratorObjectPrototype, symbolIterator,
98 GeneratorObjectIterator, DONT_ENUM | DONT_DELETE | READ_ONLY);
99 %AddNamedProperty(GeneratorObjectPrototype, "constructor",
100 GeneratorFunctionPrototype, DONT_ENUM | READ_ONLY);
101 %AddNamedProperty(GeneratorObjectPrototype,
102 symbolToStringTag, "Generator", DONT_ENUM | READ_ONLY);
103 %InternalSetPrototype(GeneratorFunctionPrototype, $Function.prototype);
104 %AddNamedProperty(GeneratorFunctionPrototype,
105 symbolToStringTag, "GeneratorFunction", DONT_ENUM | READ_ONLY);
106 %AddNamedProperty(GeneratorFunctionPrototype, "constructor",
107 GeneratorFunction, DONT_ENUM | READ_ONLY);
108 %InternalSetPrototype(GeneratorFunction, $Function);
109 %SetCode(GeneratorFunction, GeneratorFunctionConstructor);
110 }
111
112 SetUpGenerators();
OLDNEW
« no previous file with comments | « no previous file | src/json.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698