v8go icon indicating copy to clipboard operation
v8go copied to clipboard

Not providing console does not fail

Open mitar opened this issue 4 years ago • 6 comments

It looks like console is defined by default, just it does not work - it does not print anything to the terminal. I have a script which uses console and running it did not raise any error (while if I try to access some other symbol it fails).

So I suggest the default console is removed, or a working implementation is provided instead.

mitar avatar May 07 '21 06:05 mitar

console is a "special" object in V8. You can create callback functions for the API, but we don't have these exposed in v8go yet. What we do have is a way to set the console global object and use a FunctionTemplate to do what you want when console.log etc is called.

The aim of this project is to provide a rich binding to V8, not a general purpose JavaScript engine; If you are looking for some of the common polyfils I would take a look at a project like: https://github.com/kuoruan/v8go-polyfills

rogchap avatar Jun 05 '21 04:06 rogchap

This is now what this issue is about. I am saying that without setting console, a script using console should fail. But it does not. So you are setting some form of console by default, which I think you should not be doing?

mitar avatar Jun 05 '21 04:06 mitar

This project does not set anything for console, this is done be V8 itself and is the default behaviour

rogchap avatar Jun 05 '21 05:06 rogchap

I see. But then this package should provide some way to use ConsoleDelegate properly?

  • https://source.chromium.org/chromium/chromium/src/+/master:v8/src/d8/d8-console.h;l=14
  • https://stackoverflow.com/questions/57531024/v8-console-log-does-not-print

I think it still confusing and this package should probably set something which throws an error unless something else is set for console.

mitar avatar Jun 05 '21 05:06 mitar

Yup. ConsoleDelegate was what I was meaning by:

You can create callback functions for the API, but we don't have these exposed in v8go yet

I agree that it can be confusing for a first-time V8 user, but even with the ConsoleDelegate APIs exposed, it would still be the responsibility of the caller to implement that delegate.

rogchap avatar Jun 05 '21 06:06 rogchap

Yup. ConsoleDelegate was what I was meaning by:

You can create callback functions for the API, but we don't have these exposed in v8go yet

I agree that it can be confusing for a first-time V8 user, but even with the ConsoleDelegate APIs exposed, it would still be the responsibility of the caller to implement that delegate.

And thus, would it be possible to expose the API allowing us to implement the delegate? :D

Segfaultd avatar Jun 23 '21 11:06 Segfaultd