Skip to content

Commit 0411d67

Browse files
committed
Implement nofunc in JSROOT.clone
This allows to produce objects clones, which are later can be transferred to the web Worker with postMessage
1 parent a86ca6b commit 0411d67

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

scripts/JSRootCore.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,11 @@
227227
// This should be similar to the jQuery.extend method
228228
// Just copy (not clone) all fields from source to the target object
229229
JSROOT.extend = function(tgt, src, map, deep_copy) {
230-
if ((src == null) || (typeof src != 'object')) return src;
230+
if ((src === null) || (typeof src !== 'object')) return src;
231231

232-
if (deep_copy) {
232+
if (typeof deep_copy === "undefined") deep_copy = 0;
233+
234+
if (deep_copy > 0) {
233235
if (!map) map = { obj:[], clones:[] };
234236
var i = map.obj.indexOf(src);
235237
if (i>=0) return map.clones[i];
@@ -264,22 +266,33 @@
264266
map.clones.push(tgt);
265267
}
266268
} else {
267-
if ((tgt==null) || (typeof tgt != 'object')) tgt = {};
269+
if ((tgt===null) || (typeof tgt !== 'object')) tgt = {};
268270
}
269271

270272
for (var k in src)
271-
if (deep_copy)
272-
tgt[k] = JSROOT.extend(tgt[k], src[k], map, true);
273-
else
274-
tgt[k] = src[k];
273+
switch (deep_copy) {
274+
case 0:
275+
tgt[k] = src[k];
276+
break;
277+
case 1:
278+
tgt[k] = JSROOT.extend(tgt[k], src[k], map, deep_copy);
279+
break;
280+
case 2:
281+
if (typeof(src[k]) !== 'function')
282+
tgt[k] = JSROOT.extend(tgt[k], src[k], map, deep_copy);
283+
break;
284+
285+
default:
286+
tgt[k] = src[k];
287+
}
275288

276289
return tgt;
277290
}
278291

279292
// Instead of jquery use JSROOT.extend function
280293
// Make deep_copy of the object, including all sub-objects
281-
JSROOT.clone = function(obj) {
282-
return JSROOT.extend(null, obj, null, true);
294+
JSROOT.clone = function(obj, nofunc) {
295+
return JSROOT.extend(null, obj, null, nofunc ? 2 : 1);
283296
}
284297

285298
JSROOT.parse = function(arg) {

0 commit comments

Comments
 (0)