From 47211cb46d19b4e78eefc74775710cf885da22b9 Mon Sep 17 00:00:00 2001 From: Avital Oliver Date: Tue, 3 Jun 2014 16:54:56 -0700 Subject: [PATCH] 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. --- packages/deps/deps.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/packages/deps/deps.js b/packages/deps/deps.js index d05ad80052..4192f9236c 100644 --- a/packages/deps/deps.js +++ b/packages/deps/deps.js @@ -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;