E. Zacarias E. Zacarias - 15 days ago 5
C++ Question

Weird C++ syntax: type definition before a function call

I was reading NodeJS and V8 source, particulary

node_contextify.cc
file, and I could not understand the following line:

Context::Scope context_scope(debug_context);


I don't understand what is that
Context::Scope
before what seems to be a function call. I don't think it is a declaration because it is a function code, together with an
if
and other calls.

Complete relevant code:

...
if (debug_context.IsEmpty()) {
// [... lines removed for brevity ...]
}
Context::Scope context_scope(debug_context);
MaybeLocal<Script> script = Script::Compile(debug_context, script_source);
if (script.IsEmpty())
return; // Exception pending.
args.GetReturnValue().Set(script.ToLocalChecked()->Run());
}
...


What is the meaning of that
Context::Scope
?





Further information:

File: node/node_contextify.cc (the line 268 is highlighted).

While I understand it is a basic question about syntax, I don't even know how to call it, so I was not able to find any result in Google, StackOverflow or C++ reference.

The question title is one of my attempts when searching for it.

Answer

It's initializing the context_scope variable with debug_context. Context::Scope is the type (here's one ref page http://bespin.cz/~ondras/html/classv8_1_1Context_1_1Scope.html)

Here's another article on using Context::Scope How to correctly use Context::Scope ?

BTW, even if you don't know what to call it, searching for "v8 Context::Scope" will turn up information.

Comments