Skip to content

Commit 41e242d

Browse files
committed
Add 'shareSecurityToken' method
1 parent 63bec8c commit 41e242d

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

src/debug.cc

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,18 @@ namespace nodex {
5858
if (expression.IsEmpty())
5959
RETURN(Undefined());
6060

61+
Local<Context> current_context = Isolate::GetCurrent()->GetCurrentContext();
6162
Local<Context> debug_context = v8::Debug::GetDebugContext();
6263
#if (NODE_MODULE_VERSION > 45)
6364
if (debug_context.IsEmpty()) {
6465
// Force-load the debug context.
65-
v8::Debug::GetMirror(info.GetIsolate()->GetCurrentContext(), info[0]);
66+
v8::Debug::GetMirror(current_context, New<Object>());
6667
debug_context = v8::Debug::GetDebugContext();
6768
}
68-
#endif
6969

70+
// Share security token
71+
debug_context->SetSecurityToken(current_context->GetSecurityToken());
72+
#endif
7073
Context::Scope context_scope(debug_context);
7174

7275
TryCatch tryCatch;
@@ -77,12 +80,39 @@ namespace nodex {
7780
};
7881

7982
static NAN_METHOD(AllowNatives) {
83+
// TODO: deprecate this useless method
8084
const char allow_natives_syntax[] = "--allow_natives_syntax";
8185
v8::V8::SetFlagsFromString(allow_natives_syntax, sizeof(allow_natives_syntax) - 1);
8286

8387
RETURN(Undefined());
8488
}
8589

90+
static NAN_METHOD(ShareSecurityToken) {
91+
Local<Context> current_context = info.GetIsolate()->GetCurrentContext();
92+
Local<Context> debug_context = v8::Debug::GetDebugContext();
93+
#if (NODE_MODULE_VERSION > 45)
94+
if (debug_context.IsEmpty()) {
95+
// Force-load the debug context.
96+
v8::Debug::GetMirror(current_context, New<Object>());
97+
debug_context = v8::Debug::GetDebugContext();
98+
}
99+
#endif
100+
// Share security token
101+
debug_context->SetSecurityToken(current_context->GetSecurityToken());
102+
}
103+
104+
static NAN_METHOD(UnshareSecurityToken) {
105+
Local<Context> current_context = info.GetIsolate()->GetCurrentContext();
106+
Local<Context> debug_context = v8::Debug::GetDebugContext();
107+
#if (NODE_MODULE_VERSION > 45)
108+
if (debug_context.IsEmpty()) {
109+
// Force-load the debug context.
110+
v8::Debug::GetMirror(current_context, New<Object>());
111+
debug_context = v8::Debug::GetDebugContext();
112+
}
113+
#endif
114+
debug_context->UseDefaultSecurityToken();
115+
}
86116
private:
87117
Debug() {}
88118
~Debug() {}
@@ -97,6 +127,8 @@ namespace nodex {
97127
SetMethod(target, "sendCommand", Debug::SendCommand);
98128
SetMethod(target, "runScript", Debug::RunScript);
99129
SetMethod(target, "allowNatives", Debug::AllowNatives);
130+
SetMethod(target, "shareSecurityToken", Debug::ShareSecurityToken);
131+
SetMethod(target, "unshareSecurityToken", Debug::UnshareSecurityToken);
100132
}
101133

102134
NODE_MODULE(debug, Initialize)

v8-debug.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,14 @@ function V8Debug() {
107107
// After node 0.12.0 this function serves to allocate Debug Context
108108
// like a persistent value, that saves all our changes.
109109
this._setDebugEventListener();
110+
// We need to share security token between current and debug context to
111+
// get access to evaluation functions
112+
this._shareSecurityToken();
110113
this._wrapDebugCommandProcessor();
111114

112115
this.once('close', function() {
113116
this._unwrapDebugCommandProcessor();
117+
this._unshareSecurityToken();
114118
this._unsetDebugEventListener();
115119
process.nextTick(function() {
116120
this.removeAllListeners();
@@ -130,6 +134,14 @@ V8Debug.prototype._unsetDebugEventListener = function() {
130134
Debug.setListener(null);
131135
};
132136

137+
V8Debug.prototype._shareSecurityToken = function() {
138+
binding.shareSecurityToken();
139+
};
140+
141+
V8Debug.prototype._unshareSecurityToken = function() {
142+
binding.unshareSecurityToken();
143+
};
144+
133145
V8Debug.prototype._wrapDebugCommandProcessor = function() {
134146
var proto = this.get('DebugCommandProcessor.prototype');
135147
overrides.processDebugRequest_ = proto.processDebugRequest;

0 commit comments

Comments
 (0)