fable 3.0.103 → 3.0.104

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fable",
3
- "version": "3.0.103",
3
+ "version": "3.0.104",
4
4
  "description": "An entity behavior management and API bundling library.",
5
5
  "main": "source/Fable.js",
6
6
  "scripts": {
@@ -15,6 +15,8 @@ class FableServiceAnticipate extends libFableServiceBase
15
15
  this.executingOperationCount = 0;
16
16
  this.completedOperationCount = 0;
17
17
 
18
+ this.callDepth = 0;
19
+
18
20
  this.maxOperations = 1;
19
21
 
20
22
  this.lastError = undefined;
@@ -60,8 +62,8 @@ class FableServiceAnticipate extends libFableServiceBase
60
62
  Called: false,
61
63
  Error: undefined,
62
64
  OperationSet: this
63
- });
64
- return hoistedCallback;
65
+ });
66
+ return hoistedCallback.bind(this);
65
67
  function hoistedCallback(pError)
66
68
  {
67
69
  if (tmpCallbackState.Called)
@@ -75,7 +77,18 @@ class FableServiceAnticipate extends libFableServiceBase
75
77
  tmpCallbackState.OperationSet.executingOperationCount -= 1;
76
78
  tmpCallbackState.OperationSet.completedOperationCount += 1;
77
79
 
78
- tmpCallbackState.OperationSet.checkQueue();
80
+ tmpCallbackState.OperationSet.callDepth++;
81
+
82
+ // TODO: Figure out a better pattern for chaining templates so the call stack doesn't get abused.
83
+ if (tmpCallbackState.OperationSet.callDepth > 400)
84
+ {
85
+ tmpCallbackState.OperationSet.callDepth = 0;
86
+ setTimeout(tmpCallbackState.OperationSet.checkQueue.bind(this), 0);
87
+ }
88
+ else
89
+ {
90
+ tmpCallbackState.OperationSet.checkQueue();
91
+ }
79
92
  }
80
93
  }
81
94
 
@@ -85,6 +85,30 @@ suite
85
85
  });
86
86
  }
87
87
  );
88
+ test
89
+ (
90
+ 'Huge call stack',
91
+ function (fTestComplete)
92
+ {
93
+ this.timeout(10000);
94
+ let testFable = new libFable();
95
+ let tmpAnticipate = testFable.instantiateServiceProvider('Anticipate');
96
+
97
+ for (let i = 0; i < 50000; i++)
98
+ {
99
+ tmpAnticipate.anticipate(function (fCallback)
100
+ {
101
+ return fCallback();
102
+ });
103
+ }
104
+
105
+ tmpAnticipate.wait(function (pError)
106
+ {
107
+ testFable.log.info(`Waits completed!`)
108
+ return fTestComplete();
109
+ });
110
+ }
111
+ );
88
112
  }
89
113
  );
90
114
  }