Skip to content

Commit

Permalink
Merge pull request #505 from glimmerjs/maybe-fix
Browse files Browse the repository at this point in the history
[BUGFIX #484] ensure transactions are always.
  • Loading branch information
stefanpenner authored May 25, 2017
2 parents 414f9be + 34e2009 commit c62bcce
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/@glimmer/runtime/lib/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export abstract class Environment {
}

begin() {
assert(!this._transaction, 'Cannot start a nested transaction');
assert(!this._transaction, 'a glimmer transaction was begun, but one already exists. You may have a nested transaction');
this._transaction = new Transaction();
}

Expand Down Expand Up @@ -359,8 +359,9 @@ export abstract class Environment {
}

commit() {
this.transaction.commit();
let transaction = this.transaction;
this._transaction = null;
transaction.commit();
}

attributeFor(element: Simple.Element, attr: string, isTrusting: boolean, namespace?: string): AttributeManager {
Expand Down
31 changes: 31 additions & 0 deletions packages/@glimmer/runtime/test/env-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { TestEnvironment } from "@glimmer/test-helpers";

QUnit.module('env');

QUnit.test('assert against nested transactions', assert => {
let env = new TestEnvironment();
env.begin();
assert.throws(() => env.begin(), 'a glimmer transaction was begun, but one already exists. You may have a nested transaction');
});

QUnit.test('ensure commit cleans up when it can', assert => {
let env = new TestEnvironment();
env.begin();

// ghetto stub
Object.defineProperty(env, 'transaction', {
get() {
return {
scheduledInstallManagers() : void { },
commit() : void {
throw new Error('something failed');
}
};
}
});

assert.throws(() => env.commit(), 'something failed'); // commit failed

// but a previous commit failing, does not cause a future transaction to fail to start
env.begin();
});

0 comments on commit c62bcce

Please sign in to comment.