Skip to content

Commit

Permalink
deps: V8: cherry-pick 2f79d68
Browse files Browse the repository at this point in the history
Original commit message:

    Deprecate MicrotasksCompletedCallback in favor to use *WithData version

    This adds overloads of v8::Isolate::{Add,Remove}MicrotaskCompletedCallback,
    that use MicrotasksCompletedCallbackWithData, and marks the original one
    as V8_DEPRECATE_SOON for transition.

    Bug: v8:8124
    Change-Id: I124c3108545e1a2b29cd95620f36901431663c65
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1493766
    Reviewed-by: Yang Guo <yangguo@chromium.org>
    Commit-Queue: Taiju Tsuiki <tzik@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#60045}

Refs: v8/v8@2f79d68

PR-URL: #26685
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
  • Loading branch information
addaleax authored and refack committed Mar 28, 2019
1 parent cc75ba3 commit 53ea813
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 13 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.0',
'v8_embedder_string': '-node.1',

##### V8 defaults for Node.js #####

Expand Down
15 changes: 12 additions & 3 deletions deps/v8/include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -6744,7 +6744,8 @@ class PromiseRejectMessage {
typedef void (*PromiseRejectCallback)(PromiseRejectMessage message);

// --- Microtasks Callbacks ---
typedef void (*MicrotasksCompletedCallback)(Isolate*);
V8_DEPRECATE_SOON("Use *WithData version.",
typedef void (*MicrotasksCompletedCallback)(Isolate*));
typedef void (*MicrotasksCompletedCallbackWithData)(Isolate*, void*);
typedef void (*MicrotaskCallback)(void* data);

Expand Down Expand Up @@ -8231,12 +8232,20 @@ class V8_EXPORT Isolate {
* Executing scripts inside the callback will not re-trigger microtasks and
* the callback.
*/
void AddMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
V8_DEPRECATE_SOON("Use *WithData version.",
void AddMicrotasksCompletedCallback(
MicrotasksCompletedCallback callback));
void AddMicrotasksCompletedCallback(
MicrotasksCompletedCallbackWithData callback, void* data = nullptr);

/**
* Removes callback that was installed by AddMicrotasksCompletedCallback.
*/
void RemoveMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
V8_DEPRECATE_SOON("Use *WithData version.",
void RemoveMicrotasksCompletedCallback(
MicrotasksCompletedCallback callback));
void RemoveMicrotasksCompletedCallback(
MicrotasksCompletedCallbackWithData callback, void* data = nullptr);

/**
* Sets a callback for counting the number of times a feature of V8 is used.
Expand Down
15 changes: 14 additions & 1 deletion deps/v8/src/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8574,7 +8574,7 @@ MicrotasksPolicy Isolate::GetMicrotasksPolicy() const {
namespace {

void MicrotasksCompletedCallbackAdapter(v8::Isolate* isolate, void* data) {
auto callback = reinterpret_cast<MicrotasksCompletedCallback>(data);
auto callback = reinterpret_cast<void (*)(v8::Isolate*)>(data);
callback(isolate);
}

Expand All @@ -8588,6 +8588,13 @@ void Isolate::AddMicrotasksCompletedCallback(
&MicrotasksCompletedCallbackAdapter, reinterpret_cast<void*>(callback));
}

void Isolate::AddMicrotasksCompletedCallback(
MicrotasksCompletedCallbackWithData callback, void* data) {
DCHECK(callback);
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
isolate->default_microtask_queue()->AddMicrotasksCompletedCallback(callback,
data);
}

void Isolate::RemoveMicrotasksCompletedCallback(
MicrotasksCompletedCallback callback) {
Expand All @@ -8596,6 +8603,12 @@ void Isolate::RemoveMicrotasksCompletedCallback(
&MicrotasksCompletedCallbackAdapter, reinterpret_cast<void*>(callback));
}

void Isolate::RemoveMicrotasksCompletedCallback(
MicrotasksCompletedCallbackWithData callback, void* data) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
isolate->default_microtask_queue()->RemoveMicrotasksCompletedCallback(
callback, data);
}

void Isolate::SetUseCounterCallback(UseCounterCallback callback) {
reinterpret_cast<i::Isolate*>(this)->SetUseCounterCallback(callback);
Expand Down
12 changes: 9 additions & 3 deletions deps/v8/src/inspector/v8-debugger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class MatchPrototypePredicate : public v8::debug::QueryObjectPredicate {
v8::Local<v8::Context> m_context;
v8::Local<v8::Value> m_prototype;
};

} // namespace

V8Debugger::V8Debugger(v8::Isolate* isolate, V8InspectorImpl* inspector)
Expand All @@ -76,7 +77,7 @@ V8Debugger::~V8Debugger() {
m_isolate->RemoveCallCompletedCallback(
&V8Debugger::terminateExecutionCompletedCallback);
m_isolate->RemoveMicrotasksCompletedCallback(
&V8Debugger::terminateExecutionCompletedCallback);
&V8Debugger::terminateExecutionCompletedCallbackIgnoringData);
}

void V8Debugger::enable() {
Expand Down Expand Up @@ -302,7 +303,7 @@ void V8Debugger::terminateExecution(
m_isolate->AddCallCompletedCallback(
&V8Debugger::terminateExecutionCompletedCallback);
m_isolate->AddMicrotasksCompletedCallback(
&V8Debugger::terminateExecutionCompletedCallback);
&V8Debugger::terminateExecutionCompletedCallbackIgnoringData);
m_isolate->TerminateExecution();
}

Expand All @@ -311,7 +312,7 @@ void V8Debugger::reportTermination() {
m_isolate->RemoveCallCompletedCallback(
&V8Debugger::terminateExecutionCompletedCallback);
m_isolate->RemoveMicrotasksCompletedCallback(
&V8Debugger::terminateExecutionCompletedCallback);
&V8Debugger::terminateExecutionCompletedCallbackIgnoringData);
m_isolate->CancelTerminateExecution();
m_terminateExecutionCallback->sendSuccess();
m_terminateExecutionCallback.reset();
Expand All @@ -324,6 +325,11 @@ void V8Debugger::terminateExecutionCompletedCallback(v8::Isolate* isolate) {
debugger->reportTermination();
}

void V8Debugger::terminateExecutionCompletedCallbackIgnoringData(
v8::Isolate* isolate, void*) {
terminateExecutionCompletedCallback(isolate);
}

Response V8Debugger::continueToLocation(
int targetContextGroupId, V8DebuggerScript* script,
std::unique_ptr<protocol::Debugger::Location> location,
Expand Down
2 changes: 2 additions & 0 deletions deps/v8/src/inspector/v8-debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ class V8Debugger : public v8::debug::DebugDelegate,
static size_t nearHeapLimitCallback(void* data, size_t current_heap_limit,
size_t initial_heap_limit);
static void terminateExecutionCompletedCallback(v8::Isolate* isolate);
static void terminateExecutionCompletedCallbackIgnoringData(
v8::Isolate* isolate, void*);
void handleProgramBreak(
v8::Local<v8::Context> pausedContext, v8::Local<v8::Value> exception,
const std::vector<v8::debug::BreakpointId>& hitBreakpoints,
Expand Down
2 changes: 0 additions & 2 deletions deps/v8/src/microtask-queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ class V8_EXPORT_PRIVATE MicrotaskQueue final : public v8::MicrotaskQueue {
}
v8::MicrotasksPolicy microtasks_policy() const { return microtasks_policy_; }

void AddMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
void RemoveMicrotasksCompletedCallback(MicrotasksCompletedCallback callback);
void FireMicrotasksCompletedCallback(Isolate* isolate) const;

intptr_t capacity() const { return capacity_; }
Expand Down
4 changes: 1 addition & 3 deletions deps/v8/test/cctest/test-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21680,12 +21680,10 @@ TEST(RunMicrotasksIgnoresThrownExceptionsFromApi) {

uint8_t microtasks_completed_callback_count = 0;


static void MicrotasksCompletedCallback(v8::Isolate* isolate) {
static void MicrotasksCompletedCallback(v8::Isolate* isolate, void*) {
++microtasks_completed_callback_count;
}


TEST(SetAutorunMicrotasks) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
Expand Down

0 comments on commit 53ea813

Please sign in to comment.