From 7aa82c4c57bc05016d49399e91d83781379474ee Mon Sep 17 00:00:00 2001 From: saqimtiaz Date: Thu, 30 Jan 2025 16:48:52 +0100 Subject: [PATCH] refactor: moved new method out of dom.js --- core/modules/utils/dom/dom.js | 44 +---------------------------------- core/modules/utils/utils.js | 42 +++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/core/modules/utils/dom/dom.js b/core/modules/utils/dom/dom.js index 2eb17e606..6bf874cac 100644 --- a/core/modules/utils/dom/dom.js +++ b/core/modules/utils/dom/dom.js @@ -311,48 +311,6 @@ exports.getLocationPath = function() { return window.location.toString().split("#")[0]; }; -exports.copyEventProperties = function(event) { - var seen = new Set(); - - function isDOMElement(value) { - return value instanceof Node || value instanceof Window; - } - - function safeCopy(obj) { - //skip ciruclar references - if(seen.has(obj)) { - return "[Circular reference]"; - } - //skip functions - if(typeof obj !== "object" || obj === null) { - return obj; - } - //skip DOM elements - if(isDOMElement(obj)) { - return "[DOM Element]"; - } - //copy each element of the array - if(Array.isArray(obj)) { - return obj.map(safeCopy); - } - - seen.add(obj); - var copy = {}, key; - for(key in obj) { - try{ - copy[key] = safeCopy(obj[key]); - } catch(e) { - copy[key] = "[Unserializable]"; - } - } - return copy; - } - - var result = safeCopy(event); - seen.clear(); - return result; -}; - /* Collect DOM variables */ @@ -395,7 +353,7 @@ exports.collectDOMVariables = function(selectedNode,domNode,event) { variables["tv-widgetnode-height"] = domNode.offsetHeight.toString(); } if(event) { - var eventProperties = $tw.utils.copyEventProperties(event); + var eventProperties = $tw.utils.copyObjectPropertiesSafe(event); variables["event-properties"] = JSON.stringify(eventProperties,null,2); if(("clientX" in event) && ("clientY" in event)) { diff --git a/core/modules/utils/utils.js b/core/modules/utils/utils.js index 234de0c75..76f872581 100644 --- a/core/modules/utils/utils.js +++ b/core/modules/utils/utils.js @@ -292,6 +292,48 @@ exports.extendDeepCopy = function(object,extendedProperties) { return result; }; +exports.copyObjectPropertiesSafe = function(object) { + var seen = new Set(); + + function isDOMElement(value) { + return value instanceof Node || value instanceof Window; + } + + function safeCopy(obj) { + //skip ciruclar references + if(seen.has(obj)) { + return "[Circular reference]"; + } + //skip functions + if(typeof obj !== "object" || obj === null) { + return obj; + } + //skip DOM elements + if(isDOMElement(obj)) { + return "[DOM Element]"; + } + //copy each element of the array + if(Array.isArray(obj)) { + return obj.map(safeCopy); + } + + seen.add(obj); + var copy = {}, key; + for(key in obj) { + try{ + copy[key] = safeCopy(obj[key]); + } catch(e) { + copy[key] = "[Unserializable]"; + } + } + return copy; + } + + var result = safeCopy(object); + seen.clear(); + return result; +}; + exports.deepFreeze = function deepFreeze(object) { var property, key; if(object) {