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/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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 // Context::Lookup has special handling for debug-evaluate contexts: | 147 // Context::Lookup has special handling for debug-evaluate contexts: |
148 // - Look up in the materialized stack variables. | 148 // - Look up in the materialized stack variables. |
149 // - Look up in the original context. | 149 // - Look up in the original context. |
150 // - Check the whitelist to find out whether to skip contexts during lookup. | 150 // - Check the whitelist to find out whether to skip contexts during lookup. |
151 const ScopeIterator::Option option = ScopeIterator::COLLECT_NON_LOCALS; | 151 const ScopeIterator::Option option = ScopeIterator::COLLECT_NON_LOCALS; |
152 for (ScopeIterator it(isolate, &frame_inspector, option); | 152 for (ScopeIterator it(isolate, &frame_inspector, option); |
153 !it.Failed() && !it.Done(); it.Next()) { | 153 !it.Failed() && !it.Done(); it.Next()) { |
154 ScopeIterator::ScopeType scope_type = it.Type(); | 154 ScopeIterator::ScopeType scope_type = it.Type(); |
155 if (scope_type == ScopeIterator::ScopeTypeLocal) { | 155 if (scope_type == ScopeIterator::ScopeTypeLocal) { |
156 DCHECK_EQ(FUNCTION_SCOPE, it.CurrentScopeInfo()->scope_type()); | 156 DCHECK_EQ(FUNCTION_SCOPE, it.CurrentScopeInfo()->scope_type()); |
157 Handle<JSObject> materialized = NewJSObjectWithNullProto(); | 157 Handle<JSObject> materialized = factory->NewJSObjectWithNullProto(); |
158 Handle<Context> local_context = | 158 Handle<Context> local_context = |
159 it.HasContext() ? it.CurrentContext() : outer_context; | 159 it.HasContext() ? it.CurrentContext() : outer_context; |
160 Handle<StringSet> non_locals = it.GetNonLocals(); | 160 Handle<StringSet> non_locals = it.GetNonLocals(); |
161 MaterializeReceiver(materialized, local_context, local_function, | 161 MaterializeReceiver(materialized, local_context, local_function, |
162 non_locals); | 162 non_locals); |
163 frame_inspector.MaterializeStackLocals(materialized, local_function); | 163 frame_inspector.MaterializeStackLocals(materialized, local_function); |
164 MaterializeArgumentsObject(materialized, local_function); | 164 MaterializeArgumentsObject(materialized, local_function); |
165 ContextChainElement context_chain_element; | 165 ContextChainElement context_chain_element; |
166 context_chain_element.scope_info = it.CurrentScopeInfo(); | 166 context_chain_element.scope_info = it.CurrentScopeInfo(); |
167 context_chain_element.materialized_object = materialized; | 167 context_chain_element.materialized_object = materialized; |
168 // Non-locals that are already being referenced by the current function | 168 // Non-locals that are already being referenced by the current function |
169 // are guaranteed to be correctly resolved. | 169 // are guaranteed to be correctly resolved. |
170 context_chain_element.whitelist = non_locals; | 170 context_chain_element.whitelist = non_locals; |
171 if (it.HasContext()) { | 171 if (it.HasContext()) { |
172 context_chain_element.wrapped_context = it.CurrentContext(); | 172 context_chain_element.wrapped_context = it.CurrentContext(); |
173 } | 173 } |
174 context_chain_.Add(context_chain_element); | 174 context_chain_.Add(context_chain_element); |
175 evaluation_context_ = outer_context; | 175 evaluation_context_ = outer_context; |
176 break; | 176 break; |
177 } else if (scope_type == ScopeIterator::ScopeTypeCatch || | 177 } else if (scope_type == ScopeIterator::ScopeTypeCatch || |
178 scope_type == ScopeIterator::ScopeTypeWith) { | 178 scope_type == ScopeIterator::ScopeTypeWith) { |
179 ContextChainElement context_chain_element; | 179 ContextChainElement context_chain_element; |
180 Handle<Context> current_context = it.CurrentContext(); | 180 Handle<Context> current_context = it.CurrentContext(); |
181 if (!current_context->IsDebugEvaluateContext()) { | 181 if (!current_context->IsDebugEvaluateContext()) { |
182 context_chain_element.wrapped_context = current_context; | 182 context_chain_element.wrapped_context = current_context; |
183 } | 183 } |
184 context_chain_.Add(context_chain_element); | 184 context_chain_.Add(context_chain_element); |
185 } else if (scope_type == ScopeIterator::ScopeTypeBlock) { | 185 } else if (scope_type == ScopeIterator::ScopeTypeBlock) { |
186 Handle<JSObject> materialized = NewJSObjectWithNullProto(); | 186 Handle<JSObject> materialized = factory->NewJSObjectWithNullProto(); |
187 frame_inspector.MaterializeStackLocals(materialized, | 187 frame_inspector.MaterializeStackLocals(materialized, |
188 it.CurrentScopeInfo()); | 188 it.CurrentScopeInfo()); |
189 ContextChainElement context_chain_element; | 189 ContextChainElement context_chain_element; |
190 context_chain_element.scope_info = it.CurrentScopeInfo(); | 190 context_chain_element.scope_info = it.CurrentScopeInfo(); |
191 context_chain_element.materialized_object = materialized; | 191 context_chain_element.materialized_object = materialized; |
192 if (it.HasContext()) { | 192 if (it.HasContext()) { |
193 context_chain_element.wrapped_context = it.CurrentContext(); | 193 context_chain_element.wrapped_context = it.CurrentContext(); |
194 } | 194 } |
195 context_chain_.Add(context_chain_element); | 195 context_chain_.Add(context_chain_element); |
196 } else { | 196 } else { |
(...skipping 16 matching lines...) Expand all Loading... |
213 if (!element.materialized_object.is_null()) { | 213 if (!element.materialized_object.is_null()) { |
214 // Write back potential changes to materialized stack locals to the stack. | 214 // Write back potential changes to materialized stack locals to the stack. |
215 FrameInspector(frame_, inlined_jsframe_index_, isolate_) | 215 FrameInspector(frame_, inlined_jsframe_index_, isolate_) |
216 .UpdateStackLocalsFromMaterializedObject(element.materialized_object, | 216 .UpdateStackLocalsFromMaterializedObject(element.materialized_object, |
217 element.scope_info); | 217 element.scope_info); |
218 } | 218 } |
219 } | 219 } |
220 } | 220 } |
221 | 221 |
222 | 222 |
223 Handle<JSObject> DebugEvaluate::ContextBuilder::NewJSObjectWithNullProto() { | |
224 Handle<JSObject> result = | |
225 isolate_->factory()->NewJSObject(isolate_->object_function()); | |
226 Handle<Map> new_map = | |
227 Map::Copy(Handle<Map>(result->map()), "ObjectWithNullProto"); | |
228 Map::SetPrototype(new_map, isolate_->factory()->null_value()); | |
229 JSObject::MigrateToMap(result, new_map); | |
230 return result; | |
231 } | |
232 | |
233 | |
234 void DebugEvaluate::ContextBuilder::MaterializeArgumentsObject( | 223 void DebugEvaluate::ContextBuilder::MaterializeArgumentsObject( |
235 Handle<JSObject> target, Handle<JSFunction> function) { | 224 Handle<JSObject> target, Handle<JSFunction> function) { |
236 // Do not materialize the arguments object for eval or top-level code. | 225 // Do not materialize the arguments object for eval or top-level code. |
237 // Skip if "arguments" is already taken. | 226 // Skip if "arguments" is already taken. |
238 if (!function->shared()->is_function()) return; | 227 if (!function->shared()->is_function()) return; |
239 Maybe<bool> maybe = JSReceiver::HasOwnProperty( | 228 Maybe<bool> maybe = JSReceiver::HasOwnProperty( |
240 target, isolate_->factory()->arguments_string()); | 229 target, isolate_->factory()->arguments_string()); |
241 DCHECK(maybe.IsJust()); | 230 DCHECK(maybe.IsJust()); |
242 if (maybe.FromJust()) return; | 231 if (maybe.FromJust()) return; |
243 | 232 |
(...skipping 15 matching lines...) Expand all Loading... |
259 // referenced by the current function, so it can be correctly resolved. | 248 // referenced by the current function, so it can be correctly resolved. |
260 return; | 249 return; |
261 } else if (local_function->shared()->scope_info()->HasReceiver()) { | 250 } else if (local_function->shared()->scope_info()->HasReceiver()) { |
262 recv = handle(frame_->receiver(), isolate_); | 251 recv = handle(frame_->receiver(), isolate_); |
263 } | 252 } |
264 JSObject::SetOwnPropertyIgnoreAttributes(target, name, recv, NONE).Check(); | 253 JSObject::SetOwnPropertyIgnoreAttributes(target, name, recv, NONE).Check(); |
265 } | 254 } |
266 | 255 |
267 } // namespace internal | 256 } // namespace internal |
268 } // namespace v8 | 257 } // namespace v8 |
OLD | NEW |