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

Side by Side Diff: src/contexts.cc

Issue 1218783005: Support for global var shortcuts in script contexts. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 5 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
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/bootstrapper.h" 7 #include "src/bootstrapper.h"
8 #include "src/debug.h" 8 #include "src/debug.h"
9 #include "src/scopeinfo.h" 9 #include "src/scopeinfo.h"
10 10
(...skipping 22 matching lines...) Expand all
33 } 33 }
34 34
35 35
36 bool ScriptContextTable::Lookup(Handle<ScriptContextTable> table, 36 bool ScriptContextTable::Lookup(Handle<ScriptContextTable> table,
37 Handle<String> name, LookupResult* result) { 37 Handle<String> name, LookupResult* result) {
38 for (int i = 0; i < table->used(); i++) { 38 for (int i = 0; i < table->used(); i++) {
39 Handle<Context> context = GetContext(table, i); 39 Handle<Context> context = GetContext(table, i);
40 DCHECK(context->IsScriptContext()); 40 DCHECK(context->IsScriptContext());
41 Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension())); 41 Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension()));
42 int slot_index = ScopeInfo::ContextSlotIndex( 42 int slot_index = ScopeInfo::ContextSlotIndex(
43 scope_info, name, &result->mode, &result->init_flag, 43 scope_info, name, &result->mode, &result->slot_kind, &result->init_flag,
44 &result->maybe_assigned_flag); 44 &result->maybe_assigned_flag);
45 45
46 if (slot_index >= 0) { 46 if (slot_index >= 0 && result->slot_kind == ContextSlotKindFlag::kLocal) {
47 result->context_index = i; 47 result->context_index = i;
48 result->slot_index = slot_index; 48 result->slot_index = slot_index;
49 return true; 49 return true;
50 } 50 }
51 } 51 }
52 return false; 52 return false;
53 } 53 }
54 54
55 55
56 Context* Context::declaration_context() { 56 Context* Context::declaration_context() {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 // for the context index. 289 // for the context index.
290 Handle<ScopeInfo> scope_info; 290 Handle<ScopeInfo> scope_info;
291 if (context->IsFunctionContext()) { 291 if (context->IsFunctionContext()) {
292 scope_info = Handle<ScopeInfo>( 292 scope_info = Handle<ScopeInfo>(
293 context->closure()->shared()->scope_info(), isolate); 293 context->closure()->shared()->scope_info(), isolate);
294 } else { 294 } else {
295 scope_info = Handle<ScopeInfo>( 295 scope_info = Handle<ScopeInfo>(
296 ScopeInfo::cast(context->extension()), isolate); 296 ScopeInfo::cast(context->extension()), isolate);
297 } 297 }
298 VariableMode mode; 298 VariableMode mode;
299 ContextSlotKindFlag slot_kind;
299 InitializationFlag init_flag; 300 InitializationFlag init_flag;
300 // TODO(sigurds) Figure out whether maybe_assigned_flag should 301 // TODO(sigurds) Figure out whether maybe_assigned_flag should
301 // be used to compute binding_flags. 302 // be used to compute binding_flags.
302 MaybeAssignedFlag maybe_assigned_flag; 303 MaybeAssignedFlag maybe_assigned_flag;
303 int slot_index = ScopeInfo::ContextSlotIndex( 304 int slot_index =
304 scope_info, name, &mode, &init_flag, &maybe_assigned_flag); 305 ScopeInfo::ContextSlotIndex(scope_info, name, &mode, &slot_kind,
306 &init_flag, &maybe_assigned_flag);
305 DCHECK(slot_index < 0 || slot_index >= MIN_CONTEXT_SLOTS); 307 DCHECK(slot_index < 0 || slot_index >= MIN_CONTEXT_SLOTS);
306 if (slot_index >= 0) { 308 if (slot_index >= 0 && slot_kind == ContextSlotKindFlag::kLocal) {
307 if (FLAG_trace_contexts) { 309 if (FLAG_trace_contexts) {
308 PrintF("=> found local in context slot %d (mode = %d)\n", 310 PrintF("=> found local in context slot %d (mode = %d)\n",
309 slot_index, mode); 311 slot_index, mode);
310 } 312 }
311 *index = slot_index; 313 *index = slot_index;
312 GetAttributesAndBindingFlags(mode, init_flag, attributes, 314 GetAttributesAndBindingFlags(mode, init_flag, attributes,
313 binding_flags); 315 binding_flags);
314 return context; 316 return context;
315 } 317 }
316 318
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 } 356 }
355 } while (follow_context_chain); 357 } while (follow_context_chain);
356 358
357 if (FLAG_trace_contexts) { 359 if (FLAG_trace_contexts) {
358 PrintF("=> no property/slot found\n"); 360 PrintF("=> no property/slot found\n");
359 } 361 }
360 return Handle<Object>::null(); 362 return Handle<Object>::null();
361 } 363 }
362 364
363 365
366 void Context::InvalidateGlobalSlots() {
367 DCHECK(IsScriptContext());
368 DisallowHeapAllocation no_gc;
369
370 ScopeInfo* scope_info = ScopeInfo::cast(extension());
371
372 int context_globals = scope_info->ContextGlobalCount();
373 if (context_globals > 0) {
374 PropertyCell* empty_cell = GetHeap()->empty_property_cell();
375
376 int context_locals = scope_info->ContextLocalCount();
377 int index = Context::MIN_CONTEXT_SLOTS + context_locals;
378 for (int i = 0; i < context_globals; i++) {
379 // Clear both read and write slots.
380 set(index++, empty_cell);
381 set(index++, empty_cell);
382 }
383 }
384 }
385
386
364 void Context::AddOptimizedFunction(JSFunction* function) { 387 void Context::AddOptimizedFunction(JSFunction* function) {
365 DCHECK(IsNativeContext()); 388 DCHECK(IsNativeContext());
366 #ifdef ENABLE_SLOW_DCHECKS 389 #ifdef ENABLE_SLOW_DCHECKS
367 if (FLAG_enable_slow_asserts) { 390 if (FLAG_enable_slow_asserts) {
368 Object* element = get(OPTIMIZED_FUNCTIONS_LIST); 391 Object* element = get(OPTIMIZED_FUNCTIONS_LIST);
369 while (!element->IsUndefined()) { 392 while (!element->IsUndefined()) {
370 CHECK(element != function); 393 CHECK(element != function);
371 element = JSFunction::cast(element)->next_function_link(); 394 element = JSFunction::cast(element)->next_function_link();
372 } 395 }
373 } 396 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 // During bootstrapping we allow all objects to pass as global 521 // During bootstrapping we allow all objects to pass as global
499 // objects. This is necessary to fix circular dependencies. 522 // objects. This is necessary to fix circular dependencies.
500 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || 523 return isolate->heap()->gc_state() != Heap::NOT_IN_GC ||
501 isolate->bootstrapper()->IsActive() || 524 isolate->bootstrapper()->IsActive() ||
502 object->IsGlobalObject(); 525 object->IsGlobalObject();
503 } 526 }
504 #endif 527 #endif
505 528
506 } // namespace internal 529 } // namespace internal
507 } // namespace v8 530 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698