OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 PrintF(")\n"); | 89 PrintF(")\n"); |
90 } | 90 } |
91 | 91 |
92 do { | 92 do { |
93 if (FLAG_trace_contexts) { | 93 if (FLAG_trace_contexts) { |
94 PrintF(" - looking in context %p", reinterpret_cast<void*>(*context)); | 94 PrintF(" - looking in context %p", reinterpret_cast<void*>(*context)); |
95 if (context->IsGlobalContext()) PrintF(" (global context)"); | 95 if (context->IsGlobalContext()) PrintF(" (global context)"); |
96 PrintF("\n"); | 96 PrintF("\n"); |
97 } | 97 } |
98 | 98 |
99 // check extension/with object | 99 // Check extension/with/global object. |
100 if (context->has_extension()) { | 100 if (context->has_extension()) { |
101 Handle<JSObject> extension = Handle<JSObject>(context->extension(), | 101 Handle<JSObject> extension = Handle<JSObject>(context->extension(), |
102 isolate); | 102 isolate); |
103 // Context extension objects needs to behave as if they have no | 103 // Context extension objects needs to behave as if they have no |
104 // prototype. So even if we want to follow prototype chains, we | 104 // prototype. So even if we want to follow prototype chains, we |
105 // need to only do a local lookup for context extension objects. | 105 // need to only do a local lookup for context extension objects. |
106 if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 || | 106 if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 || |
107 extension->IsJSContextExtensionObject()) { | 107 extension->IsJSContextExtensionObject()) { |
108 *attributes = extension->GetLocalPropertyAttribute(*name); | 108 *attributes = extension->GetLocalPropertyAttribute(*name); |
109 } else { | 109 } else { |
110 *attributes = extension->GetPropertyAttribute(*name); | 110 *attributes = extension->GetPropertyAttribute(*name); |
111 } | 111 } |
112 if (*attributes != ABSENT) { | 112 if (*attributes != ABSENT) { |
113 // property found | 113 // property found |
114 if (FLAG_trace_contexts) { | 114 if (FLAG_trace_contexts) { |
115 PrintF("=> found property in context object %p\n", | 115 PrintF("=> found property in context object %p\n", |
116 reinterpret_cast<void*>(*extension)); | 116 reinterpret_cast<void*>(*extension)); |
117 } | 117 } |
118 return extension; | 118 return extension; |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 if (context->is_function_context()) { | 122 if (context->IsFunctionContext()) { |
Kevin Millikin (Chromium)
2011/06/08 16:35:52
Global contexts used to satisfy this predicate, bu
Mads Ager (chromium)
2011/06/09 07:31:00
Could you add a comment to that effect before the
| |
123 // we have context-local slots | 123 // we have context-local slots |
124 | 124 |
125 // check non-parameter locals in context | 125 // check non-parameter locals in context |
126 Handle<SerializedScopeInfo> scope_info( | 126 Handle<SerializedScopeInfo> scope_info( |
127 context->closure()->shared()->scope_info(), isolate); | 127 context->closure()->shared()->scope_info(), isolate); |
128 Variable::Mode mode; | 128 Variable::Mode mode; |
129 int index = scope_info->ContextSlotIndex(*name, &mode); | 129 int index = scope_info->ContextSlotIndex(*name, &mode); |
130 ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); | 130 ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); |
131 if (index >= 0) { | 131 if (index >= 0) { |
132 // slot found | 132 // slot found |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 *index_ = index; | 182 *index_ = index; |
183 *attributes = READ_ONLY; | 183 *attributes = READ_ONLY; |
184 return context; | 184 return context; |
185 } | 185 } |
186 } | 186 } |
187 } | 187 } |
188 | 188 |
189 // proceed with enclosing context | 189 // proceed with enclosing context |
190 if (context->IsGlobalContext()) { | 190 if (context->IsGlobalContext()) { |
191 follow_context_chain = false; | 191 follow_context_chain = false; |
192 } else if (context->is_function_context()) { | 192 } else if (context->IsFunctionContext()) { |
Kevin Millikin (Chromium)
2011/06/08 16:35:52
Global contexts couldn't reach this site.
| |
193 context = Handle<Context>(Context::cast(context->closure()->context()), | 193 context = Handle<Context>(context->closure()->context(), isolate); |
194 isolate); | |
195 } else { | 194 } else { |
196 context = Handle<Context>(context->previous(), isolate); | 195 context = Handle<Context>(context->previous(), isolate); |
197 } | 196 } |
198 } while (follow_context_chain); | 197 } while (follow_context_chain); |
199 | 198 |
200 // slot not found | 199 // slot not found |
201 if (FLAG_trace_contexts) { | 200 if (FLAG_trace_contexts) { |
202 PrintF("=> no property/slot found\n"); | 201 PrintF("=> no property/slot found\n"); |
203 } | 202 } |
204 return Handle<Object>::null(); | 203 return Handle<Object>::null(); |
205 } | 204 } |
206 | 205 |
207 | 206 |
208 bool Context::GlobalIfNotShadowedByEval(Handle<String> name) { | 207 bool Context::GlobalIfNotShadowedByEval(Handle<String> name) { |
209 Context* context = this; | 208 Context* context = this; |
210 | 209 |
211 // Check that there is no local with the given name in contexts | 210 // Check that there is no local with the given name in contexts |
212 // before the global context and check that there are no context | 211 // before the global context and check that there are no context |
213 // extension objects (conservative check for with statements). | 212 // extension objects (conservative check for with statements). |
214 while (!context->IsGlobalContext()) { | 213 while (!context->IsGlobalContext()) { |
215 // Check if the context is a potentially a with context. | 214 // Check if the context is a catch or with context, or has called |
215 // non-strict eval. | |
216 if (context->has_extension()) return false; | 216 if (context->has_extension()) return false; |
217 | 217 |
218 // Not a with context so it must be a function context. | 218 // Not a with context so it must be a function context. |
219 ASSERT(context->is_function_context()); | 219 ASSERT(context->IsFunctionContext()); |
Kevin Millikin (Chromium)
2011/06/08 16:35:52
Global contexts couldn't reach this site.
| |
220 | 220 |
221 // Check non-parameter locals. | 221 // Check non-parameter locals. |
222 Handle<SerializedScopeInfo> scope_info( | 222 Handle<SerializedScopeInfo> scope_info( |
223 context->closure()->shared()->scope_info()); | 223 context->closure()->shared()->scope_info()); |
224 Variable::Mode mode; | 224 Variable::Mode mode; |
225 int index = scope_info->ContextSlotIndex(*name, &mode); | 225 int index = scope_info->ContextSlotIndex(*name, &mode); |
226 ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); | 226 ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); |
227 if (index >= 0) return false; | 227 if (index >= 0) return false; |
228 | 228 |
229 // Check parameter locals. | 229 // Check parameter locals. |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
338 // During bootstrapping we allow all objects to pass as global | 338 // During bootstrapping we allow all objects to pass as global |
339 // objects. This is necessary to fix circular dependencies. | 339 // objects. This is necessary to fix circular dependencies. |
340 Isolate* isolate = Isolate::Current(); | 340 Isolate* isolate = Isolate::Current(); |
341 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || | 341 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || |
342 isolate->bootstrapper()->IsActive() || | 342 isolate->bootstrapper()->IsActive() || |
343 object->IsGlobalObject(); | 343 object->IsGlobalObject(); |
344 } | 344 } |
345 #endif | 345 #endif |
346 | 346 |
347 } } // namespace v8::internal | 347 } } // namespace v8::internal |
OLD | NEW |