Commit 127b944a authored by rossberg@chromium.org's avatar rossberg@chromium.org

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 <adamk@chromium.org>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12913 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 803d8ead
...@@ -38,25 +38,25 @@ if (IS_UNDEFINED(observationState.observerInfoMap)) { ...@@ -38,25 +38,25 @@ if (IS_UNDEFINED(observationState.observerInfoMap)) {
observationState.observerPriority = 0; observationState.observerPriority = 0;
} }
function InternalObjectHashTable(table) { function InternalObjectHashTable(tableName) {
this.table = table; this.tableName = tableName;
} }
InternalObjectHashTable.prototype = { InternalObjectHashTable.prototype = {
get: function(key) { get: function(key) {
return %ObjectHashTableGet(this.table, key); return %ObjectHashTableGet(observationState[this.tableName], key);
}, },
set: function(key, value) { set: function(key, value) {
this.table = %ObjectHashTableSet(this.table, key, value); observationState[this.tableName] =
%ObjectHashTableSet(observationState[this.tableName], key, value);
}, },
has: function(key) { has: function(key) {
return %ObjectHashTableHas(this.table, key); return %ObjectHashTableHas(observationState[this.tableName], key);
} }
}; };
var observerInfoMap = new InternalObjectHashTable( var observerInfoMap = new InternalObjectHashTable('observerInfoMap');
observationState.observerInfoMap); var objectInfoMap = new InternalObjectHashTable('objectInfoMap');
var objectInfoMap = new InternalObjectHashTable(observationState.objectInfoMap);
function ObjectObserve(object, callback) { function ObjectObserve(object, callback) {
if (!IS_SPEC_OBJECT(object)) if (!IS_SPEC_OBJECT(object))
......
...@@ -165,3 +165,32 @@ TEST(DeliveryOrderingReentrant) { ...@@ -165,3 +165,32 @@ TEST(DeliveryOrderingReentrant) {
CHECK_EQ(1, CompileRun("ordering[3]")->Int32Value()); CHECK_EQ(1, CompileRun("ordering[3]")->Int32Value());
CHECK_EQ(2, CompileRun("ordering[1]")->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());
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment