Remove one unhelpful stack frame from Deps

Instead of `callWithNoYieldsAllowed` which calls a function
within (introducing a new stack frame that doesn't absolutely
nothing on the client), we now use `withNoYieldsAllowed` that
returns a new function that then gets called.

Since Deps is used all over the place, and in particular
in Blaze, this makes it much easier to look at the stack
trace when stopping in a debugger (for example, when a helper
gets re-executed).

Motivated by the Blaze manual.
This commit is contained in:
Avital Oliver
2014-06-03 16:54:56 -07:00
parent b1781939a9
commit 47211cb46d

View File

@@ -44,17 +44,21 @@ var _throwOrLog = function (from, e) {
}
};
// Like `Meteor._noYieldsAllowed(function () { f(comp); })` but shorter,
// and doesn't clutter the stack with an extra frame on the client,
// where `_noYieldsAllowed` is a no-op. `f` may be a computation
// function or an onInvalidate callback.
var callWithNoYieldsAllowed = function (f, comp) {
// Takes a function `f`, and wraps it in a `Meteor._noYieldsAllowed`
// block if we are running on the server. On the client, returns the
// original function (since `Meteor._noYieldsAllowed` is a
// no-op). This has the benefit of not adding an unnecessary stack
// frame on the client.
var withNoYieldsAllowed = function (f) {
if ((typeof Meteor === 'undefined') || Meteor.isClient) {
f(comp);
return f;
} else {
Meteor._noYieldsAllowed(function () {
f(comp);
});
return function () {
var args = arguments;
Meteor._noYieldsAllowed(function () {
f.apply(null, args);
});
};
}
};
@@ -140,7 +144,7 @@ _assign(Deps.Computation.prototype, {
if (self.invalidated) {
Deps.nonreactive(function () {
callWithNoYieldsAllowed(f, self);
withNoYieldsAllowed(f)(self);
});
} else {
self._onInvalidateCallbacks.push(f);
@@ -164,7 +168,7 @@ _assign(Deps.Computation.prototype, {
// self.invalidated === true.
for(var i = 0, f; f = self._onInvalidateCallbacks[i]; i++) {
Deps.nonreactive(function () {
callWithNoYieldsAllowed(f, self);
withNoYieldsAllowed(f)(self);
});
}
self._onInvalidateCallbacks = [];
@@ -188,7 +192,7 @@ _assign(Deps.Computation.prototype, {
var previousInCompute = inCompute;
inCompute = true;
try {
callWithNoYieldsAllowed(self._func, self);
withNoYieldsAllowed(self._func)(self);
} finally {
setCurrentComputation(previous);
inCompute = false;