Skip to content

Commit

Permalink
Merge pull request #18222 from emberjs/bugfix/tracked/match-previous-…
Browse files Browse the repository at this point in the history
…cp-assertion-behavior

[BUGFIX] Matches assertion behavior for CPs computing after destroy
  • Loading branch information
Chris Garrett committed Jul 30, 2019
2 parents e629225 + 7892e34 commit 8179b69
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/@ember/-internals/metal/lib/computed.ts
Expand Up @@ -541,9 +541,11 @@ export class ComputedProperty extends ComputedDescriptor {
let ret;

if (EMBER_METAL_TRACKED_PROPERTIES) {
// For backwards compatibility, we only throw if the CP has any dependencies. CPs without dependencies
// should be allowed, even after the object has been destroyed, which is why we check _dependentKeys.
assert(
`Attempted to access the computed ${obj}.${keyName} on a destroyed object, which is not allowed`,
!metaFor(obj).isMetaDestroyed()
this._dependentKeys === undefined || !metaFor(obj).isMetaDestroyed()
);

// Create a tracker that absorbs any trackable actions inside the CP
Expand Down
17 changes: 17 additions & 0 deletions packages/@ember/-internals/metal/tests/computed_test.js
Expand Up @@ -604,6 +604,23 @@ moduleFor(

expectAssertion(() => get(obj, 'foo'), message);
}

['@test does not throw an assertion if an uncached `get` is called on computed without dependencies after object is destroyed'](
assert
) {
let meta = metaFor(obj);
defineProperty(
obj,
'foo',
computed(function() {
return 'baz';
})
);

meta.destroy();

assert.equal(get(obj, 'foo'), 'baz', 'CP calculated successfully');
}
}
);

Expand Down

0 comments on commit 8179b69

Please sign in to comment.