Revision: 12913
Author: [email protected]
Date: Fri Nov 9 02:51:35 2012
Log: Fix InternalObjectHashTable to properly update table ref in
observationState
The previous fix wasn't broad enough: it only fixed the reference for a
single Context.
Review URL: https://codereview.chromium.org/11361172
Patch from Adam Klein <[email protected]>.
http://code.google.com/p/v8/source/detail?r=12913
Modified:
/branches/bleeding_edge/src/object-observe.js
/branches/bleeding_edge/test/cctest/test-object-observe.cc
=======================================
--- /branches/bleeding_edge/src/object-observe.js Thu Nov 8 05:44:59 2012
+++ /branches/bleeding_edge/src/object-observe.js Fri Nov 9 02:51:35 2012
@@ -38,25 +38,25 @@
observationState.observerPriority = 0;
}
-function InternalObjectHashTable(table) {
- this.table = table;
+function InternalObjectHashTable(tableName) {
+ this.tableName = tableName;
}
InternalObjectHashTable.prototype = {
get: function(key) {
- return %ObjectHashTableGet(this.table, key);
+ return %ObjectHashTableGet(observationState[this.tableName], key);
},
set: function(key, value) {
- this.table = %ObjectHashTableSet(this.table, key, value);
+ observationState[this.tableName] =
+ %ObjectHashTableSet(observationState[this.tableName], key, value);
},
has: function(key) {
- return %ObjectHashTableHas(this.table, key);
+ return %ObjectHashTableHas(observationState[this.tableName], key);
}
};
-var observerInfoMap = new InternalObjectHashTable(
- observationState.observerInfoMap);
-var objectInfoMap = new
InternalObjectHashTable(observationState.objectInfoMap);
+var observerInfoMap = new InternalObjectHashTable('observerInfoMap');
+var objectInfoMap = new InternalObjectHashTable('objectInfoMap');
function ObjectObserve(object, callback) {
if (!IS_SPEC_OBJECT(object))
=======================================
--- /branches/bleeding_edge/test/cctest/test-object-observe.cc Thu Nov 8
05:44:59 2012
+++ /branches/bleeding_edge/test/cctest/test-object-observe.cc Fri Nov 9
02:51:35 2012
@@ -165,3 +165,32 @@
CHECK_EQ(1, CompileRun("ordering[3]")->Int32Value());
CHECK_EQ(2, CompileRun("ordering[1]")->Int32Value());
}
+
+TEST(ObjectHashTableGrowth) {
+ HarmonyIsolate isolate;
+ HandleScope scope;
+ // Initializing this context sets up initial hash tables.
+ LocalContext context;
+ Handle<Value> obj = CompileRun("obj = {};");
+ Handle<Value> observer = CompileRun(
+ "var ran = false;"
+ "(function() { ran = true })");
+ {
+ // As does initializing this context.
+ LocalContext context2;
+ context2->Global()->Set(String::New("obj"), obj);
+ context2->Global()->Set(String::New("observer"), observer);
+ CompileRun(
+ "var objArr = [];"
+ // 100 objects should be enough to make the hash table grow
+ // (and thus relocate).
+ "for (var i = 0; i < 100; ++i) {"
+ " objArr.push({});"
+ " Object.observe(objArr[objArr.length-1], function(){});"
+ "}"
+ "Object.observe(obj, observer);");
+ }
+ // obj is now marked "is_observed", but our map has moved.
+ CompileRun("obj.foo = 'bar'");
+ CHECK(CompileRun("ran")->BooleanValue());
+}
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev