embedding: allow NewContext to create inspectable context #31411
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
NodeJS should allow C++ users to create contexts, whose compiled script can be debugged through the inspector agent. Currently this functionality is only available for JavaScript modules through VM module. Unfortunately, VM creates a context whose global is completely new and hidden
v8::FunctionTemplate
. C++ users might already havev8::FunctionTemplate
orv8::ObjectTemplate
from which they create a context.The only option now is to call V8 API directly:
v8::Context::New(...)
. The created context is not associated with anynode::Environment
and code executed in that context cannot be debugged in the inspector agent (the context is missingdebug_context_id
as this is provided when the agent is notified byContextCreated
). This might actually be an intended behavior. Thenode::NewContext
also create a context and do not report it to any agent (agent is a part ofnode::Environment
andnode::NewContext
does not access any environments.This is a proposal of a new feature to allow mitigate that gap. It provides another form of
node::NewContext
wherenode::Environment
is accepted as the first parameter instead ofv8::Isolate
. When such an environment is available, it will create a context with a specificv8::ObjectTemplate
and then callv8::Environment::AssignToContext
. The latter will report the newly created context to the environment's inspector agent (if one is available) and add some embedders properties to allow proper handling of stack traces.Without this feature, C++ modules can create
v8::Context
and usev8::ScriptCompiler
to compile functions and scripts. Those scripts are not reported to the inspector agent and functions has[[FunctionLocation]]
internal slot set to<unknown>
even whenv8::Source
specify resource name, line and column offset, etc. If a context is reported to the inspector agent, it receives adebug_context_id
. If this is available, compilation of new scripts and functions in that context will report to the inspector agent, which will send the source to the inspector frontend. Furthermore, the environment that has setupPrepareStackTraceCallback
calls forEnvironment::GetCurrent(context)
. If an exception occurs into a context not assigned to environment, stack trace would be ignored, even when it is available.This feature can be implemented using the following principles:
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes