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

Side by Side Diff: src/isolate.cc

Issue 2915793002: [api] Prototype WeakRef implementation
Patch Set: Created 3 years, 6 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/isolate.h ('k') | src/js/macros.py » ('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 #include "src/isolate.h" 5 #include "src/isolate.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include <fstream> // NOLINT(readability/streams) 9 #include <fstream> // NOLINT(readability/streams)
10 #include <sstream> 10 #include <sstream>
(...skipping 3319 matching lines...) Expand 10 before | Expand all | Expand 10 after
3330 call_completed_callbacks_.Remove(i); 3330 call_completed_callbacks_.Remove(i);
3331 } 3331 }
3332 } 3332 }
3333 } 3333 }
3334 3334
3335 3335
3336 void Isolate::FireCallCompletedCallback() { 3336 void Isolate::FireCallCompletedCallback() {
3337 if (!handle_scope_implementer()->CallDepthIsZero()) return; 3337 if (!handle_scope_implementer()->CallDepthIsZero()) return;
3338 3338
3339 bool run_microtasks = 3339 bool run_microtasks =
3340 pending_microtask_count() && 3340 (heap()->weak_refs()->length() ||
3341 pending_microtask_count()) &&
3341 !handle_scope_implementer()->HasMicrotasksSuppressions() && 3342 !handle_scope_implementer()->HasMicrotasksSuppressions() &&
3342 handle_scope_implementer()->microtasks_policy() == 3343 handle_scope_implementer()->microtasks_policy() ==
3343 v8::MicrotasksPolicy::kAuto; 3344 v8::MicrotasksPolicy::kAuto;
3344 3345
3345 if (run_microtasks) RunMicrotasks(); 3346 if (run_microtasks) RunMicrotasks();
3346 3347
3347 if (call_completed_callbacks_.is_empty()) return; 3348 if (call_completed_callbacks_.is_empty()) return;
3348 // Fire callbacks. Increase call depth to prevent recursive callbacks. 3349 // Fire callbacks. Increase call depth to prevent recursive callbacks.
3349 v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(this); 3350 v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(this);
3350 v8::Isolate::SuppressMicrotaskExecutionScope suppress(isolate); 3351 v8::Isolate::SuppressMicrotaskExecutionScope suppress(isolate);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
3495 3496
3496 3497
3497 void Isolate::RunMicrotasks() { 3498 void Isolate::RunMicrotasks() {
3498 // Increase call depth to prevent recursive callbacks. 3499 // Increase call depth to prevent recursive callbacks.
3499 v8::Isolate::SuppressMicrotaskExecutionScope suppress( 3500 v8::Isolate::SuppressMicrotaskExecutionScope suppress(
3500 reinterpret_cast<v8::Isolate*>(this)); 3501 reinterpret_cast<v8::Isolate*>(this));
3501 is_running_microtasks_ = true; 3502 is_running_microtasks_ = true;
3502 RunMicrotasksInternal(); 3503 RunMicrotasksInternal();
3503 is_running_microtasks_ = false; 3504 is_running_microtasks_ = false;
3504 FireMicrotasksCompletedCallback(); 3505 FireMicrotasksCompletedCallback();
3506 int left = 0;
3507 for (int i = 0; i < heap()->weak_refs()->length(); i++) {
3508 JSWeakRef* weak_ref = reinterpret_cast<JSWeakRef*>(
3509 heap()->weak_refs()->get(i));
3510 if (weak_ref->queued()) {
3511 JSFunction* executor = weak_ref->executor();
3512 if (executor == nullptr) continue;
3513 MaybeHandle<Object> maybe_exception;
3514 Handle<Object> argv[] = {
3515 Handle<Object>(weak_ref->holdings(), this),
3516 Handle<Object>(weak_ref, this)
3517 };
3518 int argc = 2;
3519 Execution::TryCall(this,
3520 Handle<Object>(executor, this),
3521 factory()->undefined_value(),
3522 argc, argv,
3523 Execution::MessageHandling::kReport, &maybe_exception);
3524 weak_ref->set_executor(nullptr);
3525 weak_ref->set_holdings(nullptr);
3526 weak_ref->set_held(false);
3527 heap()->weak_refs()->set(left, weak_ref);
3528 } else {
3529 left++;
3530 }
3531 weak_ref->set_held(false);
3532 }
3533 heap()->weak_refs()->Shrink(left);
3505 } 3534 }
3506 3535
3507 3536
3508 void Isolate::RunMicrotasksInternal() { 3537 void Isolate::RunMicrotasksInternal() {
3509 if (!pending_microtask_count()) return; 3538 if (!pending_microtask_count()) return;
3510 TRACE_EVENT0("v8.execute", "RunMicrotasks"); 3539 TRACE_EVENT0("v8.execute", "RunMicrotasks");
3511 TRACE_EVENT_CALL_STATS_SCOPED(this, "v8", "V8.RunMicrotasks"); 3540 TRACE_EVENT_CALL_STATS_SCOPED(this, "v8", "V8.RunMicrotasks");
3512 while (pending_microtask_count() > 0) { 3541 while (pending_microtask_count() > 0) {
3513 HandleScope scope(this); 3542 HandleScope scope(this);
3514 int num_tasks = pending_microtask_count(); 3543 int num_tasks = pending_microtask_count();
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
3595 } 3624 }
3596 } 3625 }
3597 3626
3598 3627
3599 void Isolate::FireMicrotasksCompletedCallback() { 3628 void Isolate::FireMicrotasksCompletedCallback() {
3600 for (int i = 0; i < microtasks_completed_callbacks_.length(); i++) { 3629 for (int i = 0; i < microtasks_completed_callbacks_.length(); i++) {
3601 microtasks_completed_callbacks_.at(i)(reinterpret_cast<v8::Isolate*>(this)); 3630 microtasks_completed_callbacks_.at(i)(reinterpret_cast<v8::Isolate*>(this));
3602 } 3631 }
3603 } 3632 }
3604 3633
3605
3606 void Isolate::SetUseCounterCallback(v8::Isolate::UseCounterCallback callback) { 3634 void Isolate::SetUseCounterCallback(v8::Isolate::UseCounterCallback callback) {
3607 DCHECK(!use_counter_callback_); 3635 DCHECK(!use_counter_callback_);
3608 use_counter_callback_ = callback; 3636 use_counter_callback_ = callback;
3609 } 3637 }
3610 3638
3611 3639
3612 void Isolate::CountUsage(v8::Isolate::UseCounterFeature feature) { 3640 void Isolate::CountUsage(v8::Isolate::UseCounterFeature feature) {
3613 // The counter callback may cause the embedder to call into V8, which is not 3641 // The counter callback may cause the embedder to call into V8, which is not
3614 // generally possible during GC. 3642 // generally possible during GC.
3615 if (heap_.gc_state() == Heap::NOT_IN_GC) { 3643 if (heap_.gc_state() == Heap::NOT_IN_GC) {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
3778 // Then check whether this scope intercepts. 3806 // Then check whether this scope intercepts.
3779 if ((flag & intercept_mask_)) { 3807 if ((flag & intercept_mask_)) {
3780 intercepted_flags_ |= flag; 3808 intercepted_flags_ |= flag;
3781 return true; 3809 return true;
3782 } 3810 }
3783 return false; 3811 return false;
3784 } 3812 }
3785 3813
3786 } // namespace internal 3814 } // namespace internal
3787 } // namespace v8 3815 } // namespace v8
OLDNEW
« no previous file with comments | « src/isolate.h ('k') | src/js/macros.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698