From a8ad1390e7bee1d084b07d4f90c332a03e53ad00 Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Wed, 9 Apr 2014 09:01:38 +0000 Subject: [PATCH] Fix regexp compilation cache. R=ulan@chromium.org Review URL: https://codereview.chromium.org/230283002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20601 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/compilation-cache.cc | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/compilation-cache.cc b/src/compilation-cache.cc index 5f8b41c..64c1116 100644 --- a/src/compilation-cache.cc +++ b/src/compilation-cache.cc @@ -254,19 +254,16 @@ MaybeHandle CompilationCacheEval::Lookup( Handle context, StrictMode strict_mode, int scope_position) { + HandleScope scope(isolate()); // 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. Handle result = isolate()->factory()->undefined_value(); int generation; - { HandleScope scope(isolate()); - Handle temp = result; - for (generation = 0; generation < generations(); generation++) { - Handle table = GetTable(generation); - temp = table->LookupEval(source, context, strict_mode, scope_position); - if (temp->IsSharedFunctionInfo()) break; - } - if (temp->IsSharedFunctionInfo()) result = scope.CloseAndEscape(temp); + for (generation = 0; generation < generations(); generation++) { + Handle table = GetTable(generation); + result = table->LookupEval(source, context, strict_mode, scope_position); + if (result->IsSharedFunctionInfo()) break; } if (result->IsSharedFunctionInfo()) { Handle function_info = @@ -275,7 +272,7 @@ MaybeHandle CompilationCacheEval::Lookup( Put(source, context, function_info, scope_position); } isolate()->counters()->compilation_cache_hits()->Increment(); - return function_info; + return scope.CloseAndEscape(function_info); } else { isolate()->counters()->compilation_cache_misses()->Increment(); return MaybeHandle(); @@ -298,21 +295,16 @@ void CompilationCacheEval::Put(Handle source, MaybeHandle CompilationCacheRegExp::Lookup( Handle source, JSRegExp::Flags flags) { + HandleScope scope(isolate()); // 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. Handle result = isolate()->factory()->undefined_value(); int generation; - { HandleScope scope(isolate()); - Handle temp = result; - for (generation = 0; generation < generations(); generation++) { - Handle table = GetTable(generation); - temp = table->LookupRegExp(source, flags); - if (temp->IsFixedArray()) { - break; - } - } - if (temp->IsSharedFunctionInfo()) result = scope.CloseAndEscape(temp); + for (generation = 0; generation < generations(); generation++) { + Handle table = GetTable(generation); + result = table->LookupRegExp(source, flags); + if (result->IsFixedArray()) break; } if (result->IsFixedArray()) { Handle data = Handle::cast(result); @@ -320,7 +312,7 @@ MaybeHandle CompilationCacheRegExp::Lookup( Put(source, flags, data); } isolate()->counters()->compilation_cache_hits()->Increment(); - return data; + return scope.CloseAndEscape(data); } else { isolate()->counters()->compilation_cache_misses()->Increment(); return MaybeHandle(); -- 2.7.4