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

Side by Side Diff: src/api.h

Issue 1741893003: Introduce v8::MicrotasksScope. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: SetAutorunMicrotasks fix Created 4 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
« no previous file with comments | « include/v8.h ('k') | src/api.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_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
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),
455 last_handle_before_deferred_block_(NULL) { } 461 last_handle_before_deferred_block_(NULL) { }
456 462
457 ~HandleScopeImplementer() { 463 ~HandleScopeImplementer() {
458 DeleteArray(spare_); 464 DeleteArray(spare_);
459 } 465 }
460 466
461 // Threading support for handle data. 467 // Threading support for handle data.
462 static int ArchiveSpacePerThread(); 468 static int ArchiveSpacePerThread();
463 char* RestoreThread(char* from); 469 char* RestoreThread(char* from);
464 char* ArchiveThread(char* to); 470 char* ArchiveThread(char* to);
465 void FreeThreadResources(); 471 void FreeThreadResources();
466 472
467 // Garbage collection support. 473 // Garbage collection support.
468 void Iterate(v8::internal::ObjectVisitor* v); 474 void Iterate(v8::internal::ObjectVisitor* v);
469 static char* Iterate(v8::internal::ObjectVisitor* v, char* data); 475 static char* Iterate(v8::internal::ObjectVisitor* v, char* data);
470 476
471 477
472 inline internal::Object** GetSpareOrNewBlock(); 478 inline internal::Object** GetSpareOrNewBlock();
473 inline void DeleteExtensions(internal::Object** prev_limit); 479 inline void DeleteExtensions(internal::Object** prev_limit);
474 480
481 // Call depth represents nested v8 api calls.
475 inline void IncrementCallDepth() {call_depth_++;} 482 inline void IncrementCallDepth() {call_depth_++;}
476 inline void DecrementCallDepth() {call_depth_--;} 483 inline void DecrementCallDepth() {call_depth_--;}
477 inline bool CallDepthIsZero() { return call_depth_ == 0; } 484 inline bool CallDepthIsZero() { return call_depth_ == 0; }
478 485
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
479 inline void EnterContext(Handle<Context> context); 511 inline void EnterContext(Handle<Context> context);
480 inline void LeaveContext(); 512 inline void LeaveContext();
481 inline bool LastEnteredContextWas(Handle<Context> context); 513 inline bool LastEnteredContextWas(Handle<Context> context);
482 514
483 // Returns the last entered context or an empty handle if no 515 // Returns the last entered context or an empty handle if no
484 // contexts have been entered. 516 // contexts have been entered.
485 inline Handle<Context> LastEnteredContext(); 517 inline Handle<Context> LastEnteredContext();
486 518
487 inline void SaveContext(Context* context); 519 inline void SaveContext(Context* context);
488 inline Context* RestoreContext(); 520 inline Context* RestoreContext();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 DeferredHandles* Detach(Object** prev_limit); 557 DeferredHandles* Detach(Object** prev_limit);
526 558
527 Isolate* isolate_; 559 Isolate* isolate_;
528 List<internal::Object**> blocks_; 560 List<internal::Object**> blocks_;
529 // Used as a stack to keep track of entered contexts. 561 // Used as a stack to keep track of entered contexts.
530 List<Context*> entered_contexts_; 562 List<Context*> entered_contexts_;
531 // Used as a stack to keep track of saved contexts. 563 // Used as a stack to keep track of saved contexts.
532 List<Context*> saved_contexts_; 564 List<Context*> saved_contexts_;
533 Object** spare_; 565 Object** spare_;
534 int call_depth_; 566 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_;
535 Object** last_handle_before_deferred_block_; 573 Object** last_handle_before_deferred_block_;
536 // This is only used for threading support. 574 // This is only used for threading support.
537 HandleScopeData handle_scope_data_; 575 HandleScopeData handle_scope_data_;
538 576
539 void IterateThis(ObjectVisitor* v); 577 void IterateThis(ObjectVisitor* v);
540 char* RestoreThreadHelper(char* from); 578 char* RestoreThreadHelper(char* from);
541 char* ArchiveThreadHelper(char* to); 579 char* ArchiveThreadHelper(char* to);
542 580
543 friend class DeferredHandles; 581 friend class DeferredHandles;
544 friend class DeferredHandleScope; 582 friend class DeferredHandleScope;
545 583
546 DISALLOW_COPY_AND_ASSIGN(HandleScopeImplementer); 584 DISALLOW_COPY_AND_ASSIGN(HandleScopeImplementer);
547 }; 585 };
548 586
549 587
550 const int kHandleBlockSize = v8::internal::KB - 2; // fit in one page 588 const int kHandleBlockSize = v8::internal::KB - 2; // fit in one page
551 589
552 590
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
553 void HandleScopeImplementer::SaveContext(Context* context) { 602 void HandleScopeImplementer::SaveContext(Context* context) {
554 saved_contexts_.Add(context); 603 saved_contexts_.Add(context);
555 } 604 }
556 605
557 606
558 Context* HandleScopeImplementer::RestoreContext() { 607 Context* HandleScopeImplementer::RestoreContext() {
559 return saved_contexts_.RemoveLast(); 608 return saved_contexts_.RemoveLast();
560 } 609 }
561 610
562 611
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 } 690 }
642 691
643 private: 692 private:
644 static v8::Testing::StressType stress_type_; 693 static v8::Testing::StressType stress_type_;
645 }; 694 };
646 695
647 } // namespace internal 696 } // namespace internal
648 } // namespace v8 697 } // namespace v8
649 698
650 #endif // V8_API_H_ 699 #endif // V8_API_H_
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698