Commit 1920e6c9 authored by Shu-yu Guo's avatar Shu-yu Guo Committed by Commit Bot

[platform] Require the foreground taskrunner to support non-nestable tasks for weak refs

Bug: v8:8179
Change-Id: I2e7024412216decc06e814e88eecd5b4eb5ae8cb
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2013696Reviewed-by: 's avatarBen Smith <binji@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65966}
parent 1dc3ac96
...@@ -326,7 +326,8 @@ class Platform { ...@@ -326,7 +326,8 @@ class Platform {
/** /**
* Returns a TaskRunner which can be used to post a task on the foreground. * Returns a TaskRunner which can be used to post a task on the foreground.
* This function should only be called from a foreground thread. * The TaskRunner's NonNestableTasksEnabled() must be true. This function
* should only be called from a foreground thread.
*/ */
virtual std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner( virtual std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner(
Isolate* isolate) = 0; Isolate* isolate) = 0;
......
...@@ -8269,6 +8269,14 @@ void Isolate::Initialize(Isolate* isolate, ...@@ -8269,6 +8269,14 @@ void Isolate::Initialize(Isolate* isolate,
} }
i_isolate->set_only_terminate_in_safe_scope( i_isolate->set_only_terminate_in_safe_scope(
params.only_terminate_in_safe_scope); params.only_terminate_in_safe_scope);
if (!i::V8::GetCurrentPlatform()
->GetForegroundTaskRunner(isolate)
->NonNestableTasksEnabled()) {
FATAL(
"The current platform's foreground task runner does not have "
"non-nestable tasks enabled. The embedder must provide one.");
}
} }
Isolate* Isolate::New(const Isolate::CreateParams& params) { Isolate* Isolate::New(const Isolate::CreateParams& params) {
......
...@@ -175,6 +175,11 @@ class DelayedTasksPlatform : public Platform { ...@@ -175,6 +175,11 @@ class DelayedTasksPlatform : public Platform {
task_runner_->PostTask(platform_->MakeDelayedTask(std::move(task))); task_runner_->PostTask(platform_->MakeDelayedTask(std::move(task)));
} }
void PostNonNestableTask(std::unique_ptr<Task> task) final {
task_runner_->PostNonNestableTask(
platform_->MakeDelayedTask(std::move(task)));
}
void PostDelayedTask(std::unique_ptr<Task> task, void PostDelayedTask(std::unique_ptr<Task> task,
double delay_in_seconds) final { double delay_in_seconds) final {
task_runner_->PostDelayedTask(platform_->MakeDelayedTask(std::move(task)), task_runner_->PostDelayedTask(platform_->MakeDelayedTask(std::move(task)),
...@@ -188,6 +193,10 @@ class DelayedTasksPlatform : public Platform { ...@@ -188,6 +193,10 @@ class DelayedTasksPlatform : public Platform {
bool IdleTasksEnabled() final { return task_runner_->IdleTasksEnabled(); } bool IdleTasksEnabled() final { return task_runner_->IdleTasksEnabled(); }
bool NonNestableTasksEnabled() const final {
return task_runner_->NonNestableTasksEnabled();
}
private: private:
friend class DelayedTaskRunnerDeleter; friend class DelayedTaskRunnerDeleter;
std::shared_ptr<TaskRunner> task_runner_; std::shared_ptr<TaskRunner> task_runner_;
......
...@@ -272,6 +272,11 @@ class MockPlatform : public v8::Platform { ...@@ -272,6 +272,11 @@ class MockPlatform : public v8::Platform {
platform_->foreground_tasks_.push_back(std::move(task)); platform_->foreground_tasks_.push_back(std::move(task));
} }
void PostNonNestableTask(std::unique_ptr<v8::Task> task) override {
// The mock platform does not nest tasks.
PostTask(std::move(task));
}
void PostDelayedTask(std::unique_ptr<Task> task, void PostDelayedTask(std::unique_ptr<Task> task,
double delay_in_seconds) override { double delay_in_seconds) override {
UNREACHABLE(); UNREACHABLE();
...@@ -286,6 +291,8 @@ class MockPlatform : public v8::Platform { ...@@ -286,6 +291,8 @@ class MockPlatform : public v8::Platform {
bool IdleTasksEnabled() override { return true; } bool IdleTasksEnabled() override { return true; }
bool NonNestableTasksEnabled() const override { return false; }
private: private:
MockPlatform* platform_; MockPlatform* platform_;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment