diff options
author | Zubarev Evgeny <zubarev.eugene@gmail.com> | 2016-05-04 20:34:12 +0600 |
---|---|---|
committer | Zubarev Evgeny <zubarev.eugene@gmail.com> | 2016-05-04 20:34:12 +0600 |
commit | a1b8d048963e99e9a9ff5c4a570a103707e303ba (patch) | |
tree | 73772934ed22f6db13188b5ffbd82ed3c7f948ba /lib | |
parent | 77f6a80a049ce070476c7031ca79a400bee83d33 (diff) | |
download | async-a1b8d048963e99e9a9ff5c4a570a103707e303ba.tar.gz |
Make once and onlyOnce exception safe
More details in issue#1106
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); }; } |