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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 } | 102 } |
103 | 103 |
104 do { | 104 do { |
105 if (FLAG_trace_contexts) { | 105 if (FLAG_trace_contexts) { |
106 PrintF(" - looking in context %p", reinterpret_cast<void*>(*context)); | 106 PrintF(" - looking in context %p", reinterpret_cast<void*>(*context)); |
107 if (context->IsGlobalContext()) PrintF(" (global context)"); | 107 if (context->IsGlobalContext()) PrintF(" (global context)"); |
108 PrintF("\n"); | 108 PrintF("\n"); |
109 } | 109 } |
110 | 110 |
111 // Check extension/with/global object. | 111 // Check extension/with/global object. |
112 if (context->has_extension()) { | 112 if (!context->IsBlockContext() && context->has_extension()) { |
113 if (context->IsCatchContext()) { | 113 if (context->IsCatchContext()) { |
114 // Catch contexts have the variable name in the extension slot. | 114 // Catch contexts have the variable name in the extension slot. |
115 if (name->Equals(String::cast(context->extension()))) { | 115 if (name->Equals(String::cast(context->extension()))) { |
116 if (FLAG_trace_contexts) { | 116 if (FLAG_trace_contexts) { |
117 PrintF("=> found in catch context\n"); | 117 PrintF("=> found in catch context\n"); |
118 } | 118 } |
119 *index_ = Context::THROWN_OBJECT_INDEX; | 119 *index_ = Context::THROWN_OBJECT_INDEX; |
120 *attributes = NONE; | 120 *attributes = NONE; |
121 return context; | 121 return context; |
122 } | 122 } |
123 } else { | 123 } else { |
| 124 ASSERT(context->IsGlobalContext() || |
| 125 context->IsFunctionContext() || |
| 126 context->IsWithContext()); |
124 // Global, function, and with contexts may have an object in the | 127 // Global, function, and with contexts may have an object in the |
125 // extension slot. | 128 // extension slot. |
126 Handle<JSObject> extension(JSObject::cast(context->extension()), | 129 Handle<JSObject> extension(JSObject::cast(context->extension()), |
127 isolate); | 130 isolate); |
128 // Context extension objects needs to behave as if they have no | 131 // Context extension objects needs to behave as if they have no |
129 // prototype. So even if we want to follow prototype chains, we | 132 // prototype. So even if we want to follow prototype chains, we |
130 // need to only do a local lookup for context extension objects. | 133 // need to only do a local lookup for context extension objects. |
131 if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 || | 134 if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 || |
132 extension->IsJSContextExtensionObject()) { | 135 extension->IsJSContextExtensionObject()) { |
133 *attributes = extension->GetLocalPropertyAttribute(*name); | 136 *attributes = extension->GetLocalPropertyAttribute(*name); |
134 } else { | 137 } else { |
135 *attributes = extension->GetPropertyAttribute(*name); | 138 *attributes = extension->GetPropertyAttribute(*name); |
136 } | 139 } |
137 if (*attributes != ABSENT) { | 140 if (*attributes != ABSENT) { |
138 // property found | 141 // property found |
139 if (FLAG_trace_contexts) { | 142 if (FLAG_trace_contexts) { |
140 PrintF("=> found property in context object %p\n", | 143 PrintF("=> found property in context object %p\n", |
141 reinterpret_cast<void*>(*extension)); | 144 reinterpret_cast<void*>(*extension)); |
142 } | 145 } |
143 return extension; | 146 return extension; |
144 } | 147 } |
145 } | 148 } |
146 } | 149 } |
147 | 150 |
148 // Only functions can have locals, parameters, and a function name. | 151 // Check serialized scope information of functions and blocks. Only |
149 if (context->IsFunctionContext()) { | 152 // functions can have parameters, and a function name. |
| 153 if (context->IsFunctionContext() || context->IsBlockContext()) { |
150 // We may have context-local slots. Check locals in the context. | 154 // We may have context-local slots. Check locals in the context. |
151 Handle<SerializedScopeInfo> scope_info( | 155 Handle<SerializedScopeInfo> scope_info; |
152 context->closure()->shared()->scope_info(), isolate); | 156 if (context->IsFunctionContext()) { |
| 157 scope_info = Handle<SerializedScopeInfo>( |
| 158 context->closure()->shared()->scope_info(), isolate); |
| 159 } else { |
| 160 ASSERT(context->IsBlockContext()); |
| 161 scope_info = Handle<SerializedScopeInfo>( |
| 162 SerializedScopeInfo::cast(context->extension()), isolate); |
| 163 } |
| 164 |
153 Variable::Mode mode; | 165 Variable::Mode mode; |
154 int index = scope_info->ContextSlotIndex(*name, &mode); | 166 int index = scope_info->ContextSlotIndex(*name, &mode); |
155 ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); | 167 ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); |
156 if (index >= 0) { | 168 if (index >= 0) { |
157 if (FLAG_trace_contexts) { | 169 if (FLAG_trace_contexts) { |
158 PrintF("=> found local in context slot %d (mode = %d)\n", | 170 PrintF("=> found local in context slot %d (mode = %d)\n", |
159 index, mode); | 171 index, mode); |
160 } | 172 } |
161 *index_ = index; | 173 *index_ = index; |
162 // Note: Fixed context slots are statically allocated by the compiler. | 174 // Note: Fixed context slots are statically allocated by the compiler. |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 // During bootstrapping we allow all objects to pass as global | 363 // During bootstrapping we allow all objects to pass as global |
352 // objects. This is necessary to fix circular dependencies. | 364 // objects. This is necessary to fix circular dependencies. |
353 Isolate* isolate = Isolate::Current(); | 365 Isolate* isolate = Isolate::Current(); |
354 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || | 366 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || |
355 isolate->bootstrapper()->IsActive() || | 367 isolate->bootstrapper()->IsActive() || |
356 object->IsGlobalObject(); | 368 object->IsGlobalObject(); |
357 } | 369 } |
358 #endif | 370 #endif |
359 | 371 |
360 } } // namespace v8::internal | 372 } } // namespace v8::internal |
OLD | NEW |