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

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

Issue 2685483002: [debugger] expose side-effect free evaluate to inspector. (Closed)
Patch Set: add inspector test Created 3 years, 10 months 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/debug/mirrors.js » ('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/compiler.h" 8 #include "src/compiler.h"
9 #include "src/contexts.h" 9 #include "src/contexts.h"
10 #include "src/debug/debug-frames.h" 10 #include "src/debug/debug-frames.h"
(...skipping 23 matching lines...) Expand all
34 while (top != NULL && IsDebugContext(isolate, *top->context())) { 34 while (top != NULL && IsDebugContext(isolate, *top->context())) {
35 top = top->prev(); 35 top = top->prev();
36 } 36 }
37 if (top != NULL) isolate->set_context(*top->context()); 37 if (top != NULL) isolate->set_context(*top->context());
38 38
39 // Get the native context now set to the top context from before the 39 // Get the native context now set to the top context from before the
40 // debugger was invoked. 40 // debugger was invoked.
41 Handle<Context> context = isolate->native_context(); 41 Handle<Context> context = isolate->native_context();
42 Handle<JSObject> receiver(context->global_proxy()); 42 Handle<JSObject> receiver(context->global_proxy());
43 Handle<SharedFunctionInfo> outer_info(context->closure()->shared(), isolate); 43 Handle<SharedFunctionInfo> outer_info(context->closure()->shared(), isolate);
44 return Evaluate(isolate, outer_info, context, receiver, source); 44 return Evaluate(isolate, outer_info, context, receiver, source, false);
45 } 45 }
46 46
47 MaybeHandle<Object> DebugEvaluate::Local(Isolate* isolate, 47 MaybeHandle<Object> DebugEvaluate::Local(Isolate* isolate,
48 StackFrame::Id frame_id, 48 StackFrame::Id frame_id,
49 int inlined_jsframe_index, 49 int inlined_jsframe_index,
50 Handle<String> source) { 50 Handle<String> source,
51 bool throw_on_side_effect) {
51 // Handle the processing of break. 52 // Handle the processing of break.
52 DisableBreak disable_break_scope(isolate->debug()); 53 DisableBreak disable_break_scope(isolate->debug());
53 54
54 // Get the frame where the debugging is performed. 55 // Get the frame where the debugging is performed.
55 StackTraceFrameIterator it(isolate, frame_id); 56 StackTraceFrameIterator it(isolate, frame_id);
56 if (!it.is_javascript()) return isolate->factory()->undefined_value(); 57 if (!it.is_javascript()) return isolate->factory()->undefined_value();
57 JavaScriptFrame* frame = it.javascript_frame(); 58 JavaScriptFrame* frame = it.javascript_frame();
58 59
59 // Traverse the saved contexts chain to find the active context for the 60 // Traverse the saved contexts chain to find the active context for the
60 // selected frame. 61 // selected frame.
61 SaveContext* save = 62 SaveContext* save =
62 DebugFrameHelper::FindSavedContextForFrame(isolate, frame); 63 DebugFrameHelper::FindSavedContextForFrame(isolate, frame);
63 SaveContext savex(isolate); 64 SaveContext savex(isolate);
64 isolate->set_context(*(save->context())); 65 isolate->set_context(*(save->context()));
65 66
66 // This is not a lot different than DebugEvaluate::Global, except that 67 // This is not a lot different than DebugEvaluate::Global, except that
67 // variables accessible by the function we are evaluating from are 68 // variables accessible by the function we are evaluating from are
68 // materialized and included on top of the native context. Changes to 69 // materialized and included on top of the native context. Changes to
69 // the materialized object are written back afterwards. 70 // the materialized object are written back afterwards.
70 // Note that the native context is taken from the original context chain, 71 // Note that the native context is taken from the original context chain,
71 // which may not be the current native context of the isolate. 72 // which may not be the current native context of the isolate.
72 ContextBuilder context_builder(isolate, frame, inlined_jsframe_index); 73 ContextBuilder context_builder(isolate, frame, inlined_jsframe_index);
73 if (isolate->has_pending_exception()) return MaybeHandle<Object>(); 74 if (isolate->has_pending_exception()) return MaybeHandle<Object>();
74 75
75 Handle<Context> context = context_builder.evaluation_context(); 76 Handle<Context> context = context_builder.evaluation_context();
76 Handle<JSObject> receiver(context->global_proxy()); 77 Handle<JSObject> receiver(context->global_proxy());
77 MaybeHandle<Object> maybe_result = Evaluate( 78 MaybeHandle<Object> maybe_result =
78 isolate, context_builder.outer_info(), context, receiver, source); 79 Evaluate(isolate, context_builder.outer_info(), context, receiver, source,
80 throw_on_side_effect);
79 if (!maybe_result.is_null()) context_builder.UpdateValues(); 81 if (!maybe_result.is_null()) context_builder.UpdateValues();
80 return maybe_result; 82 return maybe_result;
81 } 83 }
82 84
83 85
84 // Compile and evaluate source for the given context. 86 // Compile and evaluate source for the given context.
85 MaybeHandle<Object> DebugEvaluate::Evaluate( 87 MaybeHandle<Object> DebugEvaluate::Evaluate(
86 Isolate* isolate, Handle<SharedFunctionInfo> outer_info, 88 Isolate* isolate, Handle<SharedFunctionInfo> outer_info,
87 Handle<Context> context, Handle<Object> receiver, Handle<String> source) { 89 Handle<Context> context, Handle<Object> receiver, Handle<String> source,
90 bool throw_on_side_effect) {
88 Handle<JSFunction> eval_fun; 91 Handle<JSFunction> eval_fun;
89 ASSIGN_RETURN_ON_EXCEPTION( 92 ASSIGN_RETURN_ON_EXCEPTION(
90 isolate, eval_fun, 93 isolate, eval_fun,
91 Compiler::GetFunctionFromEval(source, outer_info, context, SLOPPY, 94 Compiler::GetFunctionFromEval(source, outer_info, context, SLOPPY,
92 NO_PARSE_RESTRICTION, kNoSourcePosition, 95 NO_PARSE_RESTRICTION, kNoSourcePosition,
93 kNoSourcePosition), 96 kNoSourcePosition),
94 Object); 97 Object);
95 98
96 Handle<Object> result; 99 Handle<Object> result;
97 { 100 {
98 NoSideEffectScope no_side_effect(isolate, 101 NoSideEffectScope no_side_effect(isolate, throw_on_side_effect);
99 FLAG_side_effect_free_debug_evaluate);
100 ASSIGN_RETURN_ON_EXCEPTION( 102 ASSIGN_RETURN_ON_EXCEPTION(
101 isolate, result, Execution::Call(isolate, eval_fun, receiver, 0, NULL), 103 isolate, result, Execution::Call(isolate, eval_fun, receiver, 0, NULL),
102 Object); 104 Object);
103 } 105 }
104 106
105 // Skip the global proxy as it has no properties and always delegates to the 107 // Skip the global proxy as it has no properties and always delegates to the
106 // real global object. 108 // real global object.
107 if (result->IsJSGlobalProxy()) { 109 if (result->IsJSGlobalProxy()) {
108 PrototypeIterator iter(isolate, Handle<JSGlobalProxy>::cast(result)); 110 PrototypeIterator iter(isolate, Handle<JSGlobalProxy>::cast(result));
109 // TODO(verwaest): This will crash when the global proxy is detached. 111 // TODO(verwaest): This will crash when the global proxy is detached.
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 539
538 if (FLAG_trace_side_effect_free_debug_evaluate) { 540 if (FLAG_trace_side_effect_free_debug_evaluate) {
539 PrintF("[debug-evaluate] API Callback at %p may cause side effect.\n", 541 PrintF("[debug-evaluate] API Callback at %p may cause side effect.\n",
540 reinterpret_cast<void*>(function_addr)); 542 reinterpret_cast<void*>(function_addr));
541 } 543 }
542 return false; 544 return false;
543 } 545 }
544 546
545 } // namespace internal 547 } // namespace internal
546 } // namespace v8 548 } // namespace v8
OLDNEW
« no previous file with comments | « src/debug/debug-evaluate.h ('k') | src/debug/mirrors.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698