vm: allow modifying context name in inspector

The `auxData` field is not exposed to JavaScript, as DevTools uses it
for its `isDefault` parameter, which is implemented faithfully,
contributing to the nice indentation in the context selection panel.
Without the indentation, when `Target` domain gets implemented (along
with a single Inspector for cluster) in #16627, subprocesses and VM
contexts will be mixed up, causing confusion.

PR-URL: https://github.com/nodejs/node/pull/17720
Refs: https://github.com/nodejs/node/pull/14231#issuecomment-315924067
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Timothy Gu committed 2017-12-23 14:05:18 +08:00
1 parent c339931d8b
commit 2cb2145162
8 files changed
+264 -59

No files matched your search

+31 -5
View File
@@ -100,8 +100,11 @@ class ContextifyContext {
Persistent<Context> context_;
public:
ContextifyContext(Environment* env, Local<Object> sandbox_obj) : env_(env) {
Local<Context> v8_context = CreateV8Context(env, sandbox_obj);
ContextifyContext(Environment* env,
Local<Object> sandbox_obj,
Local<Object> options_obj)
: env_(env) {
Local<Context> v8_context = CreateV8Context(env, sandbox_obj, options_obj);
context_.Reset(env->isolate(), v8_context);
// Allocation failure or maximum call stack size reached
@@ -154,7 +157,9 @@ class ContextifyContext {
}
Local<Context> CreateV8Context(Environment* env, Local<Object> sandbox_obj) {
Local<Context> CreateV8Context(Environment* env,
Local<Object> sandbox_obj,
Local<Object> options_obj) {
EscapableHandleScope scope(env->isolate());
Local<FunctionTemplate> function_template =
FunctionTemplate::New(env->isolate());
@@ -204,7 +209,25 @@ class ContextifyContext {
env->contextify_global_private_symbol(),
ctx->Global());
env->AssignToContext(ctx);
Local<Value> name =
options_obj->Get(env->context(), env->name_string())
.ToLocalChecked();
CHECK(name->IsString());
Utf8Value name_val(env->isolate(), name);
ContextInfo info(*name_val);
Local<Value> origin =
options_obj->Get(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "origin"))
.ToLocalChecked();
if (!origin->IsUndefined()) {
CHECK(origin->IsString());
Utf8Value origin_val(env->isolate(), origin);
info.origin = *origin_val;
}
env->AssignToContext(ctx, info);
return scope.Escape(ctx);
}
@@ -235,8 +258,11 @@ class ContextifyContext {
env->context(),
env->contextify_context_private_symbol()).FromJust());
Local<Object> options = args[1].As<Object>();
CHECK(options->IsObject());
TryCatch try_catch(env->isolate());
ContextifyContext* context = new ContextifyContext(env, sandbox);
ContextifyContext* context = new ContextifyContext(env, sandbox, options);
if (try_catch.HasCaught()) {
try_catch.ReThrow();