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-scopes.h" | 5 #include "src/debug/debug-scopes.h" |
6 | 6 |
7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
8 #include "src/debug/debug.h" | 8 #include "src/debug/debug.h" |
9 #include "src/frames-inl.h" | 9 #include "src/frames-inl.h" |
10 #include "src/globals.h" | 10 #include "src/globals.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 if (collect_non_locals) CollectNonLocals(scope); | 101 if (collect_non_locals) CollectNonLocals(scope); |
102 } else { | 102 } else { |
103 // Function code | 103 // Function code |
104 ParseInfo info(&zone, function); | 104 ParseInfo info(&zone, function); |
105 if (Parser::ParseStatic(&info) && Scope::Analyze(&info)) { | 105 if (Parser::ParseStatic(&info) && Scope::Analyze(&info)) { |
106 scope = info.literal()->scope(); | 106 scope = info.literal()->scope(); |
107 } | 107 } |
108 if (!ignore_nested_scopes) RetrieveScopeChain(scope); | 108 if (!ignore_nested_scopes) RetrieveScopeChain(scope); |
109 if (collect_non_locals) CollectNonLocals(scope); | 109 if (collect_non_locals) CollectNonLocals(scope); |
110 } | 110 } |
111 UnwrapEvaluationContext(); | |
111 } | 112 } |
112 | 113 |
113 | 114 |
114 ScopeIterator::ScopeIterator(Isolate* isolate, Handle<JSFunction> function) | 115 ScopeIterator::ScopeIterator(Isolate* isolate, Handle<JSFunction> function) |
115 : isolate_(isolate), | 116 : isolate_(isolate), |
116 frame_inspector_(NULL), | 117 frame_inspector_(NULL), |
117 context_(function->context()), | 118 context_(function->context()), |
118 seen_script_scope_(false), | 119 seen_script_scope_(false), |
119 failed_(false) { | 120 failed_(false) { |
120 if (!function->shared()->IsSubjectToDebugging()) context_ = Handle<Context>(); | 121 if (!function->shared()->IsSubjectToDebugging()) context_ = Handle<Context>(); |
122 UnwrapEvaluationContext(); | |
123 } | |
124 | |
125 void ScopeIterator::UnwrapEvaluationContext() { | |
126 while (true) { | |
127 if (context_.is_null()) return; | |
128 if (!context_->IsDebugEvaluateContext()) return; | |
Camillo Bruni
2016/04/05 11:37:59
so you can have only one debug context (or directl
Yang
2016/04/05 11:43:00
No. The point of this CL is that the scope iterato
| |
129 // An existing debug-evaluate context can only be outside the local scope. | |
130 DCHECK(nested_scope_chain_.is_empty()); | |
131 Handle<Object> wrapped(context_->get(Context::WRAPPED_CONTEXT_INDEX), | |
132 isolate_); | |
133 if (wrapped->IsContext()) { | |
134 context_ = Handle<Context>::cast(wrapped); | |
135 } else { | |
136 context_ = Handle<Context>(context_->previous(), isolate_); | |
137 } | |
138 } | |
121 } | 139 } |
122 | 140 |
123 | 141 |
124 MUST_USE_RESULT MaybeHandle<JSObject> ScopeIterator::MaterializeScopeDetails() { | 142 MUST_USE_RESULT MaybeHandle<JSObject> ScopeIterator::MaterializeScopeDetails() { |
125 // Calculate the size of the result. | 143 // Calculate the size of the result. |
126 Handle<FixedArray> details = | 144 Handle<FixedArray> details = |
127 isolate_->factory()->NewFixedArray(kScopeDetailsSize); | 145 isolate_->factory()->NewFixedArray(kScopeDetailsSize); |
128 // Fill in scope details. | 146 // Fill in scope details. |
129 details->set(kScopeDetailsTypeIndex, Smi::FromInt(Type())); | 147 details->set(kScopeDetailsTypeIndex, Smi::FromInt(Type())); |
130 Handle<JSObject> scope_object; | 148 Handle<JSObject> scope_object; |
(...skipping 30 matching lines...) Expand all Loading... | |
161 } | 179 } |
162 | 180 |
163 | 181 |
164 void ScopeIterator::Next() { | 182 void ScopeIterator::Next() { |
165 DCHECK(!failed_); | 183 DCHECK(!failed_); |
166 ScopeType scope_type = Type(); | 184 ScopeType scope_type = Type(); |
167 if (scope_type == ScopeTypeGlobal) { | 185 if (scope_type == ScopeTypeGlobal) { |
168 // The global scope is always the last in the chain. | 186 // The global scope is always the last in the chain. |
169 DCHECK(context_->IsNativeContext()); | 187 DCHECK(context_->IsNativeContext()); |
170 context_ = Handle<Context>(); | 188 context_ = Handle<Context>(); |
171 return; | 189 } else if (scope_type == ScopeTypeScript) { |
172 } | |
173 if (scope_type == ScopeTypeScript) { | |
174 seen_script_scope_ = true; | 190 seen_script_scope_ = true; |
175 if (context_->IsScriptContext()) { | 191 if (context_->IsScriptContext()) { |
176 context_ = Handle<Context>(context_->previous(), isolate_); | 192 context_ = Handle<Context>(context_->previous(), isolate_); |
177 } | 193 } |
178 if (!nested_scope_chain_.is_empty()) { | 194 if (!nested_scope_chain_.is_empty()) { |
179 DCHECK_EQ(nested_scope_chain_.last().scope_info->scope_type(), | 195 DCHECK_EQ(nested_scope_chain_.last().scope_info->scope_type(), |
180 SCRIPT_SCOPE); | 196 SCRIPT_SCOPE); |
181 nested_scope_chain_.RemoveLast(); | 197 nested_scope_chain_.RemoveLast(); |
182 DCHECK(nested_scope_chain_.is_empty()); | 198 DCHECK(nested_scope_chain_.is_empty()); |
183 } | 199 } |
184 CHECK(context_->IsNativeContext()); | 200 CHECK(context_->IsNativeContext()); |
185 return; | 201 } else if (nested_scope_chain_.is_empty()) { |
186 } | |
187 if (nested_scope_chain_.is_empty()) { | |
188 context_ = Handle<Context>(context_->previous(), isolate_); | 202 context_ = Handle<Context>(context_->previous(), isolate_); |
189 } else { | 203 } else { |
190 if (nested_scope_chain_.last().scope_info->HasContext()) { | 204 if (nested_scope_chain_.last().scope_info->HasContext()) { |
191 DCHECK(context_->previous() != NULL); | 205 DCHECK(context_->previous() != NULL); |
192 context_ = Handle<Context>(context_->previous(), isolate_); | 206 context_ = Handle<Context>(context_->previous(), isolate_); |
193 } | 207 } |
194 nested_scope_chain_.RemoveLast(); | 208 nested_scope_chain_.RemoveLast(); |
195 } | 209 } |
210 UnwrapEvaluationContext(); | |
196 } | 211 } |
197 | 212 |
198 | 213 |
199 // Return the type of the current scope. | 214 // Return the type of the current scope. |
200 ScopeIterator::ScopeType ScopeIterator::Type() { | 215 ScopeIterator::ScopeType ScopeIterator::Type() { |
201 DCHECK(!failed_); | 216 DCHECK(!failed_); |
202 if (!nested_scope_chain_.is_empty()) { | 217 if (!nested_scope_chain_.is_empty()) { |
203 Handle<ScopeInfo> scope_info = nested_scope_chain_.last().scope_info; | 218 Handle<ScopeInfo> scope_info = nested_scope_chain_.last().scope_info; |
204 switch (scope_info->scope_type()) { | 219 switch (scope_info->scope_type()) { |
205 case FUNCTION_SCOPE: | 220 case FUNCTION_SCOPE: |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 switch (Type()) { | 270 switch (Type()) { |
256 case ScopeIterator::ScopeTypeGlobal: | 271 case ScopeIterator::ScopeTypeGlobal: |
257 return Handle<JSObject>(CurrentContext()->global_proxy()); | 272 return Handle<JSObject>(CurrentContext()->global_proxy()); |
258 case ScopeIterator::ScopeTypeScript: | 273 case ScopeIterator::ScopeTypeScript: |
259 return MaterializeScriptScope(); | 274 return MaterializeScriptScope(); |
260 case ScopeIterator::ScopeTypeLocal: | 275 case ScopeIterator::ScopeTypeLocal: |
261 // Materialize the content of the local scope into a JSObject. | 276 // Materialize the content of the local scope into a JSObject. |
262 DCHECK(nested_scope_chain_.length() == 1); | 277 DCHECK(nested_scope_chain_.length() == 1); |
263 return MaterializeLocalScope(); | 278 return MaterializeLocalScope(); |
264 case ScopeIterator::ScopeTypeWith: | 279 case ScopeIterator::ScopeTypeWith: |
265 // Return the with object. | 280 return WithContextExtension(); |
266 // TODO(neis): This breaks for proxies. | |
267 return handle(JSObject::cast(CurrentContext()->extension_receiver())); | |
268 case ScopeIterator::ScopeTypeCatch: | 281 case ScopeIterator::ScopeTypeCatch: |
269 return MaterializeCatchScope(); | 282 return MaterializeCatchScope(); |
270 case ScopeIterator::ScopeTypeClosure: | 283 case ScopeIterator::ScopeTypeClosure: |
271 // Materialize the content of the closure scope into a JSObject. | 284 // Materialize the content of the closure scope into a JSObject. |
272 return MaterializeClosure(); | 285 return MaterializeClosure(); |
273 case ScopeIterator::ScopeTypeBlock: | 286 case ScopeIterator::ScopeTypeBlock: |
274 return MaterializeBlockScope(); | 287 return MaterializeBlockScope(); |
275 case ScopeIterator::ScopeTypeModule: | 288 case ScopeIterator::ScopeTypeModule: |
276 return MaterializeModuleScope(); | 289 return MaterializeModuleScope(); |
277 } | 290 } |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
527 Handle<Object> thrown_object(context->get(Context::THROWN_OBJECT_INDEX), | 540 Handle<Object> thrown_object(context->get(Context::THROWN_OBJECT_INDEX), |
528 isolate_); | 541 isolate_); |
529 Handle<JSObject> catch_scope = | 542 Handle<JSObject> catch_scope = |
530 isolate_->factory()->NewJSObject(isolate_->object_function()); | 543 isolate_->factory()->NewJSObject(isolate_->object_function()); |
531 JSObject::SetOwnPropertyIgnoreAttributes(catch_scope, name, thrown_object, | 544 JSObject::SetOwnPropertyIgnoreAttributes(catch_scope, name, thrown_object, |
532 NONE) | 545 NONE) |
533 .Check(); | 546 .Check(); |
534 return catch_scope; | 547 return catch_scope; |
535 } | 548 } |
536 | 549 |
550 // Retrieve the with-context extension object. If the extension object is | |
551 // a proxy, return an empty object. | |
552 Handle<JSObject> ScopeIterator::WithContextExtension() { | |
553 Handle<Context> context = CurrentContext(); | |
554 DCHECK(context->IsWithContext()); | |
555 if (context->extension_receiver()->IsJSProxy()) { | |
556 return isolate_->factory()->NewJSObjectWithNullProto(); | |
557 } | |
558 return handle(JSObject::cast(context->extension_receiver())); | |
559 } | |
537 | 560 |
538 // Create a plain JSObject which materializes the block scope for the specified | 561 // Create a plain JSObject which materializes the block scope for the specified |
539 // block context. | 562 // block context. |
540 Handle<JSObject> ScopeIterator::MaterializeBlockScope() { | 563 Handle<JSObject> ScopeIterator::MaterializeBlockScope() { |
541 Handle<JSObject> block_scope = | 564 Handle<JSObject> block_scope = |
542 isolate_->factory()->NewJSObject(isolate_->object_function()); | 565 isolate_->factory()->NewJSObject(isolate_->object_function()); |
543 | 566 |
544 Handle<Context> context = Handle<Context>::null(); | 567 Handle<Context> context = Handle<Context>::null(); |
545 if (!nested_scope_chain_.is_empty()) { | 568 if (!nested_scope_chain_.is_empty()) { |
546 Handle<ScopeInfo> scope_info = nested_scope_chain_.last().scope_info; | 569 Handle<ScopeInfo> scope_info = nested_scope_chain_.last().scope_info; |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
831 DCHECK(beg_pos >= 0 && end_pos >= 0); | 854 DCHECK(beg_pos >= 0 && end_pos >= 0); |
832 if (beg_pos <= position && position < end_pos) { | 855 if (beg_pos <= position && position < end_pos) { |
833 GetNestedScopeChain(isolate, inner_scope, position); | 856 GetNestedScopeChain(isolate, inner_scope, position); |
834 return; | 857 return; |
835 } | 858 } |
836 } | 859 } |
837 } | 860 } |
838 | 861 |
839 } // namespace internal | 862 } // namespace internal |
840 } // namespace v8 | 863 } // namespace v8 |
OLD | NEW |