-
Notifications
You must be signed in to change notification settings - Fork 832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minmax #866
Closed
Closed
Minmax #866
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
UrielCh
commented
Mar 9, 2023
- add cv.min
- add cv.max
- integrate native-node-utils code inside cc/native-node-utils
- add comments in native-node-utils
Matrix constructor from rows, cols, Buffer, step
Update highguiConstants.cc
In some scenarios the JS files of the library may be reloaded, such as when loaded by Jest. It seems that the underlying node extension is not reloaded in this case. This causes an exception to be thrown when rebuilding the exported API object: > TypeError: Cannot read properties of undefined (reading 'constructor') This happens in the `isAsyncFn` function inside `promisify.js` because `fn.prototype` is undefined. This code works fine the first time, so why does it fail when run again? The reason is that the functions attached to the `cv` namespace are all defined in C++ and are thus essentially the equivalent of a `FunctionExpression`, which have a `prototype.constructor.name`. Calling `loadOpenCV` calls `getOpenCV` which loads the node extension, then calls `promisify` on that namespace, and finally calls `extendWithJsSources`. This is where we run into problems. These are the functions that get added to the `cv` namespace from JS: ``` drawTextBox drawDetection toMatTypeName getScoreMax dropOverlappingZone ``` Almost all of these are defined as `ArrowFunctionExpression`s which DO NOT have a `prototype`. So after the JS files get cleared from `require.cache` by Jest or some other means, loading this library again REUSES the `cv` namespace because the node extension is not cleared from memory. But this time it has those extra functions attached, causing the exception mentioned above in `isAsyncFn`. I changed two things to fix this: 1. make `promisify.ts` not assume that all functions have prototypes; they don't. 2. define the extra from-JS functions as `FunctionExpression`s so they will have prototypes (and names).
fix exception thrown on reload
oups |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.