mirror of
https://github.com/opencv/opencv.git
synced 2026-11-21 00:35:35 -06:00
fix(js): restore deep copy behavior of Mat.clone() - #30433 ## Description Fixes #30408. With Emscripten 4+, the existing `onRuntimeInitialized` callback can be registered after runtime initialization has already completed. As a result, the override of Emscripten's shallow `ClassHandle.clone()` is never applied, causing `cv.Mat.clone()` to perform a shallow copy instead of the expected deep copy. This PR applies the `mat_clone` override immediately when `cv.Mat` is available, while retaining the initialization callback as a fallback. ## Changes - Restore deep-copy behavior for `cv.Mat.clone()`. - Preserve the existing `onRuntimeInitialized` callback. - Add regression tests for matrix data independence and cloning non-contiguous ROIs. ## Testing Environment: - OpenCV 5.x - Emscripten 6.0.12 - Node.js 22.23.3 Results: - Confirmed the original shallow-copy behavior before the fix. - Verified deep-copy behavior after the fix. - Verified that cloning a non-contiguous ROI produces independent, continuous data. - `CoreMat.test_mat_creation`: 91/91 assertions passed. - Full OpenCV.js test suite: 414 passed, 8 failed. The remaining eight failures involve heap-memory views and unavailable JavaScript bindings. These failures have not yet been verified against an unmodified baseline.
24 lines
774 B
JavaScript
24 lines
774 B
JavaScript
// This file is part of OpenCV project.
|
|
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
|
// of this distribution and at http://opencv.org/license.html.
|
|
|
|
QUnit.test("init_cv", (assert) => {
|
|
if (cv instanceof Promise) {
|
|
const done = assert.async();
|
|
cv.then((ready_cv) => {
|
|
cv = ready_cv;
|
|
done();
|
|
});
|
|
} else if (cv.getBuildInformation === undefined) {
|
|
const done = assert.async();
|
|
const previousOnRuntimeInitialized = cv['onRuntimeInitialized'];
|
|
cv['onRuntimeInitialized'] = () => {
|
|
if (previousOnRuntimeInitialized) {
|
|
previousOnRuntimeInitialized();
|
|
}
|
|
done();
|
|
};
|
|
}
|
|
assert.ok(true);
|
|
});
|