From b62de7c04ea28b637cf0bdb98d85ab77e13c5b1f Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Wed, 20 Feb 2013 14:12:31 +0000 Subject: [PATCH] Debugger: ScopeMirror has N^2 algorithm when building closure mirrors. R=yangguo@chromium.org BUG= Review URL: https://chromiumcodereview.appspot.com/12326009 Patch from Pavel Feldman . git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13699 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/objects.h | 7 +++++++ src/runtime.cc | 44 ++++++++------------------------------------ src/scopeinfo.cc | 23 +++++++++++++++++++++++ 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/src/objects.h b/src/objects.h index 600faee..e15eee3 100644 --- a/src/objects.h +++ b/src/objects.h @@ -3559,6 +3559,13 @@ class ScopeInfo : public FixedArray { // must be a symbol (canonicalized). int FunctionContextSlotIndex(String* name, VariableMode* mode); + + // Copies all the context locals into an object used to materialize a scope. + bool CopyContextLocalsToScopeObject(Isolate* isolate, + Handle context, + Handle scope_object); + + static Handle Create(Scope* scope, Zone* zone); // Serializes empty scope info. diff --git a/src/runtime.cc b/src/runtime.cc index c379ec9..7b13f05 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -10766,34 +10766,6 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_GetFrameDetails) { } -// Copy all the context locals into an object used to materialize a scope. -static bool CopyContextLocalsToScopeObject( - Isolate* isolate, - Handle scope_info, - Handle context, - Handle scope_object) { - // Fill all context locals to the context extension. - for (int i = 0; i < scope_info->ContextLocalCount(); i++) { - VariableMode mode; - InitializationFlag init_flag; - int context_index = scope_info->ContextSlotIndex( - scope_info->ContextLocalName(i), &mode, &init_flag); - - RETURN_IF_EMPTY_HANDLE_VALUE( - isolate, - SetProperty(isolate, - scope_object, - Handle(scope_info->ContextLocalName(i)), - Handle(context->get(context_index), isolate), - NONE, - kNonStrictMode), - false); - } - - return true; -} - - // Create a plain JSObject which materializes the local scope for the specified // frame. static Handle MaterializeLocalScopeWithFrameInspector( @@ -10843,8 +10815,8 @@ static Handle MaterializeLocalScopeWithFrameInspector( // Third fill all context locals. Handle frame_context(Context::cast(frame->context())); Handle function_context(frame_context->declaration_context()); - if (!CopyContextLocalsToScopeObject( - isolate, scope_info, function_context, local_scope)) { + if (!scope_info->CopyContextLocalsToScopeObject( + isolate, function_context, local_scope)) { return Handle(); } @@ -10996,8 +10968,8 @@ static Handle MaterializeClosure(Isolate* isolate, isolate->factory()->NewJSObject(isolate->object_function()); // Fill all context locals to the context extension. - if (!CopyContextLocalsToScopeObject( - isolate, scope_info, context, closure_scope)) { + if (!scope_info->CopyContextLocalsToScopeObject( + isolate, context, closure_scope)) { return Handle(); } @@ -11116,8 +11088,8 @@ static Handle MaterializeBlockScope( isolate->factory()->NewJSObject(isolate->object_function()); // Fill all context locals. - if (!CopyContextLocalsToScopeObject( - isolate, scope_info, context, block_scope)) { + if (!scope_info->CopyContextLocalsToScopeObject( + isolate, context, block_scope)) { return Handle(); } @@ -11139,8 +11111,8 @@ static Handle MaterializeModuleScope( isolate->factory()->NewJSObject(isolate->object_function()); // Fill all context locals. - if (!CopyContextLocalsToScopeObject( - isolate, scope_info, context, module_scope)) { + if (!scope_info->CopyContextLocalsToScopeObject( + isolate, context, module_scope)) { return Handle(); } diff --git a/src/scopeinfo.cc b/src/scopeinfo.cc index c0b2c4c..5ec2527 100644 --- a/src/scopeinfo.cc +++ b/src/scopeinfo.cc @@ -362,6 +362,29 @@ int ScopeInfo::FunctionContextSlotIndex(String* name, VariableMode* mode) { } +bool ScopeInfo::CopyContextLocalsToScopeObject( + Isolate* isolate, + Handle context, + Handle scope_object) { + // Fill all context locals to the context extension. + int start = ContextLocalNameEntriesIndex(); + int end = start + ContextLocalCount(); + for (int i = start; i < end; ++i) { + int context_index = Context::MIN_CONTEXT_SLOTS + i - start; + RETURN_IF_EMPTY_HANDLE_VALUE( + isolate, + SetProperty(isolate, + scope_object, + Handle(String::cast(get(i))), + Handle(context->get(context_index), isolate), + ::NONE, + kNonStrictMode), + false); + } + return true; +} + + int ScopeInfo::ParameterEntriesIndex() { ASSERT(length() > 0); return kVariablePartIndex; -- 2.7.4