| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 67 |
| 68 JSObject* Context::global_proxy() { | 68 JSObject* Context::global_proxy() { |
| 69 return global_context()->global_proxy_object(); | 69 return global_context()->global_proxy_object(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void Context::set_global_proxy(JSObject* object) { | 72 void Context::set_global_proxy(JSObject* object) { |
| 73 global_context()->set_global_proxy_object(object); | 73 global_context()->set_global_proxy_object(object); |
| 74 } | 74 } |
| 75 | 75 |
| 76 | 76 |
| 77 Handle<Object> Context::Lookup(Handle<String> name, ContextLookupFlags flags, | 77 Handle<Object> Context::Lookup(Handle<String> name, |
| 78 int* index_, PropertyAttributes* attributes) { | 78 ContextLookupFlags flags, |
| 79 int* index_, |
| 80 PropertyAttributes* attributes) { |
| 79 Handle<Context> context(this); | 81 Handle<Context> context(this); |
| 80 | 82 |
| 81 bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0; | 83 bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0; |
| 82 *index_ = -1; | 84 *index_ = -1; |
| 83 *attributes = ABSENT; | 85 *attributes = ABSENT; |
| 84 | 86 |
| 85 if (FLAG_trace_contexts) { | 87 if (FLAG_trace_contexts) { |
| 86 PrintF("Context::Lookup("); | 88 PrintF("Context::Lookup("); |
| 87 name->ShortPrint(); | 89 name->ShortPrint(); |
| 88 PrintF(")\n"); | 90 PrintF(")\n"); |
| 89 } | 91 } |
| 90 | 92 |
| 91 do { | 93 do { |
| 92 if (FLAG_trace_contexts) { | 94 if (FLAG_trace_contexts) { |
| 93 PrintF(" - looking in context %p", reinterpret_cast<void*>(*context)); | 95 PrintF(" - looking in context %p", reinterpret_cast<void*>(*context)); |
| 94 if (context->IsGlobalContext()) PrintF(" (global context)"); | 96 if (context->IsGlobalContext()) PrintF(" (global context)"); |
| 95 PrintF("\n"); | 97 PrintF("\n"); |
| 96 } | 98 } |
| 97 | 99 |
| 98 // check extension/with object | 100 // Check the context extension object. |
| 99 if (context->has_extension()) { | 101 if (context->has_extension()) { |
| 100 Handle<JSObject> extension = Handle<JSObject>(context->extension()); | 102 Handle<JSObject> extension = Handle<JSObject>(context->extension()); |
| 101 // Context extension objects needs to behave as if they have no | 103 // Context extension objects needs to behave as if they have no |
| 102 // prototype. So even if we want to follow prototype chains, we | 104 // prototype. So even if we want to follow prototype chains, we |
| 103 // need to only do a local lookup for context extension objects. | 105 // need to only do a local lookup for context extension objects. |
| 104 if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 || | 106 if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 || |
| 105 extension->IsJSContextExtensionObject()) { | 107 extension->IsJSContextExtensionObject()) { |
| 106 *attributes = extension->GetLocalPropertyAttribute(*name); | 108 *attributes = extension->GetLocalPropertyAttribute(*name); |
| 107 } else { | 109 } else { |
| 108 *attributes = extension->GetPropertyAttribute(*name); | 110 *attributes = extension->GetPropertyAttribute(*name); |
| 109 } | 111 } |
| 110 if (*attributes != ABSENT) { | 112 if (*attributes != ABSENT) { |
| 111 // property found | |
| 112 if (FLAG_trace_contexts) { | 113 if (FLAG_trace_contexts) { |
| 113 PrintF("=> found property in context object %p\n", | 114 PrintF("=> found property in context object %p\n", |
| 114 reinterpret_cast<void*>(*extension)); | 115 reinterpret_cast<void*>(*extension)); |
| 115 } | 116 } |
| 116 return extension; | 117 return extension; |
| 117 } | 118 } |
| 118 } | 119 } |
| 119 | 120 |
| 120 if (context->is_function_context()) { | 121 if (context->is_function_context()) { |
| 121 // we have context-local slots | 122 // We may have context-local slots. Check locals in the context. |
| 122 | |
| 123 // check non-parameter locals in context | |
| 124 Handle<SerializedScopeInfo> scope_info( | 123 Handle<SerializedScopeInfo> scope_info( |
| 125 context->closure()->shared()->scope_info()); | 124 context->closure()->shared()->scope_info()); |
| 126 Variable::Mode mode; | 125 Variable::Mode mode; |
| 127 int index = scope_info->ContextSlotIndex(*name, &mode); | 126 int index = scope_info->ContextSlotIndex(*name, &mode); |
| 128 ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); | 127 ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); |
| 129 if (index >= 0) { | 128 if (index >= 0) { |
| 130 // slot found | |
| 131 if (FLAG_trace_contexts) { | 129 if (FLAG_trace_contexts) { |
| 132 PrintF("=> found local in context slot %d (mode = %d)\n", | 130 PrintF("=> found local in context slot %d (mode = %d)\n", |
| 133 index, mode); | 131 index, mode); |
| 134 } | 132 } |
| 135 *index_ = index; | 133 *index_ = index; |
| 136 // Note: Fixed context slots are statically allocated by the compiler. | 134 // Note: Fixed context slots are statically allocated by the compiler. |
| 137 // Statically allocated variables always have a statically known mode, | 135 // Statically allocated variables always have a statically known mode, |
| 138 // which is the mode with which they were declared when added to the | 136 // which is the mode with which they were declared when added to the |
| 139 // scope. Thus, the DYNAMIC mode (which corresponds to dynamically | 137 // scope. Thus, the DYNAMIC mode (which corresponds to dynamically |
| 140 // declared variables that were introduced through declaration nodes) | 138 // declared variables that were introduced through declaration nodes) |
| 141 // must not appear here. | 139 // must not appear here. |
| 142 switch (mode) { | 140 switch (mode) { |
| 143 case Variable::INTERNAL: // fall through | 141 case Variable::INTERNAL: // Fall through. |
| 144 case Variable::VAR: *attributes = NONE; break; | 142 case Variable::VAR: |
| 145 case Variable::CONST: *attributes = READ_ONLY; break; | 143 *attributes = NONE; |
| 146 case Variable::DYNAMIC: UNREACHABLE(); break; | 144 break; |
| 147 case Variable::DYNAMIC_GLOBAL: UNREACHABLE(); break; | 145 case Variable::CONST: |
| 148 case Variable::DYNAMIC_LOCAL: UNREACHABLE(); break; | 146 *attributes = READ_ONLY; |
| 149 case Variable::TEMPORARY: UNREACHABLE(); break; | 147 break; |
| 148 case Variable::DYNAMIC: |
| 149 case Variable::DYNAMIC_GLOBAL: |
| 150 case Variable::DYNAMIC_LOCAL: |
| 151 case Variable::TEMPORARY: |
| 152 UNREACHABLE(); |
| 153 break; |
| 150 } | 154 } |
| 151 return context; | 155 return context; |
| 152 } | 156 } |
| 153 | 157 |
| 154 // check parameter locals in context | 158 // Check the slot corresponding to the intermediate context holding |
| 155 int param_index = scope_info->ParameterIndex(*name); | 159 // only the function name variable. |
| 156 if (param_index >= 0) { | |
| 157 // slot found. | |
| 158 int index = | |
| 159 scope_info->ContextSlotIndex(Heap::arguments_shadow_symbol(), NULL); | |
| 160 ASSERT(index >= 0); // arguments must exist and be in the heap context | |
| 161 Handle<JSObject> arguments(JSObject::cast(context->get(index))); | |
| 162 ASSERT(arguments->HasLocalProperty(Heap::length_symbol())); | |
| 163 if (FLAG_trace_contexts) { | |
| 164 PrintF("=> found parameter %d in arguments object\n", param_index); | |
| 165 } | |
| 166 *index_ = param_index; | |
| 167 *attributes = NONE; | |
| 168 return arguments; | |
| 169 } | |
| 170 | |
| 171 // check intermediate context (holding only the function name variable) | |
| 172 if (follow_context_chain) { | 160 if (follow_context_chain) { |
| 173 int index = scope_info->FunctionContextSlotIndex(*name); | 161 int index = scope_info->FunctionContextSlotIndex(*name); |
| 174 if (index >= 0) { | 162 if (index >= 0) { |
| 175 // slot found | |
| 176 if (FLAG_trace_contexts) { | 163 if (FLAG_trace_contexts) { |
| 177 PrintF("=> found intermediate function in context slot %d\n", | 164 PrintF("=> found intermediate function in context slot %d\n", |
| 178 index); | 165 index); |
| 179 } | 166 } |
| 180 *index_ = index; | 167 *index_ = index; |
| 181 *attributes = READ_ONLY; | 168 *attributes = READ_ONLY; |
| 182 return context; | 169 return context; |
| 183 } | 170 } |
| 184 } | 171 } |
| 185 } | 172 } |
| 186 | 173 |
| 187 // proceed with enclosing context | 174 // Proceed with the enclosing context. |
| 188 if (context->IsGlobalContext()) { | 175 if (context->IsGlobalContext()) { |
| 189 follow_context_chain = false; | 176 follow_context_chain = false; |
| 190 } else if (context->is_function_context()) { | 177 } else if (context->is_function_context()) { |
| 191 context = Handle<Context>(Context::cast(context->closure()->context())); | 178 context = Handle<Context>(Context::cast(context->closure()->context())); |
| 192 } else { | 179 } else { |
| 193 context = Handle<Context>(context->previous()); | 180 context = Handle<Context>(context->previous()); |
| 194 } | 181 } |
| 195 } while (follow_context_chain); | 182 } while (follow_context_chain); |
| 196 | 183 |
| 197 // slot not found | |
| 198 if (FLAG_trace_contexts) { | 184 if (FLAG_trace_contexts) { |
| 199 PrintF("=> no property/slot found\n"); | 185 PrintF("=> no property/slot found\n"); |
| 200 } | 186 } |
| 201 return Handle<Object>::null(); | 187 return Handle<Object>::null(); |
| 202 } | 188 } |
| 203 | 189 |
| 204 | 190 |
| 205 bool Context::GlobalIfNotShadowedByEval(Handle<String> name) { | 191 bool Context::GlobalIfNotShadowedByEval(Handle<String> name) { |
| 206 Context* context = this; | 192 Context* context = this; |
| 207 | 193 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 | 297 |
| 312 | 298 |
| 313 bool Context::IsBootstrappingOrGlobalObject(Object* object) { | 299 bool Context::IsBootstrappingOrGlobalObject(Object* object) { |
| 314 // During bootstrapping we allow all objects to pass as global | 300 // During bootstrapping we allow all objects to pass as global |
| 315 // objects. This is necessary to fix circular dependencies. | 301 // objects. This is necessary to fix circular dependencies. |
| 316 return Bootstrapper::IsActive() || object->IsGlobalObject(); | 302 return Bootstrapper::IsActive() || object->IsGlobalObject(); |
| 317 } | 303 } |
| 318 #endif | 304 #endif |
| 319 | 305 |
| 320 } } // namespace v8::internal | 306 } } // namespace v8::internal |
| OLD | NEW |