var events = require("../level2/events"),1core = require("../level2/core").dom.level2.core,2defineGetter = require('../utils').defineGetter,3defineSetter = require('../utils').defineSetter,4HtmlToDom = require('../browser/htmltodom').HtmlToDom,5domToHtml = require('../browser/domtohtml').domToHtml,6htmlencoding = require('../browser/htmlencoding'),7HTMLEncode = htmlencoding.HTMLEncode,8HTMLDecode = htmlencoding.HTMLDecode;910// modify cloned instance for more info check: https://github.com/tmpvar/jsdom/issues/32511core = Object.create(core);1213/*14valuetype DOMString sequence<unsigned short>;15typedef unsigned long long DOMTimeStamp;16typedef any DOMUserData;17typedef Object DOMObject;1819*/20// ExceptionCode21core.VALIDATION_ERR = 16;22core.TYPE_MISMATCH_ERR = 17;2324/*25// Introduced in DOM Level 3:26interface NameList {27DOMString getName(in unsigned long index);28DOMString getNamespaceURI(in unsigned long index);29readonly attribute unsigned long length;30boolean contains(in DOMString str);31boolean containsNS(in DOMString namespaceURI,32in DOMString name);33};3435// Introduced in DOM Level 3:36interface DOMImplementationList {37DOMImplementation item(in unsigned long index);38readonly attribute unsigned long length;39};4041// Introduced in DOM Level 3:42interface DOMImplementationSource {43DOMImplementation getDOMImplementation(in DOMString features);44DOMImplementationList getDOMImplementationList(in DOMString features);45};46*/474849core.DOMImplementation.prototype.getFeature = function(feature, version) {5051};5253/*54interface Node {55// Modified in DOM Level 3:56Node insertBefore(in Node newChild,57in Node refChild)58raises(DOMException);59// Modified in DOM Level 3:60Node replaceChild(in Node newChild,61in Node oldChild)62raises(DOMException);63// Modified in DOM Level 3:64Node removeChild(in Node oldChild)65raises(DOMException);66// Modified in DOM Level 3:67Node appendChild(in Node newChild)68raises(DOMException);69boolean hasChildNodes();70Node cloneNode(in boolean deep);71// Modified in DOM Level 3:72void normalize();73// Introduced in DOM Level 3:74readonly attribute DOMString baseURI;75*/7677// Compare Document Position78var DOCUMENT_POSITION_DISCONNECTED = core.Node.prototype.DOCUMENT_POSITION_DISCONNECTED = 0x01;79var DOCUMENT_POSITION_PRECEDING = core.Node.prototype.DOCUMENT_POSITION_PRECEDING = 0x02;80var DOCUMENT_POSITION_FOLLOWING = core.Node.prototype.DOCUMENT_POSITION_FOLLOWING = 0x04;81var DOCUMENT_POSITION_CONTAINS = core.Node.prototype.DOCUMENT_POSITION_CONTAINS = 0x08;82var DOCUMENT_POSITION_CONTAINED_BY = core.Node.prototype.DOCUMENT_POSITION_CONTAINED_BY = 0x10;83var DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = core.Node.prototype.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20;84var DOCUMENT_TYPE_NODE = core.Node.prototype.DOCUMENT_TYPE_NODE;8586core.Node.prototype.compareDocumentPosition = function compareDocumentPosition( otherNode ) {87if( !(otherNode instanceof core.Node) ) {88throw Error("Comparing position against non-Node values is not allowed")89}90var thisOwner, otherOwner;9192if( this.nodeType === this.DOCUMENT_NODE)93thisOwner = this94else95thisOwner = this.ownerDocument9697if( otherNode.nodeType === this.DOCUMENT_NODE)98otherOwner = otherNode99else100otherOwner = otherNode.ownerDocument101102if( this === otherNode ) return 0103if( this === otherNode.ownerDocument ) return DOCUMENT_POSITION_FOLLOWING + DOCUMENT_POSITION_CONTAINED_BY104if( this.ownerDocument === otherNode ) return DOCUMENT_POSITION_PRECEDING + DOCUMENT_POSITION_CONTAINS105if( thisOwner !== otherOwner ) return DOCUMENT_POSITION_DISCONNECTED106107// Text nodes for attributes does not have a _parentNode. So we need to find them as attribute child.108if( this.nodeType === this.ATTRIBUTE_NODE && this._childNodes && this._childNodes._toArray().indexOf(otherNode) !== -1)109return DOCUMENT_POSITION_FOLLOWING + DOCUMENT_POSITION_CONTAINED_BY110111if( otherNode.nodeType === this.ATTRIBUTE_NODE && otherNode._childNodes && otherNode._childNodes._toArray().indexOf(this) !== -1)112return DOCUMENT_POSITION_PRECEDING + DOCUMENT_POSITION_CONTAINS113114var point = this115var parents = [ ]116var previous = null117while( point ) {118if( point == otherNode ) return DOCUMENT_POSITION_PRECEDING + DOCUMENT_POSITION_CONTAINS119parents.push( point )120point = point._parentNode121}122point = otherNode123previous = null124while( point ) {125if( point == this ) return DOCUMENT_POSITION_FOLLOWING + DOCUMENT_POSITION_CONTAINED_BY126var location_index = parents.indexOf( point )127if( location_index !== -1) {128var smallest_common_ancestor = parents[ location_index ]129var this_index = smallest_common_ancestor._childNodes._toArray().indexOf( parents[location_index - 1] )130var other_index = smallest_common_ancestor._childNodes._toArray().indexOf( previous )131if( this_index > other_index ) {132return DOCUMENT_POSITION_PRECEDING133}134else {135return DOCUMENT_POSITION_FOLLOWING136}137}138previous = point139point = point._parentNode140}141return DOCUMENT_POSITION_DISCONNECTED142};143/*144// Introduced in DOM Level 3:145attribute DOMString textContent;146// raises(DOMException) on setting147// raises(DOMException) on retrieval148*/149core.Node.prototype.isSameNode = function(other) {150return (other === this);151};152153// @see http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Node3-textContent154defineGetter(core.Node.prototype, 'textContent', function() {155switch (this.nodeType) {156case this.COMMENT_NODE:157case this.CDATA_SECTION_NODE:158case this.PROCESSING_INSTRUCTION_NODE:159case this.TEXT_NODE:160return this.nodeValue;161162case this.ATTRIBUTE_NODE:163case this.DOCUMENT_FRAGMENT_NODE:164case this.ELEMENT_NODE:165case this.ENTITY_NODE:166case this.ENTITY_REFERENCE_NODE:167var out = '';168for (var i = 0 ; i < this.childNodes.length ; ++i) {169if (this.childNodes[i].nodeType !== this.COMMENT_NODE &&170this.childNodes[i].nodeType !== this.PROCESSING_INSTRUCTION_NODE) {171out += this.childNodes[i].textContent || '';172}173}174return out;175176default:177return null;178}179});180181defineSetter(core.Node.prototype, 'textContent', function(txt) {182for (var i = this.childNodes.length; --i >=0;) {183this.removeChild(this.childNodes.item(i));184}185if (txt !== "" && txt != null) {186this.appendChild(this._ownerDocument.createTextNode(txt));187}188return txt;189});190191/*192// Introduced in DOM Level 3:193DOMString lookupPrefix(in DOMString namespaceURI);194// Introduced in DOM Level 3:195boolean isDefaultNamespace(in DOMString namespaceURI);196// Introduced in DOM Level 3:197DOMString lookupNamespaceURI(in DOMString prefix);198*/199// Introduced in DOM Level 3:200core.Node.prototype.isEqualNode = function(other) {201var self = this;202var diffValues = function() {203for (var i=0;i<arguments.length;i++) {204var k = arguments[i];205if (self[k] != other[k]) return(true);206}207return(false);208};209var diffNamedNodeMaps = function(snnm, onnm) {210if ((snnm == null) && (onnm == null)) return(false);211if ((snnm == null) || (onnm == null)) return(true);212if (snnm.length != onnm.length) return(true);213var js = [];214for (var j=0;j<onnm.length;j++) { js[j] = j }215for (var i=0;i<snnm.length;i++) {216var found=false;217for (var j=0;j<js.length;j++) {218if (snnm.item(i).isEqualNode(onnm.item(js[j]))) {219found = true;220// in order to be 100% accurate, we remove index values from consideration once they've matched221js.splice(j,1);222break;223}224}225if (!found) return(true);226}227return(false);228};229var diffNodeLists = function(snl, onl) {230if ((snl == null) && (onl == null)) return(false);231if ((snl == null) || (onl == null)) return(true);232if (snl.length != onl.length) return(true);233for (var i=0;i<snl.length;i++) {234if (!snl.item(i).isEqualNode(onl.item(i))) return(true);235}236return(false);237};238if (!other) return(false);239if (this.isSameNode(other)) return(true);240if (this.nodeType != other.nodeType) return(false);241if (diffValues('nodeName', 'localName', 'namespaceURI', 'prefix', 'nodeValue')) return(false);242if (diffNamedNodeMaps(this.attributes, other.attributes)) return(false);243if (diffNodeLists(this.childNodes, other.childNodes)) return(false);244if (this.nodeType == DOCUMENT_TYPE_NODE) {245if (diffValues('publicId', 'systemId', 'internalSubset')) return(false);246if (diffNamedNodeMaps(this.entities, other.entities)) return(false);247if (diffNamedNodeMaps(this.notations, other.notations)) return(false);248}249return (true);250};251/*252// Introduced in DOM Level 3:253DOMObject getFeature(in DOMString feature,254in DOMString version);255*/256// Introduced in DOM Level 3:257core.Node.prototype.setUserData = function(key, data, handler) {258var r = this[key] || null;259this[key] = data;260return(r);261};262263// Introduced in DOM Level 3:264core.Node.prototype.getUserData = function(key) {265var r = this[key] || null;266return(r);267};268/*269interface NodeList {270Node item(in unsigned long index);271readonly attribute unsigned long length;272};273274interface NamedNodeMap {275Node getNamedItem(in DOMString name);276Node setNamedItem(in Node arg)277raises(DOMException);278Node removeNamedItem(in DOMString name)279raises(DOMException);280Node item(in unsigned long index);281readonly attribute unsigned long length;282// Introduced in DOM Level 2:283Node getNamedItemNS(in DOMString namespaceURI,284in DOMString localName)285raises(DOMException);286// Introduced in DOM Level 2:287Node setNamedItemNS(in Node arg)288raises(DOMException);289// Introduced in DOM Level 2:290Node removeNamedItemNS(in DOMString namespaceURI,291in DOMString localName)292raises(DOMException);293};294295interface CharacterData : Node {296attribute DOMString data;297// raises(DOMException) on setting298// raises(DOMException) on retrieval299300readonly attribute unsigned long length;301DOMString substringData(in unsigned long offset,302in unsigned long count)303raises(DOMException);304void appendData(in DOMString arg)305raises(DOMException);306void insertData(in unsigned long offset,307in DOMString arg)308raises(DOMException);309void deleteData(in unsigned long offset,310in unsigned long count)311raises(DOMException);312void replaceData(in unsigned long offset,313in unsigned long count,314in DOMString arg)315raises(DOMException);316};317318interface Attr : Node {319readonly attribute DOMString name;320readonly attribute boolean specified;321attribute DOMString value;322// raises(DOMException) on setting323324// Introduced in DOM Level 2:325readonly attribute Element ownerElement;326// Introduced in DOM Level 3:327readonly attribute TypeInfo schemaTypeInfo;328329*/330// Introduced in DOM Level 3:331defineGetter(core.Attr.prototype, 'isId', function() {332return (this.name.toLowerCase() === 'id');333});334/*335};336337interface Element : Node {338readonly attribute DOMString tagName;339DOMString getAttribute(in DOMString name);340void setAttribute(in DOMString name,341in DOMString value)342raises(DOMException);343void removeAttribute(in DOMString name)344raises(DOMException);345Attr getAttributeNode(in DOMString name);346Attr setAttributeNode(in Attr newAttr)347raises(DOMException);348Attr removeAttributeNode(in Attr oldAttr)349raises(DOMException);350NodeList getElementsByTagName(in DOMString name);351// Introduced in DOM Level 2:352DOMString getAttributeNS(in DOMString namespaceURI,353in DOMString localName)354raises(DOMException);355// Introduced in DOM Level 2:356void setAttributeNS(in DOMString namespaceURI,357in DOMString qualifiedName,358in DOMString value)359raises(DOMException);360// Introduced in DOM Level 2:361void removeAttributeNS(in DOMString namespaceURI,362in DOMString localName)363raises(DOMException);364// Introduced in DOM Level 2:365Attr getAttributeNodeNS(in DOMString namespaceURI,366in DOMString localName)367raises(DOMException);368// Introduced in DOM Level 2:369Attr setAttributeNodeNS(in Attr newAttr)370raises(DOMException);371// Introduced in DOM Level 2:372NodeList getElementsByTagNameNS(in DOMString namespaceURI,373in DOMString localName)374raises(DOMException);375// Introduced in DOM Level 2:376boolean hasAttribute(in DOMString name);377// Introduced in DOM Level 2:378boolean hasAttributeNS(in DOMString namespaceURI,379in DOMString localName)380raises(DOMException);381// Introduced in DOM Level 3:382readonly attribute TypeInfo schemaTypeInfo;383// Introduced in DOM Level 3:384void setIdAttribute(in DOMString name,385in boolean isId)386raises(DOMException);387// Introduced in DOM Level 3:388void setIdAttributeNS(in DOMString namespaceURI,389in DOMString localName,390in boolean isId)391raises(DOMException);392// Introduced in DOM Level 3:393void setIdAttributeNode(in Attr idAttr,394in boolean isId)395raises(DOMException);396};397398interface Text : CharacterData {399Text splitText(in unsigned long offset)400raises(DOMException);401// Introduced in DOM Level 3:402readonly attribute boolean isElementContentWhitespace;403// Introduced in DOM Level 3:404readonly attribute DOMString wholeText;405// Introduced in DOM Level 3:406Text replaceWholeText(in DOMString content)407raises(DOMException);408};409410interface Comment : CharacterData {411};412413// Introduced in DOM Level 3:414interface TypeInfo {415readonly attribute DOMString typeName;416readonly attribute DOMString typeNamespace;417418// DerivationMethods419const unsigned long DERIVATION_RESTRICTION = 0x00000001;420const unsigned long DERIVATION_EXTENSION = 0x00000002;421const unsigned long DERIVATION_UNION = 0x00000004;422const unsigned long DERIVATION_LIST = 0x00000008;423424boolean isDerivedFrom(in DOMString typeNamespaceArg,425in DOMString typeNameArg,426in unsigned long derivationMethod);427};428*/429// Introduced in DOM Level 3:430core.UserDataHandler = function() {};431core.UserDataHandler.prototype.NODE_CLONED = 1;432core.UserDataHandler.prototype.NODE_IMPORTED = 2;433core.UserDataHandler.prototype.NODE_DELETED = 3;434core.UserDataHandler.prototype.NODE_RENAMED = 4;435core.UserDataHandler.prototype.NODE_ADOPTED = 5;436core.UserDataHandler.prototype.handle = function(operation, key, data, src, dst) {};437438// Introduced in DOM Level 3:439core.DOMError = function(severity, message, type, relatedException, relatedData, location) {440this._severity = severity;441this._message = message;442this._type = type;443this._relatedException = relatedException;444this._relatedData = relatedData;445this._location = location;446};447core.DOMError.prototype = {};448core.DOMError.prototype.SEVERITY_WARNING = 1;449core.DOMError.prototype.SEVERITY_ERROR = 2;450core.DOMError.prototype.SEVERITY_FATAL_ERROR = 3;451defineGetter(core.DOMError.prototype, 'severity', function() {452return this._severity;453});454defineGetter(core.DOMError.prototype, 'message', function() {455return this._message;456});457defineGetter(core.DOMError.prototype, 'type', function() {458return this._type;459});460defineGetter(core.DOMError.prototype, 'relatedException', function() {461return this._relatedException;462});463defineGetter(core.DOMError.prototype, 'relatedData', function() {464return this._relatedData;465});466defineGetter(core.DOMError.prototype, 'location', function() {467return this._location;468});469470/*471// Introduced in DOM Level 3:472interface DOMErrorHandler {473boolean handleError(in DOMError error);474};475476// Introduced in DOM Level 3:477interface DOMLocator {478readonly attribute long lineNumber;479readonly attribute long columnNumber;480readonly attribute long byteOffset;481readonly attribute long utf16Offset;482readonly attribute Node relatedNode;483readonly attribute DOMString uri;484};485*/486487// Introduced in DOM Level 3:488core.DOMConfiguration = function(){489var possibleParameterNames = {490'canonical-form': [false, true], // extra rules for true491'cdata-sections': [true, false],492'check-character-normalization': [false, true],493'comments': [true, false],494'datatype-normalization': [false, true],495'element-content-whitespace': [true, false],496'entities': [true, false],497// 'error-handler': [],498'infoset': [undefined, true, false], // extra rules for true499'namespaces': [true, false],500'namespace-declarations': [true, false], // only checked if namespaces is true501'normalize-characters': [false, true],502// 'schema-location': [],503// 'schema-type': [],504'split-cdata-sections': [true, false],505'validate': [false, true],506'validate-if-schema': [false, true],507'well-formed': [true, false]508}509};510511core.DOMConfiguration.prototype = {512setParameter: function(name, value) {},513getParameter: function(name) {},514canSetParameter: function(name, value) {},515parameterNames: function() {}516};517518//core.Document.prototype._domConfig = new core.DOMConfiguration();519defineGetter(core.Document.prototype, 'domConfig', function() {520return this._domConfig || new core.DOMConfiguration();;521});522523// Introduced in DOM Level 3:524core.DOMStringList = function() {};525526core.DOMStringList.prototype = {527item: function() {},528length: function() {},529contains: function() {}530};531532533/*534interface CDATASection : Text {535};536537interface DocumentType : Node {538readonly attribute DOMString name;539readonly attribute NamedNodeMap entities;540readonly attribute NamedNodeMap notations;541// Introduced in DOM Level 2:542readonly attribute DOMString publicId;543// Introduced in DOM Level 2:544readonly attribute DOMString systemId;545// Introduced in DOM Level 2:546readonly attribute DOMString internalSubset;547};548549interface Notation : Node {550readonly attribute DOMString publicId;551readonly attribute DOMString systemId;552};553554interface Entity : Node {555readonly attribute DOMString publicId;556readonly attribute DOMString systemId;557readonly attribute DOMString notationName;558// Introduced in DOM Level 3:559readonly attribute DOMString inputEncoding;560// Introduced in DOM Level 3:561readonly attribute DOMString xmlEncoding;562// Introduced in DOM Level 3:563readonly attribute DOMString xmlVersion;564};565566interface EntityReference : Node {567};568569interface ProcessingInstruction : Node {570readonly attribute DOMString target;571attribute DOMString data;572// raises(DOMException) on setting573574};575576interface DocumentFragment : Node {577};578579interface Document : Node {580// Modified in DOM Level 3:581readonly attribute DocumentType doctype;582readonly attribute DOMImplementation implementation;583readonly attribute Element documentElement;584Element createElement(in DOMString tagName)585raises(DOMException);586DocumentFragment createDocumentFragment();587Text createTextNode(in DOMString data);588Comment createComment(in DOMString data);589CDATASection createCDATASection(in DOMString data)590raises(DOMException);591ProcessingInstruction createProcessingInstruction(in DOMString target,592in DOMString data)593raises(DOMException);594Attr createAttribute(in DOMString name)595raises(DOMException);596EntityReference createEntityReference(in DOMString name)597raises(DOMException);598NodeList getElementsByTagName(in DOMString tagname);599// Introduced in DOM Level 2:600Node importNode(in Node importedNode,601in boolean deep)602raises(DOMException);603// Introduced in DOM Level 2:604Element createElementNS(in DOMString namespaceURI,605in DOMString qualifiedName)606raises(DOMException);607// Introduced in DOM Level 2:608Attr createAttributeNS(in DOMString namespaceURI,609in DOMString qualifiedName)610raises(DOMException);611// Introduced in DOM Level 2:612NodeList getElementsByTagNameNS(in DOMString namespaceURI,613in DOMString localName);614// Introduced in DOM Level 2:615Element getElementById(in DOMString elementId);616*/617618// Introduced in DOM Level 3:619core.Document.prototype._inputEncoding = null;620defineGetter(core.Document.prototype, 'inputEncoding', function() {621return this._inputEncoding;622});623/*624// Introduced in DOM Level 3:625readonly attribute DOMString xmlEncoding;626// Introduced in DOM Level 3:627attribute boolean xmlStandalone;628// raises(DOMException) on setting629630// Introduced in DOM Level 3:631attribute DOMString xmlVersion;632// raises(DOMException) on setting633634// Introduced in DOM Level 3:635attribute boolean strictErrorChecking;636// Introduced in DOM Level 3:637attribute DOMString documentURI;638// Introduced in DOM Level 3:639Node adoptNode(in Node source)640raises(DOMException);641// Introduced in DOM Level 3:642readonly attribute DOMConfiguration domConfig;643// Introduced in DOM Level 3:644void normalizeDocument();645// Introduced in DOM Level 3:646Node renameNode(in Node n,647in DOMString namespaceURI,648in DOMString qualifiedName)649raises(DOMException);650};651};652653#endif // _DOM_IDL_654*/655656exports.dom = {657level3 : {658core: core659}660};661662663