From 127b944ab581a0fbdb0f3bc9def57ea7faafd651 Mon Sep 17 00:00:00 2001 From: "rossberg@chromium.org" Date: Fri, 9 Nov 2012 10:51:35 +0000 Subject: [PATCH] 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 . git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12913 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/object-observe.js | 16 ++++++++-------- test/cctest/test-object-observe.cc | 29 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/object-observe.js b/src/object-observe.js index 5214f7a..086159f 100644 --- a/src/object-observe.js +++ b/src/object-observe.js @@ -38,25 +38,25 @@ if (IS_UNDEFINED(observationState.observerInfoMap)) { 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)) diff --git a/test/cctest/test-object-observe.cc b/test/cctest/test-object-observe.cc index 2321bb2..4a21eb2 100644 --- a/test/cctest/test-object-observe.cc +++ b/test/cctest/test-object-observe.cc @@ -165,3 +165,32 @@ TEST(DeliveryOrderingReentrant) { 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 obj = CompileRun("obj = {};"); + Handle 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()); +} -- 2.7.4