Since its inefficient to write so much code, while making sure SetMethod and SetPrototypeMethod is called on each overload and track the namespaces used to store the callbacks manually, an experimental namespace_wrap and class_wrap were introduced, these two classes wrap the needed calls as well as track the targets (v8::Object).
The wrappers do add overhead to function execution time but it didn't even register when I did performance analysis.
to use the wrappers you'll need to initialize an overload_resolution instance normally but also start tracking a root target:
void init(v8::Handle<v8::Object> target) {
auto overload = std::make_shared<overload_resolution>();
auto base_overload = overload->register_module(target);
...
}
NODE_MODULE(tester, init);
once you have the base_overload you can start attaching methods:
base_overload->add_overload("standalone_function_construct", {}, standalone_function_construct);
nest methods:
auto nested = base_overload->add_namespace("namespace_construct");
nested->add_overload("nc_standalone_function_construct", {}, nc_standalone_function_construct_nc);
add classes:
auto class_def = base_overload->add_class("class_constructs");
class_def->add_overload_constructor({}, New);
class_def->add_static_overload("test_static", {}, test_static);
class_def->add_overload("test_member", {}, test_member);
constructor.Reset(class_def->done<class_constructs>());
note: you must call done<T>() when you're done defining the class methods, otherwise the class won't register in both the overload_resolution and V8.
for now classes can be nested inside namespaces but not the other way around, though it should be theoretically possible.
Minor build and bug fixes:
- integration with node-addon-tracer npm package so build is simpler.
- expose node-overload-resolution as an npm module, so require("node-overload-resolution") works in parent module gyp files.
- remove support for node 0.11
- fix travis ci builds
0 comments:
Post a Comment