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

Side by Side Diff: src/contexts.h

Issue 1322883002: Make isolate.h usable without objects-inl.h header. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@local_cleanup-includes-frames-2
Patch Set: Rebased. Created 5 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
« no previous file with comments | « src/compiler/source-position.cc ('k') | src/contexts.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 #ifndef V8_CONTEXTS_H_ 5 #ifndef V8_CONTEXTS_H_
6 #define V8_CONTEXTS_H_ 6 #define V8_CONTEXTS_H_
7 7
8 #include "src/heap/heap.h" 8 #include "src/heap/heap.h"
9 #include "src/objects.h" 9 #include "src/objects.h"
10 10
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 NATIVE_CONTEXT_IMPORTED_FIELDS(V) 292 NATIVE_CONTEXT_IMPORTED_FIELDS(V)
293 293
294 // A table of all script contexts. Every loaded top-level script with top-level 294 // A table of all script contexts. Every loaded top-level script with top-level
295 // lexical declarations contributes its ScriptContext into this table. 295 // lexical declarations contributes its ScriptContext into this table.
296 // 296 //
297 // The table is a fixed array, its first slot is the current used count and 297 // The table is a fixed array, its first slot is the current used count and
298 // the subsequent slots 1..used contain ScriptContexts. 298 // the subsequent slots 1..used contain ScriptContexts.
299 class ScriptContextTable : public FixedArray { 299 class ScriptContextTable : public FixedArray {
300 public: 300 public:
301 // Conversions. 301 // Conversions.
302 static ScriptContextTable* cast(Object* context) { 302 static inline ScriptContextTable* cast(Object* context);
303 DCHECK(context->IsScriptContextTable());
304 return reinterpret_cast<ScriptContextTable*>(context);
305 }
306 303
307 struct LookupResult { 304 struct LookupResult {
308 int context_index; 305 int context_index;
309 int slot_index; 306 int slot_index;
310 VariableMode mode; 307 VariableMode mode;
311 VariableLocation location; 308 VariableLocation location;
312 InitializationFlag init_flag; 309 InitializationFlag init_flag;
313 MaybeAssignedFlag maybe_assigned_flag; 310 MaybeAssignedFlag maybe_assigned_flag;
314 }; 311 };
315 312
316 int used() const { return Smi::cast(get(kUsedSlot))->value(); } 313 inline int used() const;
317 void set_used(int used) { set(kUsedSlot, Smi::FromInt(used)); } 314 inline void set_used(int used);
318 315
319 static Handle<Context> GetContext(Handle<ScriptContextTable> table, int i) { 316 static inline Handle<Context> GetContext(Handle<ScriptContextTable> table,
320 DCHECK(i < table->used()); 317 int i);
321 return Handle<Context>::cast(FixedArray::get(table, i + kFirstContextSlot));
322 }
323 318
324 // Lookup a variable `name` in a ScriptContextTable. 319 // Lookup a variable `name` in a ScriptContextTable.
325 // If it returns true, the variable is found and `result` contains 320 // If it returns true, the variable is found and `result` contains
326 // valid information about its location. 321 // valid information about its location.
327 // If it returns false, `result` is untouched. 322 // If it returns false, `result` is untouched.
328 MUST_USE_RESULT 323 MUST_USE_RESULT
329 static bool Lookup(Handle<ScriptContextTable> table, Handle<String> name, 324 static bool Lookup(Handle<ScriptContextTable> table, Handle<String> name,
330 LookupResult* result); 325 LookupResult* result);
331 326
332 MUST_USE_RESULT 327 MUST_USE_RESULT
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 // properties. 387 // properties.
393 // 388 //
394 // Finally, with Harmony scoping, the JSFunction representing a top level 389 // Finally, with Harmony scoping, the JSFunction representing a top level
395 // script will have the ScriptContext rather than a FunctionContext. 390 // script will have the ScriptContext rather than a FunctionContext.
396 // Script contexts from all top-level scripts are gathered in 391 // Script contexts from all top-level scripts are gathered in
397 // ScriptContextTable. 392 // ScriptContextTable.
398 393
399 class Context: public FixedArray { 394 class Context: public FixedArray {
400 public: 395 public:
401 // Conversions. 396 // Conversions.
402 static Context* cast(Object* context) { 397 static inline Context* cast(Object* context);
403 DCHECK(context->IsContext());
404 return reinterpret_cast<Context*>(context);
405 }
406 398
407 // The default context slot layout; indices are FixedArray slot indices. 399 // The default context slot layout; indices are FixedArray slot indices.
408 enum { 400 enum {
409 // These slots are in all contexts. 401 // These slots are in all contexts.
410 CLOSURE_INDEX, 402 CLOSURE_INDEX,
411 PREVIOUS_INDEX, 403 PREVIOUS_INDEX,
412 // The extension slot is used for either the global object (in global 404 // The extension slot is used for either the global object (in global
413 // contexts), eval extension object (function contexts), subject of with 405 // contexts), eval extension object (function contexts), subject of with
414 // (with contexts), or the variable name (catch contexts), the serialized 406 // (with contexts), or the variable name (catch contexts), the serialized
415 // scope info (block contexts), or the module instance (module contexts). 407 // scope info (block contexts), or the module instance (module contexts).
(...skipping 15 matching lines...) Expand all
431 // Total number of slots. 423 // Total number of slots.
432 NATIVE_CONTEXT_SLOTS, 424 NATIVE_CONTEXT_SLOTS,
433 FIRST_WEAK_SLOT = OPTIMIZED_FUNCTIONS_LIST, 425 FIRST_WEAK_SLOT = OPTIMIZED_FUNCTIONS_LIST,
434 426
435 MIN_CONTEXT_SLOTS = GLOBAL_PROXY_INDEX, 427 MIN_CONTEXT_SLOTS = GLOBAL_PROXY_INDEX,
436 // This slot holds the thrown value in catch contexts. 428 // This slot holds the thrown value in catch contexts.
437 THROWN_OBJECT_INDEX = MIN_CONTEXT_SLOTS, 429 THROWN_OBJECT_INDEX = MIN_CONTEXT_SLOTS,
438 }; 430 };
439 431
440 // Direct slot access. 432 // Direct slot access.
441 JSFunction* closure() { return JSFunction::cast(get(CLOSURE_INDEX)); } 433 inline JSFunction* closure();
442 void set_closure(JSFunction* closure) { set(CLOSURE_INDEX, closure); } 434 inline void set_closure(JSFunction* closure);
443 435
444 Context* previous() { 436 inline Context* previous();
445 Object* result = unchecked_previous(); 437 inline void set_previous(Context* context);
446 DCHECK(IsBootstrappingOrValidParentContext(result, this));
447 return reinterpret_cast<Context*>(result);
448 }
449 void set_previous(Context* context) { set(PREVIOUS_INDEX, context); }
450 438
451 bool has_extension() { return extension() != nullptr; } 439 inline bool has_extension();
452 Object* extension() { return get(EXTENSION_INDEX); } 440 inline Object* extension();
453 void set_extension(Object* object) { set(EXTENSION_INDEX, object); } 441 inline void set_extension(Object* object);
454 JSObject* extension_object(); 442 JSObject* extension_object();
455 JSReceiver* extension_receiver(); 443 JSReceiver* extension_receiver();
456 ScopeInfo* scope_info(); 444 ScopeInfo* scope_info();
457 String* catch_name(); 445 String* catch_name();
458 446
459 JSModule* module() { return JSModule::cast(get(EXTENSION_INDEX)); } 447 inline JSModule* module();
460 void set_module(JSModule* module) { set(EXTENSION_INDEX, module); } 448 inline void set_module(JSModule* module);
461 449
462 // Get the context where var declarations will be hoisted to, which 450 // Get the context where var declarations will be hoisted to, which
463 // may be the context itself. 451 // may be the context itself.
464 Context* declaration_context(); 452 Context* declaration_context();
465 bool is_declaration_context(); 453 bool is_declaration_context();
466 454
467 GlobalObject* global_object() { 455 inline GlobalObject* global_object();
468 Object* result = get(GLOBAL_OBJECT_INDEX); 456 inline void set_global_object(GlobalObject* object);
469 DCHECK(IsBootstrappingOrGlobalObject(this->GetIsolate(), result));
470 return reinterpret_cast<GlobalObject*>(result);
471 }
472 void set_global_object(GlobalObject* object) {
473 set(GLOBAL_OBJECT_INDEX, object);
474 }
475 457
476 // Returns a JSGlobalProxy object or null. 458 // Returns a JSGlobalProxy object or null.
477 JSObject* global_proxy(); 459 JSObject* global_proxy();
478 void set_global_proxy(JSObject* global); 460 void set_global_proxy(JSObject* global);
479 461
480 // The builtins object. 462 // The builtins object.
481 JSBuiltinsObject* builtins(); 463 JSBuiltinsObject* builtins();
482 464
483 // Get the script context by traversing the context chain. 465 // Get the script context by traversing the context chain.
484 Context* script_context(); 466 Context* script_context();
485 467
486 // Compute the native context by traversing the context chain. 468 // Compute the native context by traversing the context chain.
487 Context* native_context(); 469 Context* native_context();
488 470
489 // Predicates for context types. IsNativeContext is also defined on Object 471 // Predicates for context types. IsNativeContext is also defined on Object
490 // because we frequently have to know if arbitrary objects are natives 472 // because we frequently have to know if arbitrary objects are natives
491 // contexts. 473 // contexts.
492 bool IsNativeContext() { 474 inline bool IsNativeContext();
493 Map* map = this->map(); 475 inline bool IsFunctionContext();
494 return map == map->GetHeap()->native_context_map(); 476 inline bool IsCatchContext();
495 } 477 inline bool IsWithContext();
496 bool IsFunctionContext() { 478 inline bool IsBlockContext();
497 Map* map = this->map(); 479 inline bool IsModuleContext();
498 return map == map->GetHeap()->function_context_map(); 480 inline bool IsScriptContext();
499 }
500 bool IsCatchContext() {
501 Map* map = this->map();
502 return map == map->GetHeap()->catch_context_map();
503 }
504 bool IsWithContext() {
505 Map* map = this->map();
506 return map == map->GetHeap()->with_context_map();
507 }
508 bool IsBlockContext() {
509 Map* map = this->map();
510 return map == map->GetHeap()->block_context_map();
511 }
512 bool IsModuleContext() {
513 Map* map = this->map();
514 return map == map->GetHeap()->module_context_map();
515 }
516 bool IsScriptContext() {
517 Map* map = this->map();
518 return map == map->GetHeap()->script_context_map();
519 }
520 481
521 bool HasSameSecurityTokenAs(Context* that) { 482 inline bool HasSameSecurityTokenAs(Context* that);
522 return this->global_object()->native_context()->security_token() ==
523 that->global_object()->native_context()->security_token();
524 }
525 483
526 // Initializes global variable bindings in given script context. 484 // Initializes global variable bindings in given script context.
527 void InitializeGlobalSlots(); 485 void InitializeGlobalSlots();
528 486
529 // A native context holds a list of all functions with optimized code. 487 // A native context holds a list of all functions with optimized code.
530 void AddOptimizedFunction(JSFunction* function); 488 void AddOptimizedFunction(JSFunction* function);
531 void RemoveOptimizedFunction(JSFunction* function); 489 void RemoveOptimizedFunction(JSFunction* function);
532 void SetOptimizedFunctionsListHead(Object* head); 490 void SetOptimizedFunctionsListHead(Object* head);
533 Object* OptimizedFunctionsListHead(); 491 Object* OptimizedFunctionsListHead();
534 492
535 // The native context also stores a list of all optimized code and a 493 // The native context also stores a list of all optimized code and a
536 // list of all deoptimized code, which are needed by the deoptimizer. 494 // list of all deoptimized code, which are needed by the deoptimizer.
537 void AddOptimizedCode(Code* code); 495 void AddOptimizedCode(Code* code);
538 void SetOptimizedCodeListHead(Object* head); 496 void SetOptimizedCodeListHead(Object* head);
539 Object* OptimizedCodeListHead(); 497 Object* OptimizedCodeListHead();
540 void SetDeoptimizedCodeListHead(Object* head); 498 void SetDeoptimizedCodeListHead(Object* head);
541 Object* DeoptimizedCodeListHead(); 499 Object* DeoptimizedCodeListHead();
542 500
543 Handle<Object> ErrorMessageForCodeGenerationFromStrings(); 501 Handle<Object> ErrorMessageForCodeGenerationFromStrings();
544 502
545 static int ImportedFieldIndexForName(Handle<String> name); 503 static int ImportedFieldIndexForName(Handle<String> name);
546 static int IntrinsicIndexForName(Handle<String> name); 504 static int IntrinsicIndexForName(Handle<String> name);
547 505
548 static bool IsJSBuiltin(Handle<Context> native_context, 506 static bool IsJSBuiltin(Handle<Context> native_context,
549 Handle<JSFunction> function); 507 Handle<JSFunction> function);
550 508
551 #define NATIVE_CONTEXT_FIELD_ACCESSORS(index, type, name) \ 509 #define NATIVE_CONTEXT_FIELD_ACCESSORS(index, type, name) \
552 void set_##name(type* value) { \ 510 inline void set_##name(type* value); \
553 DCHECK(IsNativeContext()); \ 511 inline bool is_##name(type* value); \
554 set(index, value); \ 512 inline type* name();
555 } \
556 bool is_##name(type* value) { \
557 DCHECK(IsNativeContext()); \
558 return type::cast(get(index)) == value; \
559 } \
560 type* name() { \
561 DCHECK(IsNativeContext()); \
562 return type::cast(get(index)); \
563 }
564 NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSORS) 513 NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSORS)
565 #undef NATIVE_CONTEXT_FIELD_ACCESSORS 514 #undef NATIVE_CONTEXT_FIELD_ACCESSORS
566 515
567 // Lookup the slot called name, starting with the current context. 516 // Lookup the slot called name, starting with the current context.
568 // There are three possibilities: 517 // There are three possibilities:
569 // 518 //
570 // 1) result->IsContext(): 519 // 1) result->IsContext():
571 // The binding was found in a context. *index is always the 520 // The binding was found in a context. *index is always the
572 // non-negative slot index. *attributes is NONE for var and let 521 // non-negative slot index. *attributes is NONE for var and let
573 // declarations, READ_ONLY for const declarations (never ABSENT). 522 // declarations, READ_ONLY for const declarations (never ABSENT).
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 // GC support. 572 // GC support.
624 typedef FixedBodyDescriptor< 573 typedef FixedBodyDescriptor<
625 kHeaderSize, kSize, kSize> ScavengeBodyDescriptor; 574 kHeaderSize, kSize, kSize> ScavengeBodyDescriptor;
626 575
627 typedef FixedBodyDescriptor< 576 typedef FixedBodyDescriptor<
628 kHeaderSize, 577 kHeaderSize,
629 kHeaderSize + FIRST_WEAK_SLOT * kPointerSize, 578 kHeaderSize + FIRST_WEAK_SLOT * kPointerSize,
630 kSize> MarkCompactBodyDescriptor; 579 kSize> MarkCompactBodyDescriptor;
631 580
632 private: 581 private:
633 // Unchecked access to the slots.
634 Object* unchecked_previous() { return get(PREVIOUS_INDEX); }
635
636 #ifdef DEBUG 582 #ifdef DEBUG
637 // Bootstrapping-aware type checks. 583 // Bootstrapping-aware type checks.
638 static bool IsBootstrappingOrValidParentContext(Object* object, Context* kid); 584 static bool IsBootstrappingOrValidParentContext(Object* object, Context* kid);
639 static bool IsBootstrappingOrGlobalObject(Isolate* isolate, Object* object); 585 static bool IsBootstrappingOrGlobalObject(Isolate* isolate, Object* object);
640 #endif 586 #endif
641 587
642 STATIC_ASSERT(kHeaderSize == Internals::kContextHeaderSize); 588 STATIC_ASSERT(kHeaderSize == Internals::kContextHeaderSize);
643 STATIC_ASSERT(EMBEDDER_DATA_INDEX == Internals::kContextEmbedderDataIndex); 589 STATIC_ASSERT(EMBEDDER_DATA_INDEX == Internals::kContextEmbedderDataIndex);
644 }; 590 };
645 591
646 } } // namespace v8::internal 592 } } // namespace v8::internal
647 593
648 #endif // V8_CONTEXTS_H_ 594 #endif // V8_CONTEXTS_H_
OLDNEW
« no previous file with comments | « src/compiler/source-position.cc ('k') | src/contexts.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698