Commit a691632c authored by Simon Zünd's avatar Simon Zünd Committed by V8 LUCI CQ

[inspector] Rename console.scheduleTask to console.createTask

After some solid bike shedding, we decided to rename one part of the
API.

R=jarin@chromium.org

Bug: chromium:1334585
Change-Id: Ie967f9f4947b2c328433e4c4a9d748ad15ae7175
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3788095Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81987}
parent 6a2a9d28
...@@ -488,7 +488,7 @@ void V8Console::memorySetterCallback( ...@@ -488,7 +488,7 @@ void V8Console::memorySetterCallback(
// setter just ignores the passed value. http://crbug.com/468611 // setter just ignores the passed value. http://crbug.com/468611
} }
void V8Console::scheduleTask(const v8::FunctionCallbackInfo<v8::Value>& info) { void V8Console::createTask(const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate(); v8::Isolate* isolate = info.GetIsolate();
if (info.Length() < 1 || !info[0]->IsString() || if (info.Length() < 1 || !info[0]->IsString() ||
!info[0].As<v8::String>()->Length()) { !info[0].As<v8::String>()->Length()) {
...@@ -824,12 +824,11 @@ void V8Console::installAsyncStackTaggingAPI(v8::Local<v8::Context> context, ...@@ -824,12 +824,11 @@ void V8Console::installAsyncStackTaggingAPI(v8::Local<v8::Context> context,
v8::MicrotasksScope::kDoNotRunMicrotasks); v8::MicrotasksScope::kDoNotRunMicrotasks);
console console
->Set( ->Set(context, toV8StringInternalized(isolate, "createTask"),
context, toV8StringInternalized(isolate, "scheduleTask"), v8::Function::New(context, &V8Console::call<&V8Console::createTask>,
v8::Function::New(context, &V8Console::call<&V8Console::scheduleTask>, data, 0, v8::ConstructorBehavior::kThrow,
data, 0, v8::ConstructorBehavior::kThrow, v8::SideEffectType::kHasSideEffect)
v8::SideEffectType::kHasSideEffect) .ToLocalChecked())
.ToLocalChecked())
.Check(); .Check();
} }
......
...@@ -141,7 +141,7 @@ class V8Console : public v8::debug::ConsoleDelegate { ...@@ -141,7 +141,7 @@ class V8Console : public v8::debug::ConsoleDelegate {
void memoryGetterCallback(const v8::FunctionCallbackInfo<v8::Value>&); void memoryGetterCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void memorySetterCallback(const v8::FunctionCallbackInfo<v8::Value>&); void memorySetterCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void scheduleTask(const v8::FunctionCallbackInfo<v8::Value>&); void createTask(const v8::FunctionCallbackInfo<v8::Value>&);
void runTask(const v8::FunctionCallbackInfo<v8::Value>&); void runTask(const v8::FunctionCallbackInfo<v8::Value>&);
// CommandLineAPI // CommandLineAPI
...@@ -203,7 +203,7 @@ class V8Console : public v8::debug::ConsoleDelegate { ...@@ -203,7 +203,7 @@ class V8Console : public v8::debug::ConsoleDelegate {
std::map<void*, std::unique_ptr<TaskInfo>> m_tasks; std::map<void*, std::unique_ptr<TaskInfo>> m_tasks;
// We use a private symbol to stash the `TaskInfo` as an v8::External on the // We use a private symbol to stash the `TaskInfo` as an v8::External on the
// JS task objects created by `console.scheduleTask`. // JS task objects created by `console.createTask`.
v8::Global<v8::Private> m_taskInfoKey; v8::Global<v8::Private> m_taskInfoKey;
// We cache the task template for the async stack tagging API for faster // We cache the task template for the async stack tagging API for faster
...@@ -213,7 +213,7 @@ class V8Console : public v8::debug::ConsoleDelegate { ...@@ -213,7 +213,7 @@ class V8Console : public v8::debug::ConsoleDelegate {
}; };
/** /**
* Each JS task object created via `console.scheduleTask` has a corresponding * Each JS task object created via `console.createTask` has a corresponding
* `TaskInfo` object on the C++ side (in a 1:1 relationship). * `TaskInfo` object on the C++ side (in a 1:1 relationship).
* *
* The `TaskInfo` holds on weakly to the JS task object. * The `TaskInfo` holds on weakly to the JS task object.
......
...@@ -274,7 +274,7 @@ TEST(ApiCreatedTasksAreCleanedUp) { ...@@ -274,7 +274,7 @@ TEST(ApiCreatedTasksAreCleanedUp) {
{ {
v8::HandleScope handle_scope(isolate); v8::HandleScope handle_scope(isolate);
v8::MaybeLocal<v8::Value> result = CompileRun(env.local(), R"( v8::MaybeLocal<v8::Value> result = CompileRun(env.local(), R"(
globalThis['task'] = console.scheduleTask('Task'); globalThis['task'] = console.createTask('Task');
)"); )");
CHECK(!result.IsEmpty()); CHECK(!result.IsEmpty());
......
...@@ -13,26 +13,26 @@ session.setupScriptMap(); ...@@ -13,26 +13,26 @@ session.setupScriptMap();
const testCases = [ const testCases = [
function simpleTaskLogsCorrectAsyncTrace() { function simpleTaskLogsCorrectAsyncTrace() {
function foo() { return console.scheduleTask('Task'); } function foo() { return console.createTask('Task'); }
const task = foo(); const task = foo();
task.run(function runner() { task.run(function runner() {
console.trace('Inside run'); console.trace('Inside run');
}); });
}, },
function nestedTasksLogCorrectAsyncTrace() { function nestedTasksLogCorrectAsyncTrace() {
const outerTask = console.scheduleTask('Outer Task'); const outerTask = console.createTask('Outer Task');
outerTask.run(function runOuter() { outerTask.run(function runOuter() {
const innerTask = console.scheduleTask('Inner Task'); const innerTask = console.createTask('Inner Task');
innerTask.run(function runInner() { innerTask.run(function runInner() {
console.trace('Inside runInner'); console.trace('Inside runInner');
}); });
}); });
}, },
async function setTimeoutWorksCorrectly() { async function setTimeoutWorksCorrectly() {
const outerTask = console.scheduleTask('Outer Task'); const outerTask = console.createTask('Outer Task');
await outerTask.run(async function runOuter() { await outerTask.run(async function runOuter() {
return new Promise(r => setTimeout(() => { return new Promise(r => setTimeout(() => {
const innerTask = console.scheduleTask('Inner Task'); const innerTask = console.createTask('Inner Task');
innerTask.run(function runInner() { innerTask.run(function runInner() {
console.trace('Inside runInner'); console.trace('Inside runInner');
r(); r();
...@@ -41,35 +41,35 @@ const testCases = [ ...@@ -41,35 +41,35 @@ const testCases = [
}); });
}, },
function runForwardsTheReturnValue() { function runForwardsTheReturnValue() {
const task = console.scheduleTask('Task'); const task = console.createTask('Task');
const result = task.run(() => 42); const result = task.run(() => 42);
console.log(result); console.log(result);
}, },
async function runWorksWithAsyncPayloads() { async function runWorksWithAsyncPayloads() {
const task = console.scheduleTask('Task'); const task = console.createTask('Task');
const result = await task.run(async () => 42); const result = await task.run(async () => 42);
console.log(result); console.log(result);
}, },
function runWorksWithGenerators() { function runWorksWithGenerators() {
const task = console.scheduleTask('Task'); const task = console.createTask('Task');
const iter = task.run(function* () { yield 42; }); const iter = task.run(function* () { yield 42; });
console.log(iter.next().value); console.log(iter.next().value);
}, },
function runCanBeCalledMultipleTimes() { function runCanBeCalledMultipleTimes() {
const task = console.scheduleTask('Task'); const task = console.createTask('Task');
task.run(() => console.log('First run')); task.run(() => console.log('First run'));
task.run(() => console.log('Second run')); task.run(() => console.log('Second run'));
}, },
function runForwardsExceptions() { function runForwardsExceptions() {
const task = console.scheduleTask('Task'); const task = console.createTask('Task');
task.run(() => { task.run(() => {
throw new Error('Thrown from task.run'); throw new Error('Thrown from task.run');
}); });
}, },
function recursivelyCalledRunDoesntCrash() { function recursivelyCalledRunDoesntCrash() {
const outerTask = console.scheduleTask('Outer Task'); const outerTask = console.createTask('Outer Task');
outerTask.run(function runOuter() { outerTask.run(function runOuter() {
const innerTask = console.scheduleTask('Inner Task'); const innerTask = console.createTask('Inner Task');
innerTask.run(function runInner() { innerTask.run(function runInner() {
outerTask.run(function nestedRunOuter() { outerTask.run(function nestedRunOuter() {
console.trace('Inside nestedRunOuter'); console.trace('Inside nestedRunOuter');
...@@ -78,25 +78,25 @@ const testCases = [ ...@@ -78,25 +78,25 @@ const testCases = [
}); });
}, },
function scheduleThrowsAnErrorWhenCalledWithoutAnArgument() { function scheduleThrowsAnErrorWhenCalledWithoutAnArgument() {
console.scheduleTask(); console.createTask();
}, },
function scheduleThrowsAnErrorWhenCalledWithAnEmptyString() { function scheduleThrowsAnErrorWhenCalledWithAnEmptyString() {
console.scheduleTask(''); console.createTask('');
}, },
function runThrowsAnErrorWhenCalledWithoutAnArgument() { function runThrowsAnErrorWhenCalledWithoutAnArgument() {
const task = console.scheduleTask('Task'); const task = console.createTask('Task');
task.run(); task.run();
}, },
function runThrowsAnErrorWhenCalledWithNonFunction() { function runThrowsAnErrorWhenCalledWithNonFunction() {
const task = console.scheduleTask('Task'); const task = console.createTask('Task');
task.run(42); task.run(42);
}, },
function runThrowsAnErrorWhenCalledWithNullReceiver() { function runThrowsAnErrorWhenCalledWithNullReceiver() {
const task = console.scheduleTask('Task'); const task = console.createTask('Task');
task.run.call(undefined, () => { }); task.run.call(undefined, () => { });
}, },
function runThrowsAnErrorWhenCalledWithIllegalReceiver() { function runThrowsAnErrorWhenCalledWithIllegalReceiver() {
const task = console.scheduleTask('Task'); const task = console.createTask('Task');
task.run.call({}, () => { }); // The private symbol is missing. task.run.call({}, () => { }); // The private symbol is missing.
}, },
]; ];
......
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