Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: src/object-observe.js

Issue 11593028: Object.observe: Change semantics of deliverChangeRecords to iterate. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/harmony/object-observe.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/object-observe.js
diff --git a/src/object-observe.js b/src/object-observe.js
index 3ed27716837d9980a818f6c8d30cd665692eb78b..2923ec86a71695b629a80057c7b4dcff1f90e162 100644
--- a/src/object-observe.js
+++ b/src/object-observe.js
@@ -82,14 +82,11 @@ function ObjectObserve(object, callback) {
}
var objectInfo = objectInfoMap.get(object);
- if (IS_UNDEFINED(objectInfo)) {
- objectInfo = CreateObjectInfo(object);
- }
+ if (IS_UNDEFINED(objectInfo)) objectInfo = CreateObjectInfo(object);
%SetIsObserved(object, true);
var changeObservers = objectInfo.changeObservers;
- if (changeObservers.indexOf(callback) < 0)
- changeObservers.push(callback);
+ if (changeObservers.indexOf(callback) < 0) changeObservers.push(callback);
return object;
}
@@ -108,8 +105,7 @@ function ObjectUnobserve(object, callback) {
var index = changeObservers.indexOf(callback);
if (index >= 0) {
changeObservers.splice(index, 1);
- if (changeObservers.length === 0)
- %SetIsObserved(object, false);
+ if (changeObservers.length === 0) %SetIsObserved(object, false);
}
return object;
@@ -141,30 +137,21 @@ function NotifyChange(type, object, name, oldValue) {
var notifierPrototype = {};
function ObjectNotifierNotify(changeRecord) {
+ var target = notifierTargetMap.get(this);
if (!IS_SPEC_OBJECT(this))
throw MakeTypeError("called_on_non_object", ["notify"]);
-
- var target = notifierTargetMap.get(this);
if (IS_UNDEFINED(target))
throw MakeTypeError("observe_notify_non_notifier");
-
if (!IS_STRING(changeRecord.type))
throw MakeTypeError("observe_type_non_string");
var objectInfo = objectInfoMap.get(target);
- if (IS_UNDEFINED(objectInfo))
+ if (IS_UNDEFINED(objectInfo) || objectInfo.changeObservers.length === 0)
return;
- if (!objectInfo.changeObservers.length)
- return;
-
- var newRecord = {
- object: target
- };
+ var newRecord = { object: target };
for (var prop in changeRecord) {
- if (prop === 'object')
- continue;
-
+ if (prop === 'object') continue;
%DefineOrRedefineDataProperty(newRecord, prop, changeRecord[prop],
READ_ONLY + DONT_DELETE);
}
@@ -177,17 +164,13 @@ function ObjectGetNotifier(object) {
if (!IS_SPEC_OBJECT(object))
throw MakeTypeError("observe_non_object", ["getNotifier"]);
- if (ObjectIsFrozen(object))
- return null;
+ if (ObjectIsFrozen(object)) return null;
var objectInfo = objectInfoMap.get(object);
- if (IS_UNDEFINED(objectInfo))
- objectInfo = CreateObjectInfo(object);
+ if (IS_UNDEFINED(objectInfo)) objectInfo = CreateObjectInfo(object);
if (IS_NULL(objectInfo.notifier)) {
- objectInfo.notifier = {
- __proto__: notifierPrototype
- };
+ objectInfo.notifier = { __proto__: notifierPrototype };
notifierTargetMap.set(objectInfo.notifier, object);
}
@@ -197,11 +180,11 @@ function ObjectGetNotifier(object) {
function DeliverChangeRecordsForObserver(observer) {
var observerInfo = observerInfoMap.get(observer);
if (IS_UNDEFINED(observerInfo))
- return;
+ return false;
var pendingChangeRecords = observerInfo.pendingChangeRecords;
if (IS_NULL(pendingChangeRecords))
- return;
+ return false;
observerInfo.pendingChangeRecords = null;
delete observationState.pendingObservers[observerInfo.priority];
@@ -210,13 +193,14 @@ function DeliverChangeRecordsForObserver(observer) {
try {
%Call(void 0, delivered, observer);
} catch (ex) {}
+ return true;
}
function ObjectDeliverChangeRecords(callback) {
if (!IS_SPEC_FUNCTION(callback))
throw MakeTypeError("observe_non_function", ["deliverChangeRecords"]);
- DeliverChangeRecordsForObserver(callback);
+ while (DeliverChangeRecordsForObserver(callback)) {}
}
function DeliverChangeRecords() {
« no previous file with comments | « no previous file | test/mjsunit/harmony/object-observe.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698