diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /libgo/go/html/testdata/webkit/dom2string.js | |
download | cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2 cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'libgo/go/html/testdata/webkit/dom2string.js')
-rw-r--r-- | libgo/go/html/testdata/webkit/dom2string.js | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/libgo/go/html/testdata/webkit/dom2string.js b/libgo/go/html/testdata/webkit/dom2string.js new file mode 100644 index 000000000..45897fda4 --- /dev/null +++ b/libgo/go/html/testdata/webkit/dom2string.js @@ -0,0 +1,135 @@ +String.prototype.toAsciiLowerCase = function () { + var output = ""; + for (var i = 0, len = this.length; i < len; ++i) { + if (this.charCodeAt(i) >= 0x41 && this.charCodeAt(i) <= 0x5A) { + output += String.fromCharCode(this.charCodeAt(i) + 0x20) + } else { + output += this.charAt(i); + } + } + return output; +} + +function indent(ancestors) { + var str = ""; + if (ancestors > 0) { + while (ancestors--) + str += " "; + } + return str; +} + +function dom2string(node, ancestors) { + var str = ""; + if (typeof ancestors == "undefined") + var ancestors = 0; + if (!node.firstChild) + return "| "; + var parent = node; + var current = node.firstChild; + var next = null; + var misnested = null; + for (;;) { + str += "\n| " + indent(ancestors); + switch (current.nodeType) { + case 10: + str += '<!DOCTYPE ' + current.nodeName + '>'; + break; + case 8: + try { + str += '<!-- ' + current.nodeValue + ' -->'; + } catch (e) { + str += '<!-- -->'; + } + if (parent != current.parentNode) { + return str += ' (misnested... aborting)'; + } + break; + case 7: + str += '<?' + current.nodeName + current.nodeValue + '>'; + break; + case 4: + str += '<![CDATA[ ' + current.nodeValue + ' ]]>'; + break; + case 3: + str += '"' + current.nodeValue + '"'; + if (parent != current.parentNode) { + return str += ' (misnested... aborting)'; + } + break; + case 1: + str += "<"; + switch (current.namespaceURI) { + case "http://www.w3.org/2000/svg": + str += "svg "; + break; + case "http://www.w3.org/1998/Math/MathML": + str += "math "; + break; + } + if (current.localName && current.namespaceURI && current.namespaceURI != null) { + str += current.localName; + } else { + str += current.nodeName.toAsciiLowerCase(); + } + str += '>'; + if (parent != current.parentNode) { + return str += ' (misnested... aborting)'; + } else { + if (current.attributes) { + var attrNames = []; + var attrPos = {}; + for (var j = 0; j < current.attributes.length; j += 1) { + if (current.attributes[j].specified) { + var name = ""; + switch (current.attributes[j].namespaceURI) { + case "http://www.w3.org/XML/1998/namespace": + name += "xml "; + break; + case "http://www.w3.org/2000/xmlns/": + name += "xmlns "; + break; + case "http://www.w3.org/1999/xlink": + name += "xlink "; + break; + } + if (current.attributes[j].localName) { + name += current.attributes[j].localName; + } else { + name += current.attributes[j].nodeName; + } + attrNames.push(name); + attrPos[name] = j; + } + } + if (attrNames.length > 0) { + attrNames.sort(); + for (var j = 0; j < attrNames.length; j += 1) { + str += "\n| " + indent(1 + ancestors) + attrNames[j]; + str += '="' + current.attributes[attrPos[attrNames[j]]].nodeValue + '"'; + } + } + } + if (next = current.firstChild) { + parent = current; + current = next; + ancestors++; + continue; + } + } + break; + } + for (;;) { + if (next = current.nextSibling) { + current = next; + break; + } + current = current.parentNode; + parent = parent.parentNode; + ancestors--; + if (current == node) { + return str.substring(1); + } + } + } +} |