Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: src/contexts.cc

Issue 7862032: Reapply "Clean up Context::Lookup and its uses." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/contexts.h ('k') | src/hydrogen.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 return global_context()->global_proxy_object(); 79 return global_context()->global_proxy_object();
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 BindingFlags* binding_flags) {
92 Isolate* isolate = GetIsolate(); 92 Isolate* isolate = GetIsolate();
93 Handle<Context> context(this, isolate); 93 Handle<Context> context(this, isolate);
94 94
95 bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0; 95 bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0;
96 *index_ = -1; 96 *index = -1;
97 *attributes = ABSENT; 97 *attributes = ABSENT;
98 *binding_flags = MISSING_BINDING; 98 *binding_flags = MISSING_BINDING;
99 99
100 if (FLAG_trace_contexts) { 100 if (FLAG_trace_contexts) {
101 PrintF("Context::Lookup("); 101 PrintF("Context::Lookup(");
102 name->ShortPrint(); 102 name->ShortPrint();
103 PrintF(")\n"); 103 PrintF(")\n");
104 } 104 }
105 105
106 do { 106 do {
107 if (FLAG_trace_contexts) { 107 if (FLAG_trace_contexts) {
108 PrintF(" - looking in context %p", reinterpret_cast<void*>(*context)); 108 PrintF(" - looking in context %p", reinterpret_cast<void*>(*context));
109 if (context->IsGlobalContext()) PrintF(" (global context)"); 109 if (context->IsGlobalContext()) PrintF(" (global context)");
110 PrintF("\n"); 110 PrintF("\n");
111 } 111 }
112 112
113 // Check extension/with/global object. 113 // 1. Check global objects, subjects of with, and extension objects.
114 if (!context->IsBlockContext() && context->has_extension()) { 114 if (context->IsGlobalContext() ||
115 if (context->IsCatchContext()) { 115 context->IsWithContext() ||
116 // Catch contexts have the variable name in the extension slot. 116 (context->IsFunctionContext() && context->has_extension())) {
117 if (name->Equals(String::cast(context->extension()))) { 117 Handle<JSObject> object(JSObject::cast(context->extension()), isolate);
118 if (FLAG_trace_contexts) { 118 // Context extension objects needs to behave as if they have no
119 PrintF("=> found in catch context\n"); 119 // prototype. So even if we want to follow prototype chains, we need
120 } 120 // to only do a local lookup for context extension objects.
121 *index_ = Context::THROWN_OBJECT_INDEX; 121 if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 ||
122 *attributes = NONE; 122 object->IsJSContextExtensionObject()) {
123 *binding_flags = MUTABLE_IS_INITIALIZED; 123 *attributes = object->GetLocalPropertyAttribute(*name);
124 return context; 124 } else {
125 *attributes = object->GetPropertyAttribute(*name);
126 }
127 if (*attributes != ABSENT) {
128 if (FLAG_trace_contexts) {
129 PrintF("=> found property in context object %p\n",
130 reinterpret_cast<void*>(*object));
125 } 131 }
126 } else { 132 return object;
127 ASSERT(context->IsGlobalContext() ||
128 context->IsFunctionContext() ||
129 context->IsWithContext());
130 // Global, function, and with contexts may have an object in the
131 // extension slot.
132 Handle<JSObject> extension(JSObject::cast(context->extension()),
133 isolate);
134 // Context extension objects needs to behave as if they have no
135 // prototype. So even if we want to follow prototype chains, we
136 // need to only do a local lookup for context extension objects.
137 if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 ||
138 extension->IsJSContextExtensionObject()) {
139 *attributes = extension->GetLocalPropertyAttribute(*name);
140 } else {
141 *attributes = extension->GetPropertyAttribute(*name);
142 }
143 if (*attributes != ABSENT) {
144 // property found
145 if (FLAG_trace_contexts) {
146 PrintF("=> found property in context object %p\n",
147 reinterpret_cast<void*>(*extension));
148 }
149 return extension;
150 }
151 } 133 }
152 } 134 }
153 135
154 // Check serialized scope information of functions and blocks. Only 136 // 2. Check the context proper if it has slots.
155 // functions can have parameters, and a function name.
156 if (context->IsFunctionContext() || context->IsBlockContext()) { 137 if (context->IsFunctionContext() || context->IsBlockContext()) {
157 // We may have context-local slots. Check locals in the context. 138 // Use serialized scope information of functions and blocks to search
139 // for the context index.
158 Handle<SerializedScopeInfo> scope_info; 140 Handle<SerializedScopeInfo> scope_info;
159 if (context->IsFunctionContext()) { 141 if (context->IsFunctionContext()) {
160 scope_info = Handle<SerializedScopeInfo>( 142 scope_info = Handle<SerializedScopeInfo>(
161 context->closure()->shared()->scope_info(), isolate); 143 context->closure()->shared()->scope_info(), isolate);
162 } else { 144 } else {
163 ASSERT(context->IsBlockContext());
164 scope_info = Handle<SerializedScopeInfo>( 145 scope_info = Handle<SerializedScopeInfo>(
165 SerializedScopeInfo::cast(context->extension()), isolate); 146 SerializedScopeInfo::cast(context->extension()), isolate);
166 } 147 }
167
168 Variable::Mode mode; 148 Variable::Mode mode;
169 int index = scope_info->ContextSlotIndex(*name, &mode); 149 int slot_index = scope_info->ContextSlotIndex(*name, &mode);
170 ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); 150 ASSERT(slot_index < 0 || slot_index >= MIN_CONTEXT_SLOTS);
171 if (index >= 0) { 151 if (slot_index >= 0) {
172 if (FLAG_trace_contexts) { 152 if (FLAG_trace_contexts) {
173 PrintF("=> found local in context slot %d (mode = %d)\n", 153 PrintF("=> found local in context slot %d (mode = %d)\n",
174 index, mode); 154 slot_index, mode);
175 } 155 }
176 *index_ = index; 156 *index = slot_index;
177 // Note: Fixed context slots are statically allocated by the compiler. 157 // Note: Fixed context slots are statically allocated by the compiler.
178 // Statically allocated variables always have a statically known mode, 158 // Statically allocated variables always have a statically known mode,
179 // which is the mode with which they were declared when added to the 159 // which is the mode with which they were declared when added to the
180 // scope. Thus, the DYNAMIC mode (which corresponds to dynamically 160 // scope. Thus, the DYNAMIC mode (which corresponds to dynamically
181 // declared variables that were introduced through declaration nodes) 161 // declared variables that were introduced through declaration nodes)
182 // must not appear here. 162 // must not appear here.
183 switch (mode) { 163 switch (mode) {
184 case Variable::INTERNAL: // Fall through. 164 case Variable::INTERNAL: // Fall through.
185 case Variable::VAR: 165 case Variable::VAR:
186 *attributes = NONE; 166 *attributes = NONE;
(...skipping 12 matching lines...) Expand all
199 case Variable::DYNAMIC_LOCAL: 179 case Variable::DYNAMIC_LOCAL:
200 case Variable::TEMPORARY: 180 case Variable::TEMPORARY:
201 UNREACHABLE(); 181 UNREACHABLE();
202 break; 182 break;
203 } 183 }
204 return context; 184 return context;
205 } 185 }
206 186
207 // Check the slot corresponding to the intermediate context holding 187 // Check the slot corresponding to the intermediate context holding
208 // only the function name variable. 188 // only the function name variable.
209 if (follow_context_chain) { 189 if (follow_context_chain && context->IsFunctionContext()) {
210 int index = scope_info->FunctionContextSlotIndex(*name); 190 int function_index = scope_info->FunctionContextSlotIndex(*name);
211 if (index >= 0) { 191 if (function_index >= 0) {
212 if (FLAG_trace_contexts) { 192 if (FLAG_trace_contexts) {
213 PrintF("=> found intermediate function in context slot %d\n", 193 PrintF("=> found intermediate function in context slot %d\n",
214 index); 194 function_index);
215 } 195 }
216 *index_ = index; 196 *index = function_index;
217 *attributes = READ_ONLY; 197 *attributes = READ_ONLY;
218 *binding_flags = IMMUTABLE_IS_INITIALIZED; 198 *binding_flags = IMMUTABLE_IS_INITIALIZED;
219 return context; 199 return context;
220 } 200 }
221 } 201 }
202
203 } else if (context->IsCatchContext()) {
204 // Catch contexts have the variable name in the extension slot.
205 if (name->Equals(String::cast(context->extension()))) {
206 if (FLAG_trace_contexts) {
207 PrintF("=> found in catch context\n");
208 }
209 *index = Context::THROWN_OBJECT_INDEX;
210 *attributes = NONE;
211 *binding_flags = MUTABLE_IS_INITIALIZED;
212 return context;
213 }
222 } 214 }
223 215
224 // Proceed with the previous context. 216 // 3. Prepare to continue with the previous (next outermost) context.
225 if (context->IsGlobalContext()) { 217 if (context->IsGlobalContext()) {
226 follow_context_chain = false; 218 follow_context_chain = false;
227 } else { 219 } else {
228 context = Handle<Context>(context->previous(), isolate); 220 context = Handle<Context>(context->previous(), isolate);
229 } 221 }
230 } while (follow_context_chain); 222 } while (follow_context_chain);
231 223
232 if (FLAG_trace_contexts) { 224 if (FLAG_trace_contexts) {
233 PrintF("=> no property/slot found\n"); 225 PrintF("=> no property/slot found\n");
234 } 226 }
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 // During bootstrapping we allow all objects to pass as global 365 // During bootstrapping we allow all objects to pass as global
374 // objects. This is necessary to fix circular dependencies. 366 // objects. This is necessary to fix circular dependencies.
375 Isolate* isolate = Isolate::Current(); 367 Isolate* isolate = Isolate::Current();
376 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || 368 return isolate->heap()->gc_state() != Heap::NOT_IN_GC ||
377 isolate->bootstrapper()->IsActive() || 369 isolate->bootstrapper()->IsActive() ||
378 object->IsGlobalObject(); 370 object->IsGlobalObject();
379 } 371 }
380 #endif 372 #endif
381 373
382 } } // namespace v8::internal 374 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/contexts.h ('k') | src/hydrogen.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698