mirror of
https://github.com/opencv/opencv.git
synced 2026-11-09 18:04:29 -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.