OLD | NEW |
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" |
11 #include "src/debug/debug-scopes.h" | 11 #include "src/debug/debug-scopes.h" |
12 #include "src/debug/debug.h" | 12 #include "src/debug/debug.h" |
13 #include "src/frames-inl.h" | 13 #include "src/frames-inl.h" |
14 #include "src/globals.h" | 14 #include "src/globals.h" |
15 #include "src/isolate-inl.h" | 15 #include "src/isolate-inl.h" |
16 | 16 |
17 namespace v8 { | 17 namespace v8 { |
18 namespace internal { | 18 namespace internal { |
19 | 19 |
20 static inline bool IsDebugContext(Isolate* isolate, Context* context) { | 20 static inline bool IsDebugContext(Isolate* isolate, Context* context) { |
21 return context->native_context() == *isolate->debug()->debug_context(); | 21 return context->native_context() == *isolate->debug()->debug_context(); |
22 } | 22 } |
23 | 23 |
24 | 24 MaybeHandle<Object> DebugEvaluate::Global(Isolate* isolate, |
25 MaybeHandle<Object> DebugEvaluate::Global( | 25 Handle<String> source) { |
26 Isolate* isolate, Handle<String> source, bool disable_break, | |
27 Handle<HeapObject> context_extension) { | |
28 // Handle the processing of break. | 26 // Handle the processing of break. |
29 DisableBreak disable_break_scope(isolate->debug(), disable_break); | 27 DisableBreak disable_break_scope(isolate->debug()); |
30 | 28 |
31 // Enter the top context from before the debugger was invoked. | 29 // Enter the top context from before the debugger was invoked. |
32 SaveContext save(isolate); | 30 SaveContext save(isolate); |
33 SaveContext* top = &save; | 31 SaveContext* top = &save; |
34 while (top != NULL && IsDebugContext(isolate, *top->context())) { | 32 while (top != NULL && IsDebugContext(isolate, *top->context())) { |
35 top = top->prev(); | 33 top = top->prev(); |
36 } | 34 } |
37 if (top != NULL) isolate->set_context(*top->context()); | 35 if (top != NULL) isolate->set_context(*top->context()); |
38 | 36 |
39 // Get the native context now set to the top context from before the | 37 // Get the native context now set to the top context from before the |
40 // debugger was invoked. | 38 // debugger was invoked. |
41 Handle<Context> context = isolate->native_context(); | 39 Handle<Context> context = isolate->native_context(); |
42 Handle<JSObject> receiver(context->global_proxy()); | 40 Handle<JSObject> receiver(context->global_proxy()); |
43 Handle<SharedFunctionInfo> outer_info(context->closure()->shared(), isolate); | 41 Handle<SharedFunctionInfo> outer_info(context->closure()->shared(), isolate); |
44 return Evaluate(isolate, outer_info, context, context_extension, receiver, | 42 return Evaluate(isolate, outer_info, context, receiver, source); |
45 source); | |
46 } | 43 } |
47 | 44 |
48 | |
49 MaybeHandle<Object> DebugEvaluate::Local(Isolate* isolate, | 45 MaybeHandle<Object> DebugEvaluate::Local(Isolate* isolate, |
50 StackFrame::Id frame_id, | 46 StackFrame::Id frame_id, |
51 int inlined_jsframe_index, | 47 int inlined_jsframe_index, |
52 Handle<String> source, | 48 Handle<String> source) { |
53 bool disable_break, | |
54 Handle<HeapObject> context_extension) { | |
55 // Handle the processing of break. | 49 // Handle the processing of break. |
56 DisableBreak disable_break_scope(isolate->debug(), disable_break); | 50 DisableBreak disable_break_scope(isolate->debug()); |
57 | 51 |
58 // Get the frame where the debugging is performed. | 52 // Get the frame where the debugging is performed. |
59 StackTraceFrameIterator it(isolate, frame_id); | 53 StackTraceFrameIterator it(isolate, frame_id); |
60 if (!it.is_javascript()) return isolate->factory()->undefined_value(); | 54 if (!it.is_javascript()) return isolate->factory()->undefined_value(); |
61 JavaScriptFrame* frame = it.javascript_frame(); | 55 JavaScriptFrame* frame = it.javascript_frame(); |
62 | 56 |
63 // Traverse the saved contexts chain to find the active context for the | 57 // Traverse the saved contexts chain to find the active context for the |
64 // selected frame. | 58 // selected frame. |
65 SaveContext* save = | 59 SaveContext* save = |
66 DebugFrameHelper::FindSavedContextForFrame(isolate, frame); | 60 DebugFrameHelper::FindSavedContextForFrame(isolate, frame); |
67 SaveContext savex(isolate); | 61 SaveContext savex(isolate); |
68 isolate->set_context(*(save->context())); | 62 isolate->set_context(*(save->context())); |
69 | 63 |
70 // This is not a lot different than DebugEvaluate::Global, except that | 64 // This is not a lot different than DebugEvaluate::Global, except that |
71 // variables accessible by the function we are evaluating from are | 65 // variables accessible by the function we are evaluating from are |
72 // materialized and included on top of the native context. Changes to | 66 // materialized and included on top of the native context. Changes to |
73 // the materialized object are written back afterwards. | 67 // the materialized object are written back afterwards. |
74 // Note that the native context is taken from the original context chain, | 68 // Note that the native context is taken from the original context chain, |
75 // which may not be the current native context of the isolate. | 69 // which may not be the current native context of the isolate. |
76 ContextBuilder context_builder(isolate, frame, inlined_jsframe_index); | 70 ContextBuilder context_builder(isolate, frame, inlined_jsframe_index); |
77 if (isolate->has_pending_exception()) return MaybeHandle<Object>(); | 71 if (isolate->has_pending_exception()) return MaybeHandle<Object>(); |
78 | 72 |
79 Handle<Context> context = context_builder.evaluation_context(); | 73 Handle<Context> context = context_builder.evaluation_context(); |
80 Handle<JSObject> receiver(context->global_proxy()); | 74 Handle<JSObject> receiver(context->global_proxy()); |
81 MaybeHandle<Object> maybe_result = | 75 MaybeHandle<Object> maybe_result = Evaluate( |
82 Evaluate(isolate, context_builder.outer_info(), context, | 76 isolate, context_builder.outer_info(), context, receiver, source); |
83 context_extension, receiver, source); | |
84 if (!maybe_result.is_null()) context_builder.UpdateValues(); | 77 if (!maybe_result.is_null()) context_builder.UpdateValues(); |
85 return maybe_result; | 78 return maybe_result; |
86 } | 79 } |
87 | 80 |
88 | 81 |
89 // Compile and evaluate source for the given context. | 82 // Compile and evaluate source for the given context. |
90 MaybeHandle<Object> DebugEvaluate::Evaluate( | 83 MaybeHandle<Object> DebugEvaluate::Evaluate( |
91 Isolate* isolate, Handle<SharedFunctionInfo> outer_info, | 84 Isolate* isolate, Handle<SharedFunctionInfo> outer_info, |
92 Handle<Context> context, Handle<HeapObject> context_extension, | 85 Handle<Context> context, Handle<Object> receiver, Handle<String> source) { |
93 Handle<Object> receiver, Handle<String> source) { | |
94 if (context_extension->IsJSObject()) { | |
95 Handle<JSObject> extension = Handle<JSObject>::cast(context_extension); | |
96 Handle<JSFunction> closure(context->closure(), isolate); | |
97 context = isolate->factory()->NewWithContext( | |
98 closure, context, | |
99 ScopeInfo::CreateForWithScope( | |
100 isolate, context->IsNativeContext() | |
101 ? Handle<ScopeInfo>::null() | |
102 : Handle<ScopeInfo>(context->scope_info())), | |
103 extension); | |
104 } | |
105 | |
106 Handle<JSFunction> eval_fun; | 86 Handle<JSFunction> eval_fun; |
107 ASSIGN_RETURN_ON_EXCEPTION( | 87 ASSIGN_RETURN_ON_EXCEPTION( |
108 isolate, eval_fun, | 88 isolate, eval_fun, |
109 Compiler::GetFunctionFromEval(source, outer_info, context, SLOPPY, | 89 Compiler::GetFunctionFromEval(source, outer_info, context, SLOPPY, |
110 NO_PARSE_RESTRICTION, kNoSourcePosition, | 90 NO_PARSE_RESTRICTION, kNoSourcePosition, |
111 kNoSourcePosition), | 91 kNoSourcePosition), |
112 Object); | 92 Object); |
113 | 93 |
114 Handle<Object> result; | 94 Handle<Object> result; |
115 ASSIGN_RETURN_ON_EXCEPTION( | 95 ASSIGN_RETURN_ON_EXCEPTION( |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 return; | 244 return; |
265 } else if (local_function->shared()->scope_info()->HasReceiver() && | 245 } else if (local_function->shared()->scope_info()->HasReceiver() && |
266 !frame_->receiver()->IsTheHole(isolate_)) { | 246 !frame_->receiver()->IsTheHole(isolate_)) { |
267 recv = handle(frame_->receiver(), isolate_); | 247 recv = handle(frame_->receiver(), isolate_); |
268 } | 248 } |
269 JSObject::SetOwnPropertyIgnoreAttributes(target, name, recv, NONE).Check(); | 249 JSObject::SetOwnPropertyIgnoreAttributes(target, name, recv, NONE).Check(); |
270 } | 250 } |
271 | 251 |
272 } // namespace internal | 252 } // namespace internal |
273 } // namespace v8 | 253 } // namespace v8 |
OLD | NEW |