Generator test.

32 views
Skip to first unread message

Jane Chen

unread,
Aug 28, 2015, 1:05:43 AM8/28/15
to v8-users
Embedding v8 3.24.

Is there any API to test whether a v8 object is a generator?  I tried GetConstructorName(), or GetConstructor(), then GetName(), neither gives me "GeneratorFunctionPropotype" which I got in JavaScript using g().constructor.name.  The best I seem to get is ObjectProtoToString() which returns [object Generator].

Any advice is really appreciated!

Andy Wingo

unread,
Aug 28, 2015, 5:17:29 AM8/28/15
to Jane Chen, v8-users
On Fri 28 Aug 2015 07:05, Jane Chen <jxch...@gmail.com> writes:

> Embedding v8 3.24.
>
> Is there any API to test whether a v8 object is a generator? I tried
> GetConstructorName(), or GetConstructor(), then GetName(), neither gives
> me "GeneratorFunctionPropotype" which I got in JavaScript using g
> ().constructor.name. The best I seem to get is ObjectProtoToString()
> which returns [object Generator].
>
> Any advice is really appreciated!

var GeneratorFunction = Object.getPrototypeOf(function*(){}).constructor;

function isGeneratorFunction(f) {
return f instanceof GeneratorFunction;
}

Cheers,

Andy

Jane Chen

unread,
Aug 28, 2015, 11:18:03 AM8/28/15
to v8-users, jxch...@gmail.com
Is there a v8 c++ API to achieve this?

Ben Noordhuis

unread,
Aug 28, 2015, 5:36:57 PM8/28/15
to v8-u...@googlegroups.com, jxch...@gmail.com
On Fri, Aug 28, 2015 at 5:18 PM, Jane Chen <jxch...@gmail.com> wrote:
> Is there a v8 c++ API to achieve this?

There is, v8::Value::IsGeneratorFunction(), but it's not available in
V8 3.24. It was added in 4.2.

Jane Chen

unread,
Sep 3, 2015, 2:47:22 PM9/3/15
to v8-users, jxch...@gmail.com
Thanks Ben.  I'm working on upgrading v8 to 4.x next.
Reply all
Reply to author
Forward
0 new messages