How to set the class name of the global object

32 views
Skip to first unread message

tbl...@icloud.com

unread,
Nov 23, 2016, 10:45:55 PM11/23/16
to v8-users
I'm trying to get behavior similar to that of the global object in a Chrome JavaScript context through the V8 API. I've created a FunctionTemplate, called SetClassName on the template, set various properties on its PrototypeTemplate and InstanceTemplate, and then used the InstanceTemplate to create a context. However, when I run Object.prototype.toString.call(this), I get [object Object], instead of what I set the class name to. How does Chrome make it so that Object.prototype.toString.call(this) is [object Window]?

Thanks,
~Theodore

Ben Noordhuis

unread,
Nov 24, 2016, 5:36:34 AM11/24/16
to v8-users
I don't know if Chrome does it in C++ or JS but it executes the moral
equivalent of:

Object.defineProperty(this, Symbol.toStringTag, { configurable:
true, value: 'Window' });

Theodore Dubois

unread,
Nov 24, 2016, 6:53:40 PM11/24/16
to v8-u...@googlegroups.com
Interesting. Out of curiosity, how did this work before Chrome added support for Symbol.toStringTag?

~Theodore
> --
> --
> v8-users mailing list
> v8-u...@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/jCngtwHbGW8/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Toon Verwaest

unread,
Nov 25, 2016, 1:35:31 AM11/25/16
to v8-u...@googlegroups.com

Previously we used the class name.


You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages