Skip to content

Commit

Permalink
[BUGFIX beta] Prevent infinite cycles from lazy computed compu… (#18406)
Browse files Browse the repository at this point in the history
[BUGFIX beta] Prevent infinite cycles from lazy computed computation
  • Loading branch information
rwjblue authored Sep 18, 2019
2 parents d4df158 + ca22291 commit 338cfa6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/@ember/-internals/metal/lib/computed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,6 @@ export class ComputedProperty extends ComputedDescriptor {
});
}

finishLazyChains(obj, keyName, ret);

if (this._dependentKeys !== undefined) {
let tag = combine(getChainTagsForKeys(obj, this._dependentKeys));

Expand All @@ -565,6 +563,10 @@ export class ComputedProperty extends ComputedDescriptor {
}

setLastRevisionFor(obj, keyName, tagValue(propertyTag));

cache.set(keyName, ret);

finishLazyChains(obj, keyName, ret);
}

consume(propertyTag!);
Expand All @@ -575,8 +577,6 @@ export class ComputedProperty extends ComputedDescriptor {
consume(tagForProperty(ret, '[]'));
}

cache.set(keyName, ret);

return ret;
} else {
if (cache.has(keyName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,5 +497,26 @@ moduleFor(
set(options.objectAt(0), 'value', 'bar');
assert.deepEqual(n.normalized, ['bar']);
}

['@test lazy computation cannot cause infinite cycles'](assert) {
// This is based off a real world bug found in ember-cp-validations:
// https://github.com/offirgolan/ember-cp-validations/issues/659
let CycleObject = EmberObject.extend({
foo: computed(function() {
return EmberObject.extend({
parent: this,
alias: alias('parent.foo'),
}).create();
}),
bar: computed('foo.alias', () => {}),
});

let obj = CycleObject.create();

obj.bar;
obj.foo;

assert.ok(true);
}
}
);

0 comments on commit 338cfa6

Please sign in to comment.