Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contextify: share security token with debug ctx #748

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,13 @@ class ContextifyContext {
Local<String> script_source(args[0]->ToString(args.GetIsolate()));
if (script_source.IsEmpty())
return; // Exception pending.
Context::Scope context_scope(Debug::GetDebugContext());

Environment* env = Environment::GetCurrent(args.GetIsolate());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could move this into the if, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will account for 0% of cases, because debug context is empty only when we are hard on memory (i.e. allocation failure).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I meant to say that it'll be executed in 99.999% of cases anyway, not 0%.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah just thinking about keeping variables in their tightest scope. No big deal.

Local<Context> ctx = Debug::GetDebugContext();
if (!ctx.IsEmpty())
ctx->SetSecurityToken(env->context()->GetSecurityToken());

Context::Scope context_scope(ctx);
Local<Script> script = Script::Compile(script_source);
if (script.IsEmpty())
return; // Exception pending.
Expand Down
12 changes: 12 additions & 0 deletions test/parallel/test-vm-debug-context-token.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var common = require('../common');
var vm = require('vm');
var assert = require('assert');

var proto = vm.runInDebugContext('DebugCommandProcessor.prototype');
proto.prop = true;
assert.equal(proto.prop, true);
proto = vm.runInDebugContext('DebugCommandProcessor.prototype');
assert.equal(proto.prop, true);
proto = vm.runInDebugContext('DebugCommandProcessor.prototype.prop = true;' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this line be setting to a different value than true? To be sure it actually does something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this line could be removed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding of this line was it was testing that if you set it inside the vm, instead of outside, it still works. So it might be good to leave it in but use a different value.

'DebugCommandProcessor.prototype');
assert.equal(proto.prop, true);