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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/json.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/generator.js
diff --git a/src/generator.js b/src/generator.js
index 484afd8d6a51f62292ed178c3c5973c53d1dc134..e33cd29555352827943ddfd05203dbc0023f3994 100644
--- a/src/generator.js
+++ b/src/generator.js
@@ -2,14 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+(function() {
+
"use strict";
-// This file relies on the fact that the following declarations have been made
-// in runtime.js:
-// var $Function = global.Function;
+%CheckIsBootstrapping();
-// ----------------------------------------------------------------------------
+var GlobalFunction = global.Function;
+// ----------------------------------------------------------------------------
// Generator functions and objects are specified by ES6, sections 15.19.3 and
// 15.19.4.
@@ -39,6 +40,7 @@ function GeneratorObjectNext(value) {
}
}
+
function GeneratorObjectThrow(exn) {
if (!IS_GENERATOR(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
@@ -63,10 +65,12 @@ function GeneratorObjectThrow(exn) {
}
}
+
function GeneratorObjectIterator() {
return this;
}
+
function GeneratorFunctionConstructor(arg1) { // length == 1
var source = NewFunctionString(arguments, 'function*');
var global_proxy = %GlobalProxy(global);
@@ -77,36 +81,33 @@ function GeneratorFunctionConstructor(arg1) { // length == 1
return f;
}
+// ----------------------------------------------------------------------------
-function SetUpGenerators() {
- %CheckIsBootstrapping();
-
- // Both Runtime_GeneratorNext and Runtime_GeneratorThrow are supported by
- // neither Crankshaft nor TurboFan, disable optimization of wrappers here.
- %NeverOptimizeFunction(GeneratorObjectNext);
- %NeverOptimizeFunction(GeneratorObjectThrow);
-
- // Set up non-enumerable functions on the generator prototype object.
- var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype;
- InstallFunctions(GeneratorObjectPrototype,
- DONT_ENUM,
- ["next", GeneratorObjectNext,
- "throw", GeneratorObjectThrow]);
-
- %FunctionSetName(GeneratorObjectIterator, '[Symbol.iterator]');
- %AddNamedProperty(GeneratorObjectPrototype, symbolIterator,
- GeneratorObjectIterator, DONT_ENUM | DONT_DELETE | READ_ONLY);
- %AddNamedProperty(GeneratorObjectPrototype, "constructor",
- GeneratorFunctionPrototype, DONT_ENUM | READ_ONLY);
- %AddNamedProperty(GeneratorObjectPrototype,
- symbolToStringTag, "Generator", DONT_ENUM | READ_ONLY);
- %InternalSetPrototype(GeneratorFunctionPrototype, $Function.prototype);
- %AddNamedProperty(GeneratorFunctionPrototype,
- symbolToStringTag, "GeneratorFunction", DONT_ENUM | READ_ONLY);
- %AddNamedProperty(GeneratorFunctionPrototype, "constructor",
- GeneratorFunction, DONT_ENUM | READ_ONLY);
- %InternalSetPrototype(GeneratorFunction, $Function);
- %SetCode(GeneratorFunction, GeneratorFunctionConstructor);
-}
-
-SetUpGenerators();
+// Both Runtime_GeneratorNext and Runtime_GeneratorThrow are supported by
+// neither Crankshaft nor TurboFan, disable optimization of wrappers here.
+%NeverOptimizeFunction(GeneratorObjectNext);
+%NeverOptimizeFunction(GeneratorObjectThrow);
+
+// Set up non-enumerable functions on the generator prototype object.
+var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype;
+InstallFunctions(GeneratorObjectPrototype,
+ DONT_ENUM,
+ ["next", GeneratorObjectNext,
+ "throw", GeneratorObjectThrow]);
+
+%FunctionSetName(GeneratorObjectIterator, '[Symbol.iterator]');
+%AddNamedProperty(GeneratorObjectPrototype, symbolIterator,
+ GeneratorObjectIterator, DONT_ENUM | DONT_DELETE | READ_ONLY);
+%AddNamedProperty(GeneratorObjectPrototype, "constructor",
+ GeneratorFunctionPrototype, DONT_ENUM | READ_ONLY);
+%AddNamedProperty(GeneratorObjectPrototype,
+ symbolToStringTag, "Generator", DONT_ENUM | READ_ONLY);
+%InternalSetPrototype(GeneratorFunctionPrototype, GlobalFunction.prototype);
+%AddNamedProperty(GeneratorFunctionPrototype,
+ symbolToStringTag, "GeneratorFunction", DONT_ENUM | READ_ONLY);
+%AddNamedProperty(GeneratorFunctionPrototype, "constructor",
+ GeneratorFunction, DONT_ENUM | READ_ONLY);
+%InternalSetPrototype(GeneratorFunction, GlobalFunction);
+%SetCode(GeneratorFunction, GeneratorFunctionConstructor);
+
+})();
« 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