diff options
author | Graeme Yeates <yeatesgraeme@gmail.com> | 2016-05-05 10:07:32 -0400 |
---|---|---|
committer | Graeme Yeates <yeatesgraeme@gmail.com> | 2016-05-05 10:07:32 -0400 |
commit | 0f1f2844ab4931188f378badbf401573b46b72e1 (patch) | |
tree | 6d0fe106b1d81726afe40439e169491ea27d8b2a /lib | |
parent | 19585c1717f9694ef685af4adf1c96835c3ddfba (diff) | |
parent | d9a03388149e2dbfb23a3095910a707a836ca5d2 (diff) | |
download | async-0f1f2844ab4931188f378badbf401573b46b72e1.tar.gz |
Merge pull request #1142 from ezubarev/master
Make once and onlyOnce exception safe
Diffstat (limited to 'lib')
-rw-r--r-- | lib/internal/once.js | 3 | ||||
-rw-r--r-- | lib/internal/onlyOnce.js | 3 |
2 files changed, 4 insertions, 2 deletions
diff --git a/lib/internal/once.js b/lib/internal/once.js index 11678dc..f601185 100644 --- a/lib/internal/once.js +++ b/lib/internal/once.js @@ -1,7 +1,8 @@ export default function once(fn) { return function () { if (fn === null) return; - fn.apply(this, arguments); + var callFn = fn; fn = null; + callFn.apply(this, arguments); }; } diff --git a/lib/internal/onlyOnce.js b/lib/internal/onlyOnce.js index f4241c8..355ff41 100644 --- a/lib/internal/onlyOnce.js +++ b/lib/internal/onlyOnce.js @@ -3,7 +3,8 @@ export default function onlyOnce(fn) { return function() { if (fn === null) throw new Error("Callback was already called."); - fn.apply(this, arguments); + var callFn = fn; fn = null; + callFn.apply(this, arguments); }; } |