UNPKG

siesta-lite

Version:

Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers

273 lines (189 loc) 7.5 kB
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>The source code</title> <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" /> <script type="text/javascript" src="../resources/prettify/prettify.js"></script> <style type="text/css"> .highlight { display: block; background-color: #ddd; } </style> <script type="text/javascript"> function highlight() { document.getElementById(location.hash.replace(/#/, "")).className = "highlight"; } </script> </head> <body onload="prettyPrint(); highlight();"> <pre class="prettyprint lang-js">/* Siesta 5.6.1 Copyright(c) 2009-2022 Bryntum AB https://bryntum.com/contact https://bryntum.com/products/siesta/license */ Class(&#39;Siesta.Util.Serializer&#39;, { isa : Data.Visitor2, has : { result : Joose.I.Array, manualEnum : function () { for (var i in { toString : 1 }) return false return true } }, methods : { assignRefAdrTo : function (object) { try { return this.SUPER(object) } catch (e) { if (!object.__REFADR__) object.__REFADR__ = this.getRefAdr() } return object.__REFADR__ }, write : function (str) { this.result.push(str) }, visitOutOfDepthValue : function (value, depth) { this.write(&#39;...&#39;) }, visitSymbol: function (value) { this.write(value.toString()) }, visitValue : function (value) { if (value == null) // `null` and `undefined` this.write(value + &#39;&#39;) else { if (typeof value === &#39;symbol&#39;) this.write(value.toString()) else this.write(typeof value == &#39;string&#39; ? &#39;&quot;&#39; + value.replace(/&quot;/g, &#39;\\&quot;&#39;).replace(/\n/g, &#39;\\n&#39;) + &#39;&quot;&#39; : value + &#39;&#39;) } }, visitObjectKey : function (key, value, object) { this.write(&#39;&quot;&#39; + key + &#39;&quot;: &#39;) }, getClassNameFor : function (object) { if (object.nodeType != null &amp;&amp; object.nodeName != null &amp;&amp; object.tagName) return &#39;DOMElement&#39; // trying to detect and not dive into global window if (object.document != null &amp;&amp; object.location != null &amp;&amp; object.location.href != null) return &#39;Window&#39; return this.SUPER(object) }, visitSeen : function (value, depth) { this.write(&#39;[Circular]&#39;) }, visitRegExp : function (value, depth) { this.write(value + &#39;&#39;) }, visitFunction : function (value, depth) { this.write(&#39;function &#39; + (value.name || &#39;&#39;) + &#39;() { ... }&#39;) }, visitDate : function (value, depth) { this.write(&#39;&quot;&#39; + value + &#39;&quot;&#39;) }, // safer alternative to parent&#39;s implementation of `visitObject` - some host objects has no &quot;hasOwnProperty&quot; method visitObject : function (object, depth) { for (var key in object) { if (key != &#39;__REFADR__&#39; &amp;&amp; (!object.hasOwnProperty || object.hasOwnProperty(key))) { var value = object[ key ] this.visitObjectKey(key, value, object, depth) this.visitObjectValue(value, key, object, depth) } } var me = this if (this.manualEnum) Joose.A.each([ &#39;hasOwnProperty&#39;, &#39;valueOf&#39;, &#39;toString&#39;, &#39;constructor&#39; ], function (key) { if (object.hasOwnProperty &amp;&amp; object.hasOwnProperty(key)) { var value = object[ key ] me.visitObjectKey(key, value, object, depth) me.visitObjectValue(value, key, object, depth) } }) return object }, visitJooseInstance : function (value, depth) { if (value.meta.hasMethod(&#39;toString&#39;)) { this.write(value.toString()) return value } return this.SUPERARG(arguments) }, visitDOMElement : function (object, depth) { var output = &#39;&amp;lt;&#39; + object.tagName if (object.id) output += &#39; id=&quot;&#39; + object.id + &#39;&quot;&#39; if (object.className) output += &#39; class=&quot;&#39; + object.className + &#39;&quot;&#39; this.write(output + &#39;&amp;gt;&#39;) }, visitDOMStringMap : function () { this.write(&#39;[DOMStringMap]&#39;) }, // the Object.prototype.toString.call(window) for FF visitWindow : function () { this.write(&#39;[window]&#39;) }, // window.location type in FF visitLocation : function () { this.write(&#39;[window.location]&#39;) }, visitMap : function (map, depth) { this.write(&#39;Map(&#39; + map.size + &#39;){&#39;) // we use iterator here instead of simple &quot;for .. of&quot; loop, because IE does not support it var iterator = map.entries() for (var entry = iterator.next(); !entry.done; entry = iterator.next()) { this.visit(entry.value[ 0 ], depth + 1) this.write(&#39;=&gt;&#39;) this.visit(entry.value[ 1 ], depth + 1) this.write(&#39;, &#39;) } if (map.size &gt; 0) this.result.pop() this.write(&#39;}&#39;) } }, before : { visitObject : function () { this.write(&#39;{&#39;) }, visitArray : function () { this.write(&#39;[&#39;) } }, after : { visitObject : function () { var result = this.result if (result[ result.length - 1 ] == &#39;, &#39;) result.pop() this.write(&#39;}&#39;) }, visitArray : function () { var result = this.result if (result[ result.length - 1 ] == &#39;, &#39;) result.pop() this.write(&#39;]&#39;) }, visitObjectValue : function () { this.write(&#39;, &#39;) }, visitArrayEntry : function () { this.write(&#39;, &#39;) } }, my : { has : { HOST : null }, methods : { stringify : function (value, maxDepth) { try { if (value != null &amp;&amp; value.foobar) visitor = null } catch (e) { if (value) return &#39;Value from cross-domain context&#39; } var visitor = new this.HOST({ maxDepth : maxDepth || 4 }) visitor.visit(value, 0) return visitor.result.join(&#39;&#39;) } } } }) </pre> </body> </html>