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

Side by Side Diff: src/contexts.cc

Issue 6685088: Merge isolates to bleeding_edge. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 9 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/conversions.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 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 Context* Context::global_context() { 48 Context* Context::global_context() {
49 // Fast case: the global object for this context has been set. In 49 // Fast case: the global object for this context has been set. In
50 // that case, the global object has a direct pointer to the global 50 // that case, the global object has a direct pointer to the global
51 // context. 51 // context.
52 if (global()->IsGlobalObject()) { 52 if (global()->IsGlobalObject()) {
53 return global()->global_context(); 53 return global()->global_context();
54 } 54 }
55 55
56 // During bootstrapping, the global object might not be set and we 56 // During bootstrapping, the global object might not be set and we
57 // have to search the context chain to find the global context. 57 // have to search the context chain to find the global context.
58 ASSERT(Bootstrapper::IsActive()); 58 ASSERT(Isolate::Current()->bootstrapper()->IsActive());
59 Context* current = this; 59 Context* current = this;
60 while (!current->IsGlobalContext()) { 60 while (!current->IsGlobalContext()) {
61 JSFunction* closure = JSFunction::cast(current->closure()); 61 JSFunction* closure = JSFunction::cast(current->closure());
62 current = Context::cast(closure->context()); 62 current = Context::cast(closure->context());
63 } 63 }
64 return current; 64 return current;
65 } 65 }
66 66
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, ContextLookupFlags flags,
78 int* index_, PropertyAttributes* attributes) { 78 int* index_, PropertyAttributes* attributes) {
79 Handle<Context> context(this); 79 Isolate* isolate = GetIsolate();
80 Handle<Context> context(this, isolate);
80 81
81 bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0; 82 bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0;
82 *index_ = -1; 83 *index_ = -1;
83 *attributes = ABSENT; 84 *attributes = ABSENT;
84 85
85 if (FLAG_trace_contexts) { 86 if (FLAG_trace_contexts) {
86 PrintF("Context::Lookup("); 87 PrintF("Context::Lookup(");
87 name->ShortPrint(); 88 name->ShortPrint();
88 PrintF(")\n"); 89 PrintF(")\n");
89 } 90 }
90 91
91 do { 92 do {
92 if (FLAG_trace_contexts) { 93 if (FLAG_trace_contexts) {
93 PrintF(" - looking in context %p", reinterpret_cast<void*>(*context)); 94 PrintF(" - looking in context %p", reinterpret_cast<void*>(*context));
94 if (context->IsGlobalContext()) PrintF(" (global context)"); 95 if (context->IsGlobalContext()) PrintF(" (global context)");
95 PrintF("\n"); 96 PrintF("\n");
96 } 97 }
97 98
98 // check extension/with object 99 // check extension/with object
99 if (context->has_extension()) { 100 if (context->has_extension()) {
100 Handle<JSObject> extension = Handle<JSObject>(context->extension()); 101 Handle<JSObject> extension = Handle<JSObject>(context->extension(),
102 isolate);
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 113 // property found
112 if (FLAG_trace_contexts) { 114 if (FLAG_trace_contexts) {
113 PrintF("=> found property in context object %p\n", 115 PrintF("=> found property in context object %p\n",
114 reinterpret_cast<void*>(*extension)); 116 reinterpret_cast<void*>(*extension));
115 } 117 }
116 return extension; 118 return extension;
117 } 119 }
118 } 120 }
119 121
120 if (context->is_function_context()) { 122 if (context->is_function_context()) {
121 // we have context-local slots 123 // we have context-local slots
122 124
123 // check non-parameter locals in context 125 // check non-parameter locals in context
124 Handle<SerializedScopeInfo> scope_info( 126 Handle<SerializedScopeInfo> scope_info(
125 context->closure()->shared()->scope_info()); 127 context->closure()->shared()->scope_info(), isolate);
126 Variable::Mode mode; 128 Variable::Mode mode;
127 int index = scope_info->ContextSlotIndex(*name, &mode); 129 int index = scope_info->ContextSlotIndex(*name, &mode);
128 ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); 130 ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS);
129 if (index >= 0) { 131 if (index >= 0) {
130 // slot found 132 // slot found
131 if (FLAG_trace_contexts) { 133 if (FLAG_trace_contexts) {
132 PrintF("=> found local in context slot %d (mode = %d)\n", 134 PrintF("=> found local in context slot %d (mode = %d)\n",
133 index, mode); 135 index, mode);
134 } 136 }
135 *index_ = index; 137 *index_ = index;
(...skipping 12 matching lines...) Expand all
148 case Variable::DYNAMIC_LOCAL: UNREACHABLE(); break; 150 case Variable::DYNAMIC_LOCAL: UNREACHABLE(); break;
149 case Variable::TEMPORARY: UNREACHABLE(); break; 151 case Variable::TEMPORARY: UNREACHABLE(); break;
150 } 152 }
151 return context; 153 return context;
152 } 154 }
153 155
154 // check parameter locals in context 156 // check parameter locals in context
155 int param_index = scope_info->ParameterIndex(*name); 157 int param_index = scope_info->ParameterIndex(*name);
156 if (param_index >= 0) { 158 if (param_index >= 0) {
157 // slot found. 159 // slot found.
158 int index = 160 int index = scope_info->ContextSlotIndex(
159 scope_info->ContextSlotIndex(Heap::arguments_shadow_symbol(), NULL); 161 isolate->heap()->arguments_shadow_symbol(), NULL);
160 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
161 Handle<JSObject> arguments(JSObject::cast(context->get(index))); 163 Handle<JSObject> arguments(JSObject::cast(context->get(index)),
162 ASSERT(arguments->HasLocalProperty(Heap::length_symbol())); 164 isolate);
165 ASSERT(arguments->HasLocalProperty(isolate->heap()->length_symbol()));
163 if (FLAG_trace_contexts) { 166 if (FLAG_trace_contexts) {
164 PrintF("=> found parameter %d in arguments object\n", param_index); 167 PrintF("=> found parameter %d in arguments object\n", param_index);
165 } 168 }
166 *index_ = param_index; 169 *index_ = param_index;
167 *attributes = NONE; 170 *attributes = NONE;
168 return arguments; 171 return arguments;
169 } 172 }
170 173
171 // check intermediate context (holding only the function name variable) 174 // check intermediate context (holding only the function name variable)
172 if (follow_context_chain) { 175 if (follow_context_chain) {
173 int index = scope_info->FunctionContextSlotIndex(*name); 176 int index = scope_info->FunctionContextSlotIndex(*name);
174 if (index >= 0) { 177 if (index >= 0) {
175 // slot found 178 // slot found
176 if (FLAG_trace_contexts) { 179 if (FLAG_trace_contexts) {
177 PrintF("=> found intermediate function in context slot %d\n", 180 PrintF("=> found intermediate function in context slot %d\n",
178 index); 181 index);
179 } 182 }
180 *index_ = index; 183 *index_ = index;
181 *attributes = READ_ONLY; 184 *attributes = READ_ONLY;
182 return context; 185 return context;
183 } 186 }
184 } 187 }
185 } 188 }
186 189
187 // proceed with enclosing context 190 // proceed with enclosing context
188 if (context->IsGlobalContext()) { 191 if (context->IsGlobalContext()) {
189 follow_context_chain = false; 192 follow_context_chain = false;
190 } else if (context->is_function_context()) { 193 } else if (context->is_function_context()) {
191 context = Handle<Context>(Context::cast(context->closure()->context())); 194 context = Handle<Context>(Context::cast(context->closure()->context()),
195 isolate);
192 } else { 196 } else {
193 context = Handle<Context>(context->previous()); 197 context = Handle<Context>(context->previous(), isolate);
194 } 198 }
195 } while (follow_context_chain); 199 } while (follow_context_chain);
196 200
197 // slot not found 201 // slot not found
198 if (FLAG_trace_contexts) { 202 if (FLAG_trace_contexts) {
199 PrintF("=> no property/slot found\n"); 203 PrintF("=> no property/slot found\n");
200 } 204 }
201 return Handle<Object>::null(); 205 return Handle<Object>::null();
202 } 206 }
203 207
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 Object* element = get(OPTIMIZED_FUNCTIONS_LIST); 249 Object* element = get(OPTIMIZED_FUNCTIONS_LIST);
246 while (!element->IsUndefined()) { 250 while (!element->IsUndefined()) {
247 CHECK(element != function); 251 CHECK(element != function);
248 element = JSFunction::cast(element)->next_function_link(); 252 element = JSFunction::cast(element)->next_function_link();
249 } 253 }
250 254
251 CHECK(function->next_function_link()->IsUndefined()); 255 CHECK(function->next_function_link()->IsUndefined());
252 256
253 // Check that the context belongs to the weak global contexts list. 257 // Check that the context belongs to the weak global contexts list.
254 bool found = false; 258 bool found = false;
255 Object* context = Heap::global_contexts_list(); 259 Object* context = GetHeap()->global_contexts_list();
256 while (!context->IsUndefined()) { 260 while (!context->IsUndefined()) {
257 if (context == this) { 261 if (context == this) {
258 found = true; 262 found = true;
259 break; 263 break;
260 } 264 }
261 context = Context::cast(context)->get(Context::NEXT_CONTEXT_LINK); 265 context = Context::cast(context)->get(Context::NEXT_CONTEXT_LINK);
262 } 266 }
263 CHECK(found); 267 CHECK(found);
264 #endif 268 #endif
265 function->set_next_function_link(get(OPTIMIZED_FUNCTIONS_LIST)); 269 function->set_next_function_link(get(OPTIMIZED_FUNCTIONS_LIST));
266 set(OPTIMIZED_FUNCTIONS_LIST, function); 270 set(OPTIMIZED_FUNCTIONS_LIST, function);
267 } 271 }
268 272
269 273
270 void Context::RemoveOptimizedFunction(JSFunction* function) { 274 void Context::RemoveOptimizedFunction(JSFunction* function) {
271 ASSERT(IsGlobalContext()); 275 ASSERT(IsGlobalContext());
272 Object* element = get(OPTIMIZED_FUNCTIONS_LIST); 276 Object* element = get(OPTIMIZED_FUNCTIONS_LIST);
273 JSFunction* prev = NULL; 277 JSFunction* prev = NULL;
274 while (!element->IsUndefined()) { 278 while (!element->IsUndefined()) {
275 JSFunction* element_function = JSFunction::cast(element); 279 JSFunction* element_function = JSFunction::cast(element);
276 ASSERT(element_function->next_function_link()->IsUndefined() || 280 ASSERT(element_function->next_function_link()->IsUndefined() ||
277 element_function->next_function_link()->IsJSFunction()); 281 element_function->next_function_link()->IsJSFunction());
278 if (element_function == function) { 282 if (element_function == function) {
279 if (prev == NULL) { 283 if (prev == NULL) {
280 set(OPTIMIZED_FUNCTIONS_LIST, element_function->next_function_link()); 284 set(OPTIMIZED_FUNCTIONS_LIST, element_function->next_function_link());
281 } else { 285 } else {
282 prev->set_next_function_link(element_function->next_function_link()); 286 prev->set_next_function_link(element_function->next_function_link());
283 } 287 }
284 element_function->set_next_function_link(Heap::undefined_value()); 288 element_function->set_next_function_link(GetHeap()->undefined_value());
285 return; 289 return;
286 } 290 }
287 prev = element_function; 291 prev = element_function;
288 element = element_function->next_function_link(); 292 element = element_function->next_function_link();
289 } 293 }
290 UNREACHABLE(); 294 UNREACHABLE();
291 } 295 }
292 296
293 297
294 Object* Context::OptimizedFunctionsListHead() { 298 Object* Context::OptimizedFunctionsListHead() {
295 ASSERT(IsGlobalContext()); 299 ASSERT(IsGlobalContext());
296 return get(OPTIMIZED_FUNCTIONS_LIST); 300 return get(OPTIMIZED_FUNCTIONS_LIST);
297 } 301 }
298 302
299 303
300 void Context::ClearOptimizedFunctions() { 304 void Context::ClearOptimizedFunctions() {
301 set(OPTIMIZED_FUNCTIONS_LIST, Heap::undefined_value()); 305 set(OPTIMIZED_FUNCTIONS_LIST, GetHeap()->undefined_value());
302 } 306 }
303 307
304 308
305 #ifdef DEBUG 309 #ifdef DEBUG
306 bool Context::IsBootstrappingOrContext(Object* object) { 310 bool Context::IsBootstrappingOrContext(Object* object) {
307 // During bootstrapping we allow all objects to pass as 311 // During bootstrapping we allow all objects to pass as
308 // contexts. This is necessary to fix circular dependencies. 312 // contexts. This is necessary to fix circular dependencies.
309 return Bootstrapper::IsActive() || object->IsContext(); 313 return Isolate::Current()->bootstrapper()->IsActive() || object->IsContext();
310 } 314 }
311 315
312 316
313 bool Context::IsBootstrappingOrGlobalObject(Object* object) { 317 bool Context::IsBootstrappingOrGlobalObject(Object* object) {
314 // During bootstrapping we allow all objects to pass as global 318 // During bootstrapping we allow all objects to pass as global
315 // objects. This is necessary to fix circular dependencies. 319 // objects. This is necessary to fix circular dependencies.
316 return Bootstrapper::IsActive() || object->IsGlobalObject(); 320 Isolate* isolate = Isolate::Current();
321 return isolate->heap()->gc_state() != Heap::NOT_IN_GC ||
322 isolate->bootstrapper()->IsActive() ||
323 object->IsGlobalObject();
317 } 324 }
318 #endif 325 #endif
319 326
320 } } // namespace v8::internal 327 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/contexts.h ('k') | src/conversions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698