Context::New crashes on Fedora when global.console is set

5 views
Skip to first unread message

Jeroen Ooms

unread,
Feb 5, 2019, 9:30:01 AM2/5/19
to v8-dev
The V8 bindings for R create a context and then set the 'console' property to implement console.log() and console.warn()

    v8::Local<v8::ObjectTemplate> console = v8::ObjectTemplate::New(isolate);
    global->Set(String::NewFromUtf8(isolate, "console"), console);
    console->Set(String::NewFromUtf8(isolate, "log"), 
      v8::FunctionTemplate::New(isolate, ConsoleLog));
    ...
    Persistent<Context> context = Context::New(isolate, NULL, global);

This works on all systems except on Fedora (v8 6.7.17) it crashes when initiating the context:

  # Fatal error in ../../src/objects.cc, line 5983
  # Debug check failed: !it.IsFound().

After some trial and error I discovered that it does not crash if I change the name of the property something else than "console". Hence I suppose this name is somehow reserved on this version of V8? Is there a some way to override this, or alternatively test if 'global.console' has been reserved so I should not attempt to set it?


Yang Guo

unread,
Feb 5, 2019, 2:55:57 PM2/5/19
to v8-...@googlegroups.com
Fairly sure this is just crbug.com/v8/8669

The reason is that there is already a console object in the snapshot, and the one you set up on the global object via object template will get overwritten. We used to assert in order to avoid mistakes by embedders.

You need to cherry-pick c8567109f5536c697aea1166919e2bac23685fbd and da2047c4a276a4d0077d00630a391917a7a1fff1, or upgrade past V8 version 7.3.400

The actual way to implement the console object though is to implement an inspector frontend and communicate with V8 inspector via DevTools protocol.

Cheers,

Yang

--
--
v8-dev mailing list
v8-...@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-dev+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jeroen Ooms

unread,
Feb 5, 2019, 11:02:56 PM2/5/19
to v8-...@googlegroups.com
I was able to work around it by deleting and setting the console
property after the context has been initiated:
https://github.com/jeroen/V8/blob/e405e53743c8f4760fc7903553b262a6b7ebd2f0/src/bindings.cpp#L217-L232
> You received this message because you are subscribed to a topic in the Google Groups "v8-dev" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-dev/dVrKaQ6QXyE/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to v8-dev+un...@googlegroups.com.

Yang Guo

unread,
Feb 6, 2019, 5:28:15 AM2/6/19
to v8-...@googlegroups.com
You can, after doing that, capture a new snapshot. That one would then include your new console implementation. However, you will need to tell the SnapshotCreator about the bindings' addresses.

Cheers,

Yang
Reply all
Reply to author
Forward
0 new messages