Add method on Value::IsAsyncFunction to detect async functions

DevTools wants to be able to detect async functions in order to print
their synopsis better in stack traces and tooltips. This patch provides a
simple method to do the check.

BUG=v8:4483

Review-Url: https://codereview.chromium.org/2365833002
Cr-Commit-Position: refs/heads/master@{#39687}
This commit is contained in:
littledan 2016-09-23 11:31:15 -07:00 committed by Commit bot
parent b171109334
commit 713e247e7d
3 changed files with 31 additions and 0 deletions

View File

@ -2013,6 +2013,11 @@ class V8_EXPORT Value : public Data {
*/
bool IsRegExp() const;
/**
* Returns true if this value is an async function.
*/
bool IsAsyncFunction() const;
/**
* Returns true if this value is a Generator function.
* This is an experimental feature.

View File

@ -3384,6 +3384,12 @@ bool Value::IsRegExp() const {
return obj->IsJSRegExp();
}
bool Value::IsAsyncFunction() const {
i::Handle<i::Object> obj = Utils::OpenHandle(this);
if (!obj->IsJSFunction()) return false;
i::Handle<i::JSFunction> func = i::Handle<i::JSFunction>::cast(obj);
return func->shared()->is_async();
}
bool Value::IsGeneratorFunction() const {
i::Handle<i::Object> obj = Utils::OpenHandle(this);

View File

@ -1581,6 +1581,26 @@ THREADED_TEST(IsGeneratorFunctionOrObject) {
CHECK(!func->IsGeneratorObject());
}
THREADED_TEST(IsAsyncFunction) {
i::FLAG_harmony_async_await = true;
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope scope(isolate);
CompileRun("async function foo() {}");
v8::Local<Value> foo = CompileRun("foo");
CHECK(foo->IsAsyncFunction());
CHECK(foo->IsFunction());
CHECK(!foo->IsGeneratorFunction());
CHECK(!foo->IsGeneratorObject());
CompileRun("function bar() {}");
v8::Local<Value> bar = CompileRun("bar");
CHECK(!bar->IsAsyncFunction());
CHECK(bar->IsFunction());
}
THREADED_TEST(ArgumentsObject) {
LocalContext env;