| OLD | NEW | 
|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. | 
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without | 
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are | 
| 4 // met: | 4 // met: | 
| 5 // | 5 // | 
| 6 //     * Redistributions of source code must retain the above copyright | 6 //     * Redistributions of source code must retain the above copyright | 
| 7 //       notice, this list of conditions and the following disclaimer. | 7 //       notice, this list of conditions and the following disclaimer. | 
| 8 //     * Redistributions in binary form must reproduce the above | 8 //     * Redistributions in binary form must reproduce the above | 
| 9 //       copyright notice, this list of conditions and the following | 9 //       copyright notice, this list of conditions and the following | 
| 10 //       disclaimer in the documentation and/or other materials provided | 10 //       disclaimer in the documentation and/or other materials provided | 
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 138 assertTrue(notifyDesc.configurable); | 138 assertTrue(notifyDesc.configurable); | 
| 139 assertTrue(notifyDesc.writable); | 139 assertTrue(notifyDesc.writable); | 
| 140 assertFalse(notifyDesc.enumerable); | 140 assertFalse(notifyDesc.enumerable); | 
| 141 assertThrows(function() { notifier.notify({}); }, TypeError); | 141 assertThrows(function() { notifier.notify({}); }, TypeError); | 
| 142 assertThrows(function() { notifier.notify({ type: 4 }); }, TypeError); | 142 assertThrows(function() { notifier.notify({ type: 4 }); }, TypeError); | 
| 143 | 143 | 
| 144 assertThrows(function() { notifier.performChange(1, function(){}); }, TypeError)
      ; | 144 assertThrows(function() { notifier.performChange(1, function(){}); }, TypeError)
      ; | 
| 145 assertThrows(function() { notifier.performChange(undefined, function(){}); }, Ty
      peError); | 145 assertThrows(function() { notifier.performChange(undefined, function(){}); }, Ty
      peError); | 
| 146 assertThrows(function() { notifier.performChange('foo', undefined); }, TypeError
      ); | 146 assertThrows(function() { notifier.performChange('foo', undefined); }, TypeError
      ); | 
