| OLD | NEW |
| 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_API_H_ | 5 #ifndef V8_API_H_ |
| 6 #define V8_API_H_ | 6 #define V8_API_H_ |
| 7 | 7 |
| 8 #include "include/v8-testing.h" | 8 #include "include/v8-testing.h" |
| 9 #include "src/contexts.h" | 9 #include "src/contexts.h" |
| 10 #include "src/factory.h" | 10 #include "src/factory.h" |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 // data. | 445 // data. |
| 446 class HandleScopeImplementer { | 446 class HandleScopeImplementer { |
| 447 public: | 447 public: |
| 448 explicit HandleScopeImplementer(Isolate* isolate) | 448 explicit HandleScopeImplementer(Isolate* isolate) |
| 449 : isolate_(isolate), | 449 : isolate_(isolate), |
| 450 blocks_(0), | 450 blocks_(0), |
| 451 entered_contexts_(0), | 451 entered_contexts_(0), |
| 452 saved_contexts_(0), | 452 saved_contexts_(0), |
| 453 spare_(NULL), | 453 spare_(NULL), |
| 454 call_depth_(0), | 454 call_depth_(0), |
| 455 microtasks_depth_(0), | |
| 456 microtasks_suppressions_(0), | |
| 457 #ifdef V8_ENABLE_CHECKS | |
| 458 debug_microtasks_depth_(0), | |
| 459 #endif | |
| 460 microtasks_policy_(v8::MicrotasksPolicy::kAuto), | |
| 461 last_handle_before_deferred_block_(NULL) { } | 455 last_handle_before_deferred_block_(NULL) { } |
| 462 | 456 |
| 463 ~HandleScopeImplementer() { | 457 ~HandleScopeImplementer() { |
| 464 DeleteArray(spare_); | 458 DeleteArray(spare_); |
| 465 } | 459 } |
| 466 | 460 |
| 467 // Threading support for handle data. | 461 // Threading support for handle data. |
| 468 static int ArchiveSpacePerThread(); | 462 static int ArchiveSpacePerThread(); |
| 469 char* RestoreThread(char* from); | 463 char* RestoreThread(char* from); |
| 470 char* ArchiveThread(char* to); | 464 char* ArchiveThread(char* to); |
| 471 void FreeThreadResources(); | 465 void FreeThreadResources(); |
| 472 | 466 |
| 473 // Garbage collection support. | 467 // Garbage collection support. |
| 474 void Iterate(v8::internal::ObjectVisitor* v); | 468 void Iterate(v8::internal::ObjectVisitor* v); |
| 475 static char* Iterate(v8::internal::ObjectVisitor* v, char* data); | 469 static char* Iterate(v8::internal::ObjectVisitor* v, char* data); |
| 476 | 470 |
| 477 | 471 |
| 478 inline internal::Object** GetSpareOrNewBlock(); | 472 inline internal::Object** GetSpareOrNewBlock(); |
| 479 inline void DeleteExtensions(internal::Object** prev_limit); | 473 inline void DeleteExtensions(internal::Object** prev_limit); |
| 480 | 474 |
| 481 // Call depth represents nested v8 api calls. | |
| 482 inline void IncrementCallDepth() {call_depth_++;} | 475 inline void IncrementCallDepth() {call_depth_++;} |
| 483 inline void DecrementCallDepth() {call_depth_--;} | 476 inline void DecrementCallDepth() {call_depth_--;} |
| 484 inline bool CallDepthIsZero() { return call_depth_ == 0; } | 477 inline bool CallDepthIsZero() { return call_depth_ == 0; } |
| 485 | 478 |
| 486 // Microtasks scope depth represents nested scopes controlling microtasks | |
| 487 // invocation, which happens when depth reaches zero. | |
| 488 inline void IncrementMicrotasksScopeDepth() {microtasks_depth_++;} | |
| 489 inline void DecrementMicrotasksScopeDepth() {microtasks_depth_--;} | |
| 490 inline int GetMicrotasksScopeDepth() { return microtasks_depth_; } | |
| 491 | |
| 492 // Possibly nested microtasks suppression scopes prevent microtasks | |
| 493 // from running. | |
| 494 inline void IncrementMicrotasksSuppressions() {microtasks_suppressions_++;} | |
| 495 inline void DecrementMicrotasksSuppressions() {microtasks_suppressions_--;} | |
| 496 inline bool HasMicrotasksSuppressions() { return !!microtasks_suppressions_; } | |
| 497 | |
| 498 #ifdef V8_ENABLE_CHECKS | |
| 499 // In debug we check that calls not intended to invoke microtasks are | |
| 500 // still correctly wrapped with microtask scopes. | |
| 501 inline void IncrementDebugMicrotasksScopeDepth() {debug_microtasks_depth_++;} | |
| 502 inline void DecrementDebugMicrotasksScopeDepth() {debug_microtasks_depth_--;} | |
| 503 inline bool DebugMicrotasksScopeDepthIsZero() { | |
| 504 return debug_microtasks_depth_ == 0; | |
| 505 } | |
| 506 #endif | |
| 507 | |
| 508 inline void set_microtasks_policy(v8::MicrotasksPolicy policy); | |
| 509 inline v8::MicrotasksPolicy microtasks_policy() const; | |
| 510 | |
| 511 inline void EnterContext(Handle<Context> context); | 479 inline void EnterContext(Handle<Context> context); |
| 512 inline void LeaveContext(); | 480 inline void LeaveContext(); |
| 513 inline bool LastEnteredContextWas(Handle<Context> context); | 481 inline bool LastEnteredContextWas(Handle<Context> context); |
| 514 | 482 |
| 515 // Returns the last entered context or an empty handle if no | 483 // Returns the last entered context or an empty handle if no |
| 516 // contexts have been entered. | 484 // contexts have been entered. |
| 517 inline Handle<Context> LastEnteredContext(); | 485 inline Handle<Context> LastEnteredContext(); |
| 518 | 486 |
| 519 inline void SaveContext(Context* context); | 487 inline void SaveContext(Context* context); |
| 520 inline Context* RestoreContext(); | 488 inline Context* RestoreContext(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 DeferredHandles* Detach(Object** prev_limit); | 525 DeferredHandles* Detach(Object** prev_limit); |
| 558 | 526 |
| 559 Isolate* isolate_; | 527 Isolate* isolate_; |
| 560 List<internal::Object**> blocks_; | 528 List<internal::Object**> blocks_; |
| 561 // Used as a stack to keep track of entered contexts. | 529 // Used as a stack to keep track of entered contexts. |
| 562 List<Context*> entered_contexts_; | 530 List<Context*> entered_contexts_; |
| 563 // Used as a stack to keep track of saved contexts. | 531 // Used as a stack to keep track of saved contexts. |
| 564 List<Context*> saved_contexts_; | 532 List<Context*> saved_contexts_; |
| 565 Object** spare_; | 533 Object** spare_; |
| 566 int call_depth_; | 534 int call_depth_; |
| 567 int microtasks_depth_; | |
| 568 int microtasks_suppressions_; | |
| 569 #ifdef V8_ENABLE_CHECKS | |
| 570 int debug_microtasks_depth_; | |
| 571 #endif | |
| 572 v8::MicrotasksPolicy microtasks_policy_; | |
| 573 Object** last_handle_before_deferred_block_; | 535 Object** last_handle_before_deferred_block_; |
| 574 // This is only used for threading support. | 536 // This is only used for threading support. |
| 575 HandleScopeData handle_scope_data_; | 537 HandleScopeData handle_scope_data_; |
| 576 | 538 |
| 577 void IterateThis(ObjectVisitor* v); | 539 void IterateThis(ObjectVisitor* v); |
| 578 char* RestoreThreadHelper(char* from); | 540 char* RestoreThreadHelper(char* from); |
| 579 char* ArchiveThreadHelper(char* to); | 541 char* ArchiveThreadHelper(char* to); |
| 580 | 542 |
| 581 friend class DeferredHandles; | 543 friend class DeferredHandles; |
| 582 friend class DeferredHandleScope; | 544 friend class DeferredHandleScope; |
| 583 | 545 |
| 584 DISALLOW_COPY_AND_ASSIGN(HandleScopeImplementer); | 546 DISALLOW_COPY_AND_ASSIGN(HandleScopeImplementer); |
| 585 }; | 547 }; |
| 586 | 548 |
| 587 | 549 |
| 588 const int kHandleBlockSize = v8::internal::KB - 2; // fit in one page | 550 const int kHandleBlockSize = v8::internal::KB - 2; // fit in one page |
| 589 | 551 |
| 590 | 552 |
| 591 void HandleScopeImplementer::set_microtasks_policy( | |
| 592 v8::MicrotasksPolicy policy) { | |
| 593 microtasks_policy_ = policy; | |
| 594 } | |
| 595 | |
| 596 | |
| 597 v8::MicrotasksPolicy HandleScopeImplementer::microtasks_policy() const { | |
| 598 return microtasks_policy_; | |
| 599 } | |
| 600 | |
| 601 | |
| 602 void HandleScopeImplementer::SaveContext(Context* context) { | 553 void HandleScopeImplementer::SaveContext(Context* context) { |
| 603 saved_contexts_.Add(context); | 554 saved_contexts_.Add(context); |
| 604 } | 555 } |
| 605 | 556 |
| 606 | 557 |
| 607 Context* HandleScopeImplementer::RestoreContext() { | 558 Context* HandleScopeImplementer::RestoreContext() { |
| 608 return saved_contexts_.RemoveLast(); | 559 return saved_contexts_.RemoveLast(); |
| 609 } | 560 } |
| 610 | 561 |
| 611 | 562 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 } | 641 } |
| 691 | 642 |
| 692 private: | 643 private: |
| 693 static v8::Testing::StressType stress_type_; | 644 static v8::Testing::StressType stress_type_; |
| 694 }; | 645 }; |
| 695 | 646 |
| 696 } // namespace internal | 647 } // namespace internal |
| 697 } // namespace v8 | 648 } // namespace v8 |
| 698 | 649 |
| 699 #endif // V8_API_H_ | 650 #endif // V8_API_H_ |
| OLD | NEW |