[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/+/3788095
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81987}
This commit is contained in:
Simon Zünd 2022-07-27 07:04:32 +02:00 committed by V8 LUCI CQ
parent 6a2a9d28c6
commit a691632c81
4 changed files with 28 additions and 29 deletions

View File

@ -488,7 +488,7 @@ void V8Console::memorySetterCallback(
// 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();
if (info.Length() < 1 || !info[0]->IsString() ||
!info[0].As<v8::String>()->Length()) {
@ -824,12 +824,11 @@ void V8Console::installAsyncStackTaggingAPI(v8::Local<v8::Context> context,
v8::MicrotasksScope::kDoNotRunMicrotasks);
console
->Set(
context, toV8StringInternalized(isolate, "scheduleTask"),
v8::Function::New(context, &V8Console::call<&V8Console::scheduleTask>,
data, 0, v8::ConstructorBehavior::kThrow,
v8::SideEffectType::kHasSideEffect)
.ToLocalChecked())
->Set(context, toV8StringInternalized(isolate, "createTask"),
v8::Function::New(context, &V8Console::call<&V8Console::createTask>,
data, 0, v8::ConstructorBehavior::kThrow,
v8::SideEffectType::kHasSideEffect)
.ToLocalChecked())
.Check();
}

View File

@ -141,7 +141,7 @@ class V8Console : public v8::debug::ConsoleDelegate {
void memoryGetterCallback(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>&);
// CommandLineAPI
@ -203,7 +203,7 @@ class V8Console : public v8::debug::ConsoleDelegate {
std::map<void*, std::unique_ptr<TaskInfo>> m_tasks;
// 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;
// We cache the task template for the async stack tagging API for faster
@ -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).
*
* The `TaskInfo` holds on weakly to the JS task object.

View File

@ -274,7 +274,7 @@ TEST(ApiCreatedTasksAreCleanedUp) {
{
v8::HandleScope handle_scope(isolate);
v8::MaybeLocal<v8::Value> result = CompileRun(env.local(), R"(
globalThis['task'] = console.scheduleTask('Task');
globalThis['task'] = console.createTask('Task');
)");
CHECK(!result.IsEmpty());

View File

@ -13,26 +13,26 @@ session.setupScriptMap();
const testCases = [
function simpleTaskLogsCorrectAsyncTrace() {
function foo() { return console.scheduleTask('Task'); }
function foo() { return console.createTask('Task'); }
const task = foo();
task.run(function runner() {
console.trace('Inside run');
});
},
function nestedTasksLogCorrectAsyncTrace() {
const outerTask = console.scheduleTask('Outer Task');
const outerTask = console.createTask('Outer Task');
outerTask.run(function runOuter() {
const innerTask = console.scheduleTask('Inner Task');
const innerTask = console.createTask('Inner Task');
innerTask.run(function runInner() {
console.trace('Inside runInner');
});
});
},
async function setTimeoutWorksCorrectly() {
const outerTask = console.scheduleTask('Outer Task');
const outerTask = console.createTask('Outer Task');
await outerTask.run(async function runOuter() {
return new Promise(r => setTimeout(() => {
const innerTask = console.scheduleTask('Inner Task');
const innerTask = console.createTask('Inner Task');
innerTask.run(function runInner() {
console.trace('Inside runInner');
r();
@ -41,35 +41,35 @@ const testCases = [
});
},
function runForwardsTheReturnValue() {
const task = console.scheduleTask('Task');
const task = console.createTask('Task');
const result = task.run(() => 42);
console.log(result);
},
async function runWorksWithAsyncPayloads() {
const task = console.scheduleTask('Task');
const task = console.createTask('Task');
const result = await task.run(async () => 42);
console.log(result);
},
function runWorksWithGenerators() {
const task = console.scheduleTask('Task');
const task = console.createTask('Task');
const iter = task.run(function* () { yield 42; });
console.log(iter.next().value);
},
function runCanBeCalledMultipleTimes() {
const task = console.scheduleTask('Task');
const task = console.createTask('Task');
task.run(() => console.log('First run'));
task.run(() => console.log('Second run'));
},
function runForwardsExceptions() {
const task = console.scheduleTask('Task');
const task = console.createTask('Task');
task.run(() => {
throw new Error('Thrown from task.run');
});
},
function recursivelyCalledRunDoesntCrash() {
const outerTask = console.scheduleTask('Outer Task');
const outerTask = console.createTask('Outer Task');
outerTask.run(function runOuter() {
const innerTask = console.scheduleTask('Inner Task');
const innerTask = console.createTask('Inner Task');
innerTask.run(function runInner() {
outerTask.run(function nestedRunOuter() {
console.trace('Inside nestedRunOuter');
@ -78,25 +78,25 @@ const testCases = [
});
},
function scheduleThrowsAnErrorWhenCalledWithoutAnArgument() {
console.scheduleTask();
console.createTask();
},
function scheduleThrowsAnErrorWhenCalledWithAnEmptyString() {
console.scheduleTask('');
console.createTask('');
},
function runThrowsAnErrorWhenCalledWithoutAnArgument() {
const task = console.scheduleTask('Task');
const task = console.createTask('Task');
task.run();
},
function runThrowsAnErrorWhenCalledWithNonFunction() {
const task = console.scheduleTask('Task');
const task = console.createTask('Task');
task.run(42);
},
function runThrowsAnErrorWhenCalledWithNullReceiver() {
const task = console.scheduleTask('Task');
const task = console.createTask('Task');
task.run.call(undefined, () => { });
},
function runThrowsAnErrorWhenCalledWithIllegalReceiver() {
const task = console.scheduleTask('Task');
const task = console.createTask('Task');
task.run.call({}, () => { }); // The private symbol is missing.
},
];