Skip to content
Permalink
Browse files

deps: V8: cherry-pick 2f79d68

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 15, 2019
1 parent cc75ba3 commit 53ea813d5c0029d3ee90230054d5407a6864cb08
@@ -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 #####

@@ -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);

@@ -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.
@@ -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);
}

@@ -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) {
@@ -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);
@@ -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)
@@ -76,7 +77,7 @@ V8Debugger::~V8Debugger() {
m_isolate->RemoveCallCompletedCallback(
&V8Debugger::terminateExecutionCompletedCallback);
m_isolate->RemoveMicrotasksCompletedCallback(
&V8Debugger::terminateExecutionCompletedCallback);
&V8Debugger::terminateExecutionCompletedCallbackIgnoringData);
}

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

@@ -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();
@@ -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,
@@ -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,
@@ -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_; }

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());

0 comments on commit 53ea813

Please sign in to comment.
You can’t perform that action at this time.