-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX LTS] Don't run getters while applying mixins
This change ensures that getters are never evaluated while applying mixins. It relies on the fact that all getters (including undecorated ones) get converted into classic decorators when the mixin is originally created. (cherry picked from commit 87394c4)
- Loading branch information
1 parent
7c84305
commit aa5e4ed
Showing
3 changed files
with
77 additions
and
14 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
packages/@ember/-internals/runtime/tests/mixins/accessor_test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import EmberObject from '@ember/object'; | ||
import { moduleFor, RenderingTestCase } from 'internal-test-helpers'; | ||
|
||
moduleFor( | ||
'runtime: Mixin Accessors', | ||
class extends RenderingTestCase { | ||
['@test works with getters'](assert) { | ||
let value = 'building'; | ||
|
||
let Base = EmberObject.extend({ | ||
get foo() { | ||
if (value === 'building') { | ||
throw Error('base should not be called yet'); | ||
} | ||
|
||
return "base's foo"; | ||
}, | ||
}); | ||
|
||
// force Base to be finalized so its properties will contain `foo` | ||
Base.proto(); | ||
|
||
class Child extends Base { | ||
get foo() { | ||
if (value === 'building') { | ||
throw Error('child should not be called yet'); | ||
} | ||
|
||
return "child's foo"; | ||
} | ||
} | ||
|
||
Child.proto(); | ||
|
||
let Grandchild = Child.extend({ | ||
get foo() { | ||
if (value === 'building') { | ||
throw Error('grandchild should not be called yet'); | ||
} | ||
|
||
return value; | ||
}, | ||
}); | ||
|
||
let instance = Grandchild.create(); | ||
|
||
value = 'done building'; | ||
|
||
assert.equal(instance.foo, 'done building', 'getter defined correctly'); | ||
|
||
value = 'changed value'; | ||
|
||
assert.equal(instance.foo, 'changed value', 'the value is a real getter, not a snapshot'); | ||
} | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters