{"ScriptPreparationCode":"\r\nconst TARGET = Symbol(\u0027TARGET\u0027);\r\n/**\r\n * @param {string} key\r\n * @param {string} operation\r\n * @returns {string}\r\n */\r\nfunction getErrorMsg(key, operation) {\r\n return \u0060Attempt to ${operation} key \u0022${key}\u0022 on immutable object. Clone using deepClone() and then modify.\u0060;\r\n}\r\n/**\r\n * @param {*} obj\r\n * @returns {boolean}\r\n */\r\nconst isObject = (obj) =\u003E typeof obj === \u0027object\u0027 \u0026\u0026 obj !== null;\r\nclass DefaultProxyHandler {\r\n /**\r\n * @param {*} target\r\n * @param {*} key\r\n * @returns {*}\r\n */\r\n get(target, key /*, receiver*/) {\r\n if (key === TARGET) {\r\n return target;\r\n }\r\n const obj = target[key];\r\n if (isObject(obj)) {\r\n return new Proxy(obj, this);\r\n }\r\n return obj;\r\n }\r\n /**\r\n * @param {*} target\r\n * @param {string} key\r\n */\r\n set(target, key) {\r\n throw new Error(getErrorMsg(key, \u0027set\u0027));\r\n }\r\n /**\r\n * @param {*} target\r\n * @param {string} key\r\n * @returns {boolean}\r\n */\r\n deleteProperty(target, key) {\r\n if (key in target) {\r\n throw new Error(getErrorMsg(key, \u0027delete\u0027));\r\n }\r\n return false;\r\n }\r\n /**\r\n * @param {*} target\r\n * @param {*} key\r\n */\r\n defineProperty(target, key) {\r\n throw new Error(getErrorMsg(key, \u0027define\u0027));\r\n }\r\n}\r\nconst proxyHandler = new DefaultProxyHandler();\r\nclass ProxyHandlerForMap extends DefaultProxyHandler {\r\n /**\r\n * @param {*} target\r\n * @param {*} key\r\n * @returns {*}\r\n */\r\n get(target, key /*, receiver*/) {\r\n if (key === TARGET) {\r\n return target;\r\n }\r\n const obj = target.get(key);\r\n if (isObject(obj)) {\r\n return new Proxy(obj, proxyHandler);\r\n }\r\n return obj;\r\n }\r\n ownKeys(target) {\r\n return [...target.keys()];\r\n }\r\n has(target, name) {\r\n return target.has(name);\r\n }\r\n getPrototypeOf() {\r\n return Object.prototype;\r\n }\r\n getOwnPropertyDescriptor(target, p) {\r\n if (!target.has(p)) {\r\n return undefined;\r\n }\r\n const val = this.get(target, p);\r\n return {\r\n writable: false,\r\n configurable: true,\r\n enumerable: true,\r\n value: val\r\n };\r\n }\r\n}\r\nconst proxyHandlerForMap = new ProxyHandlerForMap();\r\nclass ProxyHandlerForMapOfMaps extends ProxyHandlerForMap {\r\n /**\r\n * @param {*} target\r\n * @param {*} key\r\n * @returns {*}\r\n */\r\n get(target, key /*, receiver*/) {\r\n if (key === TARGET) {\r\n return target;\r\n }\r\n const obj = target.get(key);\r\n if (isObject(obj)) {\r\n return new Proxy(obj, proxyHandlerForMap);\r\n }\r\n return obj;\r\n }\r\n}\r\nconst proxyHandlerForMapOfMaps = new ProxyHandlerForMapOfMaps();\r\nconst lastProxy = {\r\n rawObject: undefined,\r\n proxy: undefined\r\n};\r\nconst creator = (handler) =\u003E (obj) =\u003E {\r\n if (isObject(obj)) {\r\n // The same object is often requested more than once in succession from the Dal, so this\r\n // optimisation reduces the number of proxies that are created\r\n if (lastProxy.rawObject === obj) {\r\n return lastProxy.proxy;\r\n }\r\n // if not already a proxy\r\n if (obj \u0026\u0026 !obj[TARGET]) {\r\n lastProxy.rawObject = obj;\r\n lastProxy.proxy = new Proxy(obj, handler);\r\n return lastProxy.proxy;\r\n }\r\n }\r\n return obj;\r\n};\r\n/**\r\n * Returns a proxy that provides read only access to the underlying nested object\r\n * An attempt to modify the underlying object will result in an exception being thrown\r\n * @param {*} obj\r\n * @returns {*}\r\n */\r\nconst createImmutableProxy = creator(proxyHandler);\r\n/**\r\n * Returns an immutable proxy for a map such that the entire data structure is viewed externally as a plain javascript object\r\n * An attempt to modify the underlying object will result in an exception being thrown\r\n * @param {*} obj\r\n * @returns {*}\r\n */\r\nconst createImmutableProxyForMap = creator(proxyHandlerForMap);\r\n/**\r\n * Returns an immutable proxy for a map of maps such that the entire data structure is viewed externally as a plain javascript object\r\n * An attempt to modify the underlying object will result in an exception being thrown\r\n * @param {*} obj\r\n * @returns {*}\r\n */\r\nconst createImmutableProxyForMapOfMaps = creator(proxyHandlerForMapOfMaps);\r\nfunction deepCloneDataArray(obj) {\r\n const copy = obj.slice(0);\r\n for (let i = 0; i \u003C copy.length; \u002B\u002Bi) {\r\n const val = obj[i];\r\n if (typeof val === \u0027object\u0027 \u0026\u0026 val !== null) {\r\n copy[i] = deepCloneDataObject(val);\r\n }\r\n }\r\n return copy;\r\n}\r\nfunction deepCloneDataObject(obj) {\r\n if (Array.isArray(obj)) {\r\n return deepCloneDataArray(obj);\r\n }\r\n if (obj instanceof Map) {\r\n const copy = {};\r\n for (const [key, value] of obj) {\r\n if (typeof value === \u0027object\u0027 \u0026\u0026 value !== null) {\r\n copy[key] = deepCloneDataObject(value);\r\n }\r\n else {\r\n copy[key] = value;\r\n }\r\n }\r\n return copy;\r\n }\r\n const copy = { ...obj };\r\n // eslint-disable-next-line guard-for-in\r\n for (const key in obj) {\r\n const val = obj[key];\r\n if (typeof val === \u0027object\u0027 \u0026\u0026 val !== null) {\r\n copy[key] = deepCloneDataObject(val);\r\n }\r\n }\r\n return copy;\r\n}\r\n/**\r\n * @param {*} obj\r\n * @returns {*}\r\n */\r\nfunction deepClone(obj) {\r\n if (isObject(obj)) {\r\n // This is a performance optimization for proxies to prevent the entire nested object being proxied.\r\n // It\u0027s typically only needed for the root object of a proxy so we do it here\r\n // instead of in the recursive clone function for every nested object\r\n const proxyTarget = obj[TARGET];\r\n return deepCloneDataObject(proxyTarget || obj);\r\n }\r\n return obj;\r\n}\r\n\r\n/**\r\n * @param {*} a\r\n * @returns {*}\r\n */\r\nconst getRef = (a) =\u003E (isObject(a) ? a[TARGET] || a : a);\r\n/**\r\n * @param {*} a\r\n * @param {*} b\r\n * @returns {boolean}\r\n */\r\nfunction referenceCompare(a, b) {\r\n a = getRef(a);\r\n b = getRef(b);\r\n return a === b;\r\n}\r\n\r\nfunction isImmutableProxy(obj) {\r\n return isObject(obj) \u0026\u0026 !!obj[TARGET];\r\n}\r\n\r\n\r\n\r\n\r\nvar objectToClone = {\r\n \u0022type\u0022: \u0022Component\u0022,\r\n \u0022styleId\u0022: \u0022txtNew\u0022,\r\n \u0022id\u0022: \u0022comp-kcspbj2c\u0022,\r\n \u0022dataQuery\u0022: \u0022#dataItem-kcspbj44\u0022,\r\n \u0022skin\u0022: \u0022wysiwyg.viewer.skins.WRichTextNewSkin\u0022,\r\n \u0022layout\u0022: {\r\n \u0022width\u0022: -310,\r\n \u0022height\u0022: 65,\r\n \u0022x\u0022: 507,\r\n \u0022y\u0022: 48,\r\n \u0022scale\u0022: 1.0,\r\n \u0022rotationInDegrees\u0022: 0.0,\r\n \u0022fixedPosition\u0022: false\r\n },\r\n \u0022propertyQuery\u0022: \u0022propItem-kcspbj5q\u0022,\r\n \u0022mobileHintsQuery\u0022: \u0022mobileHints-kcspihw9\u0022,\r\n \u0022componentType\u0022: \u0022wysiwyg.viewer.components.WRichText\u0022,\r\n \u0022metaData\u0022: {\r\n \u0022pageId\u0022: \u0022c1dmp\u0022\r\n }\r\n }\r\n\r\nvar proxyToClone = createImmutableProxy(objectToClone)\r\n\r\n\r\n\r\n\r\n","TestCases":[{"Name":"_.cloneDeep(objectToClone)","Code":"_.cloneDeep(objectToClone)","IsDeferred":false},{"Name":"structuredClone(objectToClone)","Code":"structuredClone(objectToClone)","IsDeferred":false},{"Name":"deepClone(objectToClone)","Code":"deepClone(objectToClone)","IsDeferred":false},{"Name":"_.cloneDeep(proxyToClone)","Code":"_.cloneDeep(proxyToClone)","IsDeferred":false},{"Name":"structuredClone(proxyToClone)","Code":"structuredClone(proxyToClone)","IsDeferred":false},{"Name":"deepClone(proxyToClone)","Code":"deepClone(proxyToClone)","IsDeferred":false}]}