Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

also have a way to avoid stack overflows if possible.

  • Loading branch information...
commit 6e38a46471f9f85dea4bc9acc147e93cfaf52b82 1 parent 47d6dc2
@maxtaco authored
View
25 lib/coffee-script/tame.js
@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.2.1-pre
(function() {
- var Deferrals, Rendezvous, makeDeferReturn,
+ var Deferrals, Rendezvous, makeDeferReturn, tickCounter, __c,
__slice = [].slice;
exports.transform = function(x) {
@@ -48,6 +48,18 @@
return ret;
};
+ __c = 0;
+
+ tickCounter = function(mod) {
+ __c++;
+ if ((__c % mod) === 0) {
+ __c = 0;
+ return true;
+ } else {
+ return false;
+ }
+ };
+
Deferrals = (function() {
Deferrals.name = 'Deferrals';
@@ -59,7 +71,16 @@
}
Deferrals.prototype._fulfill = function() {
- if (--this.count === 0) return this.continuation(this.ret);
+ var _this = this;
+ if (--this.count === 0) {
+ if (tickCounter(500)) {
+ return process.nextTick((function() {
+ return _this.continuation(_this.ret);
+ }));
+ } else {
+ return this.continuation(this.ret);
+ }
+ }
};
Deferrals.prototype.defer = function(args) {
View
22 src/tame.coffee
@@ -40,11 +40,27 @@ makeDeferReturn = (obj, defer_args, id) ->
ret
#-----------------------------------------------------------------------
+#
+# Tick Counter --
+# count off every mod processor ticks
+#
+__c = 0
+
+tickCounter = (mod) ->
+ __c++
+ if (__c % mod) == 0
+ __c = 0
+ true
+ else
+ false
+
+#-----------------------------------------------------------------------
# Deferrals
#
# A collection of Deferrals; this is a better version than the one
# that's inline; it allows for tame tracing
#
+
class Deferrals
constructor: (k) ->
@@ -53,7 +69,11 @@ class Deferrals
@ret = null
_fulfill : ->
- @continuation @ret if --@count == 0
+ if --@count == 0
+ if tickCounter 500
+ process.nextTick (=> @continuation @ret)
+ else
+ @continuation @ret
defer : (args) ->
@count++
View
8 test/tame_advanced.coffee
@@ -64,3 +64,11 @@ if require?
for s in slots
ok = false unless s == 7
cb(ok, {})
+
+##----------------------------------------------------------------------
+
+ atest "stack protector", (cb) ->
+ noop = (cb) -> cb()
+ for i in [0..10000]
+ await noop defer()
+ cb(true, {})
Please sign in to comment.
Something went wrong with that request. Please try again.