Questions when adding global object

55 views
Skip to first unread message

zwc

unread,
Jun 25, 2018, 8:51:59 PM6/25/18
to v8-users
Hello, 
we are working on upgrading v8 from 5.3 to 6.7-lkgr. 
But I recently found a strange behavior for one global object with name "console".
In the old version, we have a global object "console" for logging info. 
But when upgraded to 6.7, the "console"'s callbacks functions won't get called. I tested if I change the name from "console" to something else, it will work as usual. 
I am feeling like that "console"seems to become a reserved word for the newer version?
May I know if this is expected? And if true, is there any workaround to overwrite this behavior? we would want to keep our old "console" name.

Thank you so much!

Jakob Kummerow

unread,
Jun 25, 2018, 9:14:42 PM6/25/18
to v8-users
V8 now provides its own "console" object, with the usual methods installed on it. Does it not serve your needs?

You can override it by providing a ConsoleDelegate via the debug interface. The d8 shell (src/d8.cc) provides an example.

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
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.
For more options, visit https://groups.google.com/d/optout.

zcw

unread,
Jun 25, 2018, 11:29:57 PM6/25/18
to v8-users
Thank you so much!
I wanted to save the log to a specific file. I tried using the provided console but couldn't find where it stored the log message.
And could the ConsoleDelegate work for the release build?

Jakob Kummerow

unread,
Jun 26, 2018, 1:27:58 AM6/26/18
to v8-users
On Mon, Jun 25, 2018 at 8:30 PM zcw <wanzhic...@gmail.com> wrote:
Thank you so much!
I wanted to save the log to a specific file. I tried using the provided console but couldn't find where it stored the log message.

On a closer look at the code, it seems that you *have to* provide a ConsoleDelegate if you want console.log to do anything.
 
And could the ConsoleDelegate work for the release build?

Yes, of course.

zcw

unread,
Jun 27, 2018, 2:03:35 PM6/27/18
to v8-users
Hello Jakob,

May I get some more directions for using the consoleDelegate?
From d8 files. I saw that we could make a console class and use set consoleDelegate to set console functions.
But in our old way, we create a global template for "console" and using setAccessor to append functions to it. 
Since I don't want to introduce too much code change. Is there a way to keep the old usage (create as global template)? or is using consoleDelegate the only way to specify console functions?

Again thank you so much!

zcw

unread,
Jun 27, 2018, 2:37:46 PM6/27/18
to v8-users
And actually is the consoleDelegate exposed in the .h files in the include directory? I saw it is defined in interface-types.h but if I were to include that, it will lead to a chain of includes from /src..
Am I misunderstanding something? 

Thanks!

Jakob Kummerow

unread,
Jun 27, 2018, 2:55:02 PM6/27/18
to v8-users
Sorry, I only know what I see in the code. I'm not sure if/how ConsoleDelegate is supposed to be used via the regular API.

If you want to hack it, you can remove the entire { // -- C o n s o l e block in src/bootstrapper.cc, that'll prevent the built-in console from overriding the global template you're providing. Of course this approach doesn't apply if your setup doesn't allow you to modify V8's source.

Maybe it's easiest to just keep the default console.log implementation, letting it print to stdout and redirecting the output of the process to a file?

zcw

unread,
Jun 27, 2018, 8:45:53 PM6/27/18
to v8-users
Thank you!
We decided to temporarily remove the console block.
Really appreciate your help!
Reply all
Reply to author
Forward
0 new messages