Opened 7 years ago
#4826 new defect
Test more object types in the ScriptInterface clone function
Reported by: | elexis | Owned by: | |
---|---|---|---|
Priority: | If Time Permits | Milestone: | Backlog |
Component: | Core engine | Keywords: | |
Cc: | Patch: |
Description
r9506 introduced a C++ deepcopy
function which creates a clone of a given object.
r15421 introduced a JS clone
function which creates a clone for a smaller subset of JS objects.
r20125 deleted the latter and renamed deepcopy
to clone
.
While cloning of casual JS objects and arrays appears in many places of the code, it's inherently tested often by people running the application.
But there can be rare situations in which we want to clone unconventional object types, for instance a TypedArray likeFloat32Array
(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays).
The clone
of the latest commit mentioned above does support cloning of typed arrays and someArray instanceof Float32Array
confirms wheather the test is actually correct.
Since the clone function is part of the ScriptInterface, the test should reside in source/scriptinterface/tests/
.
Either code to load a new JS file should be added (similar to source/simulation2/components/tests/test_scripts.h
) or the existing source/scriptinterface/tests/test_ScriptInterface.h
would be extended (
https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_InstanceOf)
All types that support cloning are listed here: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm