| 907 | |
| 908 | var baseMaxWorkDepth = 20, reduceMaxWorkDepth = 0.0001; |
| 909 | function withWorklist(f) { |
| 910 | if (cx.workList) return f(cx.workList); |
| 911 | |
| 912 | var list = [], depth = 0; |
| 913 | var add = cx.workList = function(type, target, weight) { |
| 914 | if (depth < baseMaxWorkDepth - reduceMaxWorkDepth * list.length) |
| 915 | list.push(type, target, weight, depth); |
| 916 | }; |
| 917 | var ret = f(add); |
| 918 | for (var i = 0; i < list.length; i += 4) { |
| 919 | if (timeout && +new Date >= timeout) |
| 920 | throw new exports.TimedOut(); |
| 921 | depth = list[i + 3] + 1; |
| 922 | list[i + 1].addType(list[i], list[i + 2]); |
| 923 | } |
| 924 | cx.workList = null; |
| 925 | return ret; |
| 926 | } |
| 927 | |
| 928 | function withSuper(ctor, obj, f) { |
| 929 | var oldCtor = cx.curSuperCtor, oldObj = cx.curSuper; |