| 147 assertThrows(function() { notifier.performChange('foo', 'bar'); }, TypeError); | 147 assertThrows(function() { notifier.performChange('foo', 'bar'); }, TypeError); | 
| 148 var testSelf = {}; |  | 
| 149 notifier.performChange('foo', function() { | 148 notifier.performChange('foo', function() { | 
| 150   assertTrue(testSelf === this); | 149   assertEquals(undefined, this); | 
| 151 }, testSelf); |  | 
| 152 var self = this; |  | 
| 153 notifier.performChange('foo', function() { |  | 
| 154   assertTrue(self === this); |  | 
| 155 }); | 150 }); | 
| 156 | 151 | 
| 157 var notify = notifier.notify; | 152 var notify = notifier.notify; | 
| 158 assertThrows(function() { notify.call(undefined, { type: 'a' }); }, TypeError); | 153 assertThrows(function() { notify.call(undefined, { type: 'a' }); }, TypeError); | 
| 159 assertThrows(function() { notify.call(null, { type: 'a' }); }, TypeError); | 154 assertThrows(function() { notify.call(null, { type: 'a' }); }, TypeError); | 
| 160 assertThrows(function() { notify.call(5, { type: 'a' }); }, TypeError); | 155 assertThrows(function() { notify.call(5, { type: 'a' }); }, TypeError); | 
| 161 assertThrows(function() { notify.call('hello', { type: 'a' }); }, TypeError); | 156 assertThrows(function() { notify.call('hello', { type: 'a' }); }, TypeError); | 
| 162 assertThrows(function() { notify.call(false, { type: 'a' }); }, TypeError); | 157 assertThrows(function() { notify.call(false, { type: 'a' }); }, TypeError); | 
| 163 assertThrows(function() { notify.call({}, { type: 'a' }); }, TypeError); | 158 assertThrows(function() { notify.call({}, { type: 'a' }); }, TypeError); | 
| 164 assertFalse(recordCreated); | 159 assertFalse(recordCreated); | 
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 393 } | 388 } | 
| 394 | 389 | 
| 395 Thingy.MULTIPLY = 'multiply'; | 390 Thingy.MULTIPLY = 'multiply'; | 
| 396 Thingy.INCREMENT = 'increment'; | 391 Thingy.INCREMENT = 'increment'; | 
| 397 Thingy.INCREMENT_AND_MULTIPLY = 'incrementAndMultiply'; | 392 Thingy.INCREMENT_AND_MULTIPLY = 'incrementAndMultiply'; | 
| 398 | 393 | 
| 399 Thingy.prototype = { | 394 Thingy.prototype = { | 
| 400   increment: function(amount) { | 395   increment: function(amount) { | 
| 401     var notifier = Object.getNotifier(this); | 396     var notifier = Object.getNotifier(this); | 
| 402 | 397 | 
|  | 398     var self = this; | 
| 403     notifier.performChange(Thingy.INCREMENT, function() { | 399     notifier.performChange(Thingy.INCREMENT, function() { | 
| 404       this.a += amount; | 400       self.a += amount; | 
| 405       this.b += amount; | 401       self.b += amount; | 
| 406     }, this); | 402     }); | 
| 407 | 403 | 
| 408     notifier.notify({ | 404     notifier.notify({ | 
| 409       object: this, | 405       object: this, | 
| 410       type: Thingy.INCREMENT, | 406       type: Thingy.INCREMENT, | 
| 411       incremented: amount | 407       incremented: amount | 
| 412     }); | 408     }); | 
| 413   }, | 409   }, | 
| 414 | 410 | 
| 415   multiply: function(amount) { | 411   multiply: function(amount) { | 
| 416     var notifier = Object.getNotifier(this); | 412     var notifier = Object.getNotifier(this); | 
| 417 | 413 | 
|  | 414     var self = this; | 
| 418     notifier.performChange(Thingy.MULTIPLY, function() { | 415     notifier.performChange(Thingy.MULTIPLY, function() { | 
| 419       this.a *= amount; | 416       self.a *= amount; | 
| 420       this.b *= amount; | 417       self.b *= amount; | 
| 421     }, this); | 418     }); | 
| 422 | 419 | 
| 423     notifier.notify({ | 420     notifier.notify({ | 
| 424       object: this, | 421       object: this, | 
| 425       type: Thingy.MULTIPLY, | 422       type: Thingy.MULTIPLY, | 
| 426       multiplied: amount | 423       multiplied: amount | 
| 427     }); | 424     }); | 
| 428   }, | 425   }, | 
| 429 | 426 | 
| 430   incrementAndMultiply: function(incAmount, multAmount) { | 427   incrementAndMultiply: function(incAmount, multAmount) { | 
| 431     var notifier = Object.getNotifier(this); | 428     var notifier = Object.getNotifier(this); | 
| 432 | 429 | 
|  | 430     var self = this; | 
| 433     notifier.performChange(Thingy.INCREMENT_AND_MULTIPLY, function() { | 431     notifier.performChange(Thingy.INCREMENT_AND_MULTIPLY, function() { | 
| 434       this.increment(incAmount); | 432       self.increment(incAmount); | 
| 435       this.multiply(multAmount); | 433       self.multiply(multAmount); | 
| 436     }, this); | 434     }); | 
| 437 | 435 | 
| 438     notifier.notify({ | 436     notifier.notify({ | 
| 439       object: this, | 437       object: this, | 
| 440       type: Thingy.INCREMENT_AND_MULTIPLY, | 438       type: Thingy.INCREMENT_AND_MULTIPLY, | 
| 441       incremented: incAmount, | 439       incremented: incAmount, | 
| 442       multiplied: multAmount | 440       multiplied: multAmount | 
| 443     }); | 441     }); | 
| 444   } | 442   } | 
| 445 } | 443 } | 
| 446 | 444 | 
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 498 | 496 | 
| 499 RecursiveThingy.MULTIPLY_FIRST_N = 'multiplyFirstN'; | 497 RecursiveThingy.MULTIPLY_FIRST_N = 'multiplyFirstN'; | 
| 500 | 498 | 
| 501 RecursiveThingy.prototype = { | 499 RecursiveThingy.prototype = { | 
| 502   __proto__: Array.prototype, | 500   __proto__: Array.prototype, | 
| 503 | 501 | 
| 504   multiplyFirstN: function(amount, n) { | 502   multiplyFirstN: function(amount, n) { | 
| 505     if (!n) | 503     if (!n) | 
| 506       return; | 504       return; | 
| 507     var notifier = Object.getNotifier(this); | 505     var notifier = Object.getNotifier(this); | 
|  | 506     var self = this; | 
| 508     notifier.performChange(RecursiveThingy.MULTIPLY_FIRST_N, function() { | 507     notifier.performChange(RecursiveThingy.MULTIPLY_FIRST_N, function() { | 
| 509       this[n-1] = this[n-1]*amount; | 508       self[n-1] = self[n-1]*amount; | 
| 510       this.multiplyFirstN(amount, n-1); | 509       self.multiplyFirstN(amount, n-1); | 
| 511     }, this); | 510     }); | 
| 512 | 511 | 
| 513     notifier.notify({ | 512     notifier.notify({ | 
| 514       object: this, | 513       object: this, | 
| 515       type: RecursiveThingy.MULTIPLY_FIRST_N, | 514       type: RecursiveThingy.MULTIPLY_FIRST_N, | 
| 516       multiplied: amount, | 515       multiplied: amount, | 
| 517       n: n | 516       n: n | 
| 518     }); | 517     }); | 
| 519   }, | 518   }, | 
| 520 } | 519 } | 
| 521 | 520 | 
| (...skipping 28 matching lines...) Expand all  Loading... | 
| 550   this.push('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'A', 'Q', 'K'); | 549   this.push('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'A', 'Q', 'K'); | 
| 551 } | 550 } | 
| 552 | 551 | 
| 553 DeckSuit.SHUFFLE = 'shuffle'; | 552 DeckSuit.SHUFFLE = 'shuffle'; | 
| 554 | 553 | 
| 555 DeckSuit.prototype = { | 554 DeckSuit.prototype = { | 
| 556   __proto__: Array.prototype, | 555   __proto__: Array.prototype, | 
| 557 | 556 | 
| 558   shuffle: function() { | 557   shuffle: function() { | 
| 559     var notifier = Object.getNotifier(this); | 558     var notifier = Object.getNotifier(this); | 
|  | 559     var self = this; | 
| 560     notifier.performChange(DeckSuit.SHUFFLE, function() { | 560     notifier.performChange(DeckSuit.SHUFFLE, function() { | 
| 561       this.reverse(); | 561       self.reverse(); | 
| 562       this.sort(function() { return Math.random()* 2 - 1; }); | 562       self.sort(function() { return Math.random()* 2 - 1; }); | 
| 563       var cut = this.splice(0, 6); | 563       var cut = self.splice(0, 6); | 
| 564       Array.prototype.push.apply(this, cut); | 564       Array.prototype.push.apply(self, cut); | 
| 565       this.reverse(); | 565       self.reverse(); | 
| 566       this.sort(function() { return Math.random()* 2 - 1; }); | 566       self.sort(function() { return Math.random()* 2 - 1; }); | 
| 567       var cut = this.splice(0, 6); | 567       var cut = self.splice(0, 6); | 
| 568       Array.prototype.push.apply(this, cut); | 568       Array.prototype.push.apply(self, cut); | 
| 569       this.reverse(); | 569       self.reverse(); | 
| 570       this.sort(function() { return Math.random()* 2 - 1; }); | 570       self.sort(function() { return Math.random()* 2 - 1; }); | 
| 571     }, this); | 571     }); | 
| 572 | 572 | 
| 573     notifier.notify({ | 573     notifier.notify({ | 
| 574       object: this, | 574       object: this, | 
| 575       type: DeckSuit.SHUFFLE | 575       type: DeckSuit.SHUFFLE | 
| 576     }); | 576     }); | 
| 577   }, | 577   }, | 
| 578 } | 578 } | 
| 579 | 579 | 
| 580 DeckSuit.observe = function(thingy, callback) { | 580 DeckSuit.observe = function(thingy, callback) { | 
| 581   Object.observe(thingy, callback, [DeckSuit.SHUFFLE]); | 581   Object.observe(thingy, callback, [DeckSuit.SHUFFLE]); | 
| (...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1525     for (var n1 = 0; n1 < 3; ++n1) | 1525     for (var n1 = 0; n1 < 3; ++n1) | 
| 1526       for (var n2 = 0; n2 < 3; ++n2) | 1526       for (var n2 = 0; n2 < 3; ++n2) | 
| 1527         for (var i in mutation) | 1527         for (var i in mutation) | 
| 1528           TestFastElementsLength(mutation[i], b1 != 0, b2 != 0, 20*n1, 20*n2); | 1528           TestFastElementsLength(mutation[i], b1 != 0, b2 != 0, 20*n1, 20*n2); | 
| 1529 | 1529 | 
| 1530 for (var b1 = 0; b1 < 2; ++b1) | 1530 for (var b1 = 0; b1 < 2; ++b1) | 
| 1531   for (var b2 = 0; b2 < 2; ++b2) | 1531   for (var b2 = 0; b2 < 2; ++b2) | 
| 1532     for (var n = 0; n < 3; ++n) | 1532     for (var n = 0; n < 3; ++n) | 
| 1533       for (var i in mutationByIncr) | 1533       for (var i in mutationByIncr) | 
| 1534         TestFastElementsLength(mutationByIncr[i], b1 != 0, b2 != 0, 7*n, 7*n+1); | 1534         TestFastElementsLength(mutationByIncr[i], b1 != 0, b2 != 0, 7*n, 7*n+1); | 
| OLD | NEW | 
|---|