Google was nice enough to explain how to wrap C++ class methods with accessors that can be used from the V8 Javascript engine.
However, they don't mention how to determine the name of the JavaScript object that will have these accessor properties available.
How do I tell V8 Javascript what the name of the C++ class instance (from the sample) is? Or if it already has a name, what is it?
These two lines set up the accessors:
point_templ.SetAccessor(String::New("x"), GetPointX, SetPointX);
point_templ.SetAccessor(String::New("y"), GetPointY, SetPointY);
I assume they can be used like this from JavaScript:
someObject.x = someObject.y * 2;
How do I determine what "someObject
" is?
I feel there is some code missing that finishes linking the C++ code with the V8 Javascript wrapper.
For example, in the sample code to access static global variables there was a line that explicitly exposed the accessor functions to V8 JavaScript:
Handle<ObjectTemplate> global_templ = ObjectTemplate::New();
global_templ->SetAccessor(String::New("x"), XGetter, XSetter);
global_templ->SetAccessor(String::New("y"), YGetter, YSetter);
Persistent<Context> context = Context::New(NULL, global_templ)