Index: src/object-observe.js |
diff --git a/src/object-observe.js b/src/object-observe.js |
index bd621d85e41421f17c2abf581c5b921eab6ab3a2..6225348f3bc12972e7621e285dc492a9e24b207a 100644 |
--- a/src/object-observe.js |
+++ b/src/object-observe.js |
@@ -34,6 +34,8 @@ var observationState = %GetObservationState(); |
if (IS_UNDEFINED(observationState.observerInfoMap)) { |
observationState.observerInfoMap = %CreateObjectHashTable(); |
observationState.objectInfoMap = %CreateObjectHashTable(); |
+ observationState.activeObservers = new InternalArray; |
+ observationState.observerPriority = 0; |
} |
function InternalObjectHashTable(table) { |
@@ -65,9 +67,9 @@ function ObjectObserve(object, callback) { |
throw MakeTypeError("observe_callback_frozen"); |
if (!observerInfoMap.has(callback)) { |
- // TODO: setup observerInfo.priority. |
observerInfoMap.set(callback, { |
- pendingChangeRecords: null |
+ pendingChangeRecords: null, |
+ priority: observationState.observerPriority++, |
}); |
} |
@@ -109,9 +111,8 @@ function EnqueueChangeRecord(changeRecord, observers) { |
for (var i = 0; i < observers.length; i++) { |
var observer = observers[i]; |
var observerInfo = observerInfoMap.get(observer); |
- |
- // TODO: "activate" the observer |
- |
+ observationState.activeObservers[observerInfo.priority] = observer; |
+ %SetObserverDeliveryPending(); |
if (IS_NULL(observerInfo.pendingChangeRecords)) { |
observerInfo.pendingChangeRecords = new InternalArray(changeRecord); |
} else { |
@@ -151,11 +152,8 @@ function ObjectNotify(object, changeRecord) { |
EnqueueChangeRecord(newRecord, objectInfo.changeObservers); |
} |
-function ObjectDeliverChangeRecords(callback) { |
- if (!IS_SPEC_FUNCTION(callback)) |
- throw MakeTypeError("observe_non_function", ["deliverChangeRecords"]); |
- |
- var observerInfo = observerInfoMap.get(callback); |
+function DeliverChangeRecordsForObserver(observer) { |
+ var observerInfo = observerInfoMap.get(observer); |
if (IS_UNDEFINED(observerInfo)) |
return; |
@@ -167,10 +165,27 @@ function ObjectDeliverChangeRecords(callback) { |
var delivered = []; |
%MoveArrayContents(pendingChangeRecords, delivered); |
try { |
- %Call(void 0, delivered, callback); |
+ %Call(void 0, delivered, observer); |
} catch (ex) {} |
} |
+function ObjectDeliverChangeRecords(callback) { |
+ if (!IS_SPEC_FUNCTION(callback)) |
+ throw MakeTypeError("observe_non_function", ["deliverChangeRecords"]); |
+ |
+ DeliverChangeRecordsForObserver(callback); |
+} |
+ |
+function DeliverChangeRecords() { |
+ while (observationState.activeObservers.length) { |
+ var activeObservers = observationState.activeObservers; |
+ observationState.activeObservers = new InternalArray; |
+ for (var i in activeObservers) { |
+ DeliverChangeRecordsForObserver(activeObservers[i]); |
+ } |
+ } |
+} |
+ |
function SetupObjectObserve() { |
%CheckIsBootstrapping(); |
InstallFunctions($Object, DONT_ENUM, $Array( |