Reputation: 2178
I am looking at the following source code from v8, and I am confused by the handle_scope object. It looks like it is being called before it is being initialized. The documentation specifies that it is a stack allocated Object. Is the default constructor called automatically for this object?
// Utility function that wraps a C++ http request object in a
// JavaScript object.
Handle<Object> JsHttpRequestProcessor::WrapMap(map<string, string>* obj) {
// Handle scope for temporary handles.
HandleScope handle_scope;
// Fetch the template for creating JavaScript map wrappers.
// It only has to be created once, which we do on demand.
if (map_template_.IsEmpty()) {
Handle<ObjectTemplate> raw_template = MakeMapTemplate();
map_template_ = Persistent<ObjectTemplate>::New(raw_template);
}
Handle<ObjectTemplate> templ = map_template_;
// Create an empty map wrapper.
Handle<Object> result = templ->NewInstance();
// Wrap the raw C++ pointer in an External so it can be referenced
// from within JavaScript.
Handle<External> map_ptr = External::New(obj);
// Store the map pointer in the JavaScript wrapper.
result->SetInternalField(0, map_ptr);
// Return the result through the current handle scope. Since each
// of these handles will go away when the handle scope is deleted
// we need to call Close to let one, the result, escape into the
// outer handle scope.
return handle_scope.Close(result);
}
Upvotes: 0
Views: 312
Reputation: 110658
Yes, the object is default-initialized, which means that its default constructor will be called. Just like if you declare a std::string
:
std::string str;
That str
has still been initialized.
It is only for non-class types that default-initialization means no initialization.
Upvotes: 1