Permalink
Browse files

Debugger: ScopeMirror has N^2 algorithm when building closure mirrors…

…. (take 2).

Review URL: https://chromiumcodereview.appspot.com/12326103
Patch from Pavel Feldman <pfeldman@chromium.org>.

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@13724 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
  • Loading branch information...
1 parent bec37e2 commit 9d441a57ee4eeb7d8902a773e04881d2d343472a ulan@chromium.org committed Feb 25, 2013
Showing with 40 additions and 36 deletions.
  1. +7 −0 src/objects.h
  2. +8 −36 src/runtime.cc
  3. +25 −0 src/scopeinfo.cc
View
@@ -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> context,
+ Handle<JSObject> scope_object);
+
+
static Handle<ScopeInfo> Create(Scope* scope, Zone* zone);
// Serializes empty scope info.
View
@@ -10597,34 +10597,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<ScopeInfo> scope_info,
- Handle<Context> context,
- Handle<JSObject> 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<String>(scope_info->ContextLocalName(i)),
- Handle<Object>(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<JSObject> MaterializeLocalScopeWithFrameInspector(
@@ -10675,8 +10647,8 @@ static Handle<JSObject> MaterializeLocalScopeWithFrameInspector(
// Third fill all context locals.
Handle<Context> frame_context(Context::cast(frame->context()));
Handle<Context> 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<JSObject>();
}
@@ -10828,8 +10800,8 @@ static Handle<JSObject> 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<JSObject>();
}
@@ -10949,8 +10921,8 @@ static Handle<JSObject> 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<JSObject>();
}
@@ -10972,8 +10944,8 @@ static Handle<JSObject> 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<JSObject>();
}
View
@@ -362,6 +362,31 @@ int ScopeInfo::FunctionContextSlotIndex(String* name, VariableMode* mode) {
}
+bool ScopeInfo::CopyContextLocalsToScopeObject(
+ Isolate* isolate,
+ Handle<Context> context,
+ Handle<JSObject> scope_object) {
+ int local_count = ContextLocalCount();
+ if (local_count == 0) return true;
+ // Fill all context locals to the context extension.
+ int start = ContextLocalNameEntriesIndex();
+ int end = start + local_count;
+ 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>(String::cast(get(i))),
+ Handle<Object>(context->get(context_index), isolate),
+ ::NONE,
+ kNonStrictMode),
+ false);
+ }
+ return true;
+}
+
+
int ScopeInfo::ParameterEntriesIndex() {
ASSERT(length() > 0);
return kVariablePartIndex;

0 comments on commit 9d441a5

Please sign in to comment.