Skip to content

Commit c62bcce

Browse files
authored
Merge pull request #505 from glimmerjs/maybe-fix
[BUGFIX #484] ensure transactions are always.
2 parents 414f9be + 34e2009 commit c62bcce

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

packages/@glimmer/runtime/lib/environment.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ export abstract class Environment {
330330
}
331331

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

@@ -359,8 +359,9 @@ export abstract class Environment {
359359
}
360360

361361
commit() {
362-
this.transaction.commit();
362+
let transaction = this.transaction;
363363
this._transaction = null;
364+
transaction.commit();
364365
}
365366

366367
attributeFor(element: Simple.Element, attr: string, isTrusting: boolean, namespace?: string): AttributeManager {
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { TestEnvironment } from "@glimmer/test-helpers";
2+
3+
QUnit.module('env');
4+
5+
QUnit.test('assert against nested transactions', assert => {
6+
let env = new TestEnvironment();
7+
env.begin();
8+
assert.throws(() => env.begin(), 'a glimmer transaction was begun, but one already exists. You may have a nested transaction');
9+
});
10+
11+
QUnit.test('ensure commit cleans up when it can', assert => {
12+
let env = new TestEnvironment();
13+
env.begin();
14+
15+
// ghetto stub
16+
Object.defineProperty(env, 'transaction', {
17+
get() {
18+
return {
19+
scheduledInstallManagers() : void { },
20+
commit() : void {
21+
throw new Error('something failed');
22+
}
23+
};
24+
}
25+
});
26+
27+
assert.throws(() => env.commit(), 'something failed'); // commit failed
28+
29+
// but a previous commit failing, does not cause a future transaction to fail to start
30+
env.begin();
31+
});

0 commit comments

Comments
 (0)