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

Unified Diff: src/object-observe.js

Issue 11266011: Delivery logic for Object.observe (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Renamed and added comment Created 8 years, 1 month 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 | « src/isolate.h ('k') | src/objects.h » ('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 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(
« no previous file with comments | « src/isolate.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698