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