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

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: 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
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // the materialized object are written back afterwards. 70 // the materialized object are written back afterwards.
71 ContextBuilder context_builder(isolate, frame, inlined_jsframe_index); 71 ContextBuilder context_builder(isolate, frame, inlined_jsframe_index);
72 if (isolate->has_pending_exception()) return MaybeHandle<Object>(); 72 if (isolate->has_pending_exception()) return MaybeHandle<Object>();
73 73
74 Handle<Context> context = isolate->native_context(); 74 Handle<Context> context = isolate->native_context();
75 Handle<JSObject> receiver(context->global_proxy()); 75 Handle<JSObject> receiver(context->global_proxy());
76 Handle<SharedFunctionInfo> outer_info(context->closure()->shared(), isolate); 76 Handle<SharedFunctionInfo> outer_info(context->closure()->shared(), isolate);
77 MaybeHandle<Object> maybe_result = Evaluate( 77 MaybeHandle<Object> maybe_result = Evaluate(
78 isolate, context_builder.outer_info(), 78 isolate, context_builder.outer_info(),
79 context_builder.innermost_context(), context_extension, receiver, source); 79 context_builder.innermost_context(), context_extension, receiver, source);
80 if (!maybe_result.is_null()) context_builder.UpdateValues(); 80 if (!maybe_result.is_null() && !FLAG_debug_eval_readonly_locals) {
81 context_builder.UpdateValues();
82 }
81 return maybe_result; 83 return maybe_result;
82 } 84 }
83 85
84 86
85 // Compile and evaluate source for the given context. 87 // Compile and evaluate source for the given context.
86 MaybeHandle<Object> DebugEvaluate::Evaluate( 88 MaybeHandle<Object> DebugEvaluate::Evaluate(
87 Isolate* isolate, Handle<SharedFunctionInfo> outer_info, 89 Isolate* isolate, Handle<SharedFunctionInfo> outer_info,
88 Handle<Context> context, Handle<HeapObject> context_extension, 90 Handle<Context> context, Handle<HeapObject> context_extension,
89 Handle<Object> receiver, Handle<String> source) { 91 Handle<Object> receiver, Handle<String> source) {
90 if (context_extension->IsJSObject()) { 92 if (context_extension->IsJSObject()) {
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 Handle<JSObject> arguments = 304 Handle<JSObject> arguments =
303 Handle<JSObject>::cast(Accessors::FunctionGetArguments(function)); 305 Handle<JSObject>::cast(Accessors::FunctionGetArguments(function));
304 Handle<String> arguments_str = isolate_->factory()->arguments_string(); 306 Handle<String> arguments_str = isolate_->factory()->arguments_string();
305 JSObject::SetOwnPropertyIgnoreAttributes(target, arguments_str, arguments, 307 JSObject::SetOwnPropertyIgnoreAttributes(target, arguments_str, arguments,
306 NONE) 308 NONE)
307 .Check(); 309 .Check();
308 } 310 }
309 311
310 312
311 MaybeHandle<Object> DebugEvaluate::ContextBuilder::LoadFromContext( 313 MaybeHandle<Object> DebugEvaluate::ContextBuilder::LoadFromContext(
312 Handle<Context> context, Handle<String> name) { 314 Handle<Context> context, Handle<String> name, bool* global) {
313 static const ContextLookupFlags flags = FOLLOW_CONTEXT_CHAIN; 315 static const ContextLookupFlags flags = FOLLOW_CONTEXT_CHAIN;
314 int index; 316 int index;
315 PropertyAttributes attributes; 317 PropertyAttributes attributes;
316 BindingFlags binding; 318 BindingFlags binding;
317 Handle<Object> holder = 319 Handle<Object> holder =
318 context->Lookup(name, flags, &index, &attributes, &binding); 320 context->Lookup(name, flags, &index, &attributes, &binding);
319 if (holder.is_null()) return MaybeHandle<Object>(); 321 if (holder.is_null()) return MaybeHandle<Object>();
320 Handle<Object> value; 322 Handle<Object> value;
321 if (index != Context::kNotFound) { // Found on context. 323 if (index != Context::kNotFound) { // Found on context.
322 Handle<Context> context = Handle<Context>::cast(holder); 324 Handle<Context> context = Handle<Context>::cast(holder);
325 // Do not shadow variables on the script context.
326 *global = context->IsScriptContext();
323 return Handle<Object>(context->get(index), isolate_); 327 return Handle<Object>(context->get(index), isolate_);
324 } else { // Found on object. 328 } else { // Found on object.
325 Handle<JSReceiver> object = Handle<JSReceiver>::cast(holder); 329 Handle<JSReceiver> object = Handle<JSReceiver>::cast(holder);
330 // Do not shadow properties on the global object.
331 *global = object->IsJSGlobalObject();
326 return JSReceiver::GetDataProperty(object, name); 332 return JSReceiver::GetDataProperty(object, name);
327 } 333 }
328 } 334 }
329 335
330 336
331 void DebugEvaluate::ContextBuilder::MaterializeContextChain( 337 void DebugEvaluate::ContextBuilder::MaterializeContextChain(
332 Handle<JSObject> target, Handle<Context> context) { 338 Handle<JSObject> target, Handle<Context> context) {
333 for (const Handle<String>& name : non_locals_) { 339 for (const Handle<String>& name : non_locals_) {
334 HandleScope scope(isolate_); 340 HandleScope scope(isolate_);
335 Handle<Object> value; 341 Handle<Object> value;
336 if (!LoadFromContext(context, name).ToHandle(&value)) continue; 342 bool global;
343 if (!LoadFromContext(context, name, &global).ToHandle(&value) || global) {
344 // If resolving the variable fails, skip it. If it resolves to a global
345 // variable, skip it as well since it's not read-only and can be resolved
346 // within debug-evaluate.
347 continue;
348 }
337 JSObject::SetOwnPropertyIgnoreAttributes(target, name, value, NONE).Check(); 349 JSObject::SetOwnPropertyIgnoreAttributes(target, name, value, NONE).Check();
338 } 350 }
339 } 351 }
340 352
341 353
342 void DebugEvaluate::ContextBuilder::StoreToContext(Handle<Context> context, 354 void DebugEvaluate::ContextBuilder::StoreToContext(Handle<Context> context,
343 Handle<String> name, 355 Handle<String> name,
344 Handle<Object> value) { 356 Handle<Object> value) {
345 static const ContextLookupFlags flags = FOLLOW_CONTEXT_CHAIN; 357 static const ContextLookupFlags flags = FOLLOW_CONTEXT_CHAIN;
346 int index; 358 int index;
(...skipping 27 matching lines...) Expand all
374 } 386 }
375 387
376 388
377 Handle<Context> DebugEvaluate::ContextBuilder::MaterializeReceiver( 389 Handle<Context> DebugEvaluate::ContextBuilder::MaterializeReceiver(
378 Handle<Context> parent_context, Handle<Context> lookup_context, 390 Handle<Context> parent_context, Handle<Context> lookup_context,
379 Handle<JSFunction> local_function, Handle<JSFunction> global_function, 391 Handle<JSFunction> local_function, Handle<JSFunction> global_function,
380 bool this_is_non_local) { 392 bool this_is_non_local) {
381 Handle<Object> receiver = isolate_->factory()->undefined_value(); 393 Handle<Object> receiver = isolate_->factory()->undefined_value();
382 Handle<String> this_string = isolate_->factory()->this_string(); 394 Handle<String> this_string = isolate_->factory()->this_string();
383 if (this_is_non_local) { 395 if (this_is_non_local) {
384 LoadFromContext(lookup_context, this_string).ToHandle(&receiver); 396 bool global;
397 LoadFromContext(lookup_context, this_string, &global).ToHandle(&receiver);
385 } else if (local_function->shared()->scope_info()->HasReceiver()) { 398 } else if (local_function->shared()->scope_info()->HasReceiver()) {
386 receiver = handle(frame_->receiver(), isolate_); 399 receiver = handle(frame_->receiver(), isolate_);
387 } 400 }
388 return isolate_->factory()->NewCatchContext(global_function, parent_context, 401 return isolate_->factory()->NewCatchContext(global_function, parent_context,
389 this_string, receiver); 402 this_string, receiver);
390 } 403 }
391 404
392 } // namespace internal 405 } // namespace internal
393 } // namespace v8 406 } // namespace v8
OLDNEW
« no previous file with comments | « src/debug/debug-evaluate.h ('k') | src/flag-definitions.h » ('j') | src/flag-definitions.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698