| 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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 Thingy.INCREMENT_AND_MULTIPLY = 'incrementAndMultiply'; | 427 Thingy.INCREMENT_AND_MULTIPLY = 'incrementAndMultiply'; |
| 428 | 428 |
| 429 Thingy.prototype = { | 429 Thingy.prototype = { |
| 430 increment: function(amount) { | 430 increment: function(amount) { |
| 431 var notifier = Object.getNotifier(this); | 431 var notifier = Object.getNotifier(this); |
| 432 | 432 |
| 433 var self = this; | 433 var self = this; |
| 434 notifier.performChange(Thingy.INCREMENT, function() { | 434 notifier.performChange(Thingy.INCREMENT, function() { |
| 435 self.a += amount; | 435 self.a += amount; |
| 436 self.b += amount; | 436 self.b += amount; |
| 437 }); | |
| 438 | 437 |
| 439 notifier.notify({ | 438 return { |
| 440 object: this, | 439 incremented: amount |
| 441 type: Thingy.INCREMENT, | 440 }; // implicit notify |
| 442 incremented: amount | |
| 443 }); | 441 }); |
| 444 }, | 442 }, |
| 445 | 443 |
| 446 multiply: function(amount) { | 444 multiply: function(amount) { |
| 447 var notifier = Object.getNotifier(this); | 445 var notifier = Object.getNotifier(this); |
| 448 | 446 |
| 449 var self = this; | 447 var self = this; |
| 450 notifier.performChange(Thingy.MULTIPLY, function() { | 448 notifier.performChange(Thingy.MULTIPLY, function() { |
| 451 self.a *= amount; | 449 self.a *= amount; |
| 452 self.b *= amount; | 450 self.b *= amount; |
| 453 }); | |
| 454 | 451 |
| 455 notifier.notify({ | 452 return { |
| 456 object: this, | 453 multiplied: amount |
| 457 type: Thingy.MULTIPLY, | 454 }; // implicit notify |
| 458 multiplied: amount | |
| 459 }); | 455 }); |
| 460 }, | 456 }, |
| 461 | 457 |
| 462 incrementAndMultiply: function(incAmount, multAmount) { | 458 incrementAndMultiply: function(incAmount, multAmount) { |
| 463 var notifier = Object.getNotifier(this); | 459 var notifier = Object.getNotifier(this); |
| 464 | 460 |
| 465 var self = this; | 461 var self = this; |
| 466 notifier.performChange(Thingy.INCREMENT_AND_MULTIPLY, function() { | 462 notifier.performChange(Thingy.INCREMENT_AND_MULTIPLY, function() { |
| 467 self.increment(incAmount); | 463 self.increment(incAmount); |
| 468 self.multiply(multAmount); | 464 self.multiply(multAmount); |
| 469 }); | |
| 470 | 465 |
| 471 notifier.notify({ | 466 return { |
| 472 object: this, | 467 incremented: incAmount, |
| 473 type: Thingy.INCREMENT_AND_MULTIPLY, | 468 multiplied: multAmount |
| 474 incremented: incAmount, | 469 }; // implicit notify |
| 475 multiplied: multAmount | |
| 476 }); | 470 }); |
| 477 } | 471 } |
| 478 } | 472 } |
| 479 | 473 |
| 480 Thingy.observe = function(thingy, callback) { | 474 Thingy.observe = function(thingy, callback) { |
| 481 Object.observe(thingy, callback, [Thingy.INCREMENT, | 475 Object.observe(thingy, callback, [Thingy.INCREMENT, |
| 482 Thingy.MULTIPLY, | 476 Thingy.MULTIPLY, |
| 483 Thingy.INCREMENT_AND_MULTIPLY, | 477 Thingy.INCREMENT_AND_MULTIPLY, |
| 484 'updated']); | 478 'updated']); |
| 485 } | 479 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 if (!n) | 532 if (!n) |
| 539 return; | 533 return; |
| 540 var notifier = Object.getNotifier(this); | 534 var notifier = Object.getNotifier(this); |
| 541 var self = this; | 535 var self = this; |
| 542 notifier.performChange(RecursiveThingy.MULTIPLY_FIRST_N, function() { | 536 notifier.performChange(RecursiveThingy.MULTIPLY_FIRST_N, function() { |
| 543 self[n-1] = self[n-1]*amount; | 537 self[n-1] = self[n-1]*amount; |
| 544 self.multiplyFirstN(amount, n-1); | 538 self.multiplyFirstN(amount, n-1); |
| 545 }); | 539 }); |
| 546 | 540 |
| 547 notifier.notify({ | 541 notifier.notify({ |
| 548 object: this, | |
| 549 type: RecursiveThingy.MULTIPLY_FIRST_N, | 542 type: RecursiveThingy.MULTIPLY_FIRST_N, |
| 550 multiplied: amount, | 543 multiplied: amount, |
| 551 n: n | 544 n: n |
| 552 }); | 545 }); |
| 553 }, | 546 }, |
| 554 } | 547 } |
| 555 | 548 |
| 556 RecursiveThingy.observe = function(thingy, callback) { | 549 RecursiveThingy.observe = function(thingy, callback) { |
| 557 Object.observe(thingy, callback, [RecursiveThingy.MULTIPLY_FIRST_N]); | 550 Object.observe(thingy, callback, [RecursiveThingy.MULTIPLY_FIRST_N]); |
| 558 } | 551 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 Array.prototype.push.apply(self, cut); | 592 Array.prototype.push.apply(self, cut); |
| 600 self.reverse(); | 593 self.reverse(); |
| 601 self.sort(function() { return Math.random()* 2 - 1; }); | 594 self.sort(function() { return Math.random()* 2 - 1; }); |
| 602 var cut = self.splice(0, 6); | 595 var cut = self.splice(0, 6); |
| 603 Array.prototype.push.apply(self, cut); | 596 Array.prototype.push.apply(self, cut); |
| 604 self.reverse(); | 597 self.reverse(); |
| 605 self.sort(function() { return Math.random()* 2 - 1; }); | 598 self.sort(function() { return Math.random()* 2 - 1; }); |
| 606 }); | 599 }); |
| 607 | 600 |
| 608 notifier.notify({ | 601 notifier.notify({ |
| 609 object: this, | |
| 610 type: DeckSuit.SHUFFLE | 602 type: DeckSuit.SHUFFLE |
| 611 }); | 603 }); |
| 612 }, | 604 }, |
| 613 } | 605 } |
| 614 | 606 |
| 615 DeckSuit.observe = function(thingy, callback) { | 607 DeckSuit.observe = function(thingy, callback) { |
| 616 Object.observe(thingy, callback, [DeckSuit.SHUFFLE]); | 608 Object.observe(thingy, callback, [DeckSuit.SHUFFLE]); |
| 617 } | 609 } |
| 618 | 610 |
| 619 DeckSuit.unobserve = function(thingy, callback) { | 611 DeckSuit.unobserve = function(thingy, callback) { |
| (...skipping 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1629 for (var n1 = 0; n1 < 3; ++n1) | 1621 for (var n1 = 0; n1 < 3; ++n1) |
| 1630 for (var n2 = 0; n2 < 3; ++n2) | 1622 for (var n2 = 0; n2 < 3; ++n2) |
| 1631 for (var i in mutation) | 1623 for (var i in mutation) |
| 1632 TestFastElementsLength(mutation[i], b1 != 0, b2 != 0, 20*n1, 20*n2); | 1624 TestFastElementsLength(mutation[i], b1 != 0, b2 != 0, 20*n1, 20*n2); |
| 1633 | 1625 |
| 1634 for (var b1 = 0; b1 < 2; ++b1) | 1626 for (var b1 = 0; b1 < 2; ++b1) |
| 1635 for (var b2 = 0; b2 < 2; ++b2) | 1627 for (var b2 = 0; b2 < 2; ++b2) |
| 1636 for (var n = 0; n < 3; ++n) | 1628 for (var n = 0; n < 3; ++n) |
| 1637 for (var i in mutationByIncr) | 1629 for (var i in mutationByIncr) |
| 1638 TestFastElementsLength(mutationByIncr[i], b1 != 0, b2 != 0, 7*n, 7*n+1); | 1630 TestFastElementsLength(mutationByIncr[i], b1 != 0, b2 != 0, 7*n, 7*n+1); |
| OLD | NEW |