| 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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 explicit HandleScopeImplementer(Isolate* isolate) | 382 explicit HandleScopeImplementer(Isolate* isolate) |
| 383 : isolate_(isolate), | 383 : isolate_(isolate), |
| 384 blocks_(0), | 384 blocks_(0), |
| 385 entered_contexts_(0), | 385 entered_contexts_(0), |
| 386 saved_contexts_(0), | 386 saved_contexts_(0), |
| 387 microtask_context_(nullptr), | 387 microtask_context_(nullptr), |
| 388 spare_(NULL), | 388 spare_(NULL), |
| 389 call_depth_(0), | 389 call_depth_(0), |
| 390 microtasks_depth_(0), | 390 microtasks_depth_(0), |
| 391 microtasks_suppressions_(0), | 391 microtasks_suppressions_(0), |
| 392 entered_context_count_during_microtasks_(0), |
| 392 #ifdef DEBUG | 393 #ifdef DEBUG |
| 393 debug_microtasks_depth_(0), | 394 debug_microtasks_depth_(0), |
| 394 #endif | 395 #endif |
| 395 microtasks_policy_(v8::MicrotasksPolicy::kAuto), | 396 microtasks_policy_(v8::MicrotasksPolicy::kAuto), |
| 396 last_handle_before_deferred_block_(NULL) { } | 397 last_handle_before_deferred_block_(NULL) { } |
| 397 | 398 |
| 398 ~HandleScopeImplementer() { | 399 ~HandleScopeImplementer() { |
| 399 DeleteArray(spare_); | 400 DeleteArray(spare_); |
| 400 } | 401 } |
| 401 | 402 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 inline void LeaveContext(); | 448 inline void LeaveContext(); |
| 448 inline bool LastEnteredContextWas(Handle<Context> context); | 449 inline bool LastEnteredContextWas(Handle<Context> context); |
| 449 | 450 |
| 450 // Returns the last entered context or an empty handle if no | 451 // Returns the last entered context or an empty handle if no |
| 451 // contexts have been entered. | 452 // contexts have been entered. |
| 452 inline Handle<Context> LastEnteredContext(); | 453 inline Handle<Context> LastEnteredContext(); |
| 453 | 454 |
| 454 inline void EnterMicrotaskContext(Handle<Context> context); | 455 inline void EnterMicrotaskContext(Handle<Context> context); |
| 455 inline void LeaveMicrotaskContext(); | 456 inline void LeaveMicrotaskContext(); |
| 456 inline Handle<Context> MicrotaskContext(); | 457 inline Handle<Context> MicrotaskContext(); |
| 458 inline bool MicrotaskContextIsLastEnteredContext() const { |
| 459 return microtask_context_ && |
| 460 entered_context_count_during_microtasks_ == |
| 461 entered_contexts_.length(); |
| 462 } |
| 457 | 463 |
| 458 inline void SaveContext(Context* context); | 464 inline void SaveContext(Context* context); |
| 459 inline Context* RestoreContext(); | 465 inline Context* RestoreContext(); |
| 460 inline bool HasSavedContexts(); | 466 inline bool HasSavedContexts(); |
| 461 | 467 |
| 462 inline List<internal::Object**>* blocks() { return &blocks_; } | 468 inline List<internal::Object**>* blocks() { return &blocks_; } |
| 463 Isolate* isolate() const { return isolate_; } | 469 Isolate* isolate() const { return isolate_; } |
| 464 | 470 |
| 465 void ReturnBlock(Object** block) { | 471 void ReturnBlock(Object** block) { |
| 466 DCHECK(block != NULL); | 472 DCHECK(block != NULL); |
| 467 if (spare_ != NULL) DeleteArray(spare_); | 473 if (spare_ != NULL) DeleteArray(spare_); |
| 468 spare_ = block; | 474 spare_ = block; |
| 469 } | 475 } |
| 470 | 476 |
| 471 private: | 477 private: |
| 472 void ResetAfterArchive() { | 478 void ResetAfterArchive() { |
| 473 blocks_.Initialize(0); | 479 blocks_.Initialize(0); |
| 474 entered_contexts_.Initialize(0); | 480 entered_contexts_.Initialize(0); |
| 475 saved_contexts_.Initialize(0); | 481 saved_contexts_.Initialize(0); |
| 476 microtask_context_ = nullptr; | 482 microtask_context_ = nullptr; |
| 483 entered_context_count_during_microtasks_ = 0; |
| 477 spare_ = NULL; | 484 spare_ = NULL; |
| 478 last_handle_before_deferred_block_ = NULL; | 485 last_handle_before_deferred_block_ = NULL; |
| 479 call_depth_ = 0; | 486 call_depth_ = 0; |
| 480 } | 487 } |
| 481 | 488 |
| 482 void Free() { | 489 void Free() { |
| 483 DCHECK(blocks_.length() == 0); | 490 DCHECK(blocks_.length() == 0); |
| 484 DCHECK(entered_contexts_.length() == 0); | 491 DCHECK(entered_contexts_.length() == 0); |
| 485 DCHECK(saved_contexts_.length() == 0); | 492 DCHECK(saved_contexts_.length() == 0); |
| 486 DCHECK(!microtask_context_); | 493 DCHECK(!microtask_context_); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 501 List<internal::Object**> blocks_; | 508 List<internal::Object**> blocks_; |
| 502 // Used as a stack to keep track of entered contexts. | 509 // Used as a stack to keep track of entered contexts. |
| 503 List<Context*> entered_contexts_; | 510 List<Context*> entered_contexts_; |
| 504 // Used as a stack to keep track of saved contexts. | 511 // Used as a stack to keep track of saved contexts. |
| 505 List<Context*> saved_contexts_; | 512 List<Context*> saved_contexts_; |
| 506 Context* microtask_context_; | 513 Context* microtask_context_; |
| 507 Object** spare_; | 514 Object** spare_; |
| 508 int call_depth_; | 515 int call_depth_; |
| 509 int microtasks_depth_; | 516 int microtasks_depth_; |
| 510 int microtasks_suppressions_; | 517 int microtasks_suppressions_; |
| 518 int entered_context_count_during_microtasks_; |
| 511 #ifdef DEBUG | 519 #ifdef DEBUG |
| 512 int debug_microtasks_depth_; | 520 int debug_microtasks_depth_; |
| 513 #endif | 521 #endif |
| 514 v8::MicrotasksPolicy microtasks_policy_; | 522 v8::MicrotasksPolicy microtasks_policy_; |
| 515 Object** last_handle_before_deferred_block_; | 523 Object** last_handle_before_deferred_block_; |
| 516 // This is only used for threading support. | 524 // This is only used for threading support. |
| 517 HandleScopeData handle_scope_data_; | 525 HandleScopeData handle_scope_data_; |
| 518 | 526 |
| 519 void IterateThis(ObjectVisitor* v); | 527 void IterateThis(ObjectVisitor* v); |
| 520 char* RestoreThreadHelper(char* from); | 528 char* RestoreThreadHelper(char* from); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 | 580 |
| 573 | 581 |
| 574 Handle<Context> HandleScopeImplementer::LastEnteredContext() { | 582 Handle<Context> HandleScopeImplementer::LastEnteredContext() { |
| 575 if (entered_contexts_.is_empty()) return Handle<Context>::null(); | 583 if (entered_contexts_.is_empty()) return Handle<Context>::null(); |
| 576 return Handle<Context>(entered_contexts_.last()); | 584 return Handle<Context>(entered_contexts_.last()); |
| 577 } | 585 } |
| 578 | 586 |
| 579 void HandleScopeImplementer::EnterMicrotaskContext(Handle<Context> context) { | 587 void HandleScopeImplementer::EnterMicrotaskContext(Handle<Context> context) { |
| 580 DCHECK(!microtask_context_); | 588 DCHECK(!microtask_context_); |
| 581 microtask_context_ = *context; | 589 microtask_context_ = *context; |
| 590 entered_context_count_during_microtasks_ = entered_contexts_.length(); |
| 582 } | 591 } |
| 583 | 592 |
| 584 void HandleScopeImplementer::LeaveMicrotaskContext() { | 593 void HandleScopeImplementer::LeaveMicrotaskContext() { |
| 585 DCHECK(microtask_context_); | 594 DCHECK(microtask_context_); |
| 586 microtask_context_ = nullptr; | 595 microtask_context_ = nullptr; |
| 596 entered_context_count_during_microtasks_ = 0; |
| 587 } | 597 } |
| 588 | 598 |
| 589 Handle<Context> HandleScopeImplementer::MicrotaskContext() { | 599 Handle<Context> HandleScopeImplementer::MicrotaskContext() { |
| 590 if (microtask_context_) return Handle<Context>(microtask_context_); | 600 if (microtask_context_) return Handle<Context>(microtask_context_); |
| 591 return Handle<Context>::null(); | 601 return Handle<Context>::null(); |
| 592 } | 602 } |
| 593 | 603 |
| 594 // If there's a spare block, use it for growing the current scope. | 604 // If there's a spare block, use it for growing the current scope. |
| 595 internal::Object** HandleScopeImplementer::GetSpareOrNewBlock() { | 605 internal::Object** HandleScopeImplementer::GetSpareOrNewBlock() { |
| 596 internal::Object** block = (spare_ != NULL) ? | 606 internal::Object** block = (spare_ != NULL) ? |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 } | 656 } |
| 647 | 657 |
| 648 private: | 658 private: |
| 649 static v8::Testing::StressType stress_type_; | 659 static v8::Testing::StressType stress_type_; |
| 650 }; | 660 }; |
| 651 | 661 |
| 652 } // namespace internal | 662 } // namespace internal |
| 653 } // namespace v8 | 663 } // namespace v8 |
| 654 | 664 |
| 655 #endif // V8_API_H_ | 665 #endif // V8_API_H_ |
| OLD | NEW |