Skip to content

Commit dbba9bb

Browse files
Merge pull request #144 from canjs/default-value-setter-infinite-loop
Default value setter infinite loop
2 parents 77e22d6 + b528502 commit dbba9bb

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ language: node_js
33
node_js: node
44
before_install:
55
- "export DISPLAY=:99.0"
6-
- "sh -e /etc/init.d/xvfb start"
6+
- "sh -e /etc/init.d/xvfb start"
7+
addons:
8+
firefox: "latest"

can-define.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,10 @@ replaceWith = function(obj, prop, cb, writable) {
626626
Object.defineProperty(obj, prop, {
627627
configurable: true,
628628
get: function() {
629+
Object.defineProperty(this, prop, {
630+
value: undefined,
631+
writable: true
632+
});
629633
var value = cb.call(this, obj, prop);
630634
Object.defineProperty(this, prop, {
631635
value: value,

define-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,3 +1489,18 @@ QUnit.test("async setter is provided", 5, function(){
14891489
QUnit.equal(instance.prop2, 9, "used async setter updates after");
14901490

14911491
});
1492+
1493+
QUnit.test('setter with default value causes an infinite loop (#142)', function(){
1494+
var A = define.Constructor({
1495+
val: {
1496+
value: 'hello',
1497+
set: function(val){
1498+
if(this.val) {}
1499+
return val;
1500+
}
1501+
}
1502+
});
1503+
1504+
var a = new A();
1505+
QUnit.equal(a.val, 'hello', 'creating an instance should not cause an inifinte loop');
1506+
});

0 commit comments

Comments
 (0)