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

Unified Diff: src/object-observe.js

Issue 12092079: Object.observe: use JSWeakMaps instead of raw ObjectHashTables in observation state (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix test, also test notifierTargetMap Created 7 years, 10 months 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 | src/runtime.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 d0a84f69c3eec5e45eec71043bdc52cccb829759..b35f547eda0b89f5a1530e39d552f8f86b55e601 100644
--- a/src/object-observe.js
+++ b/src/object-observe.js
@@ -29,33 +29,38 @@
var observationState = %GetObservationState();
if (IS_UNDEFINED(observationState.observerInfoMap)) {
- observationState.observerInfoMap = %CreateObjectHashTable();
- observationState.objectInfoMap = %CreateObjectHashTable();
- observationState.notifierTargetMap = %CreateObjectHashTable();
+ observationState.observerInfoMap = %ObservationWeakMapCreate();
+ observationState.objectInfoMap = %ObservationWeakMapCreate();
+ observationState.notifierTargetMap = %ObservationWeakMapCreate();
observationState.pendingObservers = new InternalArray;
observationState.observerPriority = 0;
}
-function InternalObjectHashTable(tableName) {
- this.tableName = tableName;
+function ObservationWeakMap(map) {
+ this.map_ = map;
}
-InternalObjectHashTable.prototype = {
+ObservationWeakMap.prototype = {
get: function(key) {
- return %ObjectHashTableGet(observationState[this.tableName], key);
+ key = %UnwrapGlobalProxy(key);
+ if (!IS_SPEC_OBJECT(key)) return void 0;
+ return %WeakMapGet(this.map_, key);
},
set: function(key, value) {
- observationState[this.tableName] =
- %ObjectHashTableSet(observationState[this.tableName], key, value);
+ key = %UnwrapGlobalProxy(key);
+ if (!IS_SPEC_OBJECT(key)) return void 0;
+ %WeakMapSet(this.map_, key, value);
},
has: function(key) {
return !IS_UNDEFINED(this.get(key));
}
};
-var observerInfoMap = new InternalObjectHashTable('observerInfoMap');
-var objectInfoMap = new InternalObjectHashTable('objectInfoMap');
-var notifierTargetMap = new InternalObjectHashTable('notifierTargetMap');
+var observerInfoMap =
+ new ObservationWeakMap(observationState.observerInfoMap);
+var objectInfoMap = new ObservationWeakMap(observationState.objectInfoMap);
+var notifierTargetMap =
+ new ObservationWeakMap(observationState.notifierTargetMap);
function CreateObjectInfo(object) {
var info = {
« no previous file with comments | « no previous file | src/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698