Skip to content

Commit

Permalink
Merge pull request #1119 from glimmerjs/destroyable-assertion-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue authored Jul 26, 2020
2 parents 5dd31bd + 0f1f12e commit 07577d9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/@glimmer/runtime/lib/destroyables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,15 @@ export function setScheduleDestroyed(fn: (fn: () => void) => void) {
}

export function isDestroying(destroyable: Destroyable) {
return getDestroyableMeta(destroyable).state >= DestroyingState.Destroying;
let meta = DESTROYABLE_META.get(destroyable);

return meta === undefined ? false : meta.state >= DestroyingState.Destroying;
}

export function isDestroyed(destroyable: Destroyable) {
return getDestroyableMeta(destroyable).state === DestroyingState.Destroyed;
let meta = DESTROYABLE_META.get(destroyable);

return meta === undefined ? false : meta.state >= DestroyingState.Destroyed;
}

////////////
Expand Down
22 changes: 22 additions & 0 deletions packages/@glimmer/runtime/test/destroyables-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,28 @@ module('Destroyables', hooks => {
assertDestroyablesDestroyed!();
});

test('checking isDestroying does not trigger assertion', assert => {
assert.expect(1);
enableDestroyableTracking!();

let obj = {};

isDestroying(obj);

assertDestroyablesDestroyed!();
});

test('checking isDestroyed does not trigger assertion', assert => {
assert.expect(1);
enableDestroyableTracking!();

let obj = {};

isDestroyed(obj);

assertDestroyablesDestroyed!();
});

test('attempting to call assertDestroyablesDestroyed() before calling enableDestroyableTracking() throws', assert => {
assert.throws(() => {
assertDestroyablesDestroyed!();
Expand Down

0 comments on commit 07577d9

Please sign in to comment.