Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Matches assertion behavior for CPs computing after destroy #18222

Merged
merged 2 commits into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/@ember/-internals/metal/lib/computed.ts
Original file line number Diff line number Diff line change
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()
pzuraq marked this conversation as resolved.
Show resolved Hide resolved
);

// 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
Original file line number Diff line number Diff line change
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