Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/debug/debug-evaluate.cc

Issue 1513183003: [debugger] debug-evaluate should not not modify local values. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@arrowthis
Patch Set: addressed comments. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/debug/debug-evaluate.h ('k') | src/flag-definitions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/debug/debug-evaluate.h" 5 #include "src/debug/debug-evaluate.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/contexts.h" 8 #include "src/contexts.h"
9 #include "src/debug/debug.h" 9 #include "src/debug/debug.h"
10 #include "src/debug/debug-frames.h" 10 #include "src/debug/debug-frames.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 // selected frame. 61 // selected frame.
62 SaveContext* save = 62 SaveContext* save =
63 DebugFrameHelper::FindSavedContextForFrame(isolate, frame); 63 DebugFrameHelper::FindSavedContextForFrame(isolate, frame);
64 SaveContext savex(isolate); 64 SaveContext savex(isolate);
65 isolate->set_context(*(save->context())); 65 isolate->set_context(*(save->context()));
66 66
67 // This is not a lot different than DebugEvaluate::Global, except that 67 // This is not a lot different than DebugEvaluate::Global, except that
68 // variables accessible by the function we are evaluating from are 68 // variables accessible by the function we are evaluating from are
69 // materialized and included on top of the native context. Changes to 69 // materialized and included on top of the native context. Changes to
70 // the materialized object are written back afterwards. 70 // the materialized object are written back afterwards.
71 // Note that the native context is taken from the original context chain,
72 // which may not be the current native context of the isolate.
71 ContextBuilder context_builder(isolate, frame, inlined_jsframe_index); 73 ContextBuilder context_builder(isolate, frame, inlined_jsframe_index);
72 if (isolate->has_pending_exception()) return MaybeHandle<Object>(); 74 if (isolate->has_pending_exception()) return MaybeHandle<Object>();
73 75
74 Handle<Context> context = isolate->native_context(); 76 Handle<Context> context = context_builder.native_context();
75 Handle<JSObject> receiver(context->global_proxy()); 77 Handle<JSObject> receiver(context->global_proxy());
76 Handle<SharedFunctionInfo> outer_info(context->closure()->shared(), isolate);
77 MaybeHandle<Object> maybe_result = Evaluate( 78 MaybeHandle<Object> maybe_result = Evaluate(
78 isolate, context_builder.outer_info(), 79 isolate, context_builder.outer_info(),
79 context_builder.innermost_context(), context_extension, receiver, source); 80 context_builder.innermost_context(), context_extension, receiver, source);
80 if (!maybe_result.is_null()) context_builder.UpdateValues(); 81 if (!maybe_result.is_null() && !FLAG_debug_eval_readonly_locals) {
82 context_builder.UpdateValues();
83 }
81 return maybe_result; 84 return maybe_result;
82 } 85 }
83 86
84 87
85 // Compile and evaluate source for the given context. 88 // Compile and evaluate source for the given context.
86 MaybeHandle<Object> DebugEvaluate::Evaluate( 89 MaybeHandle<Object> DebugEvaluate::Evaluate(
87 Isolate* isolate, Handle<SharedFunctionInfo> outer_info, 90 Isolate* isolate, Handle<SharedFunctionInfo> outer_info,
88 Handle<Context> context, Handle<HeapObject> context_extension, 91 Handle<Context> context, Handle<HeapObject> context_extension,
89 Handle<Object> receiver, Handle<String> source) { 92 Handle<Object> receiver, Handle<String> source) {
90 if (context_extension->IsJSObject()) { 93 if (context_extension->IsJSObject()) {
(...skipping 29 matching lines...) Expand all
120 DebugEvaluate::ContextBuilder::ContextBuilder(Isolate* isolate, 123 DebugEvaluate::ContextBuilder::ContextBuilder(Isolate* isolate,
121 JavaScriptFrame* frame, 124 JavaScriptFrame* frame,
122 int inlined_jsframe_index) 125 int inlined_jsframe_index)
123 : isolate_(isolate), 126 : isolate_(isolate),
124 frame_(frame), 127 frame_(frame),
125 inlined_jsframe_index_(inlined_jsframe_index) { 128 inlined_jsframe_index_(inlined_jsframe_index) {
126 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate); 129 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate);
127 Handle<JSFunction> local_function = 130 Handle<JSFunction> local_function =
128 handle(JSFunction::cast(frame_inspector.GetFunction())); 131 handle(JSFunction::cast(frame_inspector.GetFunction()));
129 Handle<Context> outer_context(local_function->context()); 132 Handle<Context> outer_context(local_function->context());
130 Handle<Context> native_context = isolate->native_context(); 133 native_context_ = Handle<Context>(outer_context->native_context());
131 Handle<JSFunction> global_function(native_context->closure()); 134 Handle<JSFunction> global_function(native_context_->closure());
132 outer_info_ = handle(global_function->shared()); 135 outer_info_ = handle(global_function->shared());
133 Handle<Context> inner_context; 136 Handle<Context> inner_context;
134 137
135 bool stop = false; 138 bool stop = false;
136 139
137 // Iterate the original context chain to create a context chain that reflects 140 // Iterate the original context chain to create a context chain that reflects
138 // our needs. The original context chain may look like this: 141 // our needs. The original context chain may look like this:
139 // <native context> <outer contexts> <function context> <inner contexts> 142 // <native context> <outer contexts> <function context> <inner contexts>
140 // In the resulting context chain, we want to materialize the receiver, 143 // In the resulting context chain, we want to materialize the receiver,
141 // the parameters of the current function, the stack locals. We only 144 // the parameters of the current function, the stack locals. We only
(...skipping 17 matching lines...) Expand all
159 ScopeIterator::ScopeType scope_type = it.Type(); 162 ScopeIterator::ScopeType scope_type = it.Type();
160 if (scope_type == ScopeIterator::ScopeTypeLocal) { 163 if (scope_type == ScopeIterator::ScopeTypeLocal) {
161 DCHECK_EQ(FUNCTION_SCOPE, it.CurrentScopeInfo()->scope_type()); 164 DCHECK_EQ(FUNCTION_SCOPE, it.CurrentScopeInfo()->scope_type());
162 it.GetNonLocals(&non_locals_); 165 it.GetNonLocals(&non_locals_);
163 Handle<Context> local_context = 166 Handle<Context> local_context =
164 it.HasContext() ? it.CurrentContext() : outer_context; 167 it.HasContext() ? it.CurrentContext() : outer_context;
165 168
166 // The "this" binding, if any, can't be bound via "with". If we need 169 // The "this" binding, if any, can't be bound via "with". If we need
167 // to, add another node onto the outer context to bind "this". 170 // to, add another node onto the outer context to bind "this".
168 Handle<Context> receiver_context = 171 Handle<Context> receiver_context =
169 MaterializeReceiver(native_context, local_context, local_function, 172 MaterializeReceiver(native_context_, local_context, local_function,
170 global_function, it.ThisIsNonLocal()); 173 global_function, it.ThisIsNonLocal());
171 174
172 Handle<JSObject> materialized_function = NewJSObjectWithNullProto(); 175 Handle<JSObject> materialized_function = NewJSObjectWithNullProto();
173 frame_inspector.MaterializeStackLocals(materialized_function, 176 frame_inspector.MaterializeStackLocals(materialized_function,
174 local_function); 177 local_function);
175 MaterializeArgumentsObject(materialized_function, local_function); 178 MaterializeArgumentsObject(materialized_function, local_function);
176 MaterializeContextChain(materialized_function, local_context); 179 MaterializeContextChain(materialized_function, local_context);
177 180
178 Handle<Context> with_context = isolate->factory()->NewWithContext( 181 Handle<Context> with_context = isolate->factory()->NewWithContext(
179 global_function, receiver_context, materialized_function); 182 global_function, receiver_context, materialized_function);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 Handle<JSObject> arguments = 305 Handle<JSObject> arguments =
303 Handle<JSObject>::cast(Accessors::FunctionGetArguments(function)); 306 Handle<JSObject>::cast(Accessors::FunctionGetArguments(function));
304 Handle<String> arguments_str = isolate_->factory()->arguments_string(); 307 Handle<String> arguments_str = isolate_->factory()->arguments_string();
305 JSObject::SetOwnPropertyIgnoreAttributes(target, arguments_str, arguments, 308 JSObject::SetOwnPropertyIgnoreAttributes(target, arguments_str, arguments,
306 NONE) 309 NONE)
307 .Check(); 310 .Check();
308 } 311 }
309 312
310 313
311 MaybeHandle<Object> DebugEvaluate::ContextBuilder::LoadFromContext( 314 MaybeHandle<Object> DebugEvaluate::ContextBuilder::LoadFromContext(
312 Handle<Context> context, Handle<String> name) { 315 Handle<Context> context, Handle<String> name, bool* global) {
313 static const ContextLookupFlags flags = FOLLOW_CONTEXT_CHAIN; 316 static const ContextLookupFlags flags = FOLLOW_CONTEXT_CHAIN;
314 int index; 317 int index;
315 PropertyAttributes attributes; 318 PropertyAttributes attributes;
316 BindingFlags binding; 319 BindingFlags binding;
317 Handle<Object> holder = 320 Handle<Object> holder =
318 context->Lookup(name, flags, &index, &attributes, &binding); 321 context->Lookup(name, flags, &index, &attributes, &binding);
319 if (holder.is_null()) return MaybeHandle<Object>(); 322 if (holder.is_null()) return MaybeHandle<Object>();
320 Handle<Object> value; 323 Handle<Object> value;
321 if (index != Context::kNotFound) { // Found on context. 324 if (index != Context::kNotFound) { // Found on context.
322 Handle<Context> context = Handle<Context>::cast(holder); 325 Handle<Context> context = Handle<Context>::cast(holder);
326 // Do not shadow variables on the script context.
327 *global = context->IsScriptContext();
323 return Handle<Object>(context->get(index), isolate_); 328 return Handle<Object>(context->get(index), isolate_);
324 } else { // Found on object. 329 } else { // Found on object.
325 Handle<JSReceiver> object = Handle<JSReceiver>::cast(holder); 330 Handle<JSReceiver> object = Handle<JSReceiver>::cast(holder);
331 // Do not shadow properties on the global object.
332 *global = object->IsJSGlobalObject();
326 return JSReceiver::GetDataProperty(object, name); 333 return JSReceiver::GetDataProperty(object, name);
327 } 334 }
328 } 335 }
329 336
330 337
331 void DebugEvaluate::ContextBuilder::MaterializeContextChain( 338 void DebugEvaluate::ContextBuilder::MaterializeContextChain(
332 Handle<JSObject> target, Handle<Context> context) { 339 Handle<JSObject> target, Handle<Context> context) {
333 for (const Handle<String>& name : non_locals_) { 340 for (const Handle<String>& name : non_locals_) {
334 HandleScope scope(isolate_); 341 HandleScope scope(isolate_);
335 Handle<Object> value; 342 Handle<Object> value;
336 if (!LoadFromContext(context, name).ToHandle(&value)) continue; 343 bool global;
344 if (!LoadFromContext(context, name, &global).ToHandle(&value) || global) {
345 // If resolving the variable fails, skip it. If it resolves to a global
346 // variable, skip it as well since it's not read-only and can be resolved
347 // within debug-evaluate.
348 continue;
349 }
337 JSObject::SetOwnPropertyIgnoreAttributes(target, name, value, NONE).Check(); 350 JSObject::SetOwnPropertyIgnoreAttributes(target, name, value, NONE).Check();
338 } 351 }
339 } 352 }
340 353
341 354
342 void DebugEvaluate::ContextBuilder::StoreToContext(Handle<Context> context, 355 void DebugEvaluate::ContextBuilder::StoreToContext(Handle<Context> context,
343 Handle<String> name, 356 Handle<String> name,
344 Handle<Object> value) { 357 Handle<Object> value) {
345 static const ContextLookupFlags flags = FOLLOW_CONTEXT_CHAIN; 358 static const ContextLookupFlags flags = FOLLOW_CONTEXT_CHAIN;
346 int index; 359 int index;
(...skipping 27 matching lines...) Expand all
374 } 387 }
375 388
376 389
377 Handle<Context> DebugEvaluate::ContextBuilder::MaterializeReceiver( 390 Handle<Context> DebugEvaluate::ContextBuilder::MaterializeReceiver(
378 Handle<Context> parent_context, Handle<Context> lookup_context, 391 Handle<Context> parent_context, Handle<Context> lookup_context,
379 Handle<JSFunction> local_function, Handle<JSFunction> global_function, 392 Handle<JSFunction> local_function, Handle<JSFunction> global_function,
380 bool this_is_non_local) { 393 bool this_is_non_local) {
381 Handle<Object> receiver = isolate_->factory()->undefined_value(); 394 Handle<Object> receiver = isolate_->factory()->undefined_value();
382 Handle<String> this_string = isolate_->factory()->this_string(); 395 Handle<String> this_string = isolate_->factory()->this_string();
383 if (this_is_non_local) { 396 if (this_is_non_local) {
384 LoadFromContext(lookup_context, this_string).ToHandle(&receiver); 397 bool global;
398 LoadFromContext(lookup_context, this_string, &global).ToHandle(&receiver);
385 } else if (local_function->shared()->scope_info()->HasReceiver()) { 399 } else if (local_function->shared()->scope_info()->HasReceiver()) {
386 receiver = handle(frame_->receiver(), isolate_); 400 receiver = handle(frame_->receiver(), isolate_);
387 } 401 }
388 return isolate_->factory()->NewCatchContext(global_function, parent_context, 402 return isolate_->factory()->NewCatchContext(global_function, parent_context,
389 this_string, receiver); 403 this_string, receiver);
390 } 404 }
391 405
392 } // namespace internal 406 } // namespace internal
393 } // namespace v8 407 } // namespace v8
OLDNEW
« no previous file with comments | « src/debug/debug-evaluate.h ('k') | src/flag-definitions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698