Commit 4b072d16 authored by aandrey@chromium.org's avatar aandrey@chromium.org

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
parent 47880b83
......@@ -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.
......
......@@ -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;
......
......@@ -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());
......
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