Commit efd71c99 authored by rossberg@chromium.org's avatar rossberg@chromium.org

performChange no longer takes a |receiver| argument.

The spec omits the receiver arg with the idea arrow functions with lexical |this| will obviate the need for it.

BUG=
R=rossberg@chromium.org

Review URL: https://codereview.chromium.org/23727006

Patch from Rafael Weinstein <rafaelw@chromium.org>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16644 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 0a6d1545
...@@ -466,7 +466,7 @@ function ObjectNotifierNotify(changeRecord) { ...@@ -466,7 +466,7 @@ function ObjectNotifierNotify(changeRecord) {
ObjectInfoEnqueueChangeRecord(objectInfo, newRecord); ObjectInfoEnqueueChangeRecord(objectInfo, newRecord);
} }
function ObjectNotifierPerformChange(changeType, changeFn, receiver) { function ObjectNotifierPerformChange(changeType, changeFn) {
if (!IS_SPEC_OBJECT(this)) if (!IS_SPEC_OBJECT(this))
throw MakeTypeError("called_on_non_object", ["performChange"]); throw MakeTypeError("called_on_non_object", ["performChange"]);
...@@ -479,15 +479,9 @@ function ObjectNotifierPerformChange(changeType, changeFn, receiver) { ...@@ -479,15 +479,9 @@ function ObjectNotifierPerformChange(changeType, changeFn, receiver) {
if (!IS_SPEC_FUNCTION(changeFn)) if (!IS_SPEC_FUNCTION(changeFn))
throw MakeTypeError("observe_perform_non_function"); throw MakeTypeError("observe_perform_non_function");
if (IS_NULL_OR_UNDEFINED(receiver)) {
receiver = %GetDefaultReceiver(changeFn) || receiver;
} else if (!IS_SPEC_OBJECT(receiver) && %IsClassicModeFunction(changeFn)) {
receiver = ToObject(receiver);
}
ObjectInfoAddPerformingType(objectInfo, changeType); ObjectInfoAddPerformingType(objectInfo, changeType);
try { try {
%_CallFunction(receiver, changeFn); %_CallFunction(void 0, changeFn);
} finally { } finally {
ObjectInfoRemovePerformingType(objectInfo, changeType); ObjectInfoRemovePerformingType(objectInfo, changeType);
} }
...@@ -520,7 +514,7 @@ function CallbackDeliverPending(callback) { ...@@ -520,7 +514,7 @@ function CallbackDeliverPending(callback) {
%MoveArrayContents(callbackInfo, delivered); %MoveArrayContents(callbackInfo, delivered);
try { try {
%Call(void 0, delivered, callback); %_CallFunction(void 0, delivered, callback);
} catch (ex) {} } catch (ex) {}
return true; return true;
} }
......
...@@ -145,13 +145,8 @@ assertThrows(function() { notifier.performChange(1, function(){}); }, TypeError) ...@@ -145,13 +145,8 @@ assertThrows(function() { notifier.performChange(1, function(){}); }, TypeError)
assertThrows(function() { notifier.performChange(undefined, function(){}); }, TypeError); assertThrows(function() { notifier.performChange(undefined, function(){}); }, TypeError);
assertThrows(function() { notifier.performChange('foo', undefined); }, TypeError); assertThrows(function() { notifier.performChange('foo', undefined); }, TypeError);
assertThrows(function() { notifier.performChange('foo', 'bar'); }, TypeError); assertThrows(function() { notifier.performChange('foo', 'bar'); }, TypeError);
var testSelf = {};
notifier.performChange('foo', function() { notifier.performChange('foo', function() {
assertTrue(testSelf === this); assertEquals(undefined, this);
}, testSelf);
var self = this;
notifier.performChange('foo', function() {
assertTrue(self === this);
}); });
var notify = notifier.notify; var notify = notifier.notify;
...@@ -400,10 +395,11 @@ Thingy.prototype = { ...@@ -400,10 +395,11 @@ Thingy.prototype = {
increment: function(amount) { increment: function(amount) {
var notifier = Object.getNotifier(this); var notifier = Object.getNotifier(this);
var self = this;
notifier.performChange(Thingy.INCREMENT, function() { notifier.performChange(Thingy.INCREMENT, function() {
this.a += amount; self.a += amount;
this.b += amount; self.b += amount;
}, this); });
notifier.notify({ notifier.notify({
object: this, object: this,
...@@ -415,10 +411,11 @@ Thingy.prototype = { ...@@ -415,10 +411,11 @@ Thingy.prototype = {
multiply: function(amount) { multiply: function(amount) {
var notifier = Object.getNotifier(this); var notifier = Object.getNotifier(this);
var self = this;
notifier.performChange(Thingy.MULTIPLY, function() { notifier.performChange(Thingy.MULTIPLY, function() {
this.a *= amount; self.a *= amount;
this.b *= amount; self.b *= amount;
}, this); });
notifier.notify({ notifier.notify({
object: this, object: this,
...@@ -430,10 +427,11 @@ Thingy.prototype = { ...@@ -430,10 +427,11 @@ Thingy.prototype = {
incrementAndMultiply: function(incAmount, multAmount) { incrementAndMultiply: function(incAmount, multAmount) {
var notifier = Object.getNotifier(this); var notifier = Object.getNotifier(this);
var self = this;
notifier.performChange(Thingy.INCREMENT_AND_MULTIPLY, function() { notifier.performChange(Thingy.INCREMENT_AND_MULTIPLY, function() {
this.increment(incAmount); self.increment(incAmount);
this.multiply(multAmount); self.multiply(multAmount);
}, this); });
notifier.notify({ notifier.notify({
object: this, object: this,
...@@ -505,10 +503,11 @@ RecursiveThingy.prototype = { ...@@ -505,10 +503,11 @@ RecursiveThingy.prototype = {
if (!n) if (!n)
return; return;
var notifier = Object.getNotifier(this); var notifier = Object.getNotifier(this);
var self = this;
notifier.performChange(RecursiveThingy.MULTIPLY_FIRST_N, function() { notifier.performChange(RecursiveThingy.MULTIPLY_FIRST_N, function() {
this[n-1] = this[n-1]*amount; self[n-1] = self[n-1]*amount;
this.multiplyFirstN(amount, n-1); self.multiplyFirstN(amount, n-1);
}, this); });
notifier.notify({ notifier.notify({
object: this, object: this,
...@@ -557,18 +556,19 @@ DeckSuit.prototype = { ...@@ -557,18 +556,19 @@ DeckSuit.prototype = {
shuffle: function() { shuffle: function() {
var notifier = Object.getNotifier(this); var notifier = Object.getNotifier(this);
var self = this;
notifier.performChange(DeckSuit.SHUFFLE, function() { notifier.performChange(DeckSuit.SHUFFLE, function() {
this.reverse(); self.reverse();
this.sort(function() { return Math.random()* 2 - 1; }); self.sort(function() { return Math.random()* 2 - 1; });
var cut = this.splice(0, 6); var cut = self.splice(0, 6);
Array.prototype.push.apply(this, cut); Array.prototype.push.apply(self, cut);
this.reverse(); self.reverse();
this.sort(function() { return Math.random()* 2 - 1; }); self.sort(function() { return Math.random()* 2 - 1; });
var cut = this.splice(0, 6); var cut = self.splice(0, 6);
Array.prototype.push.apply(this, cut); Array.prototype.push.apply(self, cut);
this.reverse(); self.reverse();
this.sort(function() { return Math.random()* 2 - 1; }); self.sort(function() { return Math.random()* 2 - 1; });
}, this); });
notifier.notify({ notifier.notify({
object: this, object: this,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment