Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1011)

Unified Diff: src/runtime/runtime.js

Issue 7308106: Make traceur.runtime.StopIteration into a constructor function. Base URL: https://code.google.com/p/traceur-compiler/@master
Patch Set: Created 12 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/codegeneration/generator/GeneratorTransformer.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime/runtime.js
diff --git a/src/runtime/runtime.js b/src/runtime/runtime.js
index 8adf74a0944f5ce2c5c5ffa1360afee357e75a85..f953e3ddf6e5149234081dad02fabf0a6881972d 100644
--- a/src/runtime/runtime.js
+++ b/src/runtime/runtime.js
@@ -338,43 +338,34 @@ traceur.runtime = (function(global) {
if (index < array.length) {
return array[index++];
}
- throw StopIterationLocal;
+ throw new StopIterationLocal();
}
};
}));
}
- // Generators
- var StopIterationLocal;
- var isStopIteration = function(x) {
- return x === StopIterationLocal;
+ // StopIteration
+ var StopIterationLocal = function(v) {
+ this.value = v;
};
- switch (typeof StopIteration) {
- case 'function':
- StopIterationLocal = new StopIteration();
- isStopIteration = function(x) {
- return x instanceof StopIteration;
- };
- break;
- case 'object':
- StopIterationLocal = StopIteration;
- try {
- // Firefox's StopIteration is both a valid lhs and rhs for instanceof.
- StopIteration instanceof StopIteration;
-
- isStopIteration = function(x) {
- return x instanceof StopIteration;
- };
- } catch(e) {}
- break;
- case 'undefined':
- StopIterationLocal = {
- toString: function() {
- return '[object StopIteration]';
- }
- };
- global.StopIteration = StopIterationLocal;
+ StopIterationLocal.prototype = {
+ toString: function() {
+ return '[object StopIteration]';
+ }
+ };
+
+ global.StopIteration = new StopIterationLocal();
+
+ function isStopIteration(x) {
+ return x instanceof StopIterationLocal;
+ }
+
+ function setStopIteration(StopIteration) {
+ if (typeof StopIteration !== 'function')
+ throw new TypeError('constructor function required');
+ StopIterationLocal = StopIteration;
+ global.StopIteration = new StopIteration();
}
/**
@@ -487,6 +478,7 @@ traceur.runtime = (function(global) {
Deferred: Deferred,
StopIteration: StopIterationLocal,
isStopIteration: isStopIteration,
+ setStopIteration: setStopIteration,
addIterator: addIterator,
assertName: assertName,
createName: NameModule.Name,
« no previous file with comments | « src/codegeneration/generator/GeneratorTransformer.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b