| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, ContextLookupFlags flags, |
| 78 int* index_, PropertyAttributes* attributes) { | 78 int* index_, PropertyAttributes* attributes) { |
| 79 Heap* heap = GetHeap(); | 79 Isolate* isolate = GetIsolate(); |
| 80 Handle<Context> context(this); | 80 Handle<Context> context(this, isolate); |
| 81 | 81 |
| 82 bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0; | 82 bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0; |
| 83 *index_ = -1; | 83 *index_ = -1; |
| 84 *attributes = ABSENT; | 84 *attributes = ABSENT; |
| 85 | 85 |
| 86 if (FLAG_trace_contexts) { | 86 if (FLAG_trace_contexts) { |
| 87 PrintF("Context::Lookup("); | 87 PrintF("Context::Lookup("); |
| 88 name->ShortPrint(); | 88 name->ShortPrint(); |
| 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 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 // Context extension objects needs to behave as if they have no | 103 // Context extension objects needs to behave as if they have no |
| 103 // prototype. So even if we want to follow prototype chains, we | 104 // prototype. So even if we want to follow prototype chains, we |
| 104 // need to only do a local lookup for context extension objects. | 105 // need to only do a local lookup for context extension objects. |
| 105 if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 || | 106 if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 || |
| 106 extension->IsJSContextExtensionObject()) { | 107 extension->IsJSContextExtensionObject()) { |
| 107 *attributes = extension->GetLocalPropertyAttribute(*name); | 108 *attributes = extension->GetLocalPropertyAttribute(*name); |
| 108 } else { | 109 } else { |
| 109 *attributes = extension->GetPropertyAttribute(*name); | 110 *attributes = extension->GetPropertyAttribute(*name); |
| 110 } | 111 } |
| 111 if (*attributes != ABSENT) { | 112 if (*attributes != ABSENT) { |
| 112 // property found | 113 // property found |
| 113 if (FLAG_trace_contexts) { | 114 if (FLAG_trace_contexts) { |
| 114 PrintF("=> found property in context object %p\n", | 115 PrintF("=> found property in context object %p\n", |
| 115 reinterpret_cast<void*>(*extension)); | 116 reinterpret_cast<void*>(*extension)); |
| 116 } | 117 } |
| 117 return extension; | 118 return extension; |
| 118 } | 119 } |
| 119 } | 120 } |
| 120 | 121 |
| 121 if (context->is_function_context()) { | 122 if (context->is_function_context()) { |
| 122 // we have context-local slots | 123 // we have context-local slots |
| 123 | 124 |
| 124 // check non-parameter locals in context | 125 // check non-parameter locals in context |
| 125 Handle<SerializedScopeInfo> scope_info( | 126 Handle<SerializedScopeInfo> scope_info( |
| 126 context->closure()->shared()->scope_info()); | 127 context->closure()->shared()->scope_info(), isolate); |
| 127 Variable::Mode mode; | 128 Variable::Mode mode; |
| 128 int index = scope_info->ContextSlotIndex(*name, &mode); | 129 int index = scope_info->ContextSlotIndex(*name, &mode); |
| 129 ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); | 130 ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); |
| 130 if (index >= 0) { | 131 if (index >= 0) { |
| 131 // slot found | 132 // slot found |
| 132 if (FLAG_trace_contexts) { | 133 if (FLAG_trace_contexts) { |
| 133 PrintF("=> found local in context slot %d (mode = %d)\n", | 134 PrintF("=> found local in context slot %d (mode = %d)\n", |
| 134 index, mode); | 135 index, mode); |
| 135 } | 136 } |
| 136 *index_ = index; | 137 *index_ = index; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 149 case Variable::DYNAMIC_LOCAL: UNREACHABLE(); break; | 150 case Variable::DYNAMIC_LOCAL: UNREACHABLE(); break; |
| 150 case Variable::TEMPORARY: UNREACHABLE(); break; | 151 case Variable::TEMPORARY: UNREACHABLE(); break; |
| 151 } | 152 } |
| 152 return context; | 153 return context; |
| 153 } | 154 } |
| 154 | 155 |
| 155 // check parameter locals in context | 156 // check parameter locals in context |
| 156 int param_index = scope_info->ParameterIndex(*name); | 157 int param_index = scope_info->ParameterIndex(*name); |
| 157 if (param_index >= 0) { | 158 if (param_index >= 0) { |
| 158 // slot found. | 159 // slot found. |
| 159 int index = | 160 int index = scope_info->ContextSlotIndex( |
| 160 scope_info->ContextSlotIndex(heap->arguments_shadow_symbol(), NULL); | 161 isolate->heap()->arguments_shadow_symbol(), NULL); |
| 161 ASSERT(index >= 0); // arguments must exist and be in the heap context | 162 ASSERT(index >= 0); // arguments must exist and be in the heap context |
| 162 Handle<JSObject> arguments(JSObject::cast(context->get(index))); | 163 Handle<JSObject> arguments(JSObject::cast(context->get(index)), |
| 163 ASSERT(arguments->HasLocalProperty(heap->length_symbol())); | 164 isolate); |
| 165 ASSERT(arguments->HasLocalProperty(isolate->heap()->length_symbol())); |
| 164 if (FLAG_trace_contexts) { | 166 if (FLAG_trace_contexts) { |
| 165 PrintF("=> found parameter %d in arguments object\n", param_index); | 167 PrintF("=> found parameter %d in arguments object\n", param_index); |
| 166 } | 168 } |
| 167 *index_ = param_index; | 169 *index_ = param_index; |
| 168 *attributes = NONE; | 170 *attributes = NONE; |
| 169 return arguments; | 171 return arguments; |
| 170 } | 172 } |
| 171 | 173 |
| 172 // check intermediate context (holding only the function name variable) | 174 // check intermediate context (holding only the function name variable) |
| 173 if (follow_context_chain) { | 175 if (follow_context_chain) { |
| 174 int index = scope_info->FunctionContextSlotIndex(*name); | 176 int index = scope_info->FunctionContextSlotIndex(*name); |
| 175 if (index >= 0) { | 177 if (index >= 0) { |
| 176 // slot found | 178 // slot found |
| 177 if (FLAG_trace_contexts) { | 179 if (FLAG_trace_contexts) { |
| 178 PrintF("=> found intermediate function in context slot %d\n", | 180 PrintF("=> found intermediate function in context slot %d\n", |
| 179 index); | 181 index); |
| 180 } | 182 } |
| 181 *index_ = index; | 183 *index_ = index; |
| 182 *attributes = READ_ONLY; | 184 *attributes = READ_ONLY; |
| 183 return context; | 185 return context; |
| 184 } | 186 } |
| 185 } | 187 } |
| 186 } | 188 } |
| 187 | 189 |
| 188 // proceed with enclosing context | 190 // proceed with enclosing context |
| 189 if (context->IsGlobalContext()) { | 191 if (context->IsGlobalContext()) { |
| 190 follow_context_chain = false; | 192 follow_context_chain = false; |
| 191 } else if (context->is_function_context()) { | 193 } else if (context->is_function_context()) { |
| 192 context = Handle<Context>(Context::cast(context->closure()->context())); | 194 context = Handle<Context>(Context::cast(context->closure()->context()), |
| 195 isolate); |
| 193 } else { | 196 } else { |
| 194 context = Handle<Context>(context->previous()); | 197 context = Handle<Context>(context->previous(), isolate); |
| 195 } | 198 } |
| 196 } while (follow_context_chain); | 199 } while (follow_context_chain); |
| 197 | 200 |
| 198 // slot not found | 201 // slot not found |
| 199 if (FLAG_trace_contexts) { | 202 if (FLAG_trace_contexts) { |
| 200 PrintF("=> no property/slot found\n"); | 203 PrintF("=> no property/slot found\n"); |
| 201 } | 204 } |
| 202 return Handle<Object>::null(); | 205 return Handle<Object>::null(); |
| 203 } | 206 } |
| 204 | 207 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 // During bootstrapping we allow all objects to pass as global | 318 // During bootstrapping we allow all objects to pass as global |
| 316 // objects. This is necessary to fix circular dependencies. | 319 // objects. This is necessary to fix circular dependencies. |
| 317 Isolate* isolate = Isolate::Current(); | 320 Isolate* isolate = Isolate::Current(); |
| 318 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || | 321 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || |
| 319 isolate->bootstrapper()->IsActive() || | 322 isolate->bootstrapper()->IsActive() || |
| 320 object->IsGlobalObject(); | 323 object->IsGlobalObject(); |
| 321 } | 324 } |
| 322 #endif | 325 #endif |
| 323 | 326 |
| 324 } } // namespace v8::internal | 327 } } // namespace v8::internal |
| OLD | NEW |