Fix issue 65 by making sure not to leak any of the cache
authorkasperl@chromium.org <kasperl@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 11 Sep 2008 13:39:48 +0000 (13:39 +0000)
committerkasperl@chromium.org <kasperl@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 11 Sep 2008 13:39:48 +0000 (13:39 +0000)
tables when doing compilation cache operations.
Review URL: http://codereview.chromium.org/1939

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@280 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/compilation-cache.cc
test/cctest/test-api.cc

index 67549e5..48b2870 100644 (file)
@@ -86,8 +86,14 @@ static bool HasOrigin(Handle<JSFunction> boilerplate,
 
 static Handle<JSFunction> Lookup(Handle<String> source,
                                  CompilationCache::Entry entry) {
-  Handle<CompilationCacheTable> table = GetTable(entry);
-  Object* result = table->Lookup(*source);
+  // Make sure not to leak the table into the surrounding handle
+  // scope. Otherwise, we risk keeping old tables around even after
+  // having cleared the cache.
+  Object* result;
+  { HandleScope scope;
+    Handle<CompilationCacheTable> table = GetTable(entry);
+    result = table->Lookup(*source);
+  }
   if (result->IsJSFunction()) {
     return Handle<JSFunction>(JSFunction::cast(result));
   } else {
@@ -129,6 +135,7 @@ Handle<JSFunction> CompilationCache::LookupEval(Handle<String> source,
 void CompilationCache::Associate(Handle<String> source,
                                  Entry entry,
                                  Handle<JSFunction> boilerplate) {
+  HandleScope scope;
   ASSERT(boilerplate->IsBoilerplate());
   Handle<CompilationCacheTable> table = GetTable(entry);
   CALL_HEAP_FUNCTION_VOID(table->Put(*source, *boilerplate));
index 1f2318a..273f77f 100644 (file)
@@ -445,7 +445,7 @@ class TestAsciiResource: public String::ExternalAsciiStringResource {
 int TestAsciiResource::dispose_count = 0;
 
 
-TEST(ScriptUsingStringResource) {
+THREADED_TEST(ScriptUsingStringResource) {
   TestResource::dispose_count = 0;
   const char* c_source = "1 + 2 * 3";
   uint16_t* two_byte_source = AsciiToTwoByteString(c_source);
@@ -469,7 +469,7 @@ TEST(ScriptUsingStringResource) {
 }
 
 
-TEST(ScriptUsingAsciiStringResource) {
+THREADED_TEST(ScriptUsingAsciiStringResource) {
   TestAsciiResource::dispose_count = 0;
   const char* c_source = "1 + 2 * 3";
   {