Files
opencv-MIRROR/modules/js
熊建祐 1d740084b7 Merge pull request #30433 from JoyBoy900908:fix/js-mat-clone-emscripten
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.
2026-10-22 10:34:34 +03:00
..
2024-10-18 08:37:32 -03:00
2026-04-29 16:36:02 +03:00
2020-12-03 14:18:54 +00:00