From 39930dcbcc3c28585562b9286391f7a153d88df9 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Mon, 9 Jul 2018 12:42:44 -0400 Subject: [PATCH] in .fire always set calling flag back to false (#1573) --- src/shared/index.js | 9 +++++--- .../component-events-fire-finally/_config.js | 23 +++++++++++++++++++ .../component-events-fire-finally/main.html | 1 + 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 test/runtime/samples/component-events-fire-finally/_config.js create mode 100644 test/runtime/samples/component-events-fire-finally/main.html diff --git a/src/shared/index.js b/src/shared/index.js index 4d0e7896c6..e4c71046e3 100644 --- a/src/shared/index.js +++ b/src/shared/index.js @@ -47,9 +47,12 @@ export function fire(eventName, data) { var handler = handlers[i]; if (!handler.__calling) { - handler.__calling = true; - handler.call(this, data); - handler.__calling = false; + try { + handler.__calling = true; + handler.call(this, data); + } finally { + handler.__calling = false; + } } } } diff --git a/test/runtime/samples/component-events-fire-finally/_config.js b/test/runtime/samples/component-events-fire-finally/_config.js new file mode 100644 index 0000000000..f768f5608b --- /dev/null +++ b/test/runtime/samples/component-events-fire-finally/_config.js @@ -0,0 +1,23 @@ +export default { + test(assert, component) { + const events = []; + component.on('foo', (shouldThrow) => { + events.push(shouldThrow); + if (shouldThrow) { + throw new Error(); + } + }); + component.fire('foo', false); + assert.equal(events.toString(), 'false'); + let threw = false; + try { + component.fire('foo', true); + } catch (err) { + threw = true; + } + assert.equal(threw, true); + assert.equal(events.toString(), 'false,true'); + component.fire('foo', false); + assert.equal(events.toString(), 'false,true,false'); + }, +}; diff --git a/test/runtime/samples/component-events-fire-finally/main.html b/test/runtime/samples/component-events-fire-finally/main.html new file mode 100644 index 0000000000..bc56c4d894 --- /dev/null +++ b/test/runtime/samples/component-events-fire-finally/main.html @@ -0,0 +1 @@ +Foo