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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 } | 80 } |
81 | 81 |
82 void Context::set_global_proxy(JSObject* object) { | 82 void Context::set_global_proxy(JSObject* object) { |
83 global_context()->set_global_proxy_object(object); | 83 global_context()->set_global_proxy_object(object); |
84 } | 84 } |
85 | 85 |
86 | 86 |
87 Handle<Object> Context::Lookup(Handle<String> name, | 87 Handle<Object> Context::Lookup(Handle<String> name, |
88 ContextLookupFlags flags, | 88 ContextLookupFlags flags, |
89 int* index_, | 89 int* index_, |
90 PropertyAttributes* attributes) { | 90 PropertyAttributes* attributes, |
| 91 BindingFlags* binding_flags) { |
91 Isolate* isolate = GetIsolate(); | 92 Isolate* isolate = GetIsolate(); |
92 Handle<Context> context(this, isolate); | 93 Handle<Context> context(this, isolate); |
93 | 94 |
94 bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0; | 95 bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0; |
95 *index_ = -1; | 96 *index_ = -1; |
96 *attributes = ABSENT; | 97 *attributes = ABSENT; |
| 98 *binding_flags = MISSING_BINDING; |
97 | 99 |
98 if (FLAG_trace_contexts) { | 100 if (FLAG_trace_contexts) { |
99 PrintF("Context::Lookup("); | 101 PrintF("Context::Lookup("); |
100 name->ShortPrint(); | 102 name->ShortPrint(); |
101 PrintF(")\n"); | 103 PrintF(")\n"); |
102 } | 104 } |
103 | 105 |
104 do { | 106 do { |
105 if (FLAG_trace_contexts) { | 107 if (FLAG_trace_contexts) { |
106 PrintF(" - looking in context %p", reinterpret_cast<void*>(*context)); | 108 PrintF(" - looking in context %p", reinterpret_cast<void*>(*context)); |
107 if (context->IsGlobalContext()) PrintF(" (global context)"); | 109 if (context->IsGlobalContext()) PrintF(" (global context)"); |
108 PrintF("\n"); | 110 PrintF("\n"); |
109 } | 111 } |
110 | 112 |
111 // Check extension/with/global object. | 113 // Check extension/with/global object. |
112 if (!context->IsBlockContext() && context->has_extension()) { | 114 if (!context->IsBlockContext() && context->has_extension()) { |
113 if (context->IsCatchContext()) { | 115 if (context->IsCatchContext()) { |
114 // Catch contexts have the variable name in the extension slot. | 116 // Catch contexts have the variable name in the extension slot. |
115 if (name->Equals(String::cast(context->extension()))) { | 117 if (name->Equals(String::cast(context->extension()))) { |
116 if (FLAG_trace_contexts) { | 118 if (FLAG_trace_contexts) { |
117 PrintF("=> found in catch context\n"); | 119 PrintF("=> found in catch context\n"); |
118 } | 120 } |
119 *index_ = Context::THROWN_OBJECT_INDEX; | 121 *index_ = Context::THROWN_OBJECT_INDEX; |
120 *attributes = NONE; | 122 *attributes = NONE; |
| 123 *binding_flags = MUTABLE_IS_INITIALIZED; |
121 return context; | 124 return context; |
122 } | 125 } |
123 } else { | 126 } else { |
124 ASSERT(context->IsGlobalContext() || | 127 ASSERT(context->IsGlobalContext() || |
125 context->IsFunctionContext() || | 128 context->IsFunctionContext() || |
126 context->IsWithContext()); | 129 context->IsWithContext()); |
127 // Global, function, and with contexts may have an object in the | 130 // Global, function, and with contexts may have an object in the |
128 // extension slot. | 131 // extension slot. |
129 Handle<JSObject> extension(JSObject::cast(context->extension()), | 132 Handle<JSObject> extension(JSObject::cast(context->extension()), |
130 isolate); | 133 isolate); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 *index_ = index; | 176 *index_ = index; |
174 // Note: Fixed context slots are statically allocated by the compiler. | 177 // Note: Fixed context slots are statically allocated by the compiler. |
175 // Statically allocated variables always have a statically known mode, | 178 // Statically allocated variables always have a statically known mode, |
176 // which is the mode with which they were declared when added to the | 179 // which is the mode with which they were declared when added to the |
177 // scope. Thus, the DYNAMIC mode (which corresponds to dynamically | 180 // scope. Thus, the DYNAMIC mode (which corresponds to dynamically |
178 // declared variables that were introduced through declaration nodes) | 181 // declared variables that were introduced through declaration nodes) |
179 // must not appear here. | 182 // must not appear here. |
180 switch (mode) { | 183 switch (mode) { |
181 case Variable::INTERNAL: // Fall through. | 184 case Variable::INTERNAL: // Fall through. |
182 case Variable::VAR: | 185 case Variable::VAR: |
| 186 *attributes = NONE; |
| 187 *binding_flags = MUTABLE_IS_INITIALIZED; |
| 188 break; |
183 case Variable::LET: | 189 case Variable::LET: |
184 *attributes = NONE; | 190 *attributes = NONE; |
| 191 *binding_flags = MUTABLE_CHECK_INITIALIZED; |
185 break; | 192 break; |
186 case Variable::CONST: | 193 case Variable::CONST: |
187 *attributes = READ_ONLY; | 194 *attributes = READ_ONLY; |
| 195 *binding_flags = IMMUTABLE_CHECK_INITIALIZED; |
188 break; | 196 break; |
189 case Variable::DYNAMIC: | 197 case Variable::DYNAMIC: |
190 case Variable::DYNAMIC_GLOBAL: | 198 case Variable::DYNAMIC_GLOBAL: |
191 case Variable::DYNAMIC_LOCAL: | 199 case Variable::DYNAMIC_LOCAL: |
192 case Variable::TEMPORARY: | 200 case Variable::TEMPORARY: |
193 UNREACHABLE(); | 201 UNREACHABLE(); |
194 break; | 202 break; |
195 } | 203 } |
196 return context; | 204 return context; |
197 } | 205 } |
198 | 206 |
199 // Check the slot corresponding to the intermediate context holding | 207 // Check the slot corresponding to the intermediate context holding |
200 // only the function name variable. | 208 // only the function name variable. |
201 if (follow_context_chain) { | 209 if (follow_context_chain) { |
202 int index = scope_info->FunctionContextSlotIndex(*name); | 210 int index = scope_info->FunctionContextSlotIndex(*name); |
203 if (index >= 0) { | 211 if (index >= 0) { |
204 if (FLAG_trace_contexts) { | 212 if (FLAG_trace_contexts) { |
205 PrintF("=> found intermediate function in context slot %d\n", | 213 PrintF("=> found intermediate function in context slot %d\n", |
206 index); | 214 index); |
207 } | 215 } |
208 *index_ = index; | 216 *index_ = index; |
209 *attributes = READ_ONLY; | 217 *attributes = READ_ONLY; |
| 218 *binding_flags = IMMUTABLE_IS_INITIALIZED; |
210 return context; | 219 return context; |
211 } | 220 } |
212 } | 221 } |
213 } | 222 } |
214 | 223 |
215 // Proceed with the previous context. | 224 // Proceed with the previous context. |
216 if (context->IsGlobalContext()) { | 225 if (context->IsGlobalContext()) { |
217 follow_context_chain = false; | 226 follow_context_chain = false; |
218 } else { | 227 } else { |
219 context = Handle<Context>(context->previous(), isolate); | 228 context = Handle<Context>(context->previous(), isolate); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 // During bootstrapping we allow all objects to pass as global | 373 // During bootstrapping we allow all objects to pass as global |
365 // objects. This is necessary to fix circular dependencies. | 374 // objects. This is necessary to fix circular dependencies. |
366 Isolate* isolate = Isolate::Current(); | 375 Isolate* isolate = Isolate::Current(); |
367 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || | 376 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || |
368 isolate->bootstrapper()->IsActive() || | 377 isolate->bootstrapper()->IsActive() || |
369 object->IsGlobalObject(); | 378 object->IsGlobalObject(); |
370 } | 379 } |
371 #endif | 380 #endif |
372 | 381 |
373 } } // namespace v8::internal | 382 } } // namespace v8::internal |
OLD | NEW |