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

Unified Diff: src/isolate.cc

Issue 2915793002: [api] Prototype WeakRef implementation
Patch Set: Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/isolate.h ('k') | src/js/macros.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/isolate.cc
diff --git a/src/isolate.cc b/src/isolate.cc
index 2dc01358fa3c28e80dd55e4a3e3dfabc79a8c08c..34e6453ad77ec863dd01e1f048ad143c9767fc22 100644
--- a/src/isolate.cc
+++ b/src/isolate.cc
@@ -3337,7 +3337,8 @@ void Isolate::FireCallCompletedCallback() {
if (!handle_scope_implementer()->CallDepthIsZero()) return;
bool run_microtasks =
- pending_microtask_count() &&
+ (heap()->weak_refs()->length() ||
+ pending_microtask_count()) &&
!handle_scope_implementer()->HasMicrotasksSuppressions() &&
handle_scope_implementer()->microtasks_policy() ==
v8::MicrotasksPolicy::kAuto;
@@ -3502,6 +3503,34 @@ void Isolate::RunMicrotasks() {
RunMicrotasksInternal();
is_running_microtasks_ = false;
FireMicrotasksCompletedCallback();
+ int left = 0;
+ for (int i = 0; i < heap()->weak_refs()->length(); i++) {
+ JSWeakRef* weak_ref = reinterpret_cast<JSWeakRef*>(
+ heap()->weak_refs()->get(i));
+ if (weak_ref->queued()) {
+ JSFunction* executor = weak_ref->executor();
+ if (executor == nullptr) continue;
+ MaybeHandle<Object> maybe_exception;
+ Handle<Object> argv[] = {
+ Handle<Object>(weak_ref->holdings(), this),
+ Handle<Object>(weak_ref, this)
+ };
+ int argc = 2;
+ Execution::TryCall(this,
+ Handle<Object>(executor, this),
+ factory()->undefined_value(),
+ argc, argv,
+ Execution::MessageHandling::kReport, &maybe_exception);
+ weak_ref->set_executor(nullptr);
+ weak_ref->set_holdings(nullptr);
+ weak_ref->set_held(false);
+ heap()->weak_refs()->set(left, weak_ref);
+ } else {
+ left++;
+ }
+ weak_ref->set_held(false);
+ }
+ heap()->weak_refs()->Shrink(left);
}
@@ -3602,7 +3631,6 @@ void Isolate::FireMicrotasksCompletedCallback() {
}
}
-
void Isolate::SetUseCounterCallback(v8::Isolate::UseCounterCallback callback) {
DCHECK(!use_counter_callback_);
use_counter_callback_ = callback;
« 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