Skip to content

Commit

Permalink
resolves #4. Thanks Aman.
Browse files Browse the repository at this point in the history
  • Loading branch information
thatcher committed Jan 16, 2009
1 parent 166de29 commit 8d34b82
Show file tree
Hide file tree
Showing 19 changed files with 226 additions and 280 deletions.
168 changes: 75 additions & 93 deletions dist/env.js

Large diffs are not rendered by default.

168 changes: 75 additions & 93 deletions dist/env.rhino.js

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions src/dom/attr.js
Expand Up @@ -19,20 +19,22 @@ var DOMAttr = function(ownerDocument) {
//$log("\tcreating dom attribute");
this.DOMNode = DOMNode;
this.DOMNode(ownerDocument);

this.name = ""; // the name of this attribute

this.specified = false;
this.value = ""; // the value of the attribute is returned as a string
this.nodeType = DOMNode.ATTRIBUTE_NODE;
this.ownerElement = null; // set when Attr is added to NamedNodeMap

//$log("\tfincished creating dom attribute " + this);
};
DOMAttr.prototype = new DOMNode;
__extend__(DOMAttr.prototype, {
// the name of this attribute
get name(){
return this.nodeName;
},
set name(name){
this.nodeName = name;
},
// the value of the attribute is returned as a string
get value(){
return this.nodeValue;
},
Expand All @@ -45,6 +47,9 @@ __extend__(DOMAttr.prototype, {
this.specified = (this.value.length > 0);
this.nodeValue = value;
},
get nodeType(){
return DOMNode.ATTRIBUTE_NODE;
},
get xml(){
return this.nodeName + "='" + this.nodeValue + "' ";
},
Expand Down
4 changes: 3 additions & 1 deletion src/dom/cdatasection.js
Expand Up @@ -20,10 +20,12 @@ var DOMCDATASection = function(ownerDocument) {
this.DOMText(ownerDocument);

this.nodeName = "#cdata-section";
this.nodeType = DOMNode.CDATA_SECTION_NODE;
};
DOMCDATASection.prototype = new DOMText;
__extend__(DOMCDATASection.prototype,{
get nodeType(){
return DOMNode.CDATA_SECTION_NODE;
},
get xml(){
return "<![CDATA[" + this.nodeValue + "]]>";
},
Expand Down
2 changes: 0 additions & 2 deletions src/dom/characterdata.js
Expand Up @@ -17,8 +17,6 @@ $w.__defineGetter__("CharacterData", function(){
var DOMCharacterData = function(ownerDocument) {
this.DOMNode = DOMNode;
this.DOMNode(ownerDocument);
this.data = "";
this.length = 0;
};
DOMCharacterData.prototype = new DOMNode;
__extend__(DOMCharacterData.prototype,{
Expand Down
4 changes: 3 additions & 1 deletion src/dom/comment.js
Expand Up @@ -19,10 +19,12 @@ var DOMComment = function(ownerDocument) {
this.DOMCharacterData(ownerDocument);

this.nodeName = "#comment";
this.nodeType = DOMNode.COMMENT_NODE;
};
DOMComment.prototype = new DOMCharacterData;
__extend__(DOMComment.prototype, {
get nodeType(){
return DOMNode.COMMENT_NODE;
},
get xml(){
return "<!-- " + this.nodeValue + " -->";
},
Expand Down
49 changes: 11 additions & 38 deletions src/dom/document.js
Expand Up @@ -29,7 +29,6 @@ var DOMDocument = function(implementation) {
//this.all = new Array(); // The list of all Elements

this.nodeName = "#document";
this.nodeType = DOMNode.DOCUMENT_NODE;
this._id = 0;
this._lastId = 0;
this._parseComplete = false; // initially false, set to true by parser
Expand Down Expand Up @@ -129,11 +128,6 @@ __extend__(DOMDocument.prototype, {

// assign values to properties (and aliases)
node.tagName = tagName;
node.nodeName = tagName;

// add Element to 'all' collection
//this.all[this.all.length] = node;
//$log("Document.all.length " + this.all.length);

return node;
},
Expand All @@ -149,10 +143,6 @@ __extend__(DOMDocument.prototype, {

// assign values to properties (and aliases)
node.data = data;
node.nodeValue = data;

// set initial length
node.length = data.length;

return node;
},
Expand All @@ -162,10 +152,6 @@ __extend__(DOMDocument.prototype, {

// assign values to properties (and aliases)
node.data = data;
node.nodeValue = data;

// set initial length
node.length = data.length;

return node;
},
Expand All @@ -175,10 +161,6 @@ __extend__(DOMDocument.prototype, {

// assign values to properties (and aliases)
node.data = data;
node.nodeValue = data;

// set initial length
node.length = data.length;

return node;
},
Expand All @@ -193,29 +175,23 @@ __extend__(DOMDocument.prototype, {

// assign values to properties (and aliases)
node.target = target;
node.nodeName = target;
node.data = data;
node.nodeValue = data;

// set initial length
node.length = data.length;

return node;
},
createAttribute : function(name) {
// throw Exception if the name string contains an illegal character
if (this.ownerDocument.implementation.errorChecking && (!__isValidName__(name))) {
// throw Exception if the name string contains an illegal character
if (this.ownerDocument.implementation.errorChecking && (!__isValidName__(name))) {
throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
}
}

// create DOMAttr specifying 'this' as ownerDocument
var node = new DOMAttr(this);
// create DOMAttr specifying 'this' as ownerDocument
var node = new DOMAttr(this);

// assign values to properties (and aliases)
node.name = name;
node.nodeName = name;
// assign values to properties (and aliases)
node.name = name;

return node;
return node;
},
createElementNS : function(namespaceURI, qualifiedName) {
//$log("DOMDocument.createElement( "+namespaceURI+", "+qualifiedName+" )");
Expand All @@ -237,15 +213,11 @@ __extend__(DOMDocument.prototype, {
var qname = __parseQName__(qualifiedName);

// assign values to properties (and aliases)
node.nodeName = qualifiedName;
node.namespaceURI = namespaceURI;
node.prefix = qname.prefix;
node.localName = qname.localName;
node.tagName = qualifiedName;

// add Element to 'all' collection
//this.all[this.all.length] = node;

return node;
},
createAttributeNS : function(namespaceURI, qualifiedName) {
Expand All @@ -267,7 +239,6 @@ __extend__(DOMDocument.prototype, {
var qname = __parseQName__(qualifiedName);

// assign values to properties (and aliases)
node.nodeName = qualifiedName;
node.namespaceURI = namespaceURI;
node.prefix = qname.prefix;
node.localName = qname.localName;
Expand All @@ -282,7 +253,6 @@ __extend__(DOMDocument.prototype, {
var qname = __parseQName__(qualifiedName);

// assign values to properties (and aliases)
node.nodeName = qualifiedName;
node.prefix = qname.prefix;
node.localName = qname.localName;
node.name = qualifiedName;
Expand Down Expand Up @@ -313,6 +283,9 @@ __extend__(DOMDocument.prototype, {
normalizeDocument: function(){
this.documentElement.normalize();
},
get nodeType(){
return DOMNode.DOCUMENT_NODE;
},
get xml(){
return this.documentElement.xml;
},
Expand Down
14 changes: 11 additions & 3 deletions src/dom/element.js
Expand Up @@ -19,14 +19,19 @@ $w.__defineGetter__("Element", function(){
var DOMElement = function(ownerDocument) {
//$log("\tcreating dom element");
this.DOMNode = DOMNode;
this.DOMNode(ownerDocument);
this.tagName = ""; // The name of the element.
this.DOMNode(ownerDocument);
this.id = ""; // the ID of the element
this.nodeType = DOMNode.ELEMENT_NODE;
//$log("\nfinished creating dom element " + this);
};
DOMElement.prototype = new DOMNode;
__extend__(DOMElement.prototype, {
// The name of the element.
get tagName(){
return this.nodeName;
},
set tagName(name){
this.nodeName = name;
},
addEventListener : function(){ window.addEventListener.apply(this, arguments) },
removeEventListener : function(){ window.removeEventListener.apply(this, arguments) },
dispatchEvent : function(){ window.dispatchEvent.apply(this, arguments) },
Expand Down Expand Up @@ -197,6 +202,9 @@ __extend__(DOMElement.prototype, {
// delegate to DOMNamedNodeMap._hasAttributeNS
return __hasAttributeNS__(this.attributes, namespaceURI, localName);
},
get nodeType(){
return DOMNode.ELEMENT_NODE;
},
get xml() {
var ret = "";

Expand Down
4 changes: 3 additions & 1 deletion src/dom/fragment.js
Expand Up @@ -18,10 +18,12 @@ var DOMDocumentFragment = function(ownerDocument) {
this.DOMNode = DOMNode;
this.DOMNode(ownerDocument);
this.nodeName = "#document-fragment";
this.nodeType = DOMNode.DOCUMENT_FRAGMENT_NODE;
};
DOMDocumentFragment.prototype = new DOMNode;
__extend__(DOMDocumentFragment.prototype,{
get nodeType(){
return DOMNode.DOCUMENT_FRAGMENT_NODE;
},
get xml(){
var xml = "",
count = this.childNodes.length;
Expand Down
30 changes: 14 additions & 16 deletions src/dom/implementation.js
Expand Up @@ -133,20 +133,20 @@ __extend__(DOMImplementation.prototype,{
* @return : DOMDocument
*/
function __parseLoop__(impl, doc, p) {
var iEvt, iNode, iAttr, strName;
iNodeParent = doc;

var el_close_count = 0;

var entitiesList = new Array();
var textNodesList = new Array();

// if namespaceAware, add default namespace
if (impl.namespaceAware) {
var iEvt, iNode, iAttr, strName;
iNodeParent = doc;
var el_close_count = 0;
var entitiesList = new Array();
var textNodesList = new Array();
// if namespaceAware, add default namespace
if (impl.namespaceAware) {
var iNS = doc.createNamespace(""); // add the default-default namespace
iNS.value = "http://www.w3.org/2000/xmlns/";
doc._namespaces.setNamedItem(iNS);
}
iNS.value = "http://www.w3.org/2000/xmlns/";
doc._namespaces.setNamedItem(iNS);
}

// loop until SAX parser stops emitting events
while(true) {
Expand Down Expand Up @@ -399,8 +399,6 @@ function __parseLoop__(impl, doc, p) {
else if(iEvt == XMLP._ERROR) {
$error("Fatal Error: " + p.getContent() + "\nLine: " + p.getLineNumber() + "\nColumn: " + p.getColumnNumber() + "\n");
throw(new DOMException(DOMException.SYNTAX_ERR));
// alert("Fatal Error: " + p.getContent() + "\nLine: " + p.getLineNumber() + "\nColumn: " + p.getColumnNumber() + "\n");
// break;
}
else if(iEvt == XMLP._NONE) { // no more events
if (iNodeParent == doc) { // confirm that we have recursed back up to root
Expand Down Expand Up @@ -563,4 +561,4 @@ function __parseQName__(qualifiedName) {
$log("Initializing document.implementation");
var $implementation = new DOMImplementation();
$implementation.namespaceAware = false;
$implementation.errorChecking = true;
$implementation.errorChecking = false;
13 changes: 6 additions & 7 deletions src/dom/instruction.js
Expand Up @@ -18,13 +18,6 @@ $w.__defineGetter__('ProcessingInstruction', function(){
var DOMProcessingInstruction = function(ownerDocument) {
this.DOMNode = DOMNode;
this.DOMNode(ownerDocument);
// The target of this processing instruction.
// XML defines this as being the first token following the markup that begins the processing instruction.
this.target = "";
// The content of this processing instruction.
// This is from the first non white space character after the target to the character immediately preceding the ?>
this.data = "";
this.nodeType = DOMNode.PROCESSING_INSTRUCTION_NODE;
};
DOMProcessingInstruction.prototype = new DOMNode;
__extend__(DOMProcessingInstruction.prototype, {
Expand All @@ -39,8 +32,14 @@ __extend__(DOMProcessingInstruction.prototype, {
this.nodeValue = data;
},
get target(){
// The target of this processing instruction.
// XML defines this as being the first token following the markup that begins the processing instruction.
// The content of this processing instruction.
return this.nodeName;
},
get nodeType(){
return DOMNode.PROCESSING_INSTRUCTION_NODE;
},
get xml(){
return "<?" + this.nodeName +" "+ this.nodeValue + " ?>";
},
Expand Down
8 changes: 4 additions & 4 deletions src/dom/namespace.js
Expand Up @@ -17,19 +17,19 @@ var DOMNamespace = function(ownerDocument) {
// If the user changes the value of the attribute (even if it ends up having the same value as the default value)
// then the specified flag is automatically flipped to true
this.specified = false;

this.value = ""; // the value of the attribute is returned as a string

this.nodeType = DOMNode.NAMESPACE_NODE;
};
DOMNamespace.prototype = new DOMNode;
__extend__(DOMNamespace.prototype, {
get value(){
// the value of the attribute is returned as a string
return this.nodeValue;
},
set value(value){
this.nodeValue = String(value);
},
get nodeType(){
return DOMNode.NAMESPACE_NODE;
},
get xml(){
var ret = "";

Expand Down
2 changes: 0 additions & 2 deletions src/dom/node.js
Expand Up @@ -36,7 +36,6 @@ var DOMNode = function(ownerDocument) {

this.nodeName = ""; // The name of this node
this.nodeValue = ""; // The value of this node
this.nodeType = 0; // A code representing the type of the underlying object

// The parent of this node. All nodes, except Document, DocumentFragment, and Attr may have a parent.
// However, if a node has just been created and not yet added to the tree, or if it has been removed from the tree, this is null
Expand All @@ -58,7 +57,6 @@ var DOMNode = function(ownerDocument) {
this._namespaces = new DOMNamespaceNodeMap(ownerDocument, this); // The namespaces in scope for this node

this._readonly = false;
//$log("\tfinished creating dom node");
};

// nodeType constants
Expand Down
2 changes: 1 addition & 1 deletion src/dom/nodelist.js
Expand Up @@ -19,7 +19,7 @@ $w.__defineGetter__('NodeList', function(){
*/
var DOMNodeList = function(ownerDocument, parentNode) {
//$log("\t\tcreating dom nodelist");
var nodes = new Array();
var nodes = [];

this.length = 0;
this.parentNode = parentNode;
Expand Down

0 comments on commit 8d34b82

Please sign in to comment.