Add IsGeneratorFunction and IsGeneratorObject checks to v8::Value.

R=ulan@chromium.org, yangguo@chromium.org, wingo, yangguo

Review URL: https://codereview.chromium.org/608503002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24278 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
aandrey@chromium.org 2014-09-29 10:22:56 +00:00
parent 47880b830f
commit 4b072d16f2
3 changed files with 53 additions and 0 deletions

View File

@ -1560,6 +1560,18 @@ class V8_EXPORT Value : public Data {
*/
bool IsRegExp() const;
/**
* Returns true if this value is a Generator function.
* This is an experimental feature.
*/
bool IsGeneratorFunction() const;
/**
* Returns true if this value is a Generator object (iterator).
* This is an experimental feature.
*/
bool IsGeneratorObject() const;
/**
* Returns true if this value is a Promise.
* This is an experimental feature.

View File

@ -2568,6 +2568,19 @@ bool Value::IsRegExp() const {
}
bool Value::IsGeneratorFunction() 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_generator();
}
bool Value::IsGeneratorObject() const {
return Utils::OpenHandle(this)->IsJSGeneratorObject();
}
Local<String> Value::ToString() const {
i::Handle<i::Object> obj = Utils::OpenHandle(this);
i::Handle<i::Object> str;

View File

@ -1589,6 +1589,34 @@ THREADED_TEST(IsNativeError) {
}
THREADED_TEST(IsGeneratorFunctionOrObject) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
CompileRun("function *gen() { yield 1; }\nfunction func() {}");
v8::Handle<Value> gen = CompileRun("gen");
v8::Handle<Value> genObj = CompileRun("gen()");
v8::Handle<Value> object = CompileRun("{a:42}");
v8::Handle<Value> func = CompileRun("func");
CHECK(gen->IsGeneratorFunction());
CHECK(gen->IsFunction());
CHECK(!gen->IsGeneratorObject());
CHECK(!genObj->IsGeneratorFunction());
CHECK(!genObj->IsFunction());
CHECK(genObj->IsGeneratorObject());
CHECK(!object->IsGeneratorFunction());
CHECK(!object->IsFunction());
CHECK(!object->IsGeneratorObject());
CHECK(!func->IsGeneratorFunction());
CHECK(func->IsFunction());
CHECK(!func->IsGeneratorObject());
}
THREADED_TEST(ArgumentsObject) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());