Prefix global javascript functions with sub-namespaces#20743
Prefix global javascript functions with sub-namespaces#20743alalek merged 2 commits intoopencv:3.4from
Conversation
alalek
left a comment
There was a problem hiding this comment.
Thank you for contribution!
This change also replaces names of "dnn" module calls which can break existed user code. So it can't be accepted in the current form.
Could you please reimplement namespaces_dict from Java binding?
Prefix is applied to fisheye through config file
|
@alalek as I mentioned in the PR I am aware of that problem and didn't expect the PR to be accepted. Thanks for the Nevertheless I still would prefer to see the namespaces reflected in the js interface as described in the PR. That can avoid future name clashes. Assume a new function in dnn that has a namesake in another module. This cannot be solved with the namespace dictionary approach. |
|
I take a look on original issue one more time. P.S. need to check if embindgen could emulate "namespaces" (to avoid "ns_" prefixes). |
That's where I intend to add the
I also didn't check that til now. It seens that embind doesn't support that, see also this issue |
|
Yes. this is correct place. Probably we can fix filtering process (and exclude |
- avoid functions override with same name but different namespace
|
Implemented filtering based on |
|
|
||
| if js_func_name == "_findHomography1": | ||
| os.error(ns_name, ns_parts, ns_part) | ||
|
|
There was a problem hiding this comment.
I had already a commit prepared for removing the debug output, but you were faster...
|
|
||
| white_list = makeWhiteList([core, imgproc, objdetect, video, dnn, features2d, calib3d]) | ||
|
|
||
| # namespace_prefix_override['dnn'] = '' # compatibility stuff (enabled by default) |
There was a problem hiding this comment.
Wouldn't it be clearer to define the compatibility behaviour here and leave namespace_prefix_override empty in embindgen.py?
There was a problem hiding this comment.
This file is a sample of opencv.js configuration.
Users of custom opencv.js builds already have own configurations, so we need guarantee compatibility for them.
| 'fisheye_initUndistortRectifyMap', | ||
| 'fisheye_projectPoints', | ||
| ], | ||
| } |
There was a problem hiding this comment.
Now this is the only list in the file that's formatted this way
There was a problem hiding this comment.
1 item per-line formatting is for easy merging between branches (it is already partially used on the master/4.x branch).
|
@alalek thank you for finishing the compatibility parts |
Description
Fixes #15299
Both the global namespace and the
fisheyenamespace contain the functionprojectPoints. The bindings generator exports both functions with the original name globally. This solution adds the namespace as prefix to global function names, resulting in distict function names. In this case:projectPointsandfisheye_projectPoints.Incompatibilities
All functions in namespaces will get a prefix in js. From the modules that are exported by default the dnn module is affected.
Personally I would prefer to make javscript objects for namespaces and add all enums, classes and functions there - but that would be a bigger change.
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